Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 1 | # SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD |
| 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 5 | cmake_minimum_required(VERSION 3.13) |
| 6 | |
| 7 | project(hal) |
| 8 | |
| 9 | set(esp_idf_dir ${IDF_PATH}) |
| 10 | |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 11 | set(src_dir ${CMAKE_CURRENT_LIST_DIR}/src) |
| 12 | set(include_dirs |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 13 | ${CMAKE_CURRENT_LIST_DIR}/include |
Almir Okato | d532029 | 2021-06-18 02:00:40 -0300 | [diff] [blame] | 14 | ${CMAKE_CURRENT_LIST_DIR}/include/${MCUBOOT_TARGET} |
| 15 | ) |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 16 | |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 17 | list(APPEND include_dirs |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 18 | ${esp_idf_dir}/components/${MCUBOOT_ARCH}/include |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 19 | ${esp_idf_dir}/components/esp_common/include |
| 20 | ${esp_idf_dir}/components/esp_rom/include |
Almir Okato | d532029 | 2021-06-18 02:00:40 -0300 | [diff] [blame] | 21 | ${esp_idf_dir}/components/esp_rom/include/${MCUBOOT_TARGET} |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 22 | ${esp_idf_dir}/components/spi_flash/include |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 23 | ${esp_idf_dir}/components/spi_flash/include/spi_flash |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 24 | ${esp_idf_dir}/components/soc/include |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 25 | ${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/include |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 26 | ${esp_idf_dir}/components/esp_hw_support/include |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 27 | ${esp_idf_dir}/components/esp_hw_support/include/soc |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 28 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET} |
| 29 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/private_include |
| 30 | ${esp_idf_dir}/components/bootloader_support/include |
| 31 | ${esp_idf_dir}/components/bootloader_support/include_bootloader |
| 32 | ${esp_idf_dir}/components/hal/include |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 33 | ${esp_idf_dir}/components/hal/platform_port/include |
| 34 | ${esp_idf_dir}/components/hal/${MCUBOOT_TARGET}/include |
| 35 | ${esp_idf_dir}/components/hal/${MCUBOOT_TARGET}/include/hal |
| 36 | ${esp_idf_dir}/components/heap/include |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 37 | ${esp_idf_dir}/components/efuse/include |
| 38 | ${esp_idf_dir}/components/efuse/${MCUBOOT_TARGET}/include |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 39 | ${esp_idf_dir}/components/newlib/platform_include |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 40 | ) |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 41 | |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 42 | if("${MCUBOOT_TARGET}" STREQUAL "esp32") |
| 43 | list(APPEND include_dirs |
| 44 | ${esp_idf_dir}/components/${MCUBOOT_TARGET}/include |
| 45 | ) |
| 46 | endif() |
| 47 | |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 48 | if("${MCUBOOT_ARCH}" STREQUAL "xtensa") |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 49 | list(APPEND include_dirs |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 50 | ${esp_idf_dir}/components/${MCUBOOT_ARCH}/${MCUBOOT_TARGET}/include |
| 51 | ) |
| 52 | endif() |
| 53 | |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 54 | set(hal_srcs |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 55 | ${src_dir}/bootloader_wdt.c |
| 56 | ${src_dir}/${MCUBOOT_TARGET}/bootloader_init.c |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 57 | ${esp_idf_dir}/components/hal/mpu_hal.c |
| 58 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_flash.c |
| 59 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_flash_config_${MCUBOOT_TARGET}.c |
| 60 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_clock_init.c |
| 61 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_efuse_${MCUBOOT_TARGET}.c |
| 62 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_panic.c |
| 63 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_mem.c |
| 64 | ${esp_idf_dir}/components/spi_flash/${MCUBOOT_TARGET}/spi_flash_rom_patch.c |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 65 | ${esp_idf_dir}/components/esp_hw_support/esp_clk.c |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 66 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c |
| 67 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_time.c |
| 68 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk.c |
| 69 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk_init.c |
| 70 | ${esp_idf_dir}/components/hal/wdt_hal_iram.c |
| 71 | ${esp_idf_dir}/components/esp_hw_support/cpu_util.c |
| 72 | ${esp_idf_dir}/components/esp_rom/patches/esp_rom_uart.c |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 73 | ${esp_idf_dir}/components/esp_rom/patches/esp_rom_sys.c |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 74 | ) |
| 75 | |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 76 | if("${MCUBOOT_ARCH}" STREQUAL "xtensa") |
| 77 | list(APPEND hal_srcs |
| 78 | ${esp_idf_dir}/components/esp_rom/patches/esp_rom_longjmp.S |
| 79 | ) |
| 80 | endif() |
| 81 | |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 82 | set(CFLAGS |
| 83 | "-nostdlib" |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 84 | "-Wno-frame-address" |
| 85 | "-Wall" |
| 86 | "-Wextra" |
| 87 | "-W" |
| 88 | "-Wwrite-strings" |
| 89 | "-Wlogical-op" |
| 90 | "-Wshadow" |
| 91 | "-ffunction-sections" |
| 92 | "-fdata-sections" |
| 93 | "-fstrict-volatile-bitfields" |
| 94 | "-Werror=all" |
| 95 | "-Wno-error=unused-function" |
| 96 | "-Wno-error=unused-but-set-variable" |
| 97 | "-Wno-error=unused-variable" |
| 98 | "-Wno-error=deprecated-declarations" |
| 99 | "-Wno-unused-parameter" |
| 100 | "-Wno-sign-compare" |
| 101 | "-ggdb" |
| 102 | "-Os" |
| 103 | "-D_GNU_SOURCE" |
| 104 | "-std=gnu99" |
| 105 | "-Wno-old-style-declaration" |
| 106 | "-Wno-implicit-int" |
| 107 | ) |
| 108 | |
| 109 | set(LDFLAGS |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 110 | "-Wno-frame-address" |
| 111 | "-Wl,--cref" |
| 112 | "-Wl,--Map=${APP_NAME}.map" |
| 113 | "-fno-rtti" |
| 114 | "-fno-lto" |
| 115 | "-Wl,--gc-sections" |
| 116 | "-Wl,--undefined=uxTopUsedPriority" |
| 117 | "-lm" |
| 118 | "-lgcc" |
| 119 | "-lgcov" |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 120 | ) |
| 121 | |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 122 | if("${MCUBOOT_ARCH}" STREQUAL "xtensa") |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 123 | list(APPEND CFLAGS |
| 124 | "-mlongcalls" |
| 125 | ) |
| 126 | list(APPEND LDFLAGS |
| 127 | "-mlongcalls" |
| 128 | ) |
| 129 | endif() |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 130 | |
| 131 | set_source_files_properties( |
| 132 | ${esp_idf_dir}/components/bootloader_support/src/bootloader_flash.c |
| 133 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk_init.c |
Almir Okato | d532029 | 2021-06-18 02:00:40 -0300 | [diff] [blame] | 134 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 135 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk.c |
| 136 | ${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_time.c |
| 137 | PROPERTIES COMPILE_FLAGS |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 138 | "-Wno-unused-variable" |
| 139 | ) |
| 140 | |
| 141 | set(LINKER_SCRIPTS |
| 142 | -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.ld |
| 143 | -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.libgcc.ld |
| 144 | -T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.api.ld |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 145 | -T${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.peripherals.ld |
Almir Okato | 712fdb5 | 2021-08-06 10:22:56 -0300 | [diff] [blame] | 146 | ) |
| 147 | |
| 148 | include(${CMAKE_CURRENT_LIST_DIR}/include/${MCUBOOT_TARGET}/${MCUBOOT_TARGET}.cmake) |
| 149 | |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 150 | add_library(hal STATIC ${hal_srcs} ${include_dirs}) |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 151 | |
| 152 | target_include_directories( |
| 153 | hal |
| 154 | PUBLIC |
Gustavo Henrique Nihei | 6a6b891 | 2021-11-12 11:43:10 -0300 | [diff] [blame^] | 155 | ${include_dirs} |
Shubham Kulkarni | c75b3c7 | 2021-07-20 11:43:28 +0530 | [diff] [blame] | 156 | ) |
| 157 | |
| 158 | target_compile_options( |
| 159 | hal |
| 160 | PUBLIC |
| 161 | ${CFLAGS} |
| 162 | ) |
| 163 | |
Almir Okato | d532029 | 2021-06-18 02:00:40 -0300 | [diff] [blame] | 164 | target_link_libraries( |
| 165 | hal |
| 166 | PUBLIC |
| 167 | ${LDFLAGS} |
| 168 | ${LINKER_SCRIPTS} |
| 169 | ) |