2017-11-14 08:43:46 +08:00
|
|
|
# CMakeLists.txt for building mcuboot as a Zephyr project
|
|
|
|
#
|
|
|
|
# Copyright (c) 2017 Open Source Foundries Limited
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2019-10-23 04:39:33 +08:00
|
|
|
cmake_minimum_required(VERSION 3.13.1)
|
2018-12-09 16:02:01 +08:00
|
|
|
|
2017-12-15 16:43:46 +08:00
|
|
|
# Enable Zephyr runner options which request mass erase if so
|
|
|
|
# configured.
|
|
|
|
#
|
|
|
|
# Note that this also disables the default "leave" option when
|
|
|
|
# targeting STM32 DfuSe devices with dfu-util, making the chip stay in
|
|
|
|
# the bootloader after flashing.
|
|
|
|
#
|
|
|
|
# That's the right thing, because mcuboot has nothing to do since the
|
|
|
|
# chip was just erased. The next thing the user is going to want to do
|
|
|
|
# is flash the application. (Developers can reset DfuSE devices
|
|
|
|
# manually to test mcuboot behavior on an otherwise erased flash
|
|
|
|
# device.)
|
|
|
|
macro(app_set_runner_args)
|
2018-04-13 02:13:28 +08:00
|
|
|
if(CONFIG_ZEPHYR_TRY_MASS_ERASE)
|
2017-12-15 16:43:46 +08:00
|
|
|
board_runner_args(dfu-util "--dfuse-modifiers=force:mass-erase")
|
2019-02-19 07:26:39 +08:00
|
|
|
board_runner_args(pyocd "--flash-opt=-e=chip")
|
2018-03-27 01:14:22 +08:00
|
|
|
board_runner_args(nrfjprog "--erase")
|
2017-12-15 16:43:46 +08:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2020-05-28 18:34:15 +08:00
|
|
|
# find_package(Zephyr) in order to load application boilerplate:
|
2017-11-14 08:43:46 +08:00
|
|
|
# http://docs.zephyrproject.org/application/application.html
|
2020-05-28 18:34:15 +08:00
|
|
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
2017-11-14 08:43:46 +08:00
|
|
|
project(NONE)
|
|
|
|
|
|
|
|
# Path to "boot" subdirectory of repository root.
|
|
|
|
get_filename_component(BOOT_DIR ${APPLICATION_SOURCE_DIR} DIRECTORY)
|
|
|
|
# Path to top-level repository root directory.
|
|
|
|
get_filename_component(MCUBOOT_DIR ${BOOT_DIR} DIRECTORY)
|
|
|
|
# Path to tinycrypt library source subdirectory of MCUBOOT_DIR.
|
|
|
|
set(TINYCRYPT_DIR "${MCUBOOT_DIR}/ext/tinycrypt/lib")
|
2019-03-21 17:47:32 +08:00
|
|
|
assert_exists(TINYCRYPT_DIR)
|
2020-02-03 20:59:53 +08:00
|
|
|
set(TINYCRYPT_SHA512_DIR "${MCUBOOT_DIR}/ext/tinycrypt-sha512/lib")
|
|
|
|
assert_exists(TINYCRYPT_SHA512_DIR)
|
2019-05-11 06:26:38 +08:00
|
|
|
# Path to crypto-fiat
|
|
|
|
set(FIAT_DIR "${MCUBOOT_DIR}/ext/fiat")
|
|
|
|
assert_exists(FIAT_DIR)
|
2017-12-12 18:10:40 +08:00
|
|
|
# Path to mbed-tls' asn1 parser library.
|
2019-10-12 00:07:31 +08:00
|
|
|
set(MBEDTLS_ASN1_DIR "${MCUBOOT_DIR}/ext/mbedtls-asn1")
|
2019-03-21 17:47:32 +08:00
|
|
|
assert_exists(MBEDTLS_ASN1_DIR)
|
|
|
|
set(NRF_DIR "${MCUBOOT_DIR}/ext/nrf")
|
|
|
|
|
|
|
|
if(CONFIG_BOOT_USE_NRF_CC310_BL)
|
2020-06-04 02:21:13 +08:00
|
|
|
set(NRFXLIB_DIR ${ZEPHYR_BASE}/../nrfxlib)
|
2020-10-01 19:51:48 +08:00
|
|
|
if(NOT EXISTS ${NRFXLIB_DIR})
|
|
|
|
message(FATAL_ERROR "
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
No such file or directory: ${NRFXLIB_DIR}
|
|
|
|
The current configuration enables nRF CC310 crypto accelerator hardware
|
|
|
|
with the `CONFIG_BOOT_USE_NRF_CC310_BL` option. Please follow
|
|
|
|
`ext/nrf/README.md` guide to fix your setup or use tinycrypt instead of
|
|
|
|
the HW accelerator.
|
|
|
|
To use the tinycrypt set `CONFIG_BOOT_ECDSA_TINYCRYPT` to y.
|
|
|
|
------------------------------------------------------------------------")
|
|
|
|
endif()
|
2019-03-21 17:47:32 +08:00
|
|
|
# Don't include this if we are using west
|
|
|
|
add_subdirectory(${NRFXLIB_DIR} ${PROJECT_BINARY_DIR}/nrfxlib)
|
|
|
|
endif()
|
2017-11-14 08:43:46 +08:00
|
|
|
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_include_directories(
|
|
|
|
include
|
|
|
|
targets
|
|
|
|
)
|
|
|
|
if(EXISTS targets/${BOARD}.h)
|
|
|
|
zephyr_library_compile_definitions(MCUBOOT_TARGET_CONFIG="${BOARD}.h")
|
2017-11-14 08:43:46 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Zephyr port-specific sources.
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_sources(
|
|
|
|
main.c
|
|
|
|
flash_map_extended.c
|
|
|
|
os.c
|
|
|
|
keys.c
|
|
|
|
)
|
|
|
|
|
2021-08-17 15:55:54 +08:00
|
|
|
if(DEFINED CONFIG_ENABLE_MGMT_PERUSER)
|
|
|
|
zephyr_library_sources(
|
|
|
|
boot_serial_extensions.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-11-14 08:43:46 +08:00
|
|
|
if(NOT DEFINED CONFIG_FLASH_PAGE_LAYOUT)
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_sources(
|
2019-11-05 18:55:14 +08:00
|
|
|
flash_map_legacy.c
|
|
|
|
)
|
2017-11-14 08:43:46 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Generic bootutil sources and includes.
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_include_directories(${BOOT_DIR}/bootutil/include)
|
|
|
|
zephyr_library_sources(
|
|
|
|
${BOOT_DIR}/bootutil/src/image_validate.c
|
2020-05-19 21:01:16 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/tlv.c
|
2019-01-22 21:05:14 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/encrypted.c
|
|
|
|
${BOOT_DIR}/bootutil/src/image_rsa.c
|
2023-04-22 04:43:14 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/image_ecdsa.c
|
2019-05-11 06:26:38 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/image_ed25519.c
|
2020-06-08 20:40:06 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/bootutil_misc.c
|
2020-07-10 19:40:11 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/fault_injection_hardening.c
|
2020-05-19 21:01:16 +08:00
|
|
|
)
|
|
|
|
|
2020-11-10 21:35:15 +08:00
|
|
|
# library which might be common source code for MCUBoot and an application
|
|
|
|
zephyr_link_libraries(MCUBOOT_BOOTUTIL)
|
|
|
|
|
2020-07-10 19:40:11 +08:00
|
|
|
if(CONFIG_BOOT_FIH_PROFILE_HIGH)
|
|
|
|
zephyr_library_sources(
|
|
|
|
${BOOT_DIR}/bootutil/src/fault_injection_hardening_delay_rng_mbedtls.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-09-15 14:23:25 +08:00
|
|
|
if(CONFIG_SINGLE_APPLICATION_SLOT)
|
2020-05-19 21:01:16 +08:00
|
|
|
zephyr_library_sources(
|
|
|
|
${BOOT_DIR}/zephyr/single_loader.c
|
|
|
|
)
|
|
|
|
zephyr_library_include_directories(${BOOT_DIR}/bootutil/src)
|
|
|
|
else()
|
|
|
|
zephyr_library_sources(
|
|
|
|
${BOOT_DIR}/bootutil/src/loader.c
|
|
|
|
${BOOT_DIR}/bootutil/src/swap_misc.c
|
|
|
|
${BOOT_DIR}/bootutil/src/swap_scratch.c
|
|
|
|
${BOOT_DIR}/bootutil/src/swap_move.c
|
2019-01-22 21:05:14 +08:00
|
|
|
${BOOT_DIR}/bootutil/src/caps.c
|
|
|
|
)
|
2020-05-19 21:01:16 +08:00
|
|
|
endif()
|
|
|
|
|
2021-05-03 22:53:05 +08:00
|
|
|
if(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256 OR CONFIG_BOOT_ENCRYPT_EC256 OR CONFIG_BOOT_SERIAL_ENCRYPT_EC256)
|
2019-03-21 17:47:32 +08:00
|
|
|
zephyr_library_include_directories(
|
2019-11-05 18:55:14 +08:00
|
|
|
${MBEDTLS_ASN1_DIR}/include
|
|
|
|
)
|
2019-03-21 17:47:32 +08:00
|
|
|
zephyr_library_sources(
|
2019-11-05 18:55:14 +08:00
|
|
|
# Additionally pull in just the ASN.1 parser from mbedTLS.
|
|
|
|
${MBEDTLS_ASN1_DIR}/src/asn1parse.c
|
|
|
|
${MBEDTLS_ASN1_DIR}/src/platform_util.c
|
|
|
|
)
|
2019-03-21 17:47:32 +08:00
|
|
|
if(CONFIG_BOOT_USE_TINYCRYPT)
|
zephyr: migrate signature type to Kconfig
Handle the CONFIG_BOOT_SIGNATURE_TYPE_xxx values in Zephyr's
mcuboot_config.h by converting them into the platform-agnostic MCUboot
definitions.
This requires some changes to the way the release test Makefile is
structured, since Kconfig symbols cannot be set from the command line.
Instead, use the OVERLAY_CONFIG feature of the Zephyr build system,
which allows specifying extra fragments to merge into the final
.config. (This is an orthogonal mechanism to setting CONF_FILE; it is
used by Zephyr's CI script sanitycheck to add additional fragments, so
it's appropriate for use by MCUboot's testing scripts as well.)
We additionally need to move to a single prj.conf file due to a
dependency issue. We can no longer determine CONF_FILE from the
signature type, since that is now determined from the final .config or
autoconf.h, which is a build output that depends on CONF_FILE.
To move to a single prj.conf:
- delete prj-p256.conf and adjust prj.conf to serve both signature types
- add a top-level mbedTLS configuration file which dispatches to
the right sub-header depending on the key type
- as a side effect, have the simulator pick the right config file
depending on the case
This fixes and cleans up quite a bit of the signature type handling,
which had become something of a mess over time. For example, it fixes
a bug in ECDSA mode's configuration that wasn't actually selecting
config-asn1.h, and forces the simulator to use the same mbedTLS
configuration file as builds for real hardware.
Finally, we also have to move the mbedTLS vs. TinyCrypt choice into
mcuboot_config.h at the same time as well, since CMakeLists.txt was
making that decision based on the signature type.
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-04-13 01:02:38 +08:00
|
|
|
# When using ECDSA signatures, pull in our copy of the tinycrypt library.
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_include_directories(
|
2019-11-05 18:55:14 +08:00
|
|
|
${BOOT_DIR}/zephyr/include
|
|
|
|
${TINYCRYPT_DIR}/include
|
|
|
|
)
|
2021-05-03 22:53:05 +08:00
|
|
|
zephyr_include_directories(${TINYCRYPT_DIR}/include)
|
2019-01-22 21:05:14 +08:00
|
|
|
|
|
|
|
zephyr_library_sources(
|
2019-11-05 18:55:14 +08:00
|
|
|
${TINYCRYPT_DIR}/source/ecc.c
|
|
|
|
${TINYCRYPT_DIR}/source/ecc_dsa.c
|
|
|
|
${TINYCRYPT_DIR}/source/sha256.c
|
|
|
|
${TINYCRYPT_DIR}/source/utils.c
|
|
|
|
)
|
2019-03-21 17:47:32 +08:00
|
|
|
elseif(CONFIG_BOOT_USE_NRF_CC310_BL)
|
|
|
|
zephyr_library_sources(${NRF_DIR}/cc310_glue.c)
|
|
|
|
zephyr_library_include_directories(${NRF_DIR})
|
|
|
|
zephyr_link_libraries(nrfxlib_crypto)
|
|
|
|
endif()
|
2017-12-12 18:10:40 +08:00
|
|
|
|
2018-06-08 22:37:13 +08:00
|
|
|
# Since here we are not using Zephyr's mbedTLS but rather our own, we need
|
2018-06-05 21:56:08 +08:00
|
|
|
# to set MBEDTLS_CONFIG_FILE ourselves. When using Zephyr's copy, this
|
|
|
|
# variable is set by its Kconfig in the Zephyr codebase.
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_compile_definitions(
|
2019-11-05 18:55:14 +08:00
|
|
|
MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/include/mcuboot-mbedtls-cfg.h"
|
|
|
|
)
|
2020-05-05 23:44:12 +08:00
|
|
|
elseif(CONFIG_BOOT_SIGNATURE_TYPE_NONE)
|
|
|
|
zephyr_library_include_directories(
|
|
|
|
${BOOT_DIR}/zephyr/include
|
|
|
|
${TINYCRYPT_DIR}/include
|
|
|
|
)
|
|
|
|
|
|
|
|
zephyr_library_sources(
|
|
|
|
${TINYCRYPT_DIR}/source/sha256.c
|
|
|
|
${TINYCRYPT_DIR}/source/utils.c
|
|
|
|
)
|
zephyr: migrate signature type to Kconfig
Handle the CONFIG_BOOT_SIGNATURE_TYPE_xxx values in Zephyr's
mcuboot_config.h by converting them into the platform-agnostic MCUboot
definitions.
This requires some changes to the way the release test Makefile is
structured, since Kconfig symbols cannot be set from the command line.
Instead, use the OVERLAY_CONFIG feature of the Zephyr build system,
which allows specifying extra fragments to merge into the final
.config. (This is an orthogonal mechanism to setting CONF_FILE; it is
used by Zephyr's CI script sanitycheck to add additional fragments, so
it's appropriate for use by MCUboot's testing scripts as well.)
We additionally need to move to a single prj.conf file due to a
dependency issue. We can no longer determine CONF_FILE from the
signature type, since that is now determined from the final .config or
autoconf.h, which is a build output that depends on CONF_FILE.
To move to a single prj.conf:
- delete prj-p256.conf and adjust prj.conf to serve both signature types
- add a top-level mbedTLS configuration file which dispatches to
the right sub-header depending on the key type
- as a side effect, have the simulator pick the right config file
depending on the case
This fixes and cleans up quite a bit of the signature type handling,
which had become something of a mess over time. For example, it fixes
a bug in ECDSA mode's configuration that wasn't actually selecting
config-asn1.h, and forces the simulator to use the same mbedTLS
configuration file as builds for real hardware.
Finally, we also have to move the mbedTLS vs. TinyCrypt choice into
mcuboot_config.h at the same time as well, since CMakeLists.txt was
making that decision based on the signature type.
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-04-13 01:02:38 +08:00
|
|
|
elseif(CONFIG_BOOT_SIGNATURE_TYPE_RSA)
|
|
|
|
# Use mbedTLS provided by Zephyr for RSA signatures. (Its config file
|
|
|
|
# is set using Kconfig.)
|
|
|
|
zephyr_include_directories(include)
|
2021-11-08 21:07:56 +08:00
|
|
|
if(CONFIG_BOOT_ENCRYPT_RSA)
|
|
|
|
set_source_files_properties(
|
|
|
|
${BOOT_DIR}/bootutil/src/encrypted.c
|
|
|
|
PROPERTIES
|
|
|
|
INCLUDE_DIRECTORIES ${ZEPHYR_MBEDTLS_MODULE_DIR}/library
|
|
|
|
)
|
|
|
|
endif()
|
2020-04-03 00:25:01 +08:00
|
|
|
elseif(CONFIG_BOOT_SIGNATURE_TYPE_ED25519 OR CONFIG_BOOT_ENCRYPT_X25519)
|
2020-02-03 20:59:53 +08:00
|
|
|
if(CONFIG_BOOT_USE_TINYCRYPT)
|
|
|
|
zephyr_library_include_directories(
|
|
|
|
${MBEDTLS_ASN1_DIR}/include
|
|
|
|
${BOOT_DIR}/zephyr/include
|
|
|
|
${TINYCRYPT_DIR}/include
|
|
|
|
${TINYCRYPT_SHA512_DIR}/include
|
|
|
|
)
|
|
|
|
zephyr_library_sources(
|
|
|
|
${TINYCRYPT_DIR}/source/sha256.c
|
|
|
|
${TINYCRYPT_DIR}/source/utils.c
|
|
|
|
${TINYCRYPT_SHA512_DIR}/source/sha512.c
|
|
|
|
# Additionally pull in just the ASN.1 parser from mbedTLS.
|
|
|
|
${MBEDTLS_ASN1_DIR}/src/asn1parse.c
|
|
|
|
${MBEDTLS_ASN1_DIR}/src/platform_util.c
|
|
|
|
)
|
|
|
|
zephyr_library_compile_definitions(
|
|
|
|
MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/include/mcuboot-mbedtls-cfg.h"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
zephyr_include_directories(include)
|
|
|
|
endif()
|
2019-05-11 06:26:38 +08:00
|
|
|
|
|
|
|
zephyr_library_include_directories(
|
|
|
|
${BOOT_DIR}/zephyr/include
|
|
|
|
${FIAT_DIR}/include/
|
|
|
|
)
|
|
|
|
|
|
|
|
zephyr_library_sources(
|
|
|
|
${FIAT_DIR}/src/curve25519.c
|
|
|
|
)
|
2017-11-14 08:43:46 +08:00
|
|
|
endif()
|
2017-09-08 22:49:14 +08:00
|
|
|
|
2021-05-03 22:53:05 +08:00
|
|
|
if(CONFIG_BOOT_ENCRYPT_EC256 OR CONFIG_BOOT_ENCRYPT_X25519 OR CONFIG_BOOT_SERIAL_ENCRYPT_EC256)
|
2019-11-05 18:54:41 +08:00
|
|
|
zephyr_library_sources(
|
|
|
|
${TINYCRYPT_DIR}/source/aes_encrypt.c
|
|
|
|
${TINYCRYPT_DIR}/source/aes_decrypt.c
|
|
|
|
${TINYCRYPT_DIR}/source/ctr_mode.c
|
|
|
|
${TINYCRYPT_DIR}/source/hmac.c
|
|
|
|
${TINYCRYPT_DIR}/source/ecc_dh.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-04-03 00:25:01 +08:00
|
|
|
if(CONFIG_BOOT_ENCRYPT_EC256)
|
|
|
|
zephyr_library_sources(
|
|
|
|
${TINYCRYPT_DIR}/source/ecc_dh.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2019-01-22 21:05:14 +08:00
|
|
|
if(CONFIG_MCUBOOT_SERIAL)
|
2018-07-20 22:19:09 +08:00
|
|
|
zephyr_sources(${BOOT_DIR}/zephyr/serial_adapter.c)
|
|
|
|
zephyr_sources(${BOOT_DIR}/boot_serial/src/boot_serial.c)
|
2023-04-14 16:28:24 +08:00
|
|
|
zephyr_sources(${BOOT_DIR}/boot_serial/src/zcbor_bulk.c)
|
2022-06-07 23:17:06 +08:00
|
|
|
|
2018-07-20 22:19:09 +08:00
|
|
|
zephyr_include_directories(${BOOT_DIR}/bootutil/include)
|
|
|
|
zephyr_include_directories(${BOOT_DIR}/boot_serial/include)
|
|
|
|
zephyr_include_directories(include)
|
|
|
|
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_include_directories_ifdef(
|
2019-11-05 18:55:14 +08:00
|
|
|
CONFIG_BOOT_ERASE_PROGRESSIVELY
|
|
|
|
${BOOT_DIR}/bootutil/src
|
|
|
|
)
|
2017-09-08 22:49:14 +08:00
|
|
|
endif()
|
2018-04-26 21:53:19 +08:00
|
|
|
|
2021-04-13 22:04:00 +08:00
|
|
|
if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")
|
|
|
|
# CONF_FILE points to the KConfig configuration files of the bootloader.
|
|
|
|
foreach (filepath ${CONF_FILE})
|
|
|
|
file(READ ${filepath} temp_text)
|
|
|
|
string(FIND "${temp_text}" ${CONFIG_BOOT_SIGNATURE_KEY_FILE} match)
|
|
|
|
if (${match} GREATER_EQUAL 0)
|
|
|
|
if (NOT DEFINED CONF_DIR)
|
|
|
|
get_filename_component(CONF_DIR ${filepath} DIRECTORY)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Signature key file defined in multiple conf files")
|
|
|
|
endif()
|
2020-08-12 19:29:12 +08:00
|
|
|
endif()
|
2021-04-13 22:04:00 +08:00
|
|
|
endforeach()
|
2020-08-04 17:22:55 +08:00
|
|
|
|
2018-04-26 21:53:19 +08:00
|
|
|
if(IS_ABSOLUTE ${CONFIG_BOOT_SIGNATURE_KEY_FILE})
|
|
|
|
set(KEY_FILE ${CONFIG_BOOT_SIGNATURE_KEY_FILE})
|
2020-08-12 19:29:12 +08:00
|
|
|
elseif((DEFINED CONF_DIR) AND
|
|
|
|
(EXISTS ${CONF_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}))
|
2020-08-04 17:22:55 +08:00
|
|
|
set(KEY_FILE ${CONF_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE})
|
2018-04-26 21:53:19 +08:00
|
|
|
else()
|
|
|
|
set(KEY_FILE ${MCUBOOT_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE})
|
|
|
|
endif()
|
2020-08-12 19:29:12 +08:00
|
|
|
message("MCUBoot bootloader key file: ${KEY_FILE}")
|
|
|
|
|
2018-04-26 21:53:19 +08:00
|
|
|
set(GENERATED_PUBKEY ${ZEPHYR_BINARY_DIR}/autogen-pubkey.c)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GENERATED_PUBKEY}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${MCUBOOT_DIR}/scripts/imgtool.py
|
|
|
|
getpub
|
|
|
|
-k
|
|
|
|
${KEY_FILE}
|
|
|
|
> ${GENERATED_PUBKEY}
|
|
|
|
DEPENDS ${KEY_FILE}
|
|
|
|
)
|
2019-01-22 21:05:14 +08:00
|
|
|
zephyr_library_sources(${GENERATED_PUBKEY})
|
2018-04-26 21:53:19 +08:00
|
|
|
endif()
|
2019-03-21 17:47:32 +08:00
|
|
|
|
2022-01-28 15:40:28 +08:00
|
|
|
if(CONFIG_BOOT_ENCRYPTION_KEY_FILE AND NOT CONFIG_BOOT_ENCRYPTION_KEY_FILE STREQUAL "")
|
|
|
|
# CONF_FILE points to the KConfig configuration files of the bootloader.
|
|
|
|
unset(CONF_DIR)
|
|
|
|
foreach(filepath ${CONF_FILE})
|
|
|
|
file(READ ${filepath} temp_text)
|
|
|
|
string(FIND "${temp_text}" ${CONFIG_BOOT_ENCRYPTION_KEY_FILE} match)
|
|
|
|
if(${match} GREATER_EQUAL 0)
|
|
|
|
if(NOT DEFINED CONF_DIR)
|
|
|
|
get_filename_component(CONF_DIR ${filepath} DIRECTORY)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Encryption key file defined in multiple conf files")
|
|
|
|
endif()
|
2021-05-03 22:53:05 +08:00
|
|
|
endif()
|
2022-01-28 15:40:28 +08:00
|
|
|
endforeach()
|
2021-05-03 22:53:05 +08:00
|
|
|
|
|
|
|
if(IS_ABSOLUTE ${CONFIG_BOOT_ENCRYPTION_KEY_FILE})
|
|
|
|
set(KEY_FILE ${CONFIG_BOOT_ENCRYPTION_KEY_FILE})
|
|
|
|
elseif((DEFINED CONF_DIR) AND
|
|
|
|
(EXISTS ${CONF_DIR}/${CONFIG_BOOT_ENCRYPTION_KEY_FILE}))
|
|
|
|
set(KEY_FILE ${CONF_DIR}/${CONFIG_BOOT_ENCRYPTION_KEY_FILE})
|
|
|
|
else()
|
|
|
|
set(KEY_FILE ${MCUBOOT_DIR}/${CONFIG_BOOT_ENCRYPTION_KEY_FILE})
|
|
|
|
endif()
|
2022-01-28 15:40:28 +08:00
|
|
|
message("MCUBoot bootloader encryption key file: ${KEY_FILE}")
|
2021-05-03 22:53:05 +08:00
|
|
|
|
|
|
|
set(GENERATED_ENCKEY ${ZEPHYR_BINARY_DIR}/autogen-enckey.c)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GENERATED_ENCKEY}
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE}
|
|
|
|
${MCUBOOT_DIR}/scripts/imgtool.py
|
|
|
|
getpriv
|
|
|
|
-k
|
|
|
|
${KEY_FILE}
|
|
|
|
> ${GENERATED_ENCKEY}
|
|
|
|
DEPENDS ${KEY_FILE}
|
|
|
|
)
|
|
|
|
zephyr_library_sources(${GENERATED_ENCKEY})
|
|
|
|
endif()
|
|
|
|
|
2020-03-16 20:34:30 +08:00
|
|
|
if(CONFIG_MCUBOOT_CLEANUP_ARM_CORE)
|
|
|
|
zephyr_library_sources(
|
|
|
|
${BOOT_DIR}/zephyr/arm_cleanup.c
|
|
|
|
)
|
|
|
|
endif()
|