Skip to content

Commit abebf5a

Browse files
committed
boot: zephyr: Switch to partition macros without FIXED_ prefix
Allows usage of MCUboot on devices using fixed-partitions and zephyr,mapped-partition compatibiles Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 7445cbb commit abebf5a

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

boot/zephyr/boot_serial_extension_zephyr_basic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/mgmt/mcumgr/grp/zephyr/zephyr_basic.h>
1212

1313
#include <flash_map_backend/flash_map_backend.h>
14+
#include <zephyr/devicetree/partitions.h>
1415
#include <sysflash/sysflash.h>
1516

1617
#include "bootutil/bootutil_log.h"
@@ -41,7 +42,7 @@ static int bs_custom_storage_erase(const struct nmgr_hdr *hdr,
4142
return MGMT_ERR_ENOTSUP;
4243
}
4344

44-
rc = flash_area_open(FIXED_PARTITION_ID(storage_partition), &fa);
45+
rc = flash_area_open(PARTITION_ID(storage_partition), &fa);
4546

4647
if (rc < 0) {
4748
BOOT_LOG_ERR("failed to open flash area");

boot/zephyr/flash_map_extended.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "target.h"
1313

1414
#include <flash_map_backend/flash_map_backend.h>
15+
#include <zephyr/devicetree/partitions.h>
1516
#include <sysflash/sysflash.h>
1617

1718
#include "bootutil/boot_hooks.h"
@@ -136,26 +137,26 @@ int flash_area_id_from_direct_image(int image_id)
136137
switch (image_id) {
137138
case 0:
138139
case 1:
139-
return FIXED_PARTITION_ID(slot0_partition);
140-
#if FIXED_PARTITION_EXISTS(slot1_partition)
140+
return PARTITION_ID(slot0_partition);
141+
#if PARTITION_EXISTS(slot1_partition)
141142
case 2:
142-
return FIXED_PARTITION_ID(slot1_partition);
143+
return PARTITION_ID(slot1_partition);
143144
#endif
144-
#if FIXED_PARTITION_EXISTS(slot2_partition)
145+
#if PARTITION_EXISTS(slot2_partition)
145146
case 3:
146-
return FIXED_PARTITION_ID(slot2_partition);
147+
return PARTITION_ID(slot2_partition);
147148
#endif
148-
#if FIXED_PARTITION_EXISTS(slot3_partition)
149+
#if PARTITION_EXISTS(slot3_partition)
149150
case 4:
150-
return FIXED_PARTITION_ID(slot3_partition);
151+
return PARTITION_ID(slot3_partition);
151152
#endif
152-
#if FIXED_PARTITION_EXISTS(slot4_partition)
153+
#if PARTITION_EXISTS(slot4_partition)
153154
case 5:
154-
return FIXED_PARTITION_ID(slot4_partition);
155+
return PARTITION_ID(slot4_partition);
155156
#endif
156-
#if FIXED_PARTITION_EXISTS(slot5_partition)
157+
#if PARTITION_EXISTS(slot5_partition)
157158
case 6:
158-
return FIXED_PARTITION_ID(slot5_partition);
159+
return PARTITION_ID(slot5_partition);
159160
#endif
160161
}
161162
return -EINVAL;

boot/zephyr/include/sysflash/sysflash.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <mcuboot_config/mcuboot_config.h>
1111
#include <zephyr/devicetree.h>
1212
#include <zephyr/storage/flash_map.h>
13+
#include <zephyr/devicetree/partitions.h>
1314
#include <zephyr/sys/util_macro.h>
1415

1516
#ifndef SOC_FLASH_0_ID
@@ -81,7 +82,7 @@
8182
static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
8283
{
8384
static const int all_slots[] = {
84-
FOR_EACH_NONEMPTY_TERM(FIXED_PARTITION_ID, (,), ALL_AVAILABLE_SLOTS)
85+
FOR_EACH_NONEMPTY_TERM(PARTITION_ID, (,), ALL_AVAILABLE_SLOTS)
8586
};
8687
return all_slots[img * 2 + slot];
8788
};
@@ -100,13 +101,13 @@ static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
100101
#define FLASH_AREA_IMAGE_SECONDARY(x) __flash_area_ids_for_slot(x, 1)
101102

102103
#if !defined(CONFIG_BOOT_SWAP_USING_MOVE) && !defined(CONFIG_BOOT_SWAP_USING_OFFSET)
103-
#define FLASH_AREA_IMAGE_SCRATCH FIXED_PARTITION_ID(scratch_partition)
104+
#define FLASH_AREA_IMAGE_SCRATCH PARTITION_ID(scratch_partition)
104105
#endif
105106

106107
#else /* !CONFIG_SINGLE_APPLICATION_SLOT && !CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP */
107108

108-
#define FLASH_AREA_IMAGE_PRIMARY(x) FIXED_PARTITION_ID(slot0_partition)
109-
#define FLASH_AREA_IMAGE_SECONDARY(x) FIXED_PARTITION_ID(slot0_partition)
109+
#define FLASH_AREA_IMAGE_PRIMARY(x) PARTITION_ID(slot0_partition)
110+
#define FLASH_AREA_IMAGE_SECONDARY(x) PARTITION_ID(slot0_partition)
110111

111112
#endif /* CONFIG_SINGLE_APPLICATION_SLOT */
112113

boot/zephyr/include/target.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <zephyr/devicetree.h>
2323
#include <soc.h>
2424
#include <zephyr/storage/flash_map.h>
25+
#include <zephyr/devicetree/partitions.h>
2526

2627
#define FLASH_ALIGN FLASH_WRITE_BLOCK_SIZE
2728

@@ -36,14 +37,14 @@
3637
!defined(CONFIG_SOC_FAMILY_ESPRESSIF_ESP32)) || \
3738
(defined(CONFIG_SOC_SERIES_NRF54H) && !DT_HAS_CHOSEN(zephyr_flash)) || \
3839
!defined(FLASH_ALIGN) || \
39-
!(FIXED_PARTITION_EXISTS(slot0_partition)) || \
40-
!(FIXED_PARTITION_EXISTS(slot1_partition) || CONFIG_SINGLE_APPLICATION_SLOT) || \
41-
(defined(CONFIG_BOOT_SWAP_USING_SCRATCH) && !FIXED_PARTITION_EXISTS(scratch_partition))
40+
!(PARTITION_EXISTS(slot0_partition)) || \
41+
!(PARTITION_EXISTS(slot1_partition) || CONFIG_SINGLE_APPLICATION_SLOT) || \
42+
(defined(CONFIG_BOOT_SWAP_USING_SCRATCH) && !PARTITION_EXISTS(scratch_partition))
4243
#error "Target support is incomplete; cannot build mcuboot."
4344
#endif
4445

45-
#if (MCUBOOT_IMAGE_NUMBER == 2) && (!(FIXED_PARTITION_EXISTS(slot2_partition)) || \
46-
!(FIXED_PARTITION_EXISTS(slot3_partition)))
46+
#if (MCUBOOT_IMAGE_NUMBER == 2) && (!(PARTITION_EXISTS(slot2_partition)) || \
47+
!(PARTITION_EXISTS(slot3_partition)))
4748
#error "Target support is incomplete; cannot build mcuboot."
4849
#endif
4950

boot/zephyr/main.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <zephyr/drivers/flash.h>
2727
#include <zephyr/drivers/timer/system_timer.h>
2828
#include <zephyr/usb/usb_device.h>
29+
#include <zephyr/devicetree/partitions.h>
2930
#include <soc.h>
3031
#include <zephyr/linker/linker-defs.h>
3132

@@ -65,14 +66,14 @@
6566
#define SECONDARY_SLOT 1
6667

6768
#define IMAGE0_PRIMARY_START_ADDRESS \
68-
DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_0), reg, 0)
69+
DT_PROP_BY_IDX(DT_NODE_BY_PARTITION_LABEL(image_0), reg, 0)
6970
#define IMAGE0_PRIMARY_SIZE \
70-
DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_0), reg, 1)
71+
DT_PROP_BY_IDX(DT_NODE_BY_PARTITION_LABEL(image_0), reg, 1)
7172

7273
#define IMAGE1_PRIMARY_START_ADDRESS \
73-
DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_1), reg, 0)
74+
DT_PROP_BY_IDX(DT_NODE_BY_PARTITION_LABEL(image_1), reg, 0)
7475
#define IMAGE1_PRIMARY_SIZE \
75-
DT_PROP_BY_IDX(DT_NODE_BY_FIXED_PARTITION_LABEL(image_1), reg, 1)
76+
DT_PROP_BY_IDX(DT_NODE_BY_PARTITION_LABEL(image_1), reg, 1)
7677

7778
#endif /* CONFIG_SOC_FAMILY_ESPRESSIF_ESP32 */
7879

samples/runtime-source/zephyr/hooks/hooks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <zephyr/drivers/gpio.h>
88
#include <zephyr/kernel.h>
9+
#include <zephyr/devicetree/partitions.h>
910

1011
#include "bootutil/bootutil.h"
1112
#include "bootutil/bootutil_public.h"
@@ -17,8 +18,8 @@ static struct image_header _hdr;
1718
static uint8_t tmpbuf[BOOT_TMPBUF_SZ];
1819

1920
static uint8_t known_ids[] = {
20-
FIXED_PARTITION_ID(slot0_partition),
21-
FIXED_PARTITION_ID(slot1_partition),
21+
PARTITION_ID(slot0_partition),
22+
PARTITION_ID(slot1_partition),
2223
};
2324

2425
static int current_id;

0 commit comments

Comments
 (0)