blob: dd759e240ce9f59302ef6c0ca1ad56105778a00d [file] [log] [blame]
David Brown5153bd62017-01-06 11:16:53 -07001/* Manual version of auto-generated version. */
2
3#ifndef __SYSFLASH_H__
4#define __SYSFLASH_H__
5
David Vinczeb75c12a2019-03-22 14:58:33 +01006#include <mcuboot_config/mcuboot_config.h>
Dominik Ermel0119cdb2023-02-21 13:58:03 +00007#include <zephyr/devicetree.h>
8#include <zephyr/storage/flash_map.h>
Andrzej Puzdrowski419a4752019-01-23 16:31:19 +01009
Andrzej Puzdrowskifdff3e12020-09-15 08:23:25 +020010#ifndef CONFIG_SINGLE_APPLICATION_SLOT
Dominik Ermel8101c0c2020-05-19 13:01:16 +000011
David Vinczeb75c12a2019-03-22 14:58:33 +010012#if (MCUBOOT_IMAGE_NUMBER == 1)
Fabio Utzigb0f04732019-07-31 09:49:19 -030013/*
14 * NOTE: the definition below returns the same values for true/false on
15 * purpose, to avoid having to mark x as non-used by all callers when
16 * running in single image mode.
17 */
18#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000019 FIXED_PARTITION_ID(slot0_partition) : \
20 FIXED_PARTITION_ID(slot0_partition))
Fabio Utzigb0f04732019-07-31 09:49:19 -030021#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000022 FIXED_PARTITION_ID(slot1_partition) : \
23 FIXED_PARTITION_ID(slot1_partition))
David Vinczeb75c12a2019-03-22 14:58:33 +010024#elif (MCUBOOT_IMAGE_NUMBER == 2)
25/* MCUBoot currently supports only up to 2 updateable firmware images.
26 * If the number of the current image is greater than MCUBOOT_IMAGE_NUMBER - 1
27 * then a dummy value will be assigned to the flash area macros.
28 */
Fabio Utzigb0f04732019-07-31 09:49:19 -030029#define FLASH_AREA_IMAGE_PRIMARY(x) (((x) == 0) ? \
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000030 FIXED_PARTITION_ID(slot0_partition) : \
Fabio Utzigb0f04732019-07-31 09:49:19 -030031 ((x) == 1) ? \
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000032 FIXED_PARTITION_ID(slot2_partition) : \
Fabio Utzigb0f04732019-07-31 09:49:19 -030033 255)
34#define FLASH_AREA_IMAGE_SECONDARY(x) (((x) == 0) ? \
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000035 FIXED_PARTITION_ID(slot1_partition) : \
Fabio Utzigb0f04732019-07-31 09:49:19 -030036 ((x) == 1) ? \
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000037 FIXED_PARTITION_ID(slot3_partition) : \
Fabio Utzigb0f04732019-07-31 09:49:19 -030038 255)
David Vinczeb75c12a2019-03-22 14:58:33 +010039#else
40#error "Image slot and flash area mapping is not defined"
41#endif
42
Fabio Utzigc58842e2019-11-28 10:30:01 -030043#if !defined(CONFIG_BOOT_SWAP_USING_MOVE)
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000044#define FLASH_AREA_IMAGE_SCRATCH FIXED_PARTITION_ID(scratch_partition)
Fabio Utzigc58842e2019-11-28 10:30:01 -030045#endif
David Brown5153bd62017-01-06 11:16:53 -070046
Andrzej Puzdrowskifdff3e12020-09-15 08:23:25 +020047#else /* CONFIG_SINGLE_APPLICATION_SLOT */
Dominik Ermel8101c0c2020-05-19 13:01:16 +000048
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000049#define FLASH_AREA_IMAGE_PRIMARY(x) FIXED_PARTITION_ID(slot0_partition)
50#define FLASH_AREA_IMAGE_SECONDARY(x) FIXED_PARTITION_ID(slot0_partition)
Dominik Ermel8101c0c2020-05-19 13:01:16 +000051
Andrzej Puzdrowskifdff3e12020-09-15 08:23:25 +020052#endif /* CONFIG_SINGLE_APPLICATION_SLOT */
Dominik Ermel8101c0c2020-05-19 13:01:16 +000053
David Brown5153bd62017-01-06 11:16:53 -070054#endif /* __SYSFLASH_H__ */