@@ -353,14 +353,17 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
353353#else
354354
355355/**
356- * Returns non-0 value if fixed-partition of given DTS node label exists.
356+ * Returns non-0 value if fixed-partition or fixed-subpartition of given
357+ * DTS node label exists.
357358 *
358359 * @param label DTS node label
359360 *
360361 * @return non-0 if fixed-partition node exists and is enabled;
361362 * 0 if node does not exist, is not enabled or is not fixed-partition.
362363 */
363- #define FIXED_PARTITION_EXISTS (label ) DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label))
364+ #define FIXED_PARTITION_EXISTS (label ) \
365+ UTIL_OR(DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label)), \
366+ DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)))
364367
365368/**
366369 * Get flash area ID from fixed-partition DTS node label
@@ -372,14 +375,38 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
372375#define FIXED_PARTITION_ID (label ) DT_FIXED_PARTITION_ID(DT_NODELABEL(label))
373376
374377/**
375- * Get fixed-partition offset from DTS node label
378+ * Get fixed-partition or fixed-subpartition offset from DTS node label
376379 *
377380 * @param label DTS node label of a partition
378381 *
379382 * @return fixed-partition offset, as defined for the partition in DTS.
380383 */
381384#define FIXED_PARTITION_OFFSET (label ) DT_REG_ADDR(DT_NODELABEL(label))
382385
386+ /**
387+ * Get fixed-partition or fixed-subpartition address from DTS node label
388+ *
389+ * @param label DTS node label of a partition or subpartition
390+ *
391+ * @return fixed-partition address, as defined for the partition in DTS.
392+ */
393+ #define FIXED_PARTITION_ADDRESS (label ) \
394+ (COND_CODE_1(DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)), \
395+ (DT_FIXED_SUBPARTITION_ADDR(DT_NODELABEL(label))), \
396+ (DT_FIXED_PARTITION_ADDR(DT_NODELABEL(label)))))
397+
398+ /**
399+ * Get fixed-partition or fixed-subpartition address from DTS node
400+ *
401+ * @param node DTS node of a partition
402+ *
403+ * @return fixed-partition address, as defined for the partition in DTS.
404+ */
405+ #define FIXED_PARTITION_NODE_ADDRESS (node ) \
406+ (COND_CODE_1(DT_FIXED_SUBPARTITION_EXISTS(node), \
407+ (DT_FIXED_SUBPARTITION_ADDR(node)), \
408+ (DT_FIXED_PARTITION_ADDR(node))))
409+
383410/**
384411 * Get fixed-partition offset from DTS node
385412 *
@@ -425,8 +452,10 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
425452 * @return Pointer to a device.
426453 */
427454#define FIXED_PARTITION_DEVICE (label ) \
428- DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))
429-
455+ DEVICE_DT_GET(COND_CODE_1( \
456+ DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)), \
457+ (DT_MTD_FROM_FIXED_SUBPARTITION(DT_NODELABEL(label))), \
458+ (DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))))
430459/**
431460 * Get device pointer for device the area/partition resides on
432461 *
@@ -435,7 +464,10 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
435464 * @return Pointer to a device.
436465 */
437466#define FIXED_PARTITION_NODE_DEVICE (node ) \
438- DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(node))
467+ DEVICE_DT_GET(COND_CODE_1( \
468+ DT_FIXED_SUBPARTITION_EXISTS(node), \
469+ (DT_MTD_FROM_FIXED_SUBPARTITION(node)), \
470+ (DT_MTD_FROM_FIXED_PARTITION(node))))
439471
440472/**
441473 * Get pointer to flash_area object by partition label
@@ -471,6 +503,22 @@ DT_FOREACH_STATUS_OKAY(fixed_partitions, FOR_EACH_PARTITION_TABLE)
471503#undef DECLARE_PARTITION
472504#undef DECLARE_PARTITION_0
473505#undef FOR_EACH_PARTITION_TABLE
506+
507+ #define FIXED_SUBPARTITION_1 (node ) FIXED_SUBPARTITION_0(DT_DEP_ORD(node))
508+ #define FIXED_SUBPARTITION_0 (ord ) \
509+ ((const struct flash_area *)&DT_CAT(global_fixed_subpartition_ORD_, ord))
510+
511+ #define DECLARE_SUBPARTITION (node ) DECLARE_SUBPARTITION_0(DT_DEP_ORD(node))
512+ #define DECLARE_SUBPARTITION_0 (ord ) \
513+ extern const struct flash_area DT_CAT(global_fixed_subpartition_ORD_, ord);
514+ #define FOR_EACH_SUBPARTITION_TABLE (table ) DT_FOREACH_CHILD(table, DECLARE_SUBPARTITION)
515+
516+ /* Generate declarations */
517+ DT_FOREACH_STATUS_OKAY (fixed_subpartitions , FOR_EACH_SUBPARTITION_TABLE )
518+
519+ #undef DECLARE_SUBPARTITION
520+ #undef DECLARE_SUBPARTITION_0
521+ #undef FOR_EACH_SUBPARTITION_TABLE
474522/** @endcond */
475523
476524#endif /* USE_PARTITION_MANAGER */
0 commit comments