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 )
23
-
18
+ #if (MCUBOOT_IMAGE_NUMBER == 2 ) && defined(PM_B0_ADDRESS )
24
19
/* If B0 is present then two bootloaders are present, and we must use
25
20
* a single secondary slot for both primary slots.
26
21
*/
27
- #if defined(PM_B0_ADDRESS )
28
22
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 )
23
+ #endif /* (MCUBOOT_IMAGE_NUMBER == 2 && defined(PM_B0_ADDRESS) */
37
24
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 )
25
+ #if (MCUBOOT_IMAGE_NUMBER == 2 ) && defined(PM_B0_ADDRESS ) && \
26
+ !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE )
45
27
46
28
#define FLASH_AREA_IMAGE_PRIMARY (x ) \
47
29
((x == 0) ? \
@@ -56,26 +38,52 @@ extern uint32_t _image_1_primary_slot_id[];
56
38
(x == 1) ? \
57
39
PM_MCUBOOT_SECONDARY_ID: \
58
40
255 )
41
+
42
+ #else /* MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
43
+ * !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
44
+ */
45
+
46
+ /* Each pair of slots is separated by , and there is no terminating character */
47
+ #define FLASH_AREA_IMAGE_0_SLOTS PM_MCUBOOT_PRIMARY_ID, PM_MCUBOOT_SECONDARY_ID
48
+ #define FLASH_AREA_IMAGE_1_SLOTS PM_MCUBOOT_PRIMARY_1_ID, PM_MCUBOOT_SECONDARY_1_ID
49
+ #define FLASH_AREA_IMAGE_2_SLOTS PM_MCUBOOT_PRIMARY_2_ID, PM_MCUBOOT_SECONDARY_2_ID
50
+
51
+ #if (MCUBOOT_IMAGE_NUMBER == 1 )
52
+ #define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS
53
+ #elif (MCUBOOT_IMAGE_NUMBER == 2 )
54
+ #define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
55
+ FLASH_AREA_IMAGE_1_SLOTS
56
+ #elif (MCUBOOT_IMAGE_NUMBER == 3 )
57
+ #define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
58
+ FLASH_AREA_IMAGE_1_SLOTS, \
59
+ FLASH_AREA_IMAGE_2_SLOTS
59
60
#else
61
+ #error Unsupported number of images
62
+ #endif
60
63
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 )
64
+ static inline uint32_t __flash_area_ids_for_slot (int img , int slot )
65
+ {
66
+ static const int all_slots [] = {
67
+ ALL_AVAILABLE_SLOTS
68
+ };
69
+ return all_slots [img * 2 + slot ];
70
+ };
67
71
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 )
72
+ #undef FLASH_AREA_IMAGE_0_SLOTS
73
+ #undef FLASH_AREA_IMAGE_1_SLOTS
74
+ #undef FLASH_AREA_IMAGE_2_SLOTS
75
+ #undef ALL_AVAILABLE_SLOTS
74
76
75
- #endif /* PM_B0_ADDRESS */
77
+ #define FLASH_AREA_IMAGE_PRIMARY (x ) __flash_area_ids_for_slot(x, 0)
78
+ #define FLASH_AREA_IMAGE_SECONDARY (x ) __flash_area_ids_for_slot(x, 1)
76
79
80
+ #if !defined(CONFIG_BOOT_SWAP_USING_MOVE )
81
+ #define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
77
82
#endif
78
- #define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
83
+
84
+ #endif /* MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
85
+ * !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
86
+ */
79
87
80
88
#else /* CONFIG_SINGLE_APPLICATION_SLOT */
81
89
0 commit comments