Skip to content

Commit

Permalink
[nrf noup] sysflash: Add support for three images
Browse files Browse the repository at this point in the history
The commit modifies pm_sysflash.h to add support for three
application images.

Ref. NCSDK-19223

Signed-off-by: Dominik Ermel <[email protected]>
Signed-off-by: Sigvart Hovland <[email protected]>
(cherry picked from commit 9c67351)
  • Loading branch information
de-nordic authored and anangl committed Jun 28, 2024
1 parent 6cecb1c commit d2d11bf
Showing 1 changed file with 45 additions and 37 deletions.
82 changes: 45 additions & 37 deletions boot/zephyr/include/sysflash/pm_sysflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,19 @@

#include <pm_config.h>
#include <mcuboot_config/mcuboot_config.h>
#include <flash_map_pm.h>

#ifndef CONFIG_SINGLE_APPLICATION_SLOT

#if (MCUBOOT_IMAGE_NUMBER == 1)

#define FLASH_AREA_IMAGE_PRIMARY(x) PM_MCUBOOT_PRIMARY_ID
#define FLASH_AREA_IMAGE_SECONDARY(x) PM_MCUBOOT_SECONDARY_ID

#elif (MCUBOOT_IMAGE_NUMBER == 2)

#if (MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS)
/* If B0 is present then two bootloaders are present, and we must use
* a single secondary slot for both primary slots.
*/
#if defined(PM_B0_ADDRESS)
extern uint32_t _image_1_primary_slot_id[];
#endif
#if defined(PM_B0_ADDRESS) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
#define FLASH_AREA_IMAGE_PRIMARY(x) \
((x == 0) ? \
PM_MCUBOOT_PRIMARY_ID : \
(x == 1) ? \
PM_MCUBOOT_PRIMARY_1_ID : \
255 )
#endif /* (MCUBOOT_IMAGE_NUMBER == 2 && defined(PM_B0_ADDRESS) */

#define FLASH_AREA_IMAGE_SECONDARY(x) \
((x == 0) ? \
PM_MCUBOOT_SECONDARY_ID: \
(x == 1) ? \
PM_MCUBOOT_SECONDARY_1_ID: \
255 )
#elif defined(PM_B0_ADDRESS)
#if (MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
!defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)

#define FLASH_AREA_IMAGE_PRIMARY(x) \
((x == 0) ? \
Expand All @@ -56,26 +38,52 @@ extern uint32_t _image_1_primary_slot_id[];
(x == 1) ? \
PM_MCUBOOT_SECONDARY_ID: \
255 )

#else /* MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
* !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
*/

/* Each pair of slots is separated by , and there is no terminating character */
#define FLASH_AREA_IMAGE_0_SLOTS PM_MCUBOOT_PRIMARY_ID, PM_MCUBOOT_SECONDARY_ID
#define FLASH_AREA_IMAGE_1_SLOTS PM_MCUBOOT_PRIMARY_1_ID, PM_MCUBOOT_SECONDARY_1_ID
#define FLASH_AREA_IMAGE_2_SLOTS PM_MCUBOOT_PRIMARY_2_ID, PM_MCUBOOT_SECONDARY_2_ID

#if (MCUBOOT_IMAGE_NUMBER == 1)
#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS
#elif (MCUBOOT_IMAGE_NUMBER == 2)
#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
FLASH_AREA_IMAGE_1_SLOTS
#elif (MCUBOOT_IMAGE_NUMBER == 3)
#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
FLASH_AREA_IMAGE_1_SLOTS, \
FLASH_AREA_IMAGE_2_SLOTS
#else
#error Unsupported number of images
#endif

#define FLASH_AREA_IMAGE_PRIMARY(x) \
((x == 0) ? \
PM_MCUBOOT_PRIMARY_ID : \
(x == 1) ? \
PM_MCUBOOT_PRIMARY_1_ID : \
255 )
static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
{
static const int all_slots[] = {
ALL_AVAILABLE_SLOTS
};
return all_slots[img * 2 + slot];
};

#define FLASH_AREA_IMAGE_SECONDARY(x) \
((x == 0) ? \
PM_MCUBOOT_SECONDARY_ID: \
(x == 1) ? \
PM_MCUBOOT_SECONDARY_1_ID: \
255 )
#undef FLASH_AREA_IMAGE_0_SLOTS
#undef FLASH_AREA_IMAGE_1_SLOTS
#undef FLASH_AREA_IMAGE_2_SLOTS
#undef ALL_AVAILABLE_SLOTS

#endif /* PM_B0_ADDRESS */
#define FLASH_AREA_IMAGE_PRIMARY(x) __flash_area_ids_for_slot(x, 0)
#define FLASH_AREA_IMAGE_SECONDARY(x) __flash_area_ids_for_slot(x, 1)

#if !defined(CONFIG_BOOT_SWAP_USING_MOVE)
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID
#endif
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID

#endif /* MCUBOOT_IMAGE_NUMBER == 2) && defined(PM_B0_ADDRESS) && \
* !defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
*/

#else /* CONFIG_SINGLE_APPLICATION_SLOT */

Expand Down

0 comments on commit d2d11bf

Please sign in to comment.