1 /** 2 * @file 3 * @brief Flash Devicetree macro public API header file. 4 */ 5 6 /* 7 * Copyright (c) 2020, Linaro Ltd. 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 12 #ifndef ZEPHYR_INCLUDE_DEVICETREE_FIXED_PARTITION_H_ 13 #define ZEPHYR_INCLUDE_DEVICETREE_FIXED_PARTITION_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * @defgroup devicetree-fixed-partition Devicetree Fixed Partition API 21 * @ingroup devicetree 22 * @{ 23 */ 24 25 /** 26 * @brief Get a node identifier for a fixed partition with 27 * a given label property 28 * 29 * Example devicetree fragment: 30 * 31 * flash@... { 32 * partitions { 33 * compatible = "fixed-partitions"; 34 * boot_partition: partition@0 { 35 * label = "mcuboot"; 36 * }; 37 * slot0_partition: partition@c000 { 38 * label = "image-0"; 39 * }; 40 * ... 41 * }; 42 * }; 43 * 44 * Example usage: 45 * 46 * DT_NODE_BY_FIXED_PARTITION_LABEL(mcuboot) // node identifier for boot_partition 47 * DT_NODE_BY_FIXED_PARTITION_LABEL(image_0) // node identifier for slot0_partition 48 * 49 * @param label lowercase-and-underscores label property value 50 * @return a node identifier for the partition with that label property 51 */ 52 #define DT_NODE_BY_FIXED_PARTITION_LABEL(label) \ 53 DT_CAT(DT_COMPAT_fixed_partitions_LABEL_, label) 54 55 /** 56 * @brief Test if a fixed partition with a given label property exists 57 * @param label lowercase-and-underscores label property value 58 * @return 1 if any "fixed-partitions" child node has the given label, 59 * 0 otherwise. 60 */ 61 #define DT_HAS_FIXED_PARTITION_LABEL(label) \ 62 IS_ENABLED(DT_COMPAT_fixed_partitions_LABEL_##label##_EXISTS) 63 64 /** 65 * @brief Get a numeric identifier for a fixed partition 66 * @param node_id node identifier for a fixed-partitions child node 67 * @return the partition's ID, a unique zero-based index number 68 */ 69 #define DT_FIXED_PARTITION_ID(node_id) DT_CAT(node_id, _PARTITION_ID) 70 71 /** 72 * @brief Get the node identifier of the flash device for a partition 73 * @param node_id node identifier for a fixed-partitions child node 74 * @return the node identifier of the memory technology device that 75 * contains the fixed-partitions node. 76 */ 77 #define DT_MTD_FROM_FIXED_PARTITION(node_id) \ 78 COND_CODE_1(DT_NODE_HAS_COMPAT(DT_GPARENT(node_id), soc_nv_flash), \ 79 (DT_PARENT(DT_GPARENT(node_id))), \ 80 (DT_GPARENT(node_id))) 81 82 /** 83 * @} 84 */ 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif /* ZEPHYR_INCLUDE_DEVICETREE_FIXED_PARTITION_H_ */ 91