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