11
11
12
12
#include <pm_config.h>
13
13
#include <mcuboot_config/mcuboot_config.h>
14
+ #include <flash_map_pm.h>
14
15
15
16
#ifndef CONFIG_SINGLE_APPLICATION_SLOT
16
17
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 )
23
20
24
21
/* If B0 is present then two bootloaders are present, and we must use
25
22
* a single secondary slot for both primary slots.
26
23
*/
27
- #if defined(PM_B0_ADDRESS )
28
24
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 )
45
25
46
26
#define FLASH_AREA_IMAGE_PRIMARY (x ) \
47
27
((x == 0) ? \
@@ -56,26 +36,52 @@ extern uint32_t _image_1_primary_slot_id[];
56
36
(x == 1) ? \
57
37
PM_MCUBOOT_SECONDARY_ID: \
58
38
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
59
58
#else
59
+ #error Unsupported number of images
60
+ #endif
60
61
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
+ };
67
69
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
74
74
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)
76
77
78
+ #if !defined(CONFIG_BOOT_SWAP_USING_MOVE )
79
+ #define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
77
80
#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
+ */
79
85
80
86
#else /* CONFIG_SINGLE_APPLICATION_SLOT */
81
87
0 commit comments