Skip to content

Commit

Permalink
[nrf noup] zephyr: 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.

(cherry picked from commit 8fba4db)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
(cherry picked from commit a7f6ccb)
(cherry picked from commit 5822244)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
de-nordic committed Dec 15, 2023
1 parent 0d43674 commit 77c7e25
Showing 1 changed file with 43 additions and 37 deletions.
80 changes: 43 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,17 @@

#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) && \
!defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)

/* 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 )

#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)

#define FLASH_AREA_IMAGE_PRIMARY(x) \
((x == 0) ? \
Expand All @@ -56,26 +36,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 77c7e25

Please sign in to comment.