@@ -133,6 +133,82 @@ extern "C" {
133
133
#define DT_FIXED_PARTITION_ADDR (node_id ) \
134
134
(DT_REG_ADDR(DT_MEM_FROM_FIXED_PARTITION(node_id)) + DT_REG_ADDR(node_id))
135
135
136
+ /**
137
+ * @brief Test if fixed-subpartitions compatible node exists
138
+ *
139
+ * @param node_id DTS node to test
140
+ * @return 1 if node exists and is fixed-subpartitions compatible, 0 otherwise.
141
+ */
142
+ #define DT_FIXED_SUBPARTITION_EXISTS (node_id ) \
143
+ DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions)
144
+
145
+ /**
146
+ * @brief Get the node identifier of the flash memory for a subpartition
147
+ * @param node_id node identifier for a fixed-subpartitions child node
148
+ * @return the node identifier of the internal memory that contains the
149
+ * fixed-subpartitions node, or @ref DT_INVALID_NODE if it doesn't exist.
150
+ */
151
+ #define DT_MEM_FROM_FIXED_SUBPARTITION (node_id ) \
152
+ COND_CODE_1(DT_NODE_HAS_COMPAT(DT_GPARENT(DT_PARENT(node_id)), soc_nv_flash), \
153
+ (DT_GPARENT(DT_PARENT(node_id))), (DT_INVALID_NODE))
154
+
155
+ /**
156
+ * @brief Get the node identifier of the flash controller for a subpartition
157
+ * @param node_id node identifier for a fixed-subpartitions child node
158
+ * @return the node identifier of the memory technology device that
159
+ * contains the fixed-subpartitions node.
160
+ */
161
+ #define DT_MTD_FROM_FIXED_SUBPARTITION (node_id ) \
162
+ COND_CODE_1(DT_NODE_EXISTS(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)), \
163
+ (DT_PARENT(DT_MEM_FROM_FIXED_SUBPARTITION(node_id))), (DT_GPARENT(node_id)))
164
+
165
+ /**
166
+ * @brief Get the absolute address of a fixed subpartition
167
+ *
168
+ * Example devicetree fragment:
169
+ *
170
+ * &flash_controller {
171
+ * flash@1000000 {
172
+ * compatible = "soc-nv-flash";
173
+ *
174
+ * partitions {
175
+ * compatible = "fixed-partitions";
176
+ *
177
+ * slot0_partition: partition@10000 {
178
+ * compatible = "fixed-subpartitions";
179
+ * reg = <0x00010000 0x40000>;
180
+ * ranges = <0x0 0x10000 0x40000>;
181
+ * #address-cells = <1>;
182
+ * #size-cells = <1>;
183
+ *
184
+ * storage_partition: partition@0 {
185
+ * label = "storage";
186
+ * reg = <0x00000000 0x40000>;
187
+ * };
188
+ * };
189
+ * };
190
+ * };
191
+ * };
192
+ *
193
+ * Here, the "storage" partition is seen to belong to flash memory
194
+ * starting at address 0x1000000. The partition's unit address of
195
+ * 0x10000 represents an offset inside that flash memory.
196
+ *
197
+ * Example usage:
198
+ *
199
+ * DT_FIXED_SUBPARTITION_ADDR(DT_NODELABEL(storage_partition)) // 0x1010000
200
+ *
201
+ * This macro can only be used with subpartitions of internal memory
202
+ * addressable by the CPU. Otherwise, it may produce a compile-time
203
+ * error, such as: `'__REG_IDX_0_VAL_ADDRESS' undeclared`.
204
+ *
205
+ * @param node_id node identifier for a fixed-subpartitions child node
206
+ * @return the subpartition's offset plus the base address of the flash
207
+ * node containing it.
208
+ */
209
+ #define DT_FIXED_SUBPARTITION_ADDR (node_id ) \
210
+ (DT_REG_ADDR(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)) + DT_REG_ADDR(node_id))
211
+
136
212
/**
137
213
* @}
138
214
*/
0 commit comments