Dominik Ermel | da65db0 | 2023-06-23 04:53:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 Nordic Semiconductor ASA |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 6 | |
| 7 | #ifndef __SYSFLASH_H__ |
| 8 | #define __SYSFLASH_H__ |
| 9 | |
David Vincze | b75c12a | 2019-03-22 14:58:33 +0100 | [diff] [blame] | 10 | #include <mcuboot_config/mcuboot_config.h> |
Dominik Ermel | 0119cdb | 2023-02-21 13:58:03 +0000 | [diff] [blame] | 11 | #include <zephyr/devicetree.h> |
| 12 | #include <zephyr/storage/flash_map.h> |
Dominik Ermel | da65db0 | 2023-06-23 04:53:04 +0000 | [diff] [blame] | 13 | #include <zephyr/sys/util_macro.h> |
Andrzej Puzdrowski | 419a475 | 2019-01-23 16:31:19 +0100 | [diff] [blame] | 14 | |
Andrzej Puzdrowski | fdff3e1 | 2020-09-15 08:23:25 +0200 | [diff] [blame] | 15 | #ifndef CONFIG_SINGLE_APPLICATION_SLOT |
Dominik Ermel | 8101c0c | 2020-05-19 13:01:16 +0000 | [diff] [blame] | 16 | |
Dominik Ermel | da65db0 | 2023-06-23 04:53:04 +0000 | [diff] [blame] | 17 | /* 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 Vincze | b75c12a | 2019-03-22 14:58:33 +0100 | [diff] [blame] | 22 | #if (MCUBOOT_IMAGE_NUMBER == 1) |
Dominik Ermel | da65db0 | 2023-06-23 04:53:04 +0000 | [diff] [blame] | 23 | #define ALL_AVAILABLE_SLOTS FLASH_AREA_IMAGE_0_SLOTS |
David Vincze | b75c12a | 2019-03-22 14:58:33 +0100 | [diff] [blame] | 24 | #elif (MCUBOOT_IMAGE_NUMBER == 2) |
Dominik Ermel | da65db0 | 2023-06-23 04:53:04 +0000 | [diff] [blame] | 25 | #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 Vincze | b75c12a | 2019-03-22 14:58:33 +0100 | [diff] [blame] | 31 | #endif |
| 32 | |
Dominik Ermel | da65db0 | 2023-06-23 04:53:04 +0000 | [diff] [blame] | 33 | static 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 Utzig | c58842e | 2019-11-28 10:30:01 -0300 | [diff] [blame] | 49 | #if !defined(CONFIG_BOOT_SWAP_USING_MOVE) |
Dominik Ermel | 3a82b6f | 2022-08-24 14:35:24 +0000 | [diff] [blame] | 50 | #define FLASH_AREA_IMAGE_SCRATCH FIXED_PARTITION_ID(scratch_partition) |
Fabio Utzig | c58842e | 2019-11-28 10:30:01 -0300 | [diff] [blame] | 51 | #endif |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 52 | |
Andrzej Puzdrowski | fdff3e1 | 2020-09-15 08:23:25 +0200 | [diff] [blame] | 53 | #else /* CONFIG_SINGLE_APPLICATION_SLOT */ |
Dominik Ermel | 8101c0c | 2020-05-19 13:01:16 +0000 | [diff] [blame] | 54 | |
Dominik Ermel | 3a82b6f | 2022-08-24 14:35:24 +0000 | [diff] [blame] | 55 | #define FLASH_AREA_IMAGE_PRIMARY(x) FIXED_PARTITION_ID(slot0_partition) |
| 56 | #define FLASH_AREA_IMAGE_SECONDARY(x) FIXED_PARTITION_ID(slot0_partition) |
Dominik Ermel | 8101c0c | 2020-05-19 13:01:16 +0000 | [diff] [blame] | 57 | |
Andrzej Puzdrowski | fdff3e1 | 2020-09-15 08:23:25 +0200 | [diff] [blame] | 58 | #endif /* CONFIG_SINGLE_APPLICATION_SLOT */ |
Dominik Ermel | 8101c0c | 2020-05-19 13:01:16 +0000 | [diff] [blame] | 59 | |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 60 | #endif /* __SYSFLASH_H__ */ |