|
| 1 | +# |
| 2 | +# Copyright (c) 2025 Nordic Semiconductor ASA |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | +# |
| 6 | + |
| 7 | +function(bm_install_setup) |
| 8 | + if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE) |
| 9 | + ExternalZephyrProject_Add( |
| 10 | + APPLICATION ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME} |
| 11 | + SOURCE_DIR ${SB_CONFIG_BM_BOOTLOADER_IMAGE_PATH} |
| 12 | + ) |
| 13 | + |
| 14 | + # Place MCUBoot first in list to ensure it is configured and flashed before other images. |
| 15 | + sysbuild_add_dependencies(CONFIGURE ${DEFAULT_IMAGE} ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME}) |
| 16 | + sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME}) |
| 17 | + |
| 18 | + if(NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE) |
| 19 | + ExternalZephyrProject_Add( |
| 20 | + APPLICATION ${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME} |
| 21 | + SOURCE_DIR ${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_PATH} |
| 22 | + ) |
| 23 | + |
| 24 | + add_overlay_dts(${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/image_configurations/FIRMWARE_LOADER_image_default.overlay) |
| 25 | + endif() |
| 26 | + endif() |
| 27 | +endfunction() |
| 28 | + |
| 29 | +function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake) |
| 30 | + cmake_parse_arguments(PRE_CMAKE "" "" "IMAGES" ${ARGN}) |
| 31 | + |
| 32 | + if(NOT DEFINED SB_CONFIG_NCS_BM) |
| 33 | + # Disable bare-metal on all images |
| 34 | + foreach(image ${PRE_CMAKE_IMAGES}) |
| 35 | + set_config_int(${image} CONFIG_NCS_BM n) |
| 36 | + endforeach() |
| 37 | + |
| 38 | + return() |
| 39 | + endif() |
| 40 | + |
| 41 | + if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE) |
| 42 | + set(bm_install_images 1) |
| 43 | + |
| 44 | + if(NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE) |
| 45 | + # Firmware loader present |
| 46 | + set_target_properties(${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME} PROPERTIES |
| 47 | + IMAGE_CONF_SCRIPT ${ZEPHYR_NRF_BM_MODULE_DIR}/sysbuild/image_configurations/MAIN_image_default.cmake |
| 48 | + ) |
| 49 | + |
| 50 | + set(bm_install_images 2) |
| 51 | + endif() |
| 52 | + |
| 53 | + # Use BM-supplied bootloader image configuration file |
| 54 | + get_property(tmp_conf_scripts TARGET ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME} PROPERTY IMAGE_CONF_SCRIPT) |
| 55 | + set(bootloader_script ${ZEPHYR_NRF_BM_MODULE_DIR}/sysbuild/image_configurations/BOOTLOADER_image_default.cmake) |
| 56 | + |
| 57 | + if(NOT bootloader_script IN_LIST tmp_conf_scripts) |
| 58 | + list(APPEND tmp_conf_scripts ${bootloader_script}) |
| 59 | + set_target_properties(${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME} PROPERTIES IMAGE_CONF_SCRIPT "${tmp_conf_scripts}") |
| 60 | + endif() |
| 61 | + else() |
| 62 | + set(bm_install_images 0) |
| 63 | + endif() |
| 64 | + |
| 65 | + set_target_properties(${DEFAULT_IMAGE} PROPERTIES |
| 66 | + IMAGE_CONF_SCRIPT ${ZEPHYR_NRF_BM_MODULE_DIR}/sysbuild/image_configurations/MAIN_image_default.cmake |
| 67 | + ) |
| 68 | + |
| 69 | + math(EXPR metadata_area_size "${SB_CONFIG_METADATA_SIZE}" OUTPUT_FORMAT DECIMAL) |
| 70 | + math(EXPR metadata_slots "${metadata_area_size} / ${SB_CONFIG_METADATA_ENTRY_SIZE}" OUTPUT_FORMAT DECIMAL) |
| 71 | + |
| 72 | + foreach(image ${PRE_CMAKE_IMAGES}) |
| 73 | + set_config_int(${image} CONFIG_BM_INSTALL_IMAGES ${bm_install_images}) |
| 74 | + set_config_int(${image} CONFIG_BM_INSTALL_ENTRY_SIZE ${SB_CONFIG_METADATA_ENTRY_SIZE}) |
| 75 | + set_config_int(${image} CONFIG_BM_INSTALL_ENTRIES ${metadata_slots}) |
| 76 | + |
| 77 | + if(image STREQUAL "installer") |
| 78 | + set_config_int(${image} CONFIG_BM_METADATA_WRITE y) |
| 79 | + else() |
| 80 | + set_config_int(${image} CONFIG_BM_METADATA_WRITE n) |
| 81 | + endif() |
| 82 | + |
| 83 | + if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE AND NOT image STREQUAL "mcuboot") |
| 84 | + if(SB_CONFIG_SOC_SERIES_NRF54LX) |
| 85 | + set_config_int(installer CONFIG_ROM_START_OFFSET 0x800) |
| 86 | + else() |
| 87 | + set_config_int(installer CONFIG_ROM_START_OFFSET 0x200) |
| 88 | + endif() |
| 89 | + endif() |
| 90 | + endforeach() |
| 91 | +endfunction() |
| 92 | + |
| 93 | +function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake) |
| 94 | + if(NOT DEFINED SB_CONFIG_NCS_BM) |
| 95 | + return() |
| 96 | + endif() |
| 97 | + |
| 98 | + cmake_parse_arguments(PRE_CMAKE "" "" "IMAGES" ${ARGN}) |
| 99 | + |
| 100 | + if(NOT SB_CONFIG_SOFTDEVICE_NONE) |
| 101 | + set(dependency_targets) |
| 102 | + |
| 103 | + foreach(image ${PRE_CMAKE_IMAGES}) |
| 104 | + list(APPEND dependency_targets ${image}_extra_byproducts) |
| 105 | + endforeach() |
| 106 | + |
| 107 | + # Installer metadata |
| 108 | + add_custom_target(metadata_generation |
| 109 | + ALL |
| 110 | + DEPENDS ${CMAKE_BINARY_DIR}/metadata.hex ${CMAKE_BINARY_DIR}/metadata.bin |
| 111 | + ${CMAKE_BINARY_DIR}/combined_signed_update_images.hex |
| 112 | + ) |
| 113 | + |
| 114 | + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/metadata.hex ${CMAKE_BINARY_DIR}/metadata.bin |
| 115 | + ${CMAKE_BINARY_DIR}/combined_signed_update_images.hex |
| 116 | + COMMAND |
| 117 | + ${PYTHON_EXECUTABLE} |
| 118 | + ${ZEPHYR_NRF_BM_MODULE_DIR}/scripts/generate_metadata.py |
| 119 | + --build-dir ${CMAKE_BINARY_DIR} |
| 120 | + DEPENDS ${dependency_targets} ../zephyr/.config |
| 121 | + ) |
| 122 | + |
| 123 | + if(NOT SB_CONFIG_BM_FIRMWARE_LOADER_NONE) |
| 124 | + include(${ZEPHYR_NRF_BM_MODULE_DIR}/cmake/sysbuild/image_signing_installer.cmake) |
| 125 | + endif() |
| 126 | + endif() |
| 127 | +endfunction() |
| 128 | + |
| 129 | +if(SB_CONFIG_NCS_BM) |
| 130 | + bm_install_setup() |
| 131 | +endif() |
0 commit comments