Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion include/zephyr/storage/flash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @{
*/
Expand Down Expand Up @@ -465,6 +465,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
*
Expand Down
12 changes: 9 additions & 3 deletions soc/nordic/nrf54h/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,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)

Expand Down Expand Up @@ -198,7 +204,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 {
Expand Down
8 changes: 2 additions & 6 deletions subsys/dfu/img_util/flash_img.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ LOG_MODULE_REGISTER(flash_img, CONFIG_IMG_MANAGER_LOG_LEVEL);
#include <bootutil/bootutil_public.h>
#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)

Expand Down
8 changes: 2 additions & 6 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 2 additions & 6 deletions tests/subsys/dfu/img_util/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down