Skip to content

Commit 79c2359

Browse files
Extend samples/zephyr_exteral_config with keys
Extended build file with logic copied from boot/zephyr/CMakeLists.txt to pull in keys.c **from that directory**. The build `west build -p always -b nrf52840dk_nrf52840 mcuboot/samples/zephyr_external_config` now succeeds, but is about 5000 bytes larger than the original. Inspection of the differences shows NORDIC_QSPI_NOR is enabled here and disabled in the original (through a local board-specific config). Signed-off-by: Gregory SHUE <[email protected]>
1 parent 483ac33 commit 79c2359

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed
Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,89 @@
1+
# CMakeLists.txt for building mcuboot as a Zephyr project
2+
#
3+
# Copyright (c) 2017 Open Source Foundries Limited
14
# Copyright (c) 2022 Legrand North America, LLC.
5+
#
26
# SPDX-License-Identifier: Apache-2.0
37

4-
cmake_minimum_required(VERSION 3.20.0)
8+
cmake_minimum_required(VERSION 3.13.1)
59

10+
# Add a common dts overlay necessary to ensure mcuboot is linked into,
11+
# and fits inside, the boot partition. (If the user specified a
12+
# DTC_OVERLAY_FILE on the CMake command line, we need to append onto
13+
# the list).
14+
if(DTC_OVERLAY_FILE)
15+
set(DTC_OVERLAY_FILE
16+
"${DTC_OVERLAY_FILE} ../../boot/zephyr/dts.overlay"
17+
CACHE STRING "" FORCE
18+
)
19+
else()
20+
set(DTC_OVERLAY_FILE ../../boot/zephyr/dts.overlay)
21+
endif()
22+
23+
# Enable Zephyr runner options which request mass erase if so
24+
# configured.
25+
#
26+
# Note that this also disables the default "leave" option when
27+
# targeting STM32 DfuSe devices with dfu-util, making the chip stay in
28+
# the bootloader after flashing.
29+
#
30+
# That's the right thing, because mcuboot has nothing to do since the
31+
# chip was just erased. The next thing the user is going to want to do
32+
# is flash the application. (Developers can reset DfuSE devices
33+
# manually to test mcuboot behavior on an otherwise erased flash
34+
# device.)
35+
macro(app_set_runner_args)
36+
if(CONFIG_ZEPHYR_TRY_MASS_ERASE)
37+
board_runner_args(dfu-util "--dfuse-modifiers=force:mass-erase")
38+
board_runner_args(pyocd "--flash-opt=-e=chip")
39+
board_runner_args(nrfjprog "--erase")
40+
endif()
41+
endmacro()
42+
43+
# find_package(Zephyr) in order to load application boilerplate:
44+
# http://docs.zephyrproject.org/application/application.html
645
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
746
project(mcuboot_exernal_config)
847

9-
target_sources(app PRIVATE empty.c)
48+
target_sources(app PRIVATE
49+
${ZEPHYR_MCUBOOT_MODULE_DIR}/boot/zephyr/keys.c
50+
)
51+
52+
if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")
53+
# CONF_FILE points to the KConfig configuration files of the bootloader.
54+
foreach (filepath ${CONF_FILE})
55+
file(READ ${filepath} temp_text)
56+
string(FIND "${temp_text}" ${CONFIG_BOOT_SIGNATURE_KEY_FILE} match)
57+
if (${match} GREATER_EQUAL 0)
58+
if (NOT DEFINED CONF_DIR)
59+
get_filename_component(CONF_DIR ${filepath} DIRECTORY)
60+
else()
61+
message(FATAL_ERROR "Signature key file defined in multiple conf files")
62+
endif()
63+
endif()
64+
endforeach()
65+
66+
if(IS_ABSOLUTE ${CONFIG_BOOT_SIGNATURE_KEY_FILE})
67+
set(KEY_FILE ${CONFIG_BOOT_SIGNATURE_KEY_FILE})
68+
elseif((DEFINED CONF_DIR) AND
69+
(EXISTS ${CONF_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE}))
70+
set(KEY_FILE ${CONF_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE})
71+
else()
72+
set(KEY_FILE ${ZEPHYR_MCUBOOT_MODULE_DIR}/${CONFIG_BOOT_SIGNATURE_KEY_FILE})
73+
endif()
74+
message("MCUBoot bootloader key file: ${KEY_FILE}")
75+
76+
set(GENERATED_PUBKEY ${ZEPHYR_BINARY_DIR}/autogen-pubkey.c)
77+
add_custom_command(
78+
OUTPUT ${GENERATED_PUBKEY}
79+
COMMAND
80+
${PYTHON_EXECUTABLE}
81+
${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py
82+
getpub
83+
-k
84+
${KEY_FILE}
85+
> ${GENERATED_PUBKEY}
86+
DEPENDS ${KEY_FILE}
87+
)
88+
zephyr_library_sources(${GENERATED_PUBKEY})
89+
endif()

0 commit comments

Comments
 (0)