Skip to content

Commit

Permalink
[nrf noup] zephyr: Move partition manager definitions to pm_sysflash.h
Browse files Browse the repository at this point in the history
Making sysflash.h and pm_sysflash.h more readable.

(cherry picked from commit eafdae9)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
(cherry picked from commit 99001d0)
(cherry picked from commit 0383b7c)
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
  • Loading branch information
de-nordic committed Dec 15, 2023
1 parent 03af90f commit c3b33eb
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 85 deletions.
92 changes: 92 additions & 0 deletions boot/zephyr/include/sysflash/pm_sysflash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#ifndef __PM_SYSFLASH_H__
#define __PM_SYSFLASH_H__
/* Blocking the __SYSFLASH_H__ */
#define __SYSFLASH_H__

#include <pm_config.h>
#include <mcuboot_config/mcuboot_config.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 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) ? \
PM_MCUBOOT_PRIMARY_ID : \
(x == 1) ? \
(uint32_t)_image_1_primary_slot_id : \
255 )

#define FLASH_AREA_IMAGE_SECONDARY(x) \
((x == 0) ? \
PM_MCUBOOT_SECONDARY_ID: \
(x == 1) ? \
PM_MCUBOOT_SECONDARY_ID: \
255 )
#else

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

#endif /* PM_B0_ADDRESS */

#endif
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID

#else /* CONFIG_SINGLE_APPLICATION_SLOT */

#define FLASH_AREA_IMAGE_PRIMARY(x) PM_MCUBOOT_PRIMARY_ID
#define FLASH_AREA_IMAGE_SECONDARY(x) PM_MCUBOOT_PRIMARY_ID
/* NOTE: Scratch parition is not used by single image DFU but some of
* functions in common files reference it, so the definitions has been
* provided to allow compilation of common units.
*/
#define FLASH_AREA_IMAGE_SCRATCH 0

#endif /* CONFIG_SINGLE_APPLICATION_SLOT */

#endif /* __PM_SYSFLASH_H__ */
90 changes: 5 additions & 85 deletions boot/zephyr/include/sysflash/sysflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __SYSFLASH_H__
#define __SYSFLASH_H__

#if USE_PARTITION_MANAGER
#include <pm_config.h>
#include <mcuboot_config/mcuboot_config.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 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) ? \
PM_MCUBOOT_PRIMARY_ID : \
(x == 1) ? \
(uint32_t)_image_1_primary_slot_id : \
255 )

#define FLASH_AREA_IMAGE_SECONDARY(x) \
((x == 0) ? \
PM_MCUBOOT_SECONDARY_ID: \
(x == 1) ? \
PM_MCUBOOT_SECONDARY_ID: \
255 )
#else

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

#endif /* PM_B0_ADDRESS */

/* Blocking the rest of the file */
#define __SYSFLASH_H__
#include <sysflash/pm_sysflash.h>
#endif
#define FLASH_AREA_IMAGE_SCRATCH PM_MCUBOOT_SCRATCH_ID

#else /* CONFIG_SINGLE_APPLICATION_SLOT */

#define FLASH_AREA_IMAGE_PRIMARY(x) PM_MCUBOOT_PRIMARY_ID
#define FLASH_AREA_IMAGE_SECONDARY(x) PM_MCUBOOT_PRIMARY_ID
/* NOTE: Scratch parition is not used by single image DFU but some of
* functions in common files reference it, so the definitions has been
* provided to allow compilation of common units.
*/
#define FLASH_AREA_IMAGE_SCRATCH 0

#endif /* CONFIG_SINGLE_APPLICATION_SLOT */

#else
#ifndef __SYSFLASH_H__
#define __SYSFLASH_H__

#include <zephyr/devicetree.h>
#include <mcuboot_config/mcuboot_config.h>
#include <zephyr/devicetree.h>
#include <zephyr/storage/flash_map.h>
Expand Down Expand Up @@ -141,6 +63,4 @@ static inline uint32_t __flash_area_ids_for_slot(int img, int slot)

#endif /* CONFIG_SINGLE_APPLICATION_SLOT */

#endif /* USE_PARTITION_MANAGER */

#endif /* __SYSFLASH_H__ */

0 comments on commit c3b33eb

Please sign in to comment.