From 7310eb9e4ae4abb8a78843d36473f9a013111f5d Mon Sep 17 00:00:00 2001 From: Kumar Gala Date: Wed, 6 May 2020 23:12:11 -0500 Subject: [PATCH] storage: flash_map_default: Convert to new dts macros Convert to use new DTS macros to populate default flash map Signed-off-by: Kumar Gala --- subsys/storage/flash_map/flash_map_default.c | 44 +++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/subsys/storage/flash_map/flash_map_default.c b/subsys/storage/flash_map/flash_map_default.c index 5edc3d70d7b..d7bfd040726 100644 --- a/subsys/storage/flash_map/flash_map_default.c +++ b/subsys/storage/flash_map/flash_map_default.c @@ -5,17 +5,49 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT fixed_partitions + #include #include -#define FLASH_AREA_FOO(i, _) \ - {.fa_id = i, \ - .fa_off = DT_FLASH_AREA_##i##_OFFSET, \ - .fa_dev_name = DT_FLASH_AREA_##i##_DEV, \ - .fa_size = DT_FLASH_AREA_##i##_SIZE,}, +/* Get the grand parent of a node */ +#define GPARENT(node_id) DT_PARENT(DT_PARENT(node_id)) +/* if 'soc-nv-flash' return controller label or punt to _else_code */ +#define IS_SOC_NV_FLASH(part, _else_code) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(GPARENT(part), soc_nv_flash), \ + (DT_LABEL(DT_PARENT(GPARENT(part)))), (_else_code)) + +/* if 'jedec,spi-nor' return controller label or punt to _else_code */ +#define IS_JEDEC_SPI_NOR(part, _else_code) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(GPARENT(part), jedec_spi_nor), \ + (DT_LABEL(GPARENT(part))), (_else_code)) + +/* if 'nordic,qspi-nor' return controller label or punt to _else_code */ +#define IS_NORDIC_QSPI_NOR(part, _else_code) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(GPARENT(part), nordic_qspi_nor), \ + (DT_LABEL(GPARENT(part))), (_else_code)) + +/* return flash controller label based on matching compatible or NULL */ +#define DT_FLASH_DEV_FROM_PART(part) \ + IS_SOC_NV_FLASH(part, \ + IS_JEDEC_SPI_NOR(part, \ + IS_NORDIC_QSPI_NOR(part, NULL))) + +#define FLASH_AREA_FOO(part) \ + {.fa_id = DT_FIXED_PARTITION_ID(part), \ + .fa_off = DT_REG_ADDR(part), \ + .fa_dev_name = DT_FLASH_DEV_FROM_PART(part), \ + .fa_size = DT_REG_SIZE(part),}, + +#define FOREACH_PARTION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOO) + +/* We iterate over all compatible 'fixed-partions' nodes and + * use DT_FOREACH_CHILD to iterate over all the partitions for that + * 'fixed-partions' node. This way we build a global partition map + */ const struct flash_area default_flash_map[] = { - UTIL_LISTIFY(DT_FLASH_AREA_NUM, FLASH_AREA_FOO, ~) + DT_INST_FOREACH_STATUS_OKAY(FOREACH_PARTION) }; const int flash_map_entries = ARRAY_SIZE(default_flash_map);