Skip to content

Commit 4d0b7d1

Browse files
dfu: boot: mcuboot: fix boot_fetch_active_slot
boot_fetch_active_slot needs to map the slot number to a flash ID, as this is what the DFU subsystem expects when interacting with the flash partition. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 5df59bd commit 4d0b7d1

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

subsys/dfu/boot/mcuboot.c

+47-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
/* For RAM LOAD mode, the active image must be fetched from the bootloader */
2626
#include <bootutil/boot_status.h>
2727
#include <zephyr/retention/blinfo.h>
28+
29+
#define SLOT0_PARTITION slot0_partition
30+
#define SLOT1_PARTITION slot1_partition
31+
#define SLOT2_PARTITION slot2_partition
32+
#define SLOT3_PARTITION slot3_partition
33+
#define SLOT4_PARTITION slot4_partition
34+
#define SLOT5_PARTITION slot5_partition
2835
#endif
2936

3037
#include "mcuboot_priv.h"
@@ -89,7 +96,7 @@ struct mcuboot_v1_raw_header {
8996
uint8_t boot_fetch_active_slot(void)
9097
{
9198
int rc;
92-
uint8_t slot;
99+
uint8_t slot, fa_id;
93100

94101
rc = blinfo_lookup(BLINFO_RUNNING_SLOT, &slot, sizeof(slot));
95102

@@ -100,8 +107,46 @@ uint8_t boot_fetch_active_slot(void)
100107
}
101108

102109
LOG_DBG("Active slot: %d", slot);
110+
/* Map slot number back to flash area ID */
111+
switch (slot) {
112+
case 0:
113+
fa_id = FIXED_PARTITION_ID(SLOT0_PARTITION);
114+
break;
115+
116+
case 1:
117+
fa_id = FIXED_PARTITION_ID(SLOT1_PARTITION);
118+
break;
119+
120+
#if FIXED_PARTITION_EXISTS(SLOT2_PARTITION)
121+
case 2:
122+
fa_id = FIXED_PARTITION_ID(SLOT2_PARTITION);
123+
break;
124+
#endif
125+
126+
#if FIXED_PARTITION_EXISTS(SLOT3_PARTITION)
127+
case 3:
128+
fa_id = FIXED_PARTITION_ID(SLOT3_PARTITION);
129+
break;
130+
#endif
131+
132+
#if FIXED_PARTITION_EXISTS(SLOT4_PARTITION)
133+
case 4:
134+
fa_id = FIXED_PARTITION_ID(SLOT4_PARTITION);
135+
break;
136+
#endif
137+
138+
#if FIXED_PARTITION_EXISTS(SLOT5_PARTITION)
139+
case 5:
140+
fa_id = FIXED_PARTITION_ID(SLOT5_PARTITION);
141+
break;
142+
#endif
143+
144+
default:
145+
fa_id = INVALID_SLOT_ID;
146+
break;
147+
}
103148

104-
return slot;
149+
return fa_id;
105150
}
106151
#else /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD ||
107152
* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT

0 commit comments

Comments
 (0)