diff --git a/cmake/sysbuild/image_signing.cmake b/cmake/sysbuild/image_signing.cmake index f85fe5d513fc..6520737713da 100644 --- a/cmake/sysbuild/image_signing.cmake +++ b/cmake/sysbuild/image_signing.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2023 Nordic Semiconductor ASA +# Copyright (c) 2020-2024 Nordic Semiconductor ASA # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause # This file includes extra build system logic that is enabled when @@ -74,6 +74,17 @@ function(zephyr_mcuboot_tasks) return() endif() + # Fetch devicetree details for flash and slot information + dt_chosen(flash_node PROPERTY "zephyr,flash") + dt_nodelabel(slot0_flash NODELABEL "slot0_partition" REQUIRED) + dt_prop(slot_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1 REQUIRED) + dt_prop(write_block_size PATH "${flash_node}" PROPERTY "write-block-size") + + if(NOT write_block_size) + set(write_block_size 4) + message(WARNING "slot0_partition write block size devicetree parameter is missing, assuming write block size is 4") + endif() + set(imgtool_directxip_hex_command) if(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) @@ -95,7 +106,7 @@ function(zephyr_mcuboot_tasks) # TODO: NCSDK-28461 sysbuild PM fields cannot be updated without a pristine build, will become # invalid if a static PM file is updated without pristine build set(imgtool_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_rom_command} CACHE STRING "imgtool sign sysbuild replacement") - set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 ${imgtool_sign_sysbuild}) + set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild}) # Arguments to imgtool. if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "") diff --git a/cmake/sysbuild/image_signing_firmware_loader.cmake b/cmake/sysbuild/image_signing_firmware_loader.cmake index 1ea85e334ad4..8b42bfa0d64f 100644 --- a/cmake/sysbuild/image_signing_firmware_loader.cmake +++ b/cmake/sysbuild/image_signing_firmware_loader.cmake @@ -68,13 +68,24 @@ function(zephyr_mcuboot_tasks) return() endif() + # Fetch devicetree details for flash and slot information + dt_chosen(flash_node PROPERTY "zephyr,flash") + dt_nodelabel(slot0_flash NODELABEL "slot0_partition" REQUIRED) + dt_prop(slot_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1 REQUIRED) + dt_prop(write_block_size PATH "${flash_node}" PROPERTY "write-block-size") + + if(NOT write_block_size) + set(write_block_size 4) + message(WARNING "slot0_partition write block size devicetree parameter is missing, assuming write block size is 4") + endif() + # Split fields, imgtool_sign_sysbuild is stored in cache which will have fields updated by # sysbuild, imgtool_sign must not be stored in cache because it would then prevent those fields # from being updated without a pristine build # TODO: NCSDK-28461 sysbuild PM fields cannot be updated without a pristine build, will become # invalid if a static PM file is updated without pristine build set(imgtool_sign_sysbuild --slot-size @PM_MCUBOOT_SECONDARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_rom_command} CACHE STRING "imgtool sign sysbuild replacement") - set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 ${imgtool_sign_sysbuild}) + set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_sign_sysbuild}) # Arguments to imgtool. if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "") diff --git a/cmake/sysbuild/image_signing_nrf700x.cmake b/cmake/sysbuild/image_signing_nrf700x.cmake index 7480f8ee3df8..a0698383c959 100644 --- a/cmake/sysbuild/image_signing_nrf700x.cmake +++ b/cmake/sysbuild/image_signing_nrf700x.cmake @@ -40,6 +40,17 @@ function(nrf7x_signing_tasks input output_hex output_bin dependencies) return() endif() + # Fetch devicetree details for flash and slot information + sysbuild_dt_chosen(flash_node IMAGE ${DEFAULT_IMAGE} PROPERTY "zephyr,flash") + sysbuild_dt_nodelabel(slot0_flash IMAGE ${DEFAULT_IMAGE} NODELABEL "slot0_partition" REQUIRED) + sysbuild_dt_prop(slot_size IMAGE ${DEFAULT_IMAGE} PATH "${slot0_flash}" PROPERTY "reg" INDEX 1 REQUIRED) + sysbuild_dt_prop(write_block_size IMAGE ${DEFAULT_IMAGE} PATH "${flash_node}" PROPERTY "write-block-size") + + if(NOT write_block_size) + set(write_block_size 4) + message(WARNING "slot0_partition write block size devicetree parameter is missing, assuming write block size is 4") + endif() + sysbuild_get(CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION IMAGE ${DEFAULT_IMAGE} VAR CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION KCONFIG) set(imgtool_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 --slot-size $ --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD}) diff --git a/cmake/sysbuild/image_signing_split.cmake b/cmake/sysbuild/image_signing_split.cmake index fa0addb3ad7a..784ff9b949b0 100644 --- a/cmake/sysbuild/image_signing_split.cmake +++ b/cmake/sysbuild/image_signing_split.cmake @@ -95,6 +95,17 @@ function(zephyr_mcuboot_tasks) return() endif() + # Fetch devicetree details for flash and slot information + dt_chosen(flash_node PROPERTY "zephyr,flash") + dt_nodelabel(slot0_flash NODELABEL "slot0_partition" REQUIRED) + dt_prop(slot_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1 REQUIRED) + dt_prop(write_block_size PATH "${flash_node}" PROPERTY "write-block-size") + + if(NOT write_block_size) + set(write_block_size 4) + message(WARNING "slot0_partition write block size devicetree parameter is missing, assuming write block size is 4") + endif() + # Fetch QSPI XIP MCUboot image number from sysbuild zephyr_get(qspi_xip_image_number VAR QSPI_XIP_IMAGE_NUMBER SYSBUILD) @@ -116,8 +127,8 @@ function(zephyr_mcuboot_tasks) # invalid if a static PM file is updated without pristine build set(imgtool_internal_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_internal_rom_command} CACHE STRING "imgtool sign (internal flash) sysbuild replacement") set(imgtool_external_sign_sysbuild --slot-size @PM_MCUBOOT_PRIMARY_${qspi_xip_image_number}_SIZE@ --pad-header --header-size @PM_MCUBOOT_PAD_SIZE@ ${imgtool_external_rom_command} CACHE STRING "imgtool sign (external flash) sysbuild replacement") - set(imgtool_internal_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 ${imgtool_internal_sign_sysbuild}) - set(imgtool_external_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align 4 ${imgtool_external_sign_sysbuild}) + set(imgtool_internal_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_internal_sign_sysbuild}) + set(imgtool_external_sign ${PYTHON_EXECUTABLE} ${imgtool_path} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} ${imgtool_external_sign_sysbuild}) # Arguments to imgtool. if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "")