Skip to content

Commit 15cad4d

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 <ddegrasse@tenstorrent.com>
1 parent 222c060 commit 15cad4d

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

subsys/dfu/boot/mcuboot.c

Lines changed: 49 additions & 2 deletions
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,48 @@ 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+
#if FIXED_PARTITION_EXISTS(SLOT1_PARTITION)
117+
case 1:
118+
fa_id = FIXED_PARTITION_ID(SLOT1_PARTITION);
119+
break;
120+
#endif
121+
122+
#if FIXED_PARTITION_EXISTS(SLOT2_PARTITION)
123+
case 2:
124+
fa_id = FIXED_PARTITION_ID(SLOT2_PARTITION);
125+
break;
126+
#endif
127+
128+
#if FIXED_PARTITION_EXISTS(SLOT3_PARTITION)
129+
case 3:
130+
fa_id = FIXED_PARTITION_ID(SLOT3_PARTITION);
131+
break;
132+
#endif
133+
134+
#if FIXED_PARTITION_EXISTS(SLOT4_PARTITION)
135+
case 4:
136+
fa_id = FIXED_PARTITION_ID(SLOT4_PARTITION);
137+
break;
138+
#endif
139+
140+
#if FIXED_PARTITION_EXISTS(SLOT5_PARTITION)
141+
case 5:
142+
fa_id = FIXED_PARTITION_ID(SLOT5_PARTITION);
143+
break;
144+
#endif
145+
146+
default:
147+
fa_id = INVALID_SLOT_ID;
148+
break;
149+
}
103150

104-
return slot;
151+
return fa_id;
105152
}
106153
#else /* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD ||
107154
* CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD_WITH_REVERT

0 commit comments

Comments
 (0)