blob: fa7b03b44123fd5c794da87f516e1c19e1e83832 [file] [log] [blame]
Marti Bolivarbf909a12017-11-13 19:43:46 -05001# 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
7cmake_minimum_required(VERSION 3.8.2)
8
Sigvart Hovlandebd05032019-03-21 10:47:32 +01009# Board-specific CONF_FILES should get merged into the build as well.
Sebastian Bøeb94bda02019-01-22 12:33:18 +010010# Default to qemu_x86 if no board has been specified.
11set(BOARD qemu_x86)
Marti Bolivarbf909a12017-11-13 19:43:46 -050012
Marti Bolivar58b321a2018-03-20 15:52:47 -040013# 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).
17if(DTC_OVERLAY_FILE)
18 set(DTC_OVERLAY_FILE
19 "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/dts.overlay")
20else()
21 set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/dts.overlay)
22endif()
Marti Bolivarbf909a12017-11-13 19:43:46 -050023
Rajavardhan Gundi40c28e32018-12-09 13:32:01 +053024if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay)
25 set(DTC_OVERLAY_FILE
26 "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}.overlay")
27endif()
28
Marti Bolivaraefbd462017-12-15 03:43:46 -050029# 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.)
41macro(app_set_runner_args)
Marti Bolivar53e2c262018-04-12 14:13:28 -040042 if(CONFIG_ZEPHYR_TRY_MASS_ERASE)
Marti Bolivaraefbd462017-12-15 03:43:46 -050043 board_runner_args(dfu-util "--dfuse-modifiers=force:mass-erase")
Maureen Helm4df602a2019-02-18 17:26:39 -060044 board_runner_args(pyocd "--flash-opt=-e=chip")
Marti Bolivar23e38532018-03-26 13:14:22 -040045 board_runner_args(nrfjprog "--erase")
Marti Bolivaraefbd462017-12-15 03:43:46 -050046 endif()
47endmacro()
48
Marti Bolivarbf909a12017-11-13 19:43:46 -050049# Standard Zephyr application boilerplate:
50# http://docs.zephyrproject.org/application/application.html
51include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
52project(NONE)
53
54# Path to "boot" subdirectory of repository root.
55get_filename_component(BOOT_DIR ${APPLICATION_SOURCE_DIR} DIRECTORY)
56# Path to top-level repository root directory.
57get_filename_component(MCUBOOT_DIR ${BOOT_DIR} DIRECTORY)
58# Path to tinycrypt library source subdirectory of MCUBOOT_DIR.
59set(TINYCRYPT_DIR "${MCUBOOT_DIR}/ext/tinycrypt/lib")
Sigvart Hovlandebd05032019-03-21 10:47:32 +010060assert_exists(TINYCRYPT_DIR)
Fabio Utzig28ee5b02017-12-12 08:10:40 -020061# Path to mbed-tls' asn1 parser library.
62set(MBEDTLS_ASN1_DIR "${MCUBOOT_DIR}/ext/mbedtls")
Sigvart Hovlandebd05032019-03-21 10:47:32 +010063assert_exists(MBEDTLS_ASN1_DIR)
64set(NRF_DIR "${MCUBOOT_DIR}/ext/nrf")
65
66if(CONFIG_BOOT_USE_NRF_CC310_BL)
67set(NRFXLIB_DIR ${MCUBOOT_DIR}/../nrfxlib)
68assert_exists(NRFXLIB_DIR)
69# Don't include this if we are using west
70 add_subdirectory(${NRFXLIB_DIR} ${PROJECT_BINARY_DIR}/nrfxlib)
71endif()
Marti Bolivarbf909a12017-11-13 19:43:46 -050072
Sebastian Bøebe972172019-01-22 14:05:14 +010073zephyr_library_include_directories(
74 include
75 targets
76 )
77if(EXISTS targets/${BOARD}.h)
78 zephyr_library_compile_definitions(MCUBOOT_TARGET_CONFIG="${BOARD}.h")
Marti Bolivarbf909a12017-11-13 19:43:46 -050079endif()
80
81# Zephyr port-specific sources.
Sebastian Bøebe972172019-01-22 14:05:14 +010082zephyr_library_sources(
83 main.c
84 flash_map_extended.c
85 os.c
86 keys.c
87 )
88
Marti Bolivarbf909a12017-11-13 19:43:46 -050089if(NOT DEFINED CONFIG_FLASH_PAGE_LAYOUT)
Sebastian Bøebe972172019-01-22 14:05:14 +010090 zephyr_library_sources(
91 flash_map_legacy.c
92 )
Marti Bolivarbf909a12017-11-13 19:43:46 -050093endif()
94
95# Generic bootutil sources and includes.
Sebastian Bøebe972172019-01-22 14:05:14 +010096zephyr_library_include_directories(${BOOT_DIR}/bootutil/include)
97zephyr_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 Bolivarbf909a12017-11-13 19:43:46 -0500106
Marti Bolivara4818a52018-04-12 13:02:38 -0400107if(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256)
Sigvart Hovlandebd05032019-03-21 10:47:32 +0100108 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 Bolivara4818a52018-04-12 13:02:38 -0400117 # When using ECDSA signatures, pull in our copy of the tinycrypt library.
Sebastian Bøebe972172019-01-22 14:05:14 +0100118 zephyr_library_include_directories(
119 ${BOOT_DIR}/zephyr/include
120 ${TINYCRYPT_DIR}/include
Sebastian Bøebe972172019-01-22 14:05:14 +0100121 )
Marti Bolivarbf909a12017-11-13 19:43:46 -0500122
Sebastian Bøebe972172019-01-22 14:05:14 +0100123 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 Hovlandebd05032019-03-21 10:47:32 +0100128 )
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 Utzig28ee5b02017-12-12 08:10:40 -0200134
Ding Taof97cb712018-06-08 14:37:13 +0000135 # Since here we are not using Zephyr's mbedTLS but rather our own, we need
Carles Cufi69c61d02018-06-05 15:56:08 +0200136 # 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øebe972172019-01-22 14:05:14 +0100138 zephyr_library_compile_definitions(
139 MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/include/mcuboot-mbedtls-cfg.h"
140 )
Marti Bolivara4818a52018-04-12 13:02:38 -0400141elseif(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 Bolivarbf909a12017-11-13 19:43:46 -0500145endif()
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200146
Sebastian Bøebe972172019-01-22 14:05:14 +0100147if(CONFIG_MCUBOOT_SERIAL)
Andrzej Puzdrowskic2e30cf2018-07-20 16:19:09 +0200148 zephyr_sources(${BOOT_DIR}/zephyr/serial_adapter.c)
149 zephyr_sources(${BOOT_DIR}/boot_serial/src/boot_serial.c)
Andrzej Puzdrowski8e96b832017-09-08 16:49:14 +0200150
Andrzej Puzdrowskic2e30cf2018-07-20 16:19:09 +0200151 zephyr_include_directories(${BOOT_DIR}/bootutil/include)
152 zephyr_include_directories(${BOOT_DIR}/boot_serial/include)
153 zephyr_include_directories(include)
Andrzej Puzdrowskic2e30cf2018-07-20 16:19:09 +0200154
Sebastian Bøebe972172019-01-22 14:05:14 +0100155 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 Puzdrowski8e96b832017-09-08 16:49:14 +0200164endif()
Fabio Utzigb1e0dc52018-04-26 10:53:19 -0300165
166if(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øebe972172019-01-22 14:05:14 +0100184 zephyr_library_sources(${GENERATED_PUBKEY})
Fabio Utzigb1e0dc52018-04-26 10:53:19 -0300185endif()
Sigvart Hovlandebd05032019-03-21 10:47:32 +0100186