diff --git a/cmake/sysbuild/image_signing.cmake b/cmake/sysbuild/image_signing.cmake index 136f77b730bd..7710e6df9a0e 100644 --- a/cmake/sysbuild/image_signing.cmake +++ b/cmake/sysbuild/image_signing.cmake @@ -52,8 +52,10 @@ function(zephyr_mcuboot_tasks) # MCUboot. # # Therefore, go with an explicitly installed imgtool first, falling - # back on mcuboot/scripts/imgtool.py. - if(IMGTOOL) + # back on mcuboot/scripts/imgtool.py. We exclude the system imgtool when + # compressed image support is enabled due to needing a version of imgtool + # that has features not in the most recent public release. + if(IMGTOOL AND NOT CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED) set(imgtool_path "${IMGTOOL}") elseif(DEFINED ZEPHYR_MCUBOOT_MODULE_DIR) set(IMGTOOL_PY "${ZEPHYR_MCUBOOT_MODULE_DIR}/scripts/imgtool.py") @@ -103,6 +105,19 @@ function(zephyr_mcuboot_tasks) set(imgtool_extra) endif() + if(CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED) + set(imgtool_bin_extra --compression lzma2armthumb) + else() + set(imgtool_bin_extra) + endif() + + # Apply compression to hex file if this is a test + if(ncs_compress_test_compress_hex) + set(imgtool_hex_extra ${imgtool_bin_extra}) + else() + set(imgtool_hex_extra) + endif() + if(CONFIG_MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION) set(imgtool_extra --security-counter ${CONFIG_MCUBOOT_HW_DOWNGRADE_PREVENTION_COUNTER_VALUE} ${imgtool_extra}) endif() @@ -153,7 +168,7 @@ function(zephyr_mcuboot_tasks) # calls to the "extra_post_build_commands" property ensures they run # after the commands which generate the unsigned versions. set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND - ${imgtool_sign} ${imgtool_args} ${unconfirmed_args}) + ${imgtool_sign} ${imgtool_args} ${imgtool_bin_extra} ${unconfirmed_args}) if(NOT "${keyfile_enc}" STREQUAL "") if(CONFIG_BUILD_WITH_TFM) @@ -169,7 +184,7 @@ function(zephyr_mcuboot_tasks) ) set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND - ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc}" ${unconfirmed_args}) + ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc}" ${imgtool_bin_extra} ${unconfirmed_args}) endif() endif() @@ -196,7 +211,7 @@ function(zephyr_mcuboot_tasks) # calls to the "extra_post_build_commands" property ensures they run # after the commands which generate the unsigned versions. set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND - ${imgtool_sign} ${imgtool_args} ${imgtool_directxip_hex_command} ${unconfirmed_args}) + ${imgtool_sign} ${imgtool_args} ${imgtool_directxip_hex_command} ${imgtool_hex_extra} ${unconfirmed_args}) if(NOT "${keyfile_enc}" STREQUAL "") set(unconfirmed_args ${input}.hex ${output}.encrypted.hex) @@ -206,7 +221,7 @@ function(zephyr_mcuboot_tasks) ) set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND - ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc}" ${unconfirmed_args}) + ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc}" ${imgtool_hex_extra} ${unconfirmed_args}) endif() endif() diff --git a/samples/nrf_compress/mcuboot_update/CMakeLists.txt b/samples/nrf_compress/mcuboot_update/CMakeLists.txt new file mode 100644 index 000000000000..6925d49bbe87 --- /dev/null +++ b/samples/nrf_compress/mcuboot_update/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(mcuboot_update) + +# This project uses orginal sdk-zephyr C source code +target_sources(app PRIVATE src/hook.c ${ZEPHYR_BASE}/samples/subsys/mgmt/mcumgr/smp_svr/src/main.c) +target_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_BT app PRIVATE ${ZEPHYR_BASE}/samples/subsys/mgmt/mcumgr/smp_svr/src/bluetooth.c) +zephyr_link_libraries(MCUBOOT_BOOTUTIL) diff --git a/samples/nrf_compress/mcuboot_update/prj.conf b/samples/nrf_compress/mcuboot_update/prj.conf new file mode 100644 index 000000000000..59a3b4a2f31c --- /dev/null +++ b/samples/nrf_compress/mcuboot_update/prj.conf @@ -0,0 +1,84 @@ +# Enable MCUmgr and dependencies. +CONFIG_NET_BUF=y +CONFIG_ZCBOR=y +CONFIG_CRC=y +CONFIG_MCUMGR=y +CONFIG_STREAM_FLASH=y +CONFIG_FLASH_MAP=y + +# Some command handlers require a large stack. +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304 +CONFIG_MAIN_STACK_SIZE=2048 + +# Ensure an MCUboot-compatible binary is generated. +CONFIG_BOOTLOADER_MCUBOOT=y + +# Enable flash operations. +CONFIG_FLASH=y + +# Required by the `taskstat` command. +CONFIG_THREAD_MONITOR=y + +# Support for taskstat command +CONFIG_MCUMGR_GRP_OS_TASKSTAT=y + +# Enable statistics and statistic names. +CONFIG_STATS=y +CONFIG_STATS_NAMES=y + +# Enable most core commands. +CONFIG_FLASH=y +CONFIG_IMG_MANAGER=y +CONFIG_MCUMGR_GRP_IMG=y +CONFIG_MCUMGR_GRP_OS=y +CONFIG_MCUMGR_GRP_STAT=y + +# Enable logging +CONFIG_LOG=y +CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y + +# Disable debug logging +CONFIG_LOG_MAX_LEVEL=3 + +CONFIG_BT=y +CONFIG_BT_PERIPHERAL=y + +# Allow for large Bluetooth data packets. +CONFIG_BT_L2CAP_TX_MTU=498 +CONFIG_BT_BUF_ACL_RX_SIZE=502 +CONFIG_BT_BUF_ACL_TX_SIZE=502 +CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 + +# Enable the Bluetooth mcumgr transport (unauthenticated). +CONFIG_MCUMGR_TRANSPORT_BT=y +CONFIG_MCUMGR_TRANSPORT_BT_AUTHEN=n +CONFIG_MCUMGR_TRANSPORT_BT_CONN_PARAM_CONTROL=y + +# Enable the Shell mcumgr transport. +CONFIG_BASE64=y +CONFIG_SHELL=y +CONFIG_SHELL_BACKEND_SERIAL=y +CONFIG_MCUMGR_TRANSPORT_SHELL=y +CONFIG_MCUMGR_TRANSPORT_SHELL_RX_BUF_COUNT=8 + +# Enable the mcumgr Packet Reassembly feature over Bluetooth and its configuration dependencies. +# MCUmgr buffer size is optimized to fit one SMP packet divided into five Bluetooth Write Commands, +# transmitted with the maximum possible MTU value: 498 bytes. +CONFIG_MCUMGR_TRANSPORT_BT_REASSEMBLY=y +CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=2475 +CONFIG_MCUMGR_GRP_OS_MCUMGR_PARAMS=y +CONFIG_MCUMGR_TRANSPORT_WORKQUEUE_STACK_SIZE=4608 + +# Disable Bluetooth ping support +CONFIG_BT_CTLR_LE_PING=n + +# Disable shell commands that are not needed +CONFIG_CLOCK_CONTROL_NRF_SHELL=n +CONFIG_DEVICE_SHELL=n +CONFIG_DEVMEM_SHELL=n +CONFIG_FLASH_SHELL=n + +CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS=y +CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS=y +CONFIG_MCUMGR_GRP_IMG_IMAGE_SLOT_STATE_HOOK=y +CONFIG_MCUMGR_GRP_IMG_IMAGE_SLOT_STATE_STATES=20 diff --git a/samples/nrf_compress/mcuboot_update/src/hook.c b/samples/nrf_compress/mcuboot_update/src/hook.c new file mode 100644 index 000000000000..397b9de52d07 --- /dev/null +++ b/samples/nrf_compress/mcuboot_update/src/hook.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(mcuboot_update_sample, LOG_LEVEL_DBG); + +#define SECONDARY_SLOT 1 + +#ifndef CONFIG_MCUMGR_GRP_IMG_FRUGAL_LIST +#define ZCBOR_ENCODE_FLAG(zse, label, value) \ + (zcbor_tstr_put_lit(zse, label) && zcbor_bool_put(zse, value)) +#else +/* In "frugal" lists flags are added to response only when they evaluate to true */ +/* Note that value is evaluated twice! */ +#define ZCBOR_ENCODE_FLAG(zse, label, value) (!(value) || \ + (zcbor_tstr_put_lit(zse, label) && zcbor_bool_put(zse, (value)))) +#endif + +static struct mgmt_callback image_slot_callback; +static struct k_work slot_output_work; + +static void slot_output_handler(struct k_work *work) +{ + uint32_t slot_flags; + int rc; + + rc = img_mgmt_read_info(SECONDARY_SLOT, NULL, NULL, &slot_flags); + + if (!rc) { + slot_flags &= IMAGE_F_COMPRESSED_LZMA2 && IMAGE_F_COMPRESSED_ARM_THUMB_FLT; + + if (slot_flags == (IMAGE_F_COMPRESSED_LZMA2 && IMAGE_F_COMPRESSED_ARM_THUMB_FLT)) { + LOG_INF( + "Secondary slot image is LZMA2 compressed with ARM thumb filter applied"); + } else if (slot_flags & IMAGE_F_COMPRESSED_LZMA2) { + LOG_INF("Secondary slot image is LZMA2 compressed"); + } else { + LOG_INF("Secondary slot image is uncompressed"); + } + } else { + LOG_ERR("Failed to read slot info: %d", rc); + } +} + +static enum mgmt_cb_return image_slot_state_cb(uint32_t event, enum mgmt_cb_return prev_status, + int32_t *rc, uint16_t *group, bool *abort_more, + void *data, size_t data_size) +{ + if (event == MGMT_EVT_OP_IMG_MGMT_IMAGE_SLOT_STATE) { + /* Append a field indicating if the image in the slot is compressed */ + struct img_mgmt_state_slot_encode *slot_data = + (struct img_mgmt_state_slot_encode *)data; + + *slot_data->ok = ZCBOR_ENCODE_FLAG(slot_data->zse, "compressed", + (slot_data->flags & IMAGE_F_COMPRESSED_LZMA2)); + } else if (event == MGMT_EVT_OP_IMG_MGMT_DFU_PENDING) { + (void)k_work_submit(&slot_output_work); + } + + return MGMT_CB_OK; +} + +static int setup_slot_hook(void) +{ + /* Setup hook for when img mgmt image slot state is used and DFU pending callback */ + image_slot_callback.callback = image_slot_state_cb; + image_slot_callback.event_id = MGMT_EVT_OP_IMG_MGMT_IMAGE_SLOT_STATE | + MGMT_EVT_OP_IMG_MGMT_DFU_PENDING; + mgmt_callback_register(&image_slot_callback); + k_work_init(&slot_output_work, slot_output_handler); + + return 0; +} + +SYS_INIT(setup_slot_hook, APPLICATION, 0); diff --git a/samples/nrf_compress/mcuboot_update/sysbuild.conf b/samples/nrf_compress/mcuboot_update/sysbuild.conf new file mode 100644 index 000000000000..43de0cb90004 --- /dev/null +++ b/samples/nrf_compress/mcuboot_update/sysbuild.conf @@ -0,0 +1,12 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y +SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY=y +SB_CONFIG_MCUBOOT_UPDATEABLE_IMAGES=1 +SB_CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT=y +SB_CONFIG_NETCORE_HCI_IPC=y diff --git a/samples/nrf_compress/mcuboot_update/sysbuild/mcuboot.conf b/samples/nrf_compress/mcuboot_update/sysbuild/mcuboot.conf new file mode 100644 index 000000000000..965c33a0e3ee --- /dev/null +++ b/samples/nrf_compress/mcuboot_update/sysbuild/mcuboot.conf @@ -0,0 +1 @@ +CONFIG_BOOT_MAX_IMG_SECTORS=512 diff --git a/samples/nrf_compress/mcuboot_update/testcase.yaml b/samples/nrf_compress/mcuboot_update/testcase.yaml new file mode 100644 index 000000000000..58ef1504905b --- /dev/null +++ b/samples/nrf_compress/mcuboot_update/testcase.yaml @@ -0,0 +1,14 @@ +common: + sysbuild: true + tags: sysbuild + build_only: true +tests: + nrf_compress.mcuboot_update: + platform_allow: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf54l15pdk/nrf54l15/cpuapp + integration_platforms: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf54l15pdk/nrf54l15/cpuapp diff --git a/subsys/bootloader/Kconfig b/subsys/bootloader/Kconfig index 36c5d3d1a844..b7c4eca4b03f 100644 --- a/subsys/bootloader/Kconfig +++ b/subsys/bootloader/Kconfig @@ -241,4 +241,9 @@ rsource "bl_crypto/Kconfig" rsource "bl_validation/Kconfig" rsource "bl_storage/Kconfig" +config MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED + bool "MCUboot compressed image support" + help + This is a Kconfig which is informative only, the value should not be changed. + endmenu diff --git a/subsys/partition_manager/Kconfig b/subsys/partition_manager/Kconfig index e6f397dba61b..e71f0edd1dc6 100644 --- a/subsys/partition_manager/Kconfig +++ b/subsys/partition_manager/Kconfig @@ -245,4 +245,10 @@ config PM_SRAM_SIZE default 0x40000 if SOC_NRF54L15_CPUFLPR # Because the cpuapp_rram DT node is deleted in nrf54l15_cpuflpr.dtsi default $(dt_node_reg_size_hex,/soc/memory@20000000) +config PM_USE_CONFIG_SRAM_SIZE + bool + help + Hidden option that, if set, will use the Kconfig value of PM_SRAM_SIZE for the SRAM size + value instead of the partition-manager project generated output value + endmenu # Partition Manager diff --git a/sysbuild/CMakeLists.txt b/sysbuild/CMakeLists.txt index 48db9417867f..cefa364b3cc5 100644 --- a/sysbuild/CMakeLists.txt +++ b/sysbuild/CMakeLists.txt @@ -346,6 +346,21 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake) set_config_bool(mcuboot CONFIG_USE_NRF53_MULTI_IMAGE_WITHOUT_UPGRADE_ONLY y) endif() endif() + + # Apply image compression support options + if(SB_CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT) + set_config_bool(mcuboot CONFIG_NRF_COMPRESS y) + set_config_bool(mcuboot CONFIG_NRF_COMPRESS_DECOMPRESSION y) + set_config_bool(mcuboot CONFIG_NRF_COMPRESS_LZMA y) + set_config_bool(mcuboot CONFIG_NRF_COMPRESS_LZMA_VERSION_LZMA2 y) + set_config_bool(mcuboot CONFIG_NRF_COMPRESS_ARM_THUMB y) + set_config_bool(mcuboot CONFIG_NRF_COMPRESS_CLEANUP y) + set_config_bool(mcuboot CONFIG_BOOT_DECOMPRESSION y) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED y) + else() + set_config_bool(mcuboot CONFIG_BOOT_DECOMPRESSION n) + set_config_bool(${DEFAULT_IMAGE} CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED n) + endif() endif() if(SB_CONFIG_SECURE_BOOT_APPCORE) diff --git a/sysbuild/Kconfig.mcuboot b/sysbuild/Kconfig.mcuboot index 9af7b1d4e62a..c1dcd48de71a 100644 --- a/sysbuild/Kconfig.mcuboot +++ b/sysbuild/Kconfig.mcuboot @@ -44,6 +44,15 @@ config MCUBOOT_HW_DOWNGRADE_PREVENTION_COUNTER_VALUE endif # MCUBOOT_HARDWARE_DOWNGRADE_PREVENTION +config MCUBOOT_COMPRESSED_IMAGE_SUPPORT + bool "Compressed image support" + depends on MCUBOOT_MODE_OVERWRITE_ONLY + depends on MCUBOOT_UPDATEABLE_IMAGES = "1" + depends on !BOOT_ENCRYPTION + help + When enabled, supports loading compressed images using LZMA2 to the secondary slot which + will then be decompressed and loaded to the primary slot. + config MCUBOOT_MAX_UPDATEABLE_IMAGES int default 4 diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/CMakeLists.txt b/tests/subsys/nrf_compress/decompression/mcuboot_update/CMakeLists.txt new file mode 100644 index 000000000000..5f04e0534b8b --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(mcuboot_update) + +target_sources(app PRIVATE src/main.c) + +zephyr_link_libraries(MCUBOOT_BOOTUTIL) diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/Kconfig b/tests/subsys/nrf_compress/decompression/mcuboot_update/Kconfig new file mode 100644 index 000000000000..96903f993de4 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/Kconfig @@ -0,0 +1,14 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +config UPDATE_SLOT_NUMBER + int "Image update number" + range 0 3 + default 0 + help + Should be set to the image containing the firmware to mark for upgrade + +source "Kconfig.zephyr" diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/app.overlay b/tests/subsys/nrf_compress/decompression/mcuboot_update/app.overlay new file mode 100644 index 000000000000..fcc2e240fd9e --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/app.overlay @@ -0,0 +1,5 @@ +/ { + chosen { + nordic,pm-ext-flash = &mx25r64; + }; +}; diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/CMakeLists.txt b/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/CMakeLists.txt new file mode 100644 index 000000000000..815648839be3 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(smp_svr) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/prj.conf b/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/prj.conf new file mode 100644 index 000000000000..66a29df8fe48 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/prj.conf @@ -0,0 +1,7 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +CONFIG_LOG=y diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/src/main.c b/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/src/main.c new file mode 100644 index 000000000000..3f1e858a0f50 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/compressed_app/src/main.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include + +LOG_MODULE_REGISTER(compressed_app, LOG_LEVEL_DBG); + +int main(void) +{ + LOG_INF("Compressed image running"); + + return 0; +} diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/modified_signing.cmake b/tests/subsys/nrf_compress/decompression/mcuboot_update/modified_signing.cmake new file mode 100644 index 000000000000..5360a5baad19 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/modified_signing.cmake @@ -0,0 +1,17 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +set(CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED y) +set(ncs_compress_test_compress_hex y) +include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/image_signing.cmake) +set(output ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME}.moved.signed.hex) +set(BYPRODUCT_KERNEL_SIGNED_HEX_NAME "${output}" + CACHE FILEPATH "Signed kernel hex file" FORCE + ) +set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND + ${CMAKE_OBJCOPY} -I ihex -O ihex --change-addresses 0x92000 + ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME}.signed.hex ${output}) +set_property(GLOBAL APPEND PROPERTY extra_post_build_byproducts ${output}) diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf52840dk_nrf52840.yml b/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf52840dk_nrf52840.yml new file mode 100644 index 000000000000..4ed838ca157c --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf52840dk_nrf52840.yml @@ -0,0 +1,60 @@ +app: + address: 0x10200 + end_address: 0xa2000 + region: flash_primary + size: 0x91e00 +EMPTY_1: + address: 0x0 + end_address: 0x10200 + device: MX25R64 + region: external_flash + size: 0x10200 +compressed_app: + address: 0x10200 + end_address: 0xa2000 + device: MX25R64 + region: external_flash + size: 0x91e00 +EMPTY_2: + address: 0xa2000 + end_address: 0x800000 + device: MX25R64 + region: external_flash + size: 0x75e000 +mcuboot: + address: 0x0 + end_address: 0x10000 + region: flash_primary + size: 0x10000 +mcuboot_pad: + address: 0x10000 + end_address: 0x10200 + region: flash_primary + size: 0x200 +mcuboot_primary: + address: 0x10000 + end_address: 0xa2000 + orig_span: &id001 + - mcuboot_pad + - app + region: flash_primary + size: 0x92000 + span: *id001 +mcuboot_primary_app: + address: 0x10200 + end_address: 0xa2000 + orig_span: &id002 + - app + region: flash_primary + size: 0x91e00 + span: *id002 +mcuboot_secondary: + address: 0xa2000 + end_address: 0xf0000 + region: flash_primary + size: 0x4e000 +settings_storage: + address: 0xf0000 + end_address: 0x100000 + region: flash_primary + size: 0x10000 diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf5340dk_nrf5340_cpuapp.yml b/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf5340dk_nrf5340_cpuapp.yml new file mode 100644 index 000000000000..6e8197cc8abd --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf5340dk_nrf5340_cpuapp.yml @@ -0,0 +1,78 @@ +app: + address: 0x10200 + end_address: 0xa2000 + region: flash_primary + size: 0x91e00 +EMPTY_1: + address: 0x0 + end_address: 0x10200 + device: MX25R64 + region: external_flash + size: 0x10200 +compressed_app: + address: 0x10200 + end_address: 0xa2000 + device: MX25R64 + region: external_flash + size: 0x91e00 +EMPTY_2: + address: 0xa2000 + end_address: 0x800000 + device: MX25R64 + region: external_flash + size: 0x75e000 +mcuboot: + address: 0x0 + end_address: 0x10000 + region: flash_primary + size: 0x10000 +mcuboot_pad: + address: 0x10000 + end_address: 0x10200 + region: flash_primary + size: 0x200 +mcuboot_primary: + address: 0x10000 + end_address: 0xa2000 + orig_span: &id001 + - mcuboot_pad + - app + region: flash_primary + size: 0x92000 + span: *id001 +mcuboot_primary_app: + address: 0x10200 + end_address: 0xa2000 + orig_span: &id002 + - app + region: flash_primary + size: 0x91e00 + span: *id002 +mcuboot_secondary: + address: 0xa2000 + end_address: 0xf0000 + region: flash_primary + size: 0x4e000 +otp: + address: 0xff8100 + end_address: 0xff83fc + region: otp + size: 0x2fc +rpmsg_nrf53_sram: + address: 0x20070000 + end_address: 0x20080000 + placement: + before: + - end + region: sram_primary + size: 0x10000 +settings_storage: + address: 0xf0000 + end_address: 0x100000 + region: flash_primary + size: 0x10000 +sram_primary: + address: 0x20000000 + end_address: 0x20070000 + region: sram_primary + size: 0x70000 diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf54l15dk_nrf54l15_cpuapp.yml b/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf54l15dk_nrf54l15_cpuapp.yml new file mode 100644 index 000000000000..29091d59e17f --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/pm_static_nrf54l15dk_nrf54l15_cpuapp.yml @@ -0,0 +1,65 @@ +app: + address: 0x10800 + end_address: 0xa2000 + region: flash_primary + size: 0x91800 +EMPTY_1: + address: 0x0 + end_address: 0x10800 + device: MX25R64 + region: external_flash + size: 0x10800 +compressed_app: + address: 0x10800 + end_address: 0xa2000 + device: MX25R64 + region: external_flash + size: 0x91800 +EMPTY_2: + address: 0xa2000 + end_address: 0x800000 + device: MX25R64 + region: external_flash + size: 0x75e000 +EMPTY_3: + address: 0x100000 + end_address: 0x165000 + region: flash_primary + size: 0x65000 +mcuboot: + address: 0x0 + end_address: 0x10000 + region: flash_primary + size: 0x10000 +mcuboot_pad: + address: 0x10000 + end_address: 0x10800 + region: flash_primary + size: 0x800 +mcuboot_primary: + address: 0x10000 + end_address: 0xa2000 + orig_span: &id001 + - mcuboot_pad + - app + region: flash_primary + size: 0x92000 + span: *id001 +mcuboot_primary_app: + address: 0x10800 + end_address: 0xa2000 + orig_span: &id002 + - app + region: flash_primary + size: 0x91800 + span: *id002 +mcuboot_secondary: + address: 0xa2000 + end_address: 0xf0000 + region: flash_primary + size: 0x4e000 +settings_storage: + address: 0xf0000 + end_address: 0x100000 + region: flash_primary + size: 0x10000 diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/prj.conf b/tests/subsys/nrf_compress/decompression/mcuboot_update/prj.conf new file mode 100644 index 000000000000..8205e1bb6fd5 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/prj.conf @@ -0,0 +1,22 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Enable MCUmgr and dependencies. +CONFIG_STREAM_FLASH=y +CONFIG_FLASH_MAP=y + +# Enable flash operations. +CONFIG_FLASH=y + +# Enable most core commands. +CONFIG_FLASH=y +CONFIG_IMG_MANAGER=y + +# Enable logging +CONFIG_LOG=y +CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y + +CONFIG_REBOOT=y diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/src/main.c b/tests/subsys/nrf_compress/decompression/mcuboot_update/src/main.c new file mode 100644 index 000000000000..ef0a992d1e2a --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/src/main.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_REGISTER(mcuboot_update, LOG_LEVEL_DBG); + +#define UPDATE_SLOT_NUMBER CONFIG_UPDATE_SLOT_NUMBER + +#if CONFIG_UPDATE_SLOT_NUMBER == 0 +#define UPDATE_SLOT_ID PM_MCUBOOT_SECONDARY_ID +#else +#define UPDATE_SLOT_ID PM_MCUBOOT_SECONDARY_ ## CONFIG_UPDATE_SLOT_NUMBER ## _ID +#endif + +int main(void) +{ + int rc; + struct image_header header; + const struct flash_area *fa; + + rc = flash_area_open(UPDATE_SLOT_ID, &fa); + + if (rc) { + LOG_ERR("Flash area open failed"); + + return 0; + } + + rc = flash_area_read(fa, 0, &header, sizeof(header)); + + flash_area_close(fa); + + if (rc) { + LOG_ERR("Flash area read failed"); + + return 0; + } + + header.ih_magic = sys_le32_to_cpu(header.ih_magic); + header.ih_hdr_size = sys_le16_to_cpu(header.ih_hdr_size); + header.ih_flags = sys_le32_to_cpu(header.ih_flags); + + if (header.ih_magic != IMAGE_MAGIC) { + LOG_ERR("Invalid header"); + + return 0; + } + + if ((header.ih_flags & IMAGE_F_COMPRESSED_LZMA2) == 0) { + LOG_ERR("Invalid image flags"); + + return 0; + } + + rc = boot_request_upgrade_multi(UPDATE_SLOT_NUMBER, true); + + if (rc) { + LOG_ERR("Update of image %d failed: %d", UPDATE_SLOT_NUMBER, rc); + k_sleep(K_SECONDS(1)); + + return 0; + } + + sys_reboot(SYS_REBOOT_COLD); + + return 0; +} diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild.cmake b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild.cmake new file mode 100644 index 000000000000..8f5c5427a8a8 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild.cmake @@ -0,0 +1,18 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +ExternalZephyrProject_Add( + APPLICATION compressed_app + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/compressed_app +) + +set_config_bool(compressed_app CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOOTLOADER_MCUBOOT}") +set_config_string(compressed_app CONFIG_MCUBOOT_SIGNATURE_KEY_FILE + "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}" +) +set_config_bool(compressed_app CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY y) +set(compressed_app_SIGNING_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/modified_signing.cmake" CACHE INTERNAL "MCUboot signing script" FORCE) +set_config_bool(compressed_app CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT_ENABLED y) diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild.conf b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild.conf new file mode 100644 index 000000000000..e2cb5bfe879d --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild.conf @@ -0,0 +1,11 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY=y +SB_CONFIG_MCUBOOT_UPDATEABLE_IMAGES=1 +SB_CONFIG_MCUBOOT_COMPRESSED_IMAGE_SUPPORT=y +SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/app.overlay b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/app.overlay new file mode 100644 index 000000000000..a9c88d6227f3 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/app.overlay @@ -0,0 +1,6 @@ +/ { + chosen { + zephyr,code-partition = &boot_partition; + nordic,pm-ext-flash = &mx25r64; + }; +}; diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf52840dk_nrf52840.conf b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 000000000000..7b9508f1d6f9 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1,8 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Ensure that the qspi driver is enabled by default +CONFIG_NORDIC_QSPI_NOR=y diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp.conf b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp.conf new file mode 100644 index 000000000000..ef36c45d402c --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp.conf @@ -0,0 +1,13 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# Ensure that the SPI NOR driver is enabled by default +CONFIG_SPI_NOR=n + +# TODO: below are not yet supported and need fixing +CONFIG_FPROTECT=n + +CONFIG_BOOT_WATCHDOG_FEED=n diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp.overlay new file mode 100644 index 000000000000..f19ab2ad78e0 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/ { + chosen { + nordic,pm-ext-flash = &mx25r64; + zephyr,code-partition = &boot_partition; + }; +}; + +// restore full SRAM space - by default some parts are dedicated to FLRP +&cpuapp_sram { + reg = <0x20000000 DT_SIZE_K(256)>; + ranges = <0x0 0x20000000 0x40000>; +}; diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/prj.conf b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/prj.conf new file mode 100644 index 000000000000..b6cb428120d0 --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/sysbuild/mcuboot/prj.conf @@ -0,0 +1,44 @@ +CONFIG_PM=n + +CONFIG_MAIN_STACK_SIZE=10240 +CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h" + +CONFIG_BOOT_SWAP_SAVE_ENCTLV=n +CONFIG_BOOT_ENCRYPT_IMAGE=n + +CONFIG_BOOT_UPGRADE_ONLY=n +CONFIG_BOOT_BOOTSTRAP=n + +### mbedTLS has its own heap +# CONFIG_HEAP_MEM_POOL_SIZE is not set + +### We never want Zephyr's copy of tinycrypt. If tinycrypt is needed, +### MCUboot has its own copy in tree. +# CONFIG_TINYCRYPT is not set +# CONFIG_TINYCRYPT_ECC_DSA is not set +# CONFIG_TINYCRYPT_SHA256 is not set + +CONFIG_FLASH=y +CONFIG_FPROTECT=y + +### Various Zephyr boards enable features that we don't want. +# CONFIG_BT is not set +# CONFIG_BT_CTLR is not set +# CONFIG_I2C is not set + +CONFIG_LOG=y +CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL +### Ensure Zephyr logging changes don't use more resources +CONFIG_LOG_DEFAULT_LEVEL=0 +### Use info log level by default +CONFIG_MCUBOOT_LOG_LEVEL_INF=y +### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y +CONFIG_CBPRINTF_NANO=y +### Use the minimal C library to reduce flash usage +CONFIG_MINIMAL_LIBC=y +CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=0 + +# NCS boot banner +CONFIG_NCS_APPLICATION_BOOT_BANNER_STRING="MCUboot" +CONFIG_BOOT_MAX_IMG_SECTORS=512 +CONFIG_MULTITHREADING=y diff --git a/tests/subsys/nrf_compress/decompression/mcuboot_update/testcase.yaml b/tests/subsys/nrf_compress/decompression/mcuboot_update/testcase.yaml new file mode 100644 index 000000000000..4f189bb7335d --- /dev/null +++ b/tests/subsys/nrf_compress/decompression/mcuboot_update/testcase.yaml @@ -0,0 +1,31 @@ +common: + sysbuild: true + tags: sysbuild +tests: + nrf_compress.decompression.mcuboot_update: + platform_allow: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf54l15dk/nrf54l15/cpuapp + integration_platforms: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf54l15dk/nrf54l15/cpuapp + harness: console + harness_config: + type: multi_line + ordered: true + regex: + - "Starting bootloader" + - "Image index: 0, Swap type: none" + - "Bootloader chainload address offset:" + - "Jumping to the first image slot" + - "Starting bootloader" + - "Image index: 0, Swap type: perm" + - "Image 0 upgrade secondary slot -> primary slot" + - "Erasing the primary slot" + - "Image 0 copying the secondary slot to the primary slot" + - "Bootloader chainload address offset:" + - "Jumping to the first image slot" + - "Booting nRF Connect SDK" + - "Compressed image running" diff --git a/west.yml b/west.yml index 005121f0442f..3a3c634a2548 100644 --- a/west.yml +++ b/west.yml @@ -132,7 +132,7 @@ manifest: compare-by-default: true - name: mcuboot repo-path: sdk-mcuboot - revision: 22adc04fc4b35a6ee477675c8a33e038a98258de + revision: 94212b4e3853b7b09acf0e2e1ec2b895bbbb2948 path: bootloader/mcuboot - name: qcbor url: https://github.com/laurencelundblade/QCBOR