Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 1 | # CMakeLists.txt for building mcuboot as a Zephyr project |
| 2 | # |
| 3 | # Copyright (c) 2017 Open Source Foundries Limited |
| 4 | # |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | |
| 7 | cmake_minimum_required(VERSION 3.8.2) |
| 8 | |
Sigvart Hovland | ebd0503 | 2019-03-21 10:47:32 +0100 | [diff] [blame] | 9 | # Board-specific CONF_FILES should get merged into the build as well. |
Sebastian Bøe | b94bda0 | 2019-01-22 12:33:18 +0100 | [diff] [blame] | 10 | # Default to qemu_x86 if no board has been specified. |
| 11 | set(BOARD qemu_x86) |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 12 | |
Marti Bolivar | 58b321a | 2018-03-20 15:52:47 -0400 | [diff] [blame] | 13 | # Add a common dts overlay necessary to ensure mcuboot is linked into, |
| 14 | # and fits inside, the boot partition. (If the user specified a |
| 15 | # DTC_OVERLAY_FILE on the CMake command line, we need to append onto |
| 16 | # the list). |
| 17 | if(DTC_OVERLAY_FILE) |
| 18 | set(DTC_OVERLAY_FILE |
Sebastian Bøe | ea49cd0 | 2019-04-03 15:14:37 +0200 | [diff] [blame^] | 19 | "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/dts.overlay" |
| 20 | CACHE STRING "" FORCE |
| 21 | ) |
Marti Bolivar | 58b321a | 2018-03-20 15:52:47 -0400 | [diff] [blame] | 22 | else() |
| 23 | set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/dts.overlay) |
| 24 | endif() |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 25 | |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 26 | if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay) |
| 27 | set(DTC_OVERLAY_FILE |
Sebastian Bøe | ea49cd0 | 2019-04-03 15:14:37 +0200 | [diff] [blame^] | 28 | "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay" |
| 29 | CACHE STRING "" FORCE |
| 30 | ) |
Rajavardhan Gundi | 40c28e3 | 2018-12-09 13:32:01 +0530 | [diff] [blame] | 31 | endif() |
| 32 | |
Marti Bolivar | aefbd46 | 2017-12-15 03:43:46 -0500 | [diff] [blame] | 33 | # Enable Zephyr runner options which request mass erase if so |
| 34 | # configured. |
| 35 | # |
| 36 | # Note that this also disables the default "leave" option when |
| 37 | # targeting STM32 DfuSe devices with dfu-util, making the chip stay in |
| 38 | # the bootloader after flashing. |
| 39 | # |
| 40 | # That's the right thing, because mcuboot has nothing to do since the |
| 41 | # chip was just erased. The next thing the user is going to want to do |
| 42 | # is flash the application. (Developers can reset DfuSE devices |
| 43 | # manually to test mcuboot behavior on an otherwise erased flash |
| 44 | # device.) |
| 45 | macro(app_set_runner_args) |
Marti Bolivar | 53e2c26 | 2018-04-12 14:13:28 -0400 | [diff] [blame] | 46 | if(CONFIG_ZEPHYR_TRY_MASS_ERASE) |
Marti Bolivar | aefbd46 | 2017-12-15 03:43:46 -0500 | [diff] [blame] | 47 | board_runner_args(dfu-util "--dfuse-modifiers=force:mass-erase") |
Maureen Helm | 4df602a | 2019-02-18 17:26:39 -0600 | [diff] [blame] | 48 | board_runner_args(pyocd "--flash-opt=-e=chip") |
Marti Bolivar | 23e3853 | 2018-03-26 13:14:22 -0400 | [diff] [blame] | 49 | board_runner_args(nrfjprog "--erase") |
Marti Bolivar | aefbd46 | 2017-12-15 03:43:46 -0500 | [diff] [blame] | 50 | endif() |
| 51 | endmacro() |
| 52 | |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 53 | # Standard Zephyr application boilerplate: |
| 54 | # http://docs.zephyrproject.org/application/application.html |
| 55 | include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) |
| 56 | project(NONE) |
| 57 | |
| 58 | # Path to "boot" subdirectory of repository root. |
| 59 | get_filename_component(BOOT_DIR ${APPLICATION_SOURCE_DIR} DIRECTORY) |
| 60 | # Path to top-level repository root directory. |
| 61 | get_filename_component(MCUBOOT_DIR ${BOOT_DIR} DIRECTORY) |
| 62 | # Path to tinycrypt library source subdirectory of MCUBOOT_DIR. |
| 63 | set(TINYCRYPT_DIR "${MCUBOOT_DIR}/ext/tinycrypt/lib") |
Sigvart Hovland | ebd0503 | 2019-03-21 10:47:32 +0100 | [diff] [blame] | 64 | assert_exists(TINYCRYPT_DIR) |
Fabio Utzig | 28ee5b0 | 2017-12-12 08:10:40 -0200 | [diff] [blame] | 65 | # Path to mbed-tls' asn1 parser library. |
| 66 | set(MBEDTLS_ASN1_DIR "${MCUBOOT_DIR}/ext/mbedtls") |
Sigvart Hovland | ebd0503 | 2019-03-21 10:47:32 +0100 | [diff] [blame] | 67 | assert_exists(MBEDTLS_ASN1_DIR) |
| 68 | set(NRF_DIR "${MCUBOOT_DIR}/ext/nrf") |
| 69 | |
| 70 | if(CONFIG_BOOT_USE_NRF_CC310_BL) |
| 71 | set(NRFXLIB_DIR ${MCUBOOT_DIR}/../nrfxlib) |
| 72 | assert_exists(NRFXLIB_DIR) |
| 73 | # Don't include this if we are using west |
| 74 | add_subdirectory(${NRFXLIB_DIR} ${PROJECT_BINARY_DIR}/nrfxlib) |
| 75 | endif() |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 76 | |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 77 | zephyr_library_include_directories( |
| 78 | include |
| 79 | targets |
| 80 | ) |
| 81 | if(EXISTS targets/${BOARD}.h) |
| 82 | zephyr_library_compile_definitions(MCUBOOT_TARGET_CONFIG="${BOARD}.h") |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 83 | endif() |
| 84 | |
| 85 | # Zephyr port-specific sources. |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 86 | zephyr_library_sources( |
| 87 | main.c |
| 88 | flash_map_extended.c |
| 89 | os.c |
| 90 | keys.c |
| 91 | ) |
| 92 | |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 93 | if(NOT DEFINED CONFIG_FLASH_PAGE_LAYOUT) |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 94 | zephyr_library_sources( |
| 95 | flash_map_legacy.c |
| 96 | ) |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 97 | endif() |
| 98 | |
| 99 | # Generic bootutil sources and includes. |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 100 | zephyr_library_include_directories(${BOOT_DIR}/bootutil/include) |
| 101 | zephyr_library_sources( |
| 102 | ${BOOT_DIR}/bootutil/src/loader.c |
| 103 | ${BOOT_DIR}/bootutil/src/bootutil_misc.c |
| 104 | ${BOOT_DIR}/bootutil/src/image_validate.c |
| 105 | ${BOOT_DIR}/bootutil/src/encrypted.c |
| 106 | ${BOOT_DIR}/bootutil/src/image_rsa.c |
| 107 | ${BOOT_DIR}/bootutil/src/image_ec256.c |
| 108 | ${BOOT_DIR}/bootutil/src/caps.c |
| 109 | ) |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 110 | |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 111 | if(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256) |
Sigvart Hovland | ebd0503 | 2019-03-21 10:47:32 +0100 | [diff] [blame] | 112 | zephyr_library_include_directories( |
| 113 | ${MBEDTLS_ASN1_DIR}/include |
| 114 | ) |
| 115 | zephyr_library_sources( |
| 116 | # Additionally pull in just the ASN.1 parser from mbedTLS. |
| 117 | ${MBEDTLS_ASN1_DIR}/src/asn1parse.c |
| 118 | ${MBEDTLS_ASN1_DIR}/src/platform_util.c |
| 119 | ) |
| 120 | if(CONFIG_BOOT_USE_TINYCRYPT) |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 121 | # When using ECDSA signatures, pull in our copy of the tinycrypt library. |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 122 | zephyr_library_include_directories( |
| 123 | ${BOOT_DIR}/zephyr/include |
| 124 | ${TINYCRYPT_DIR}/include |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 125 | ) |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 126 | |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 127 | zephyr_library_sources( |
| 128 | ${TINYCRYPT_DIR}/source/ecc.c |
| 129 | ${TINYCRYPT_DIR}/source/ecc_dsa.c |
| 130 | ${TINYCRYPT_DIR}/source/sha256.c |
| 131 | ${TINYCRYPT_DIR}/source/utils.c |
Sigvart Hovland | ebd0503 | 2019-03-21 10:47:32 +0100 | [diff] [blame] | 132 | ) |
| 133 | elseif(CONFIG_BOOT_USE_NRF_CC310_BL) |
| 134 | zephyr_library_sources(${NRF_DIR}/cc310_glue.c) |
| 135 | zephyr_library_include_directories(${NRF_DIR}) |
| 136 | zephyr_link_libraries(nrfxlib_crypto) |
| 137 | endif() |
Fabio Utzig | 28ee5b0 | 2017-12-12 08:10:40 -0200 | [diff] [blame] | 138 | |
Ding Tao | f97cb71 | 2018-06-08 14:37:13 +0000 | [diff] [blame] | 139 | # Since here we are not using Zephyr's mbedTLS but rather our own, we need |
Carles Cufi | 69c61d0 | 2018-06-05 15:56:08 +0200 | [diff] [blame] | 140 | # to set MBEDTLS_CONFIG_FILE ourselves. When using Zephyr's copy, this |
| 141 | # variable is set by its Kconfig in the Zephyr codebase. |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 142 | zephyr_library_compile_definitions( |
| 143 | MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/include/mcuboot-mbedtls-cfg.h" |
| 144 | ) |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 145 | elseif(CONFIG_BOOT_SIGNATURE_TYPE_RSA) |
| 146 | # Use mbedTLS provided by Zephyr for RSA signatures. (Its config file |
| 147 | # is set using Kconfig.) |
| 148 | zephyr_include_directories(include) |
Marti Bolivar | bf909a1 | 2017-11-13 19:43:46 -0500 | [diff] [blame] | 149 | endif() |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 150 | |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 151 | if(CONFIG_MCUBOOT_SERIAL) |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 152 | zephyr_sources(${BOOT_DIR}/zephyr/serial_adapter.c) |
| 153 | zephyr_sources(${BOOT_DIR}/boot_serial/src/boot_serial.c) |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 154 | |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 155 | zephyr_include_directories(${BOOT_DIR}/bootutil/include) |
| 156 | zephyr_include_directories(${BOOT_DIR}/boot_serial/include) |
| 157 | zephyr_include_directories(include) |
Andrzej Puzdrowski | c2e30cf | 2018-07-20 16:19:09 +0200 | [diff] [blame] | 158 | |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 159 | zephyr_link_libraries_ifdef( |
| 160 | CONFIG_TINYCBOR |
| 161 | TINYCBOR |
| 162 | ) |
| 163 | |
| 164 | zephyr_include_directories_ifdef( |
| 165 | CONFIG_BOOT_ERASE_PROGRESSIVELY |
| 166 | ${BOOT_DIR}/bootutil/src |
| 167 | ) |
Andrzej Puzdrowski | 8e96b83 | 2017-09-08 16:49:14 +0200 | [diff] [blame] | 168 | endif() |
Fabio Utzig | b1e0dc5 | 2018-04-26 10:53:19 -0300 | [diff] [blame] | 169 | |
| 170 | if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "") |
| 171 | if(IS_ABSOLUTE ${CONFIG_BOOT_SIGNATURE_KEY_FILE}) |
| 172 | set(KEY_FILE ${CONFIG_BOOT_SIGNATURE_KEY_FILE}) |
| 173 | else() |
| 174 | set(KEY_FILE ${MCUBOOT_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}) |
| 175 | endif() |
| 176 | set(GENERATED_PUBKEY ${ZEPHYR_BINARY_DIR}/autogen-pubkey.c) |
| 177 | add_custom_command( |
| 178 | OUTPUT ${GENERATED_PUBKEY} |
| 179 | COMMAND |
| 180 | ${PYTHON_EXECUTABLE} |
| 181 | ${MCUBOOT_DIR}/scripts/imgtool.py |
| 182 | getpub |
| 183 | -k |
| 184 | ${KEY_FILE} |
| 185 | > ${GENERATED_PUBKEY} |
| 186 | DEPENDS ${KEY_FILE} |
| 187 | ) |
Sebastian Bøe | be97217 | 2019-01-22 14:05:14 +0100 | [diff] [blame] | 188 | zephyr_library_sources(${GENERATED_PUBKEY}) |
Fabio Utzig | b1e0dc5 | 2018-04-26 10:53:19 -0300 | [diff] [blame] | 189 | endif() |
Sigvart Hovland | ebd0503 | 2019-03-21 10:47:32 +0100 | [diff] [blame] | 190 | |