@@ -349,14 +349,17 @@ const char *flash_area_label(const struct flash_area *fa);
349349uint8_t flash_area_erased_val (const struct flash_area * fa );
350350
351351/**
352- * Returns non-0 value if fixed-partition of given DTS node label exists.
352+ * Returns non-0 value if fixed-partition or fixed-subpartition of given
353+ * DTS node label exists.
353354 *
354355 * @param label DTS node label
355356 *
356357 * @return non-0 if fixed-partition node exists and is enabled;
357358 * 0 if node does not exist, is not enabled or is not fixed-partition.
358359 */
359- #define FIXED_PARTITION_EXISTS (label ) DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label))
360+ #define FIXED_PARTITION_EXISTS (label ) \
361+ UTIL_OR(DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label)), \
362+ DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)))
360363
361364/**
362365 * Get flash area ID from fixed-partition DTS node label
@@ -368,14 +371,38 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
368371#define FIXED_PARTITION_ID (label ) DT_FIXED_PARTITION_ID(DT_NODELABEL(label))
369372
370373/**
371- * Get fixed-partition offset from DTS node label
374+ * Get fixed-partition or fixed-subpartition offset from DTS node label
372375 *
373376 * @param label DTS node label of a partition
374377 *
375378 * @return fixed-partition offset, as defined for the partition in DTS.
376379 */
377380#define FIXED_PARTITION_OFFSET (label ) DT_REG_ADDR(DT_NODELABEL(label))
378381
382+ /**
383+ * Get fixed-partition or fixed-subpartition address from DTS node label
384+ *
385+ * @param label DTS node label of a partition or subpartition
386+ *
387+ * @return fixed-partition address, as defined for the partition in DTS.
388+ */
389+ #define FIXED_PARTITION_ADDRESS (label ) \
390+ (COND_CODE_1(DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)), \
391+ (DT_FIXED_SUBPARTITION_ADDR(DT_NODELABEL(label))), \
392+ (DT_FIXED_PARTITION_ADDR(DT_NODELABEL(label)))))
393+
394+ /**
395+ * Get fixed-partition or fixed-subpartition address from DTS node
396+ *
397+ * @param node DTS node of a partition
398+ *
399+ * @return fixed-partition address, as defined for the partition in DTS.
400+ */
401+ #define FIXED_PARTITION_NODE_ADDRESS (node ) \
402+ (COND_CODE_1(DT_FIXED_SUBPARTITION_EXISTS(node), \
403+ (DT_FIXED_SUBPARTITION_ADDR(node)), \
404+ (DT_FIXED_PARTITION_ADDR(node))))
405+
379406/**
380407 * Get fixed-partition offset from DTS node
381408 *
@@ -421,8 +448,10 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
421448 * @return Pointer to a device.
422449 */
423450#define FIXED_PARTITION_DEVICE (label ) \
424- DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))
425-
451+ DEVICE_DT_GET(COND_CODE_1( \
452+ DT_FIXED_SUBPARTITION_EXISTS(DT_NODELABEL(label)), \
453+ (DT_MTD_FROM_FIXED_SUBPARTITION(DT_NODELABEL(label))), \
454+ (DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))))
426455/**
427456 * Get device pointer for device the area/partition resides on
428457 *
@@ -431,7 +460,10 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
431460 * @return Pointer to a device.
432461 */
433462#define FIXED_PARTITION_NODE_DEVICE (node ) \
434- DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(node))
463+ DEVICE_DT_GET(COND_CODE_1( \
464+ DT_FIXED_SUBPARTITION_EXISTS(node), \
465+ (DT_MTD_FROM_FIXED_SUBPARTITION(node)), \
466+ (DT_MTD_FROM_FIXED_PARTITION(node))))
435467
436468/**
437469 * Get pointer to flash_area object by partition label
@@ -467,6 +499,22 @@ DT_FOREACH_STATUS_OKAY(fixed_partitions, FOR_EACH_PARTITION_TABLE)
467499#undef DECLARE_PARTITION
468500#undef DECLARE_PARTITION_0
469501#undef FOR_EACH_PARTITION_TABLE
502+
503+ #define FIXED_SUBPARTITION_1 (node ) FIXED_SUBPARTITION_0(DT_DEP_ORD(node))
504+ #define FIXED_SUBPARTITION_0 (ord ) \
505+ ((const struct flash_area *)&DT_CAT(global_fixed_subpartition_ORD_, ord))
506+
507+ #define DECLARE_SUBPARTITION (node ) DECLARE_SUBPARTITION_0(DT_DEP_ORD(node))
508+ #define DECLARE_SUBPARTITION_0 (ord ) \
509+ extern const struct flash_area DT_CAT(global_fixed_subpartition_ORD_, ord);
510+ #define FOR_EACH_SUBPARTITION_TABLE (table ) DT_FOREACH_CHILD(table, DECLARE_SUBPARTITION)
511+
512+ /* Generate declarations */
513+ DT_FOREACH_STATUS_OKAY (fixed_subpartitions , FOR_EACH_SUBPARTITION_TABLE )
514+
515+ #undef DECLARE_SUBPARTITION
516+ #undef DECLARE_SUBPARTITION_0
517+ #undef FOR_EACH_SUBPARTITION_TABLE
470518/** @endcond */
471519
472520#ifdef __cplusplus
0 commit comments