|
| 1 | +# |
| 2 | +# Copyright (c) 2025 Nordic Semiconductor |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + |
| 6 | +include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake) |
| 7 | + |
| 8 | +yaml_create(NAME mcuboot_manifest) |
| 9 | +yaml_set(NAME mcuboot_manifest KEY format VALUE "1") |
| 10 | +yaml_set(NAME mcuboot_manifest KEY images LIST) |
| 11 | +set(manifest_path "manifest.yaml") |
| 12 | +set(manifest_img_slot_0 "${DEFAULT_IMAGE}") |
| 13 | + |
| 14 | +yaml_create(NAME mcuboot_secondary_manifest) |
| 15 | +yaml_set(NAME mcuboot_secondary_manifest KEY format VALUE "1") |
| 16 | +yaml_set(NAME mcuboot_secondary_manifest KEY images LIST) |
| 17 | +set(manifest_secondary_path "manifest_secondary.yaml") |
| 18 | +set(manifest_img_slot_1 "mcuboot_secondary_app") |
| 19 | + |
| 20 | +# Since the default (merged) image is excluded from the manifest, because it contains the manifest |
| 21 | +# itself, there is no need to construct the manifest when building a merged image. |
| 22 | +if(NOT SB_CONFIG_MCUBOOT_SIGN_MERGED_BINARY) |
| 23 | + sysbuild_get(manifest_img IMAGE mcuboot VAR CONFIG_MCUBOOT_MANIFEST_IMAGE_NUMBER KCONFIG) |
| 24 | + math(EXPR manifest_slot_0 "${manifest_img} * 2") |
| 25 | + math(EXPR manifest_slot_1 "${manifest_img} * 2 + 1") |
| 26 | + dt_partition_addr(slot0_addr LABEL "slot${manifest_slot_0}_partition" TARGET mcuboot ABSOLUTE REQUIRED) |
| 27 | + dt_partition_addr(slot1_addr LABEL "slot${manifest_slot_1}_partition" TARGET mcuboot ABSOLUTE REQUIRED) |
| 28 | + |
| 29 | + UpdateableImage_Get(images GROUP "DEFAULT") |
| 30 | + foreach(image ${images}) |
| 31 | + sysbuild_get(BINARY_DIR IMAGE ${image} VAR APPLICATION_BINARY_DIR CACHE) |
| 32 | + sysbuild_get(BINARY_BIN_FILE IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG) |
| 33 | + dt_chosen(code_flash TARGET ${image} PROPERTY "zephyr,code-partition") |
| 34 | + dt_partition_addr(code_addr PATH "${code_flash}" TARGET ${image} ABSOLUTE REQUIRED) |
| 35 | + |
| 36 | + if("${code_addr}" STREQUAL "${slot0_addr}") |
| 37 | + cmake_path(APPEND BINARY_DIR "zephyr" "manifest.yaml" OUTPUT_VARIABLE manifest_path) |
| 38 | + set(manifest_img_slot_0 "${image}") |
| 39 | + continue() |
| 40 | + endif() |
| 41 | + |
| 42 | + if(NOT "${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE") |
| 43 | + cmake_path(APPEND BINARY_DIR "zephyr" "${BINARY_BIN_FILE}.signed.bin" OUTPUT_VARIABLE image_path) |
| 44 | + else() |
| 45 | + cmake_path(APPEND BINARY_DIR "zephyr" "${BINARY_BIN_FILE}.bin" OUTPUT_VARIABLE image_path) |
| 46 | + endif() |
| 47 | + |
| 48 | + yaml_set(NAME mcuboot_manifest KEY images APPEND LIST MAP "path: ${image_path}, name: ${image}") |
| 49 | + endforeach() |
| 50 | + |
| 51 | + foreach(image ${images}) |
| 52 | + if("${image}" STREQUAL "${manifest_img_slot_0}") |
| 53 | + continue() |
| 54 | + endif() |
| 55 | + add_dependencies("${manifest_img_slot_0}" "${image}") |
| 56 | + endforeach() |
| 57 | + |
| 58 | + UpdateableImage_Get(variants GROUP "VARIANT") |
| 59 | + foreach(image ${variants}) |
| 60 | + sysbuild_get(BINARY_DIR IMAGE ${image} VAR APPLICATION_BINARY_DIR CACHE) |
| 61 | + sysbuild_get(BINARY_BIN_FILE IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG) |
| 62 | + dt_chosen(code_flash TARGET ${image} PROPERTY "zephyr,code-partition") |
| 63 | + dt_partition_addr(code_addr PATH "${code_flash}" TARGET ${image} ABSOLUTE REQUIRED) |
| 64 | + |
| 65 | + if("${code_addr}" STREQUAL "${slot1_addr}") |
| 66 | + cmake_path(APPEND BINARY_DIR "zephyr" "manifest.yaml" OUTPUT_VARIABLE manifest_secondary_path) |
| 67 | + set(manifest_img_slot_1 "${image}") |
| 68 | + continue() |
| 69 | + endif() |
| 70 | + |
| 71 | + if(NOT "${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE") |
| 72 | + cmake_path(APPEND BINARY_DIR "zephyr" "${BINARY_BIN_FILE}.signed.bin" OUTPUT_VARIABLE image_path) |
| 73 | + else() |
| 74 | + cmake_path(APPEND BINARY_DIR "zephyr" "${BINARY_BIN_FILE}.bin" OUTPUT_VARIABLE image_path) |
| 75 | + endif() |
| 76 | + |
| 77 | + yaml_set(NAME mcuboot_secondary_manifest KEY images APPEND LIST MAP "path: ${image_path}, name: ${image}") |
| 78 | + endforeach() |
| 79 | + |
| 80 | + foreach(image ${variants}) |
| 81 | + if("${image}" STREQUAL "${manifest_img_slot_1}") |
| 82 | + continue() |
| 83 | + endif() |
| 84 | + add_dependencies("${manifest_img_slot_1}" "${image}") |
| 85 | + endforeach() |
| 86 | +endif() |
| 87 | + |
| 88 | +yaml_save(NAME mcuboot_manifest FILE "${manifest_path}") |
| 89 | +yaml_save(NAME mcuboot_secondary_manifest FILE "${manifest_secondary_path}") |
0 commit comments