blob: 890e69d987f4d7b08b30d5b3e45f5e2c41398e5e [file] [log] [blame]
Dominik Ermelda65db02023-06-23 04:53:04 +00001/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
David Brown5153bd62017-01-06 11:16:53 -07006
7#ifndef __SYSFLASH_H__
8#define __SYSFLASH_H__
9
David Vinczeb75c12a2019-03-22 14:58:33 +010010#include <mcuboot_config/mcuboot_config.h>
Dominik Ermel0119cdb2023-02-21 13:58:03 +000011#include <zephyr/devicetree.h>
12#include <zephyr/storage/flash_map.h>
Dominik Ermelda65db02023-06-23 04:53:04 +000013#include <zephyr/sys/util_macro.h>
Andrzej Puzdrowski419a4752019-01-23 16:31:19 +010014
Jamie McCraea88e2292023-12-07 09:40:51 +000015#if !defined(CONFIG_SINGLE_APPLICATION_SLOT) && !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP)
Dominik Ermel8101c0c2020-05-19 13:01:16 +000016
Dominik Ermelda65db02023-06-23 04:53:04 +000017/* Each pair of slots is separated by , and there is no terminating character */
18#define FLASH_AREA_IMAGE_0_SLOTS slot0_partition, slot1_partition
19#define FLASH_AREA_IMAGE_1_SLOTS slot2_partition, slot3_partition
20#define FLASH_AREA_IMAGE_2_SLOTS slot4_partition, slot5_partition
21
David Vinczeb75c12a2019-03-22 14:58:33 +010022#if (MCUBOOT_IMAGE_NUMBER == 1)
Dominik Ermelda65db02023-06-23 04:53:04 +000023#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS
David Vinczeb75c12a2019-03-22 14:58:33 +010024#elif (MCUBOOT_IMAGE_NUMBER == 2)
Dominik Ermelda65db02023-06-23 04:53:04 +000025#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
26 FLASH_AREA_IMAGE_1_SLOTS
27#elif (MCUBOOT_IMAGE_NUMBER == 3)
28#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
29 FLASH_AREA_IMAGE_1_SLOTS, \
30 FLASH_AREA_IMAGE_2_SLOTS
David Vinczeb75c12a2019-03-22 14:58:33 +010031#endif
32
Dominik Ermelda65db02023-06-23 04:53:04 +000033static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
34{
35 static const int all_slots[] = {
36 FOR_EACH_NONEMPTY_TERM(FIXED_PARTITION_ID, (,), ALL_AVAILABLE_SLOTS)
37 };
38 return all_slots[img * 2 + slot];
39};
40
41#undef FLASH_AREA_IMAGE_0_SLOTS
42#undef FLASH_AREA_IMAGE_1_SLOTS
43#undef FLASH_AREA_IMAGE_2_SLOTS
44#undef ALL_AVAILABLE_SLOTS
45
46#define FLASH_AREA_IMAGE_PRIMARY(x) __flash_area_ids_for_slot(x, 0)
47#define FLASH_AREA_IMAGE_SECONDARY(x) __flash_area_ids_for_slot(x, 1)
48
Fabio Utzigc58842e2019-11-28 10:30:01 -030049#if !defined(CONFIG_BOOT_SWAP_USING_MOVE)
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000050#define FLASH_AREA_IMAGE_SCRATCH FIXED_PARTITION_ID(scratch_partition)
Fabio Utzigc58842e2019-11-28 10:30:01 -030051#endif
David Brown5153bd62017-01-06 11:16:53 -070052
Jamie McCraea88e2292023-12-07 09:40:51 +000053#else /* !CONFIG_SINGLE_APPLICATION_SLOT && !CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP */
Dominik Ermel8101c0c2020-05-19 13:01:16 +000054
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000055#define FLASH_AREA_IMAGE_PRIMARY(x) FIXED_PARTITION_ID(slot0_partition)
56#define FLASH_AREA_IMAGE_SECONDARY(x) FIXED_PARTITION_ID(slot0_partition)
Dominik Ermel8101c0c2020-05-19 13:01:16 +000057
Andrzej Puzdrowskifdff3e12020-09-15 08:23:25 +020058#endif /* CONFIG_SINGLE_APPLICATION_SLOT */
Dominik Ermel8101c0c2020-05-19 13:01:16 +000059
David Brown5153bd62017-01-06 11:16:53 -070060#endif /* __SYSFLASH_H__ */