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