Skip to content

Commit 0e45d40

Browse files
committed
partition_manager: Add FIXED_PARTITION macro
Upstream Flash Map defines FIXED_PARTITION macro that allows to obtain direct pointer to flash_area object representing the partition, and bypass the flash_area_open call. This PR adds the macro to Partition Manager. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 063432a commit 0e45d40

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

include/flash_map_pm.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,15 @@
7171
#define FIXED_PARTITION_EXISTS(label) IS_ENABLED(PM_IS_ENABLED(label))
7272
#define FLASH_AREA_LABEL_EXISTS(label) FIXED_PARTITION_EXISTS(label)
7373

74+
#define FIXED_PARTITION(label) \
75+
((const struct flash_area *)&UTIL_CAT(global_pm_partition_, label))
76+
77+
#define DECLARE_PARTITION(label) \
78+
extern const struct flash_area UTIL_CAT(global_pm_partition_, label)
79+
80+
/* For each partition found in PM config generate the extern declaration */
81+
#define MAKE_LABEL(id, _) UTIL_CAT(PM_, UTIL_CAT(PM_##id##_LABEL))
82+
FOR_EACH(DECLARE_PARTITION, (;), LISTIFY(PM_NUM, MAKE_LABEL, (,)));
83+
#undef MAKE_LABEL
84+
7485
#endif /* FLASH_MAP_PM_H_*/

subsys/partition_manager/flash_map_partition_manager.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@
4444
COND_CODE_1(FLASH_MAP_PM_DEV_HAS_ALL(x), \
4545
(FLASH_AREA_FOO(x)), ())
4646

47-
#define FLASH_AREA_FOO(i) \
47+
#define FLASH_AREA_FOOO(i) \
4848
{ \
4949
.fa_id = FLASH_MAP_ID(i), \
5050
.fa_off = FLASH_MAP_OFFSET(i), \
5151
.fa_dev = FLASH_MAP_DEV(i), \
5252
.fa_size = FLASH_MAP_SIZE(i) \
53-
},
53+
}
54+
55+
#define FLASH_AREA_FOO(i) FLASH_AREA_FOOO(i),
5456

5557
#define MAKE_SINGLE(x) UTIL_CAT(PM_, UTIL_CAT(PM_##x##_LABEL))
5658
#define FLASH_MAP_PM_SINGLE(x, _) FLASH_MAP_PM_ENTRY(UTIL_CAT(PM_, UTIL_CAT(PM_##x##_LABEL)))
@@ -63,6 +65,14 @@ static const struct flash_area pm_flash_map[] = {
6365
const int flash_map_entries = ARRAY_SIZE(pm_flash_map);
6466
const struct flash_area *flash_map = pm_flash_map;
6567

68+
#define DEFINE_PARTITION(part) \
69+
COND_CODE_1(FLASH_MAP_PM_DEV_HAS_ALL(part), (DEFINE_PARTITION_0(part)), ())
70+
#define DEFINE_PARTITION_0(part) \
71+
const struct flash_area UTIL_CAT(global_pm_partition_, part) = FLASH_AREA_FOOO(part)
72+
73+
#define MAKE_LABEL(x, _) UTIL_CAT(PM_, UTIL_CAT(PM_##x##_LABEL))
74+
FOR_EACH(DEFINE_PARTITION, (;), LISTIFY(PM_NUM, MAKE_LABEL, (,)));
75+
6676
#else
6777

6878
const int flash_map_entries = 0;

0 commit comments

Comments
 (0)