2017-12-08 11:50:46 +01:00
|
|
|
/*
|
2024-11-06 22:36:23 +01:00
|
|
|
* Copyright (c) 2017-2024 Nordic Semiconductor ASA
|
2017-12-08 11:50:46 +01:00
|
|
|
* Copyright (c) 2015 Runtime Inc
|
2023-04-06 11:15:29 +02:00
|
|
|
* Copyright (c) 2023 Sensorfy B.V.
|
2017-12-08 11:50:46 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-07-02 21:20:23 +10:00
|
|
|
#include <zephyr/device.h>
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2022-05-06 11:12:04 +02:00
|
|
|
#include <zephyr/storage/flash_map.h>
|
2017-12-08 11:50:46 +01:00
|
|
|
|
2023-04-06 11:15:29 +02:00
|
|
|
#if CONFIG_FLASH_MAP_LABELS
|
2025-05-20 09:49:52 +01:00
|
|
|
#define FLASH_AREA_FOO(part, mtd_from_partition) \
|
2022-07-04 15:51:20 +10:00
|
|
|
{.fa_id = DT_FIXED_PARTITION_ID(part), \
|
|
|
|
.fa_off = DT_REG_ADDR(part), \
|
2025-05-20 09:49:52 +01:00
|
|
|
.fa_dev = DEVICE_DT_GET(mtd_from_partition(part)), \
|
2023-04-06 11:15:29 +02:00
|
|
|
.fa_size = DT_REG_SIZE(part), \
|
|
|
|
.fa_label = DT_PROP_OR(part, label, NULL), },
|
|
|
|
#else
|
2025-05-20 09:49:52 +01:00
|
|
|
#define FLASH_AREA_FOO(part, mtd_from_partition) \
|
2023-04-06 11:15:29 +02:00
|
|
|
{.fa_id = DT_FIXED_PARTITION_ID(part), \
|
|
|
|
.fa_off = DT_REG_ADDR(part), \
|
2025-05-20 09:49:52 +01:00
|
|
|
.fa_dev = DEVICE_DT_GET(mtd_from_partition(part)), \
|
2023-04-06 11:15:29 +02:00
|
|
|
.fa_size = DT_REG_SIZE(part), },
|
|
|
|
#endif
|
2020-05-06 23:12:11 -05:00
|
|
|
|
2024-11-11 18:47:12 +01:00
|
|
|
#define FLASH_AREA_FOOO(part) \
|
2025-05-20 09:49:52 +01:00
|
|
|
COND_CODE_1(DT_NODE_HAS_COMPAT(DT_PARENT(part), fixed_partitions), (\
|
|
|
|
COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_MTD_FROM_FIXED_PARTITION(part)), \
|
|
|
|
(FLASH_AREA_FOO(part, DT_MTD_FROM_FIXED_PARTITION)), ())), ( \
|
|
|
|
COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_MTD_FROM_FIXED_SUBPARTITION(part)), \
|
|
|
|
(FLASH_AREA_FOO(part, DT_MTD_FROM_FIXED_SUBPARTITION)), ())))
|
2024-11-11 18:47:12 +01:00
|
|
|
|
2025-05-20 09:49:52 +01:00
|
|
|
#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(n, FLASH_AREA_FOOO)
|
2020-05-06 23:12:11 -05:00
|
|
|
|
2022-03-16 21:07:43 +00:00
|
|
|
/* We iterate over all compatible 'fixed-partitions' nodes and
|
2020-05-06 23:12:11 -05:00
|
|
|
* use DT_FOREACH_CHILD to iterate over all the partitions for that
|
2022-03-16 21:07:43 +00:00
|
|
|
* 'fixed-partitions' node. This way we build a global partition map
|
2020-05-06 23:12:11 -05:00
|
|
|
*/
|
2017-12-08 11:50:46 +01:00
|
|
|
const struct flash_area default_flash_map[] = {
|
2025-05-20 09:49:52 +01:00
|
|
|
DT_FOREACH_STATUS_OKAY(fixed_partitions, FOREACH_PARTITION)
|
2017-12-08 11:50:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const int flash_map_entries = ARRAY_SIZE(default_flash_map);
|
|
|
|
const struct flash_area *flash_map = default_flash_map;
|
2024-11-06 22:36:23 +01:00
|
|
|
|
|
|
|
/* Generate objects representing each partition in system. In the end only
|
|
|
|
* objects referenced by code will be included into build.
|
|
|
|
*/
|
|
|
|
#define DEFINE_PARTITION(part) DEFINE_PARTITION_1(part, DT_DEP_ORD(part))
|
|
|
|
#define DEFINE_PARTITION_1(part, ord) \
|
|
|
|
COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_MTD_FROM_FIXED_PARTITION(part)), \
|
|
|
|
(DEFINE_PARTITION_0(part, ord)), ())
|
|
|
|
#define DEFINE_PARTITION_0(part, ord) \
|
|
|
|
const struct flash_area DT_CAT(global_fixed_partition_ORD_, ord) = { \
|
|
|
|
.fa_id = DT_FIXED_PARTITION_ID(part), \
|
|
|
|
.fa_off = DT_REG_ADDR(part), \
|
|
|
|
.fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(part)), \
|
|
|
|
.fa_size = DT_REG_SIZE(part), \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FOR_EACH_PARTITION_TABLE(table) DT_FOREACH_CHILD(table, DEFINE_PARTITION)
|
|
|
|
DT_FOREACH_STATUS_OKAY(fixed_partitions, FOR_EACH_PARTITION_TABLE)
|
2025-05-20 09:49:52 +01:00
|
|
|
|
|
|
|
#define DEFINE_SUB_PARTITION(part) DEFINE_SUB_PARTITION_1(part, DT_DEP_ORD(part))
|
|
|
|
#define DEFINE_SUB_PARTITION_1(part, ord) \
|
|
|
|
COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_MTD_FROM_FIXED_SUBPARTITION(part)), \
|
|
|
|
(DEFINE_SUB_PARTITION_0(part, ord)), ())
|
|
|
|
#define DEFINE_SUB_PARTITION_0(part, ord) \
|
|
|
|
const struct flash_area DT_CAT(global_fixed_subpartition_ORD_, ord) = { \
|
|
|
|
.fa_id = DT_FIXED_PARTITION_ID(part), \
|
|
|
|
.fa_off = DT_REG_ADDR(part), \
|
|
|
|
.fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_SUBPARTITION(part)), \
|
|
|
|
.fa_size = DT_REG_SIZE(part), \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FOR_EACH_SUB_PARTITION_TABLE(table) DT_FOREACH_CHILD(table, DEFINE_SUB_PARTITION)
|
|
|
|
DT_FOREACH_STATUS_OKAY(fixed_subpartitions, FOR_EACH_SUB_PARTITION_TABLE)
|