blob: 1952950b9202a06a9cadc16491eedfeca07f7f2c [file] [log] [blame]
Dominik Ermelda65db02023-06-23 04:53:04 +00001/*
Dominik Ermelca02c752024-01-24 16:02:16 +00002 * Copyright (c) 2023-2024 Nordic Semiconductor ASA
Dominik Ermelda65db02023-06-23 04:53:04 +00003 *
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
Dominik Ermelca02c752024-01-24 16:02:16 +000015#ifndef SOC_FLASH_0_ID
16#define SOC_FLASH_0_ID 0
17#endif
18
19#ifndef SPI_FLASH_0_ID
20#define SPI_FLASH_0_ID 1
21#endif
22
Jamie McCraea88e2292023-12-07 09:40:51 +000023#if !defined(CONFIG_SINGLE_APPLICATION_SLOT) && !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP)
Dominik Ermel8101c0c2020-05-19 13:01:16 +000024
Dominik Ermelda65db02023-06-23 04:53:04 +000025/* Each pair of slots is separated by , and there is no terminating character */
26#define FLASH_AREA_IMAGE_0_SLOTS slot0_partition, slot1_partition
27#define FLASH_AREA_IMAGE_1_SLOTS slot2_partition, slot3_partition
28#define FLASH_AREA_IMAGE_2_SLOTS slot4_partition, slot5_partition
29
David Vinczeb75c12a2019-03-22 14:58:33 +010030#if (MCUBOOT_IMAGE_NUMBER == 1)
Dominik Ermelda65db02023-06-23 04:53:04 +000031#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS
David Vinczeb75c12a2019-03-22 14:58:33 +010032#elif (MCUBOOT_IMAGE_NUMBER == 2)
Dominik Ermelda65db02023-06-23 04:53:04 +000033#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
34 FLASH_AREA_IMAGE_1_SLOTS
35#elif (MCUBOOT_IMAGE_NUMBER == 3)
36#define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS, \
37 FLASH_AREA_IMAGE_1_SLOTS, \
38 FLASH_AREA_IMAGE_2_SLOTS
David Vinczeb75c12a2019-03-22 14:58:33 +010039#endif
40
Dominik Ermelda65db02023-06-23 04:53:04 +000041static inline uint32_t __flash_area_ids_for_slot(int img, int slot)
42{
43 static const int all_slots[] = {
44 FOR_EACH_NONEMPTY_TERM(FIXED_PARTITION_ID, (,), ALL_AVAILABLE_SLOTS)
45 };
46 return all_slots[img * 2 + slot];
47};
48
49#undef FLASH_AREA_IMAGE_0_SLOTS
50#undef FLASH_AREA_IMAGE_1_SLOTS
51#undef FLASH_AREA_IMAGE_2_SLOTS
52#undef ALL_AVAILABLE_SLOTS
53
54#define FLASH_AREA_IMAGE_PRIMARY(x) __flash_area_ids_for_slot(x, 0)
55#define FLASH_AREA_IMAGE_SECONDARY(x) __flash_area_ids_for_slot(x, 1)
56
Fabio Utzigc58842e2019-11-28 10:30:01 -030057#if !defined(CONFIG_BOOT_SWAP_USING_MOVE)
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000058#define FLASH_AREA_IMAGE_SCRATCH FIXED_PARTITION_ID(scratch_partition)
Fabio Utzigc58842e2019-11-28 10:30:01 -030059#endif
David Brown5153bd62017-01-06 11:16:53 -070060
Jamie McCraea88e2292023-12-07 09:40:51 +000061#else /* !CONFIG_SINGLE_APPLICATION_SLOT && !CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP */
Dominik Ermel8101c0c2020-05-19 13:01:16 +000062
Dominik Ermel3a82b6f2022-08-24 14:35:24 +000063#define FLASH_AREA_IMAGE_PRIMARY(x) FIXED_PARTITION_ID(slot0_partition)
64#define FLASH_AREA_IMAGE_SECONDARY(x) FIXED_PARTITION_ID(slot0_partition)
Dominik Ermel8101c0c2020-05-19 13:01:16 +000065
Andrzej Puzdrowskifdff3e12020-09-15 08:23:25 +020066#endif /* CONFIG_SINGLE_APPLICATION_SLOT */
Dominik Ermel8101c0c2020-05-19 13:01:16 +000067
David Brown5153bd62017-01-06 11:16:53 -070068#endif /* __SYSFLASH_H__ */