Skip to content

Commit 718be64

Browse files
de-nordicfabiobaltieri
authored andcommitted
mgmt/mcumgr: Don't add unused slots in img_mgmt_flash_area_id
The img_mgmt_flash_area_id would add processing of slot2_partition and slot3_partition if they only exist, even if not used at all. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 302dba6 commit 718be64

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,37 @@ BUILD_ASSERT(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 1 ||
3434
FIXED_PARTITION_EXISTS(SLOT3_PARTITION)),
3535
"Missing partitions?");
3636

37+
#if defined(CONFIG_MCUMGR_GRP_IMG_DIRECT_UPLOAD) && \
38+
!(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER > 1)
39+
/* In case when direct upload is enabled, slot2 and slot3 are optional
40+
* as long as there is support for one application image only.
41+
*/
42+
#define ADD_SLOT_2_CONDITION FIXED_PARTITION_EXISTS(SLOT2_PARTITION)
43+
#define ADD_SLOT_3_CONDITION FIXED_PARTITION_EXISTS(SLOT3_PARTITION)
44+
#elif (CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER > 1)
45+
/* For more than one application image slot2 and slot3 are required. */
46+
#define ADD_SLOT_2_CONDITION 1
47+
#define ADD_SLOT_3_CONDITION 1
48+
#else
49+
/* If neither in direct upload mode nor more than one application image
50+
* is supported, then slot2 and slot3 support is useless.
51+
*/
52+
#define ADD_SLOT_2_CONDITION 0
53+
#define ADD_SLOT_3_CONDITION 0
54+
#endif
55+
3756
static int
3857
img_mgmt_slot_to_image(int slot)
3958
{
4059
switch (slot) {
4160
case 0:
4261
case 1:
4362
return 0;
44-
#if FIXED_PARTITION_EXISTS(SLOT2_PARTITION) && FIXED_PARTITION_EXISTS(SLOT2_PARTITION)
63+
#if ADD_SLOT_2_CONDITION
4564
case 2:
65+
return 1;
66+
#endif
67+
#if ADD_SLOT_3_CONDITION
4668
case 3:
4769
return 1;
4870
#endif
@@ -141,13 +163,13 @@ img_mgmt_flash_area_id(int slot)
141163
fa_id = FIXED_PARTITION_ID(SLOT1_PARTITION);
142164
break;
143165

144-
#if FIXED_PARTITION_EXISTS(SLOT2_PARTITION)
166+
#if ADD_SLOT_2_CONDITION
145167
case 2:
146168
fa_id = FIXED_PARTITION_ID(SLOT2_PARTITION);
147169
break;
148170
#endif
149171

150-
#if FIXED_PARTITION_EXISTS(SLOT3_PARTITION)
172+
#if ADD_SLOT_3_CONDITION
151173
case 3:
152174
fa_id = FIXED_PARTITION_ID(SLOT3_PARTITION);
153175
break;

0 commit comments

Comments
 (0)