Skip to content

Commit 8110ce5

Browse files
committed
boot/nuttx: add configuration for tertiary slot
This slot is used in newly introduced copy with revert algorithm. This commit allows NuttX to support this algorithm. Signed-off-by: Michal Lenc <michallenc@seznam.cz>
1 parent b407080 commit 8110ce5

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

boot/nuttx/include/mcuboot_config/mcuboot_config.h

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@
7878
# define MCUBOOT_OVERWRITE_ONLY_FAST
7979
#endif
8080

81+
/* Enable copy with revert algorithm. This algorithm uses three slots and
82+
* always keep the current image in both primary and secondary or tertiary
83+
* partitions. This way update can be done without swapping while keeping
84+
* the ability to revert.
85+
*/
86+
87+
#ifdef CONFIG_MCUBOOT_COPY_WITH_REVERT
88+
# define MCUBOOT_COPY_WITH_REVERT
89+
#endif
90+
8191
/* Enable the direct-xip code path. */
8292

8393
#ifdef CONFIG_MCUBOOT_DIRECT_XIP

boot/nuttx/include/sysflash/sysflash.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626

2727
#define PRIMARY_ID 0
2828
#define SECONDARY_ID 1
29-
#define SCRATCH_ID 2
29+
#define TERTIARY_ID 2
30+
#define SCRATCH_ID 3
3031

3132
#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
3233
PRIMARY_ID : \
3334
PRIMARY_ID)
3435
#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
3536
SECONDARY_ID : \
3637
SECONDARY_ID)
38+
#define FLASH_AREA_IMAGE_TERTIARY(x) (((x) == 0) ? \
39+
TERTIARY_ID : \
40+
TERTIARY_ID)
3741
#define FLASH_AREA_IMAGE_SCRATCH SCRATCH_ID
3842

3943
#endif /* __BOOT_NUTTX_INCLUDE_SYSFLASH_SYSFLASH_H */

boot/nuttx/src/flash_map_backend/flash_map_backend.c

+28
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@ static struct flash_device_s g_secondary_priv =
123123
.erase_state = CONFIG_MCUBOOT_DEFAULT_FLASH_ERASE_STATE
124124
};
125125

126+
static struct flash_area g_tertiary_img0 =
127+
{
128+
.fa_id = FLASH_AREA_IMAGE_TERTIARY(0),
129+
.fa_device_id = 0,
130+
.fa_off = 0,
131+
.fa_size = 0,
132+
.fa_mtd_path = CONFIG_MCUBOOT_TERTIARY_SLOT_PATH
133+
};
134+
135+
static struct flash_device_s g_tertiary_priv =
136+
{
137+
.fa_cfg = &g_tertiary_img0,
138+
.mtdgeo =
139+
{
140+
0
141+
},
142+
.partinfo =
143+
{
144+
0
145+
},
146+
.fd = -1,
147+
.refs = 0,
148+
.erase_state = CONFIG_MCUBOOT_DEFAULT_FLASH_ERASE_STATE
149+
};
150+
126151
static struct flash_area g_scratch_img0 =
127152
{
128153
.fa_id = FLASH_AREA_IMAGE_SCRATCH,
@@ -152,6 +177,7 @@ static struct flash_device_s *g_flash_devices[] =
152177
{
153178
&g_primary_priv,
154179
&g_secondary_priv,
180+
&g_tertiary_priv,
155181
&g_scratch_priv,
156182
};
157183

@@ -713,6 +739,8 @@ int flash_area_id_from_multi_image_slot(int image_index, int slot)
713739
return FLASH_AREA_IMAGE_PRIMARY(image_index);
714740
case 1:
715741
return FLASH_AREA_IMAGE_SECONDARY(image_index);
742+
case 2:
743+
return FLASH_AREA_IMAGE_TERTIARY(image_index);
716744
}
717745

718746
BOOT_LOG_ERR("Unexpected Request: image_index:%d, slot:%d",

0 commit comments

Comments
 (0)