|
| 1 | +# CMakeLists.txt for building mcuboot as a Zephyr project |
| 2 | +# |
| 3 | +# Copyright (c) 2017 Open Source Foundries Limited |
1 | 4 | # Copyright (c) 2022 Legrand North America, LLC. |
| 5 | +# |
2 | 6 | # SPDX-License-Identifier: Apache-2.0 |
3 | 7 |
|
4 | | -cmake_minimum_required(VERSION 3.20.0) |
| 8 | +cmake_minimum_required(VERSION 3.13.1) |
5 | 9 |
|
| 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 |
6 | 45 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) |
7 | 46 | project(mcuboot_exernal_config) |
8 | 47 |
|
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