Skip to content

Commit a7f6ccb

Browse files
committed
[nrf noup] zephyr: Add support for three images
The commit modifies pm_sysflash.h to add support for three application images. (cherry picked from commit 8fba4db) Signed-off-by: Dominik Ermel <[email protected]>
1 parent 8c5b560 commit a7f6ccb

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

boot/zephyr/include/sysflash/pm_sysflash.h

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,17 @@
1111

1212
#include <pm_config.h>
1313
#include <mcuboot_config/mcuboot_config.h>
14+
#include <flash_map_pm.h>
1415

1516
#ifndef CONFIG_SINGLE_APPLICATION_SLOT
1617

17-
#if (MCUBOOT_IMAGE_NUMBER == 1)
18-
19-
#define FLASH_AREA_IMAGE_PRIMARY(x) PM_MCUBOOT_PRIMARY_ID
20-
#define FLASH_AREA_IMAGE_SECONDARY(x) PM_MCUBOOT_SECONDARY_ID
21-
22-
#elif (MCUBOOT_IMAGE_NUMBER == 2)
18+
#if (MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
19+
!defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
2320

2421
/* If B0 is present then two bootloaders are present, and we must use
2522
* a single secondary slot for both primary slots.
2623
*/
27-
#if defined(PM_B0_ADDRESS)
2824
extern uint32_t _image_1_primary_slot_id[];
29-
#endif
30-
#if defined(PM_B0_ADDRESS) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
31-
#define FLASH_AREA_IMAGE_PRIMARY(x) \
32-
((x == 0) ? \
33-
PM_MCUBOOT_PRIMARY_ID : \
34-
(x == 1) ? \
35-
PM_MCUBOOT_PRIMARY_1_ID : \
36-
255 )
37-
38-
#define FLASH_AREA_IMAGE_SECONDARY(x) \
39-
((x == 0) ? \
40-
PM_MCUBOOT_SECONDARY_ID: \
41-
(x == 1) ? \
42-
PM_MCUBOOT_SECONDARY_1_ID: \
43-
255 )
44-
#elif defined(PM_B0_ADDRESS)
4525

4626
#define FLASH_AREA_IMAGE_PRIMARY(x) \
4727
((x == 0) ? \
@@ -56,26 +36,52 @@ extern uint32_t _image_1_primary_slot_id[];
5636
(x == 1) ? \
5737
PM_MCUBOOT_SECONDARY_ID: \
5838
255 )
39+
40+
#else /* MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
41+
* !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
42+
*/
43+
44+
/* Each pair of slots is separated by , and there is no terminating character */
45+
#define FLASH_AREA_IMAGE_0_SLOTS PM_MCUBOOT_PRIMARY_ID, PM_MCUBOOT_SECONDARY_ID
46+
#define FLASH_AREA_IMAGE_1_SLOTS PM_MCUBOOT_PRIMARY_1_ID, PM_MCUBOOT_SECONDARY_1_ID
47+
#define FLASH_AREA_IMAGE_2_SLOTS PM_MCUBOOT_PRIMARY_2_ID, PM_MCUBOOT_SECONDARY_2_ID
48+
49+
#if (MCUBOOT_IMAGE_NUMBER == 1)
50+
#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS
51+
#elif (MCUBOOT_IMAGE_NUMBER == 2)
52+
#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
53+
FLASH_AREA_IMAGE_1_SLOTS
54+
#elif (MCUBOOT_IMAGE_NUMBER == 3)
55+
#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
56+
FLASH_AREA_IMAGE_1_SLOTS, \
57+
FLASH_AREA_IMAGE_2_SLOTS
5958
#else
59+
#error Unsupported number of images
60+
#endif
6061

61-
#define FLASH_AREA_IMAGE_PRIMARY(x) \
62-
((x == 0) ? \
63-
PM_MCUBOOT_PRIMARY_ID : \
64-
(x == 1) ? \
65-
PM_MCUBOOT_PRIMARY_1_ID : \
66-
255 )
62+
static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
63+
{
64+
static const int all_slots[] = {
65+
ALL_AVAILABLE_SLOTS
66+
};
67+
return all_slots[img * 2 + slot];
68+
};
6769

68-
#define FLASH_AREA_IMAGE_SECONDARY(x) \
69-
((x == 0) ? \
70-
PM_MCUBOOT_SECONDARY_ID: \
71-
(x == 1) ? \
72-
PM_MCUBOOT_SECONDARY_1_ID: \
73-
255 )
70+
#undef FLASH_AREA_IMAGE_0_SLOTS
71+
#undef FLASH_AREA_IMAGE_1_SLOTS
72+
#undef FLASH_AREA_IMAGE_2_SLOTS
73+
#undef ALL_AVAILABLE_SLOTS
7474

75-
#endif /* PM_B0_ADDRESS */
75+
#define FLASH_AREA_IMAGE_PRIMARY(x) __flash_area_ids_for_slot(x, 0)
76+
#define FLASH_AREA_IMAGE_SECONDARY(x) __flash_area_ids_for_slot(x, 1)
7677

78+
#if !defined(CONFIG_BOOT_SWAP_USING_MOVE)
79+
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
7780
#endif
78-
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
81+
82+
#endif /* MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
83+
* !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
84+
*/
7985

8086
#else /* CONFIG_SINGLE_APPLICATION_SLOT */
8187

0 commit comments

Comments
 (0)