Skip to content
Closed
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 @@ -469,6 +469,32 @@
(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( \

Check notice on line 480 in include/zephyr/storage/flash_map.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/storage/flash_map.h:480 -#define FIXED_PARTITION_MTD(label) \ +#define FIXED_PARTITION_MTD(label) \

Check notice on line 480 in include/zephyr/storage/flash_map.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/storage/flash_map.h:480 -#define FIXED_PARTITION_MTD(label) \ +#define FIXED_PARTITION_MTD(label) \
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( \

Check notice on line 493 in include/zephyr/storage/flash_map.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/storage/flash_map.h:493 -#define FIXED_PARTITION_NODE_MTD(node) \ +#define FIXED_PARTITION_NODE_MTD(node) \

Check notice on line 493 in include/zephyr/storage/flash_map.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/storage/flash_map.h:493 -#define FIXED_PARTITION_NODE_MTD(node) \ +#define FIXED_PARTITION_NODE_MTD(node) \
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 @@ -41,17 +41,23 @@
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( \

Check notice on line 45 in soc/nordic/nrf54h/soc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/nordic/nrf54h/soc.c:45 -#define FIXED_PARTITION_NODE_MTD(node) \ +#define FIXED_PARTITION_NODE_MTD(node) \

Check notice on line 45 in soc/nordic/nrf54h/soc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/nordic/nrf54h/soc.c:45 -#define FIXED_PARTITION_NODE_MTD(node) \ +#define FIXED_PARTITION_NODE_MTD(node) \
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)

Check notice on line 60 in soc/nordic/nrf54h/soc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/nordic/nrf54h/soc.c:60 - 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) + 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)

Check notice on line 60 in soc/nordic/nrf54h/soc.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/nordic/nrf54h/soc.c:60 - 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) + 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)
sys_snode_t soc_node;

#define FICR_ADDR_GET(node_id, name) \
Expand Down Expand Up @@ -210,7 +216,7 @@
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
4 changes: 3 additions & 1 deletion subsys/dfu/img_util/flash_img.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <zephyr/logging/log.h>
#include <zephyr/devicetree.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/dfu/flash_img.h>
#include <zephyr/dfu/mcuboot.h>
Expand All @@ -24,10 +25,11 @@
#endif

#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(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)

Check notice on line 32 in subsys/dfu/img_util/flash_img.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/dfu/img_util/flash_img.c:32 - FIXED_PARTITION_MTD(label)) && \ - (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ - FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) + FIXED_PARTITION_MTD(label)) && \ + (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ + FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > \ + CONFIG_FLASH_LOAD_OFFSET)

Check notice on line 32 in subsys/dfu/img_util/flash_img.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/dfu/img_util/flash_img.c:32 - FIXED_PARTITION_MTD(label)) && \ - (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ - FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) + FIXED_PARTITION_MTD(label)) && \ + (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ + FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > \ + CONFIG_FLASH_LOAD_OFFSET)
#include <zephyr/devicetree.h>
#if defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) && (CONFIG_TFM_MCUBOOT_IMAGE_NUMBER == 2)
#define UPLOAD_FLASH_AREA_LABEL slot1_ns_partition
#else
Expand Down
4 changes: 3 additions & 1 deletion subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -49,9 +49,11 @@
#endif

#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(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)

Check notice on line 56 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c:56 - FIXED_PARTITION_MTD(label)) && \ - (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ - FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) + FIXED_PARTITION_MTD(label)) && \ + (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ + FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > \ + CONFIG_FLASH_LOAD_OFFSET)

Check notice on line 56 in subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c:56 - FIXED_PARTITION_MTD(label)) && \ - (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ - FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) + FIXED_PARTITION_MTD(label)) && \ + (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ + FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > \ + CONFIG_FLASH_LOAD_OFFSET)
BUILD_ASSERT(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
"struct image_header not required size");

Expand Down
3 changes: 3 additions & 0 deletions tests/subsys/dfu/img_util/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
*/

#include <zephyr/ztest.h>
#include <zephyr/devicetree.h>
#include <zephyr/storage/flash_map.h>
#include <zephyr/dfu/flash_img.h>

#define SLOT0_PARTITION slot0_partition
#define SLOT1_PARTITION slot1_partition

#define FIXED_PARTITION_IS_RUNNING_APP_PARTITION(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)

Check notice on line 21 in tests/subsys/dfu/img_util/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/dfu/img_util/src/main.c:21 - FIXED_PARTITION_MTD(label)) && \ - (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ - FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) + FIXED_PARTITION_MTD(label)) && \ + (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ + FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > \ + CONFIG_FLASH_LOAD_OFFSET)

Check notice on line 21 in tests/subsys/dfu/img_util/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/dfu/img_util/src/main.c:21 - FIXED_PARTITION_MTD(label)) && \ - (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ - FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > CONFIG_FLASH_LOAD_OFFSET) + FIXED_PARTITION_MTD(label)) && \ + (FIXED_PARTITION_OFFSET(label) <= CONFIG_FLASH_LOAD_OFFSET && \ + FIXED_PARTITION_OFFSET(label) + FIXED_PARTITION_SIZE(label) > \ + CONFIG_FLASH_LOAD_OFFSET)
#if FIXED_PARTITION_IS_RUNNING_APP_PARTITION(slot0_partition)
#define UPLOAD_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION)
#define RUNNING_PARTITION_ID FIXED_PARTITION_ID(SLOT0_PARTITION)
Expand Down
Loading