Skip to content

Commit 0771af0

Browse files
Emil-JuhlMads Bligaard Nielsen
authored and
Mads Bligaard Nielsen
committed
boot: zephyr: sysflash: restore FLASH_AREA_IMAGE_x macros
When introducing the MCUBOOT_MCUMGR_SIMPLE_IMAGE_INDEX option[1], the following macros were changed: FLASH_AREA_IMAGE_PRIMARY(x) FLASH_AREA_IMAGE_SECONDARY(x) These macros are used in other parts of the MCUboot codebase as well, so it seems more appropriate to make the config implementation a bit uglier to restore the intended behavior[2] of these macros. The SIMPLE_IMAGE_INDEX is only relevant for `boot_serial.c` to simplify the `mcumgr` image numbering. Note: one case is unreachable and commented out since the SCRATCH partition definition also is not available here. [1] 766be5d [2] nrfconnect@7c3d7ed
1 parent 10de1a2 commit 0771af0

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

boot/boot_serial/src/boot_serial.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,33 @@ static int flash_area_id_from_upload_id(uint32_t upload_id)
319319
if (upload_id >= 1) {
320320
uint32_t image_index = (upload_id - 1) / 2;
321321
uint32_t slot = (upload_id - 1) % 2;
322-
return flash_area_id_from_multi_image_slot(image_index, slot);
322+
/* This switch is essentially a manual inlining of the
323+
* `flash_area_id_from_multi_image_slot` function.
324+
* The return value has been tweaked to fit the SIMPLE_IMAGE_INDEX
325+
* scheme though.
326+
* This solution may be preferred over tweaking the FLASH_AREA_IMAGE_x
327+
* macros as they are used in other places as well.
328+
* */
329+
switch(slot) {
330+
case 0:
331+
switch(image_index) {
332+
case 0: return PM_MCUBOOT_PRIMARY_ID;
333+
case 1: return PM_S0_ID;
334+
default: return 255;
335+
}
336+
case 1:
337+
switch(image_index) {
338+
case 0: return PM_MCUBOOT_SECONDARY_ID;
339+
case 1: return PM_S1_ID;
340+
default: return 255;
341+
}
342+
/* Case unreachable. Included for completeness
343+
* case 2:
344+
* return FLASH_AREA_IMAGE_SCRATCH;
345+
* */
346+
default:
347+
return -1;
348+
}
323349
}
324350
return -1;
325351
#elif defined(MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD)

boot/zephyr/include/sysflash/sysflash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ extern uint32_t _image_1_primary_slot_id[];
3636
((x == 0) ? \
3737
PM_MCUBOOT_PRIMARY_ID : \
3838
(x == 1) ? \
39-
PM_S0_ID : \
39+
PM_MCUBOOT_PRIMARY_ID : \
4040
255 )
4141
#endif
4242

4343
#define FLASH_AREA_IMAGE_SECONDARY(x) \
4444
((x == 0) ? \
4545
PM_MCUBOOT_SECONDARY_ID: \
4646
(x == 1) ? \
47-
PM_S1_ID : \
47+
PM_MCUBOOT_SECONDARY_ID : \
4848
255 )
4949
#else
5050

0 commit comments

Comments
 (0)