|
4 | 4 |
|
5 | 5 | include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake)
|
6 | 6 |
|
| 7 | +function(check_image_boundaries merged_partition images) |
| 8 | + # Predefine the MCUboot header size. |
| 9 | + set(MCUBOOT_HEADER_SIZE 0x800) |
| 10 | + |
| 11 | + # Fetch merged slot details from the mcuboot image. |
| 12 | + dt_chosen(flash_node TARGET mcuboot PROPERTY "zephyr,flash") |
| 13 | + dt_nodelabel(slot_path TARGET mcuboot NODELABEL "${merged_partition}" REQUIRED) |
| 14 | + dt_partition_addr(slot_addr PATH "${slot_path}" TARGET mcuboot REQUIRED) |
| 15 | + dt_reg_size(slot_size TARGET mcuboot PATH ${slot_path}) |
| 16 | + |
| 17 | + # Calculate boundaries of the usable area. |
| 18 | + sysbuild_get(mcuboot_image_footer_size IMAGE mcuboot CACHE) |
| 19 | + math(EXPR slot_max_addr "${slot_addr} + ${slot_size} - ${mcuboot_image_footer_size}" OUTPUT_FORMAT HEXADECIMAL) |
| 20 | + math(EXPR slot_min_addr "${slot_addr} + ${MCUBOOT_HEADER_SIZE}" OUTPUT_FORMAT HEXADECIMAL) |
| 21 | + |
| 22 | + # Iterate over images and check that they fit in the merged slots. |
| 23 | + foreach(image ${images}) |
| 24 | + set(start_offset) |
| 25 | + set(end_offset) |
| 26 | + sysbuild_get(start_offset IMAGE ${image} VAR CONFIG_ROM_START_OFFSET |
| 27 | + KCONFIG) |
| 28 | + sysbuild_get(end_offset IMAGE ${image} VAR CONFIG_ROM_END_OFFSET |
| 29 | + KCONFIG) |
| 30 | + dt_chosen(code_flash TARGET ${image} PROPERTY "zephyr,code-partition") |
| 31 | + dt_partition_addr(code_addr PATH "${code_flash}" TARGET ${image} REQUIRED) |
| 32 | + dt_reg_size(code_size TARGET ${image} PATH ${code_flash}) |
| 33 | + |
| 34 | + math(EXPR code_end_addr "${code_addr} + ${code_size} - ${end_offset}" OUTPUT_FORMAT HEXADECIMAL) |
| 35 | + math(EXPR code_start_addr "${code_addr} + ${start_offset}" OUTPUT_FORMAT HEXADECIMAL) |
| 36 | + |
| 37 | + if((${code_end_addr} GREATER ${slot_max_addr}) OR |
| 38 | + (${code_start_addr} LESS ${slot_min_addr})) |
| 39 | + message(FATAL_ERROR "Variant image ${image} " |
| 40 | + "(${code_start_addr}, ${code_end_addr}) " |
| 41 | + "does not fit in the merged ${merged_partition} " |
| 42 | + "(${slot_min_addr}, ${slot_max_addr})") |
| 43 | + return() |
| 44 | + endif() |
| 45 | + endforeach() |
| 46 | +endfunction() |
| 47 | + |
7 | 48 | function(merge_images_nrf54h20 output_artifact images)
|
8 | 49 | find_program(MERGEHEX mergehex.py HINTS ${ZEPHYR_BASE}/scripts/build/ NAMES
|
9 | 50 | mergehex NAMES_PER_DIR)
|
|
0 commit comments