From 4a322a3407dfc6ebb9e5a5335908ad849f1ffbe8 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 21 Nov 2025 08:26:32 +0000 Subject: [PATCH 1/5] [nrf fromtree] mgmt: mcumgr: grp: img_mgmt: Fix detecting where a slot resides Fixes an issue introduced in commit 32615695ad1b96670be8f2a38a8a9fd27e2d8ae5 which wrongly did not check what the residing device was on before determining if a slot was part of a partition area Signed-off-by: Jamie McCrae (cherry picked from commit ae2b4a44dc0d675aa90d62b46a52d04374ba8419) --- subsys/dfu/img_util/flash_img.c | 8 +++++++- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c | 8 +++++++- tests/subsys/dfu/img_util/src/main.c | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/subsys/dfu/img_util/flash_img.c b/subsys/dfu/img_util/flash_img.c index 24e95a8dc1a9..152aaabe17ae 100644 --- a/subsys/dfu/img_util/flash_img.c +++ b/subsys/dfu/img_util/flash_img.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -23,11 +24,16 @@ LOG_MODULE_REGISTER(flash_img, CONFIG_IMG_MANAGER_LOG_LEVEL); #include #endif +#define FIXED_PARTITION_GET_FLASH_NODE(node_id) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions), \ + (DT_PARENT(DT_GPARENT(node_id))), (DT_GPARENT(node_id))) + #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ + DT_SAME_NODE(FIXED_PARTITION_GET_FLASH_NODE(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_GET_FLASH_NODE(DT_NODELABEL(label))) && \ (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) -#include #if defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) && (CONFIG_TFM_MCUBOOT_IMAGE_NUMBER == 2) #define UPLOAD_FLASH_AREA_LABEL slot1_ns_partition #else diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c index a2bf006b9474..5e52a9fa5c15 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2018-2021 mcumgr authors - * Copyright (c) 2022-2024 Nordic Semiconductor ASA + * Copyright (c) 2022-2025 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ @@ -48,7 +48,13 @@ to be able to figure out application running slot. #endif +#define FIXED_PARTITION_GET_FLASH_NODE(node_id) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions), \ + (DT_PARENT(DT_GPARENT(node_id))), (DT_GPARENT(node_id))) + #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ + DT_SAME_NODE(FIXED_PARTITION_GET_FLASH_NODE(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_GET_FLASH_NODE(DT_NODELABEL(label))) && \ (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) diff --git a/tests/subsys/dfu/img_util/src/main.c b/tests/subsys/dfu/img_util/src/main.c index 33956be6251e..013498f49bd3 100644 --- a/tests/subsys/dfu/img_util/src/main.c +++ b/tests/subsys/dfu/img_util/src/main.c @@ -6,13 +6,20 @@ */ #include +#include #include #include #define SLOT0_PARTITION slot0_partition #define SLOT1_PARTITION slot1_partition +#define FIXED_PARTITION_GET_FLASH_NODE(node_id) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions), \ + (DT_PARENT(DT_GPARENT(node_id))), (DT_GPARENT(node_id))) + #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ + DT_SAME_NODE(FIXED_PARTITION_GET_FLASH_NODE(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_GET_FLASH_NODE(DT_NODELABEL(label))) && \ (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) From 2a67e320de3eed862729a3461e7cc11cb460faa0 Mon Sep 17 00:00:00 2001 From: Tomasz Chyrowicz Date: Fri, 21 Nov 2025 12:05:44 +0100 Subject: [PATCH 2/5] [nrf fromlist] flash_map: Add a macro to fetch controller ID Add a macro that allows to get the node identifier of the flash controller the area/partition resides on. Upstream PR #: 99800 Signed-off-by: Tomasz Chyrowicz --- include/zephyr/storage/flash_map.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/include/zephyr/storage/flash_map.h b/include/zephyr/storage/flash_map.h index 9dc6bd91438f..558a0a0b7e72 100644 --- a/include/zephyr/storage/flash_map.h +++ b/include/zephyr/storage/flash_map.h @@ -19,7 +19,7 @@ * * @defgroup flash_area_api flash area Interface * @since 1.11 - * @version 1.0.0 + * @version 1.1.0 * @ingroup storage_apis * @{ */ @@ -469,6 +469,32 @@ uint8_t flash_area_erased_val(const struct flash_area *fa); (DT_MTD_FROM_FIXED_SUBPARTITION(node)), \ (DT_MTD_FROM_FIXED_PARTITION(node)))) +/** + * Get the node identifier of the flash controller the area/partition resides on + * + * @param label DTS node label of a partition + * + * @return Pointer to a device. + */ +#define FIXED_PARTITION_MTD(label) \ + COND_CODE_1( \ + DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)), \ + (DT_MTD_FROM_FIXED_SUBPARTITION(DT_NODELABEL(label))), \ + (DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))) + +/** + * Get the node identifier of the flash controller the area/partition resides on + * + * @param node DTS node of a partition + * + * @return Pointer to a device. + */ +#define FIXED_PARTITION_NODE_MTD(node) \ + COND_CODE_1( \ + DT_FIXED_SUBPARTITION_EXISTS(node), \ + (DT_MTD_FROM_FIXED_SUBPARTITION(node)), \ + (DT_MTD_FROM_FIXED_PARTITION(node))) + /** * Get pointer to flash_area object by partition label * From 17da85aa4e28db37b8190760572e3ed1c3b2dc37 Mon Sep 17 00:00:00 2001 From: Tomasz Chyrowicz Date: Thu, 20 Nov 2025 15:18:09 +0100 Subject: [PATCH 3/5] [nrf fromlist] soc: Use absolute address in active partition Use absolute addresses while determining a running application partition. Upstream PR #: 99800 Signed-off-by: Tomasz Chyrowicz --- soc/nordic/nrf54h/soc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/soc/nordic/nrf54h/soc.c b/soc/nordic/nrf54h/soc.c index c291767d0906..7886689dbb8d 100644 --- a/soc/nordic/nrf54h/soc.c +++ b/soc/nordic/nrf54h/soc.c @@ -41,14 +41,20 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL); DT_REG_ADDR(COND_CODE_1(DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)), \ (DT_GPARENT(DT_PARENT(DT_NODELABEL(label)))), \ (DT_GPARENT(DT_NODELABEL(label)))))) +#define FIXED_PARTITION_NODE_MTD(node) \ + COND_CODE_1( \ + DT_FIXED_SUBPARTITION_EXISTS(node), \ + (DT_MTD_FROM_FIXED_SUBPARTITION(node)), \ + (DT_MTD_FROM_FIXED_PARTITION(node))) #ifdef CONFIG_USE_DT_CODE_PARTITION #define FLASH_LOAD_OFFSET DT_REG_ADDR(DT_CHOSEN(zephyr_code_partition)) #elif defined(CONFIG_FLASH_LOAD_OFFSET) #define FLASH_LOAD_OFFSET CONFIG_FLASH_LOAD_OFFSET #endif - -#define PARTITION_IS_RUNNING_APP_PARTITION(label) \ +#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ + DT_SAME_NODE(FIXED_PARTITION_NODE_MTD(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_NODE_MTD(DT_NODELABEL(label))) && \ (DT_REG_ADDR(DT_NODELABEL(label)) <= FLASH_LOAD_OFFSET && \ DT_REG_ADDR(DT_NODELABEL(label)) + DT_REG_SIZE(DT_NODELABEL(label)) > FLASH_LOAD_OFFSET) @@ -210,7 +216,7 @@ void soc_late_init_hook(void) void *radiocore_address = NULL; #if DT_NODE_EXISTS(DT_NODELABEL(cpurad_slot1_partition)) - if (PARTITION_IS_RUNNING_APP_PARTITION(cpuapp_slot1_partition)) { + if (FIXED_PARTITION_IS_RUNNING_APP_PARTITION(cpuapp_slot1_partition)) { radiocore_address = (void *)(FIXED_PARTITION_ADDRESS(cpurad_slot1_partition) + CONFIG_ROM_START_OFFSET); } else { From 56517a53bb9e33135f19712f1cbc4ac02e16f793 Mon Sep 17 00:00:00 2001 From: Tomasz Chyrowicz Date: Thu, 20 Nov 2025 15:19:09 +0100 Subject: [PATCH 4/5] [nrf fromlist] img_util: Use absolute address in active partition Use absolute addresses while determining a running application partition. Upstream PR #: 99800 Signed-off-by: Tomasz Chyrowicz --- subsys/dfu/img_util/flash_img.c | 8 ++------ tests/subsys/dfu/img_util/src/main.c | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/subsys/dfu/img_util/flash_img.c b/subsys/dfu/img_util/flash_img.c index 152aaabe17ae..d3c9749401b2 100644 --- a/subsys/dfu/img_util/flash_img.c +++ b/subsys/dfu/img_util/flash_img.c @@ -24,13 +24,9 @@ LOG_MODULE_REGISTER(flash_img, CONFIG_IMG_MANAGER_LOG_LEVEL); #include #endif -#define FIXED_PARTITION_GET_FLASH_NODE(node_id) \ - COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions), \ - (DT_PARENT(DT_GPARENT(node_id))), (DT_GPARENT(node_id))) - #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ - DT_SAME_NODE(FIXED_PARTITION_GET_FLASH_NODE(DT_CHOSEN(zephyr_code_partition)), \ - FIXED_PARTITION_GET_FLASH_NODE(DT_NODELABEL(label))) && \ + DT_SAME_NODE(FIXED_PARTITION_NODE_MTD(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_MTD(label)) && \ (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) diff --git a/tests/subsys/dfu/img_util/src/main.c b/tests/subsys/dfu/img_util/src/main.c index 013498f49bd3..c0b5d96daeb1 100644 --- a/tests/subsys/dfu/img_util/src/main.c +++ b/tests/subsys/dfu/img_util/src/main.c @@ -13,13 +13,9 @@ #define SLOT0_PARTITION slot0_partition #define SLOT1_PARTITION slot1_partition -#define FIXED_PARTITION_GET_FLASH_NODE(node_id) \ - COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions), \ - (DT_PARENT(DT_GPARENT(node_id))), (DT_GPARENT(node_id))) - #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ - DT_SAME_NODE(FIXED_PARTITION_GET_FLASH_NODE(DT_CHOSEN(zephyr_code_partition)), \ - FIXED_PARTITION_GET_FLASH_NODE(DT_NODELABEL(label))) && \ + DT_SAME_NODE(FIXED_PARTITION_NODE_MTD(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_MTD(label)) && \ (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) From 78626a68d4f57b357244ab82e61e3077675bda6b Mon Sep 17 00:00:00 2001 From: Tomasz Chyrowicz Date: Thu, 20 Nov 2025 15:20:23 +0100 Subject: [PATCH 5/5] [nrf fromlist] img_mgmt: Use absolute address in active partition Use absolute addresses while determining a running application partition. Upstream PR #: 99800 Signed-off-by: Tomasz Chyrowicz --- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c index 5e52a9fa5c15..97fc430e374a 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c @@ -48,13 +48,9 @@ to be able to figure out application running slot. #endif -#define FIXED_PARTITION_GET_FLASH_NODE(node_id) \ - COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions), \ - (DT_PARENT(DT_GPARENT(node_id))), (DT_GPARENT(node_id))) - #define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(label) \ - DT_SAME_NODE(FIXED_PARTITION_GET_FLASH_NODE(DT_CHOSEN(zephyr_code_partition)), \ - FIXED_PARTITION_GET_FLASH_NODE(DT_NODELABEL(label))) && \ + DT_SAME_NODE(FIXED_PARTITION_NODE_MTD(DT_CHOSEN(zephyr_code_partition)), \ + FIXED_PARTITION_MTD(label)) && \ (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET)