Skip to content

Commit

Permalink
boot/nuttx: add configuration for tertiary slot
Browse files Browse the repository at this point in the history
This slot is used in newly introduced copy with revert algorithm. This
commit allows NuttX to support this algorithm.

Signed-off-by: Michal Lenc <[email protected]>
  • Loading branch information
michallenc committed Apr 23, 2024
1 parent b407080 commit 8110ce5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions boot/nuttx/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
# define MCUBOOT_OVERWRITE_ONLY_FAST
#endif

/* Enable copy with revert algorithm. This algorithm uses three slots and
* always keep the current image in both primary and secondary or tertiary
* partitions. This way update can be done without swapping while keeping
* the ability to revert.
*/

#ifdef CONFIG_MCUBOOT_COPY_WITH_REVERT
# define MCUBOOT_COPY_WITH_REVERT
#endif

/* Enable the direct-xip code path. */

#ifdef CONFIG_MCUBOOT_DIRECT_XIP
Expand Down
6 changes: 5 additions & 1 deletion boot/nuttx/include/sysflash/sysflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@

#define PRIMARY_ID 0
#define SECONDARY_ID 1
#define SCRATCH_ID 2
#define TERTIARY_ID 2
#define SCRATCH_ID 3

#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
PRIMARY_ID : \
PRIMARY_ID)
#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
SECONDARY_ID : \
SECONDARY_ID)
#define FLASH_AREA_IMAGE_TERTIARY(x) (((x) == 0) ? \
TERTIARY_ID : \
TERTIARY_ID)
#define FLASH_AREA_IMAGE_SCRATCH SCRATCH_ID

#endif /* __BOOT_NUTTX_INCLUDE_SYSFLASH_SYSFLASH_H */
28 changes: 28 additions & 0 deletions boot/nuttx/src/flash_map_backend/flash_map_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ static struct flash_device_s g_secondary_priv =
.erase_state = CONFIG_MCUBOOT_DEFAULT_FLASH_ERASE_STATE
};

static struct flash_area g_tertiary_img0 =
{
.fa_id = FLASH_AREA_IMAGE_TERTIARY(0),
.fa_device_id = 0,
.fa_off = 0,
.fa_size = 0,
.fa_mtd_path = CONFIG_MCUBOOT_TERTIARY_SLOT_PATH
};

static struct flash_device_s g_tertiary_priv =
{
.fa_cfg = &g_tertiary_img0,
.mtdgeo =
{
0
},
.partinfo =
{
0
},
.fd = -1,
.refs = 0,
.erase_state = CONFIG_MCUBOOT_DEFAULT_FLASH_ERASE_STATE
};

static struct flash_area g_scratch_img0 =
{
.fa_id = FLASH_AREA_IMAGE_SCRATCH,
Expand Down Expand Up @@ -152,6 +177,7 @@ static struct flash_device_s *g_flash_devices[] =
{
&g_primary_priv,
&g_secondary_priv,
&g_tertiary_priv,
&g_scratch_priv,
};

Expand Down Expand Up @@ -713,6 +739,8 @@ int flash_area_id_from_multi_image_slot(int image_index, int slot)
return FLASH_AREA_IMAGE_PRIMARY(image_index);
case 1:
return FLASH_AREA_IMAGE_SECONDARY(image_index);
case 2:
return FLASH_AREA_IMAGE_TERTIARY(image_index);
}

BOOT_LOG_ERR("Unexpected Request: image_index:%d, slot:%d",
Expand Down

0 comments on commit 8110ce5

Please sign in to comment.