Skip to content

Commit e249596

Browse files
nordicjmkartben
authored andcommitted
mgmt: mcumgr: grp: img_mgmt: Add support for firmware loader mode
Adds support for using img mgmt in firmware loader mode, to allow for loading an update image to a device Signed-off-by: Jamie McCrae <[email protected]>
1 parent 7508215 commit e249596

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ config MCUMGR_GRP_IMG_VERBOSE_ERR
6464

6565
config MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_SECONDARY
6666
bool "Allow to confirm secondary slot of non-active image"
67+
depends on !MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER
6768
default y
6869
help
6970
Allows to confirm secondary (non-active) slot of non-active image.
@@ -74,6 +75,7 @@ config MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_SECONDARY
7475

7576
config MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_ANY
7677
bool "Allow to confirm slots of non-active image"
78+
depends on !MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER
7779
select MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_SECONDARY
7880
help
7981
Allows to confirm any slot of non-active image.
@@ -82,18 +84,18 @@ config MCUMGR_GRP_IMG_ALLOW_CONFIRM_NON_ACTIVE_IMAGE_ANY
8284
broken and may not boot in other slot; instead application should
8385
have means to test and confirm the image.
8486

85-
if !MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
8687
config MCUMGR_GRP_IMG_ALLOW_ERASE_PENDING
8788
bool "Allow to erase pending slot"
89+
depends on !MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
8890
default y
8991
help
9092
Allows erasing secondary slot which is marked for test or confirmed; this allows
9193
erasing slots that have been set for next boot but the device has not
9294
reset yet, so has not yet been swapped.
93-
endif
9495

9596
config MCUMGR_GRP_IMG_DIRECT_UPLOAD
9697
bool "Allow direct image upload"
98+
depends on !MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER
9799
help
98100
Enables directly uploading image to selected image partition.
99101
This changes how "image" is understood by MCUmgr: normally MCUmgr allows uploading to
@@ -106,6 +108,7 @@ config MCUMGR_GRP_IMG_DIRECT_UPLOAD
106108

107109
config MCUMGR_GRP_IMG_REJECT_DIRECT_XIP_MISMATCHED_SLOT
108110
bool "Reject Direct-XIP applications with mismatched address"
111+
depends on MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP || MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT
109112
help
110113
When enabled, the MCUmgr will compare base address of application,
111114
encoded into .bin file header with use of imgtool, on upload and will

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ BUILD_ASSERT(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
8787
#define ACTIVE_IMAGE_IS 0
8888
#endif
8989

90+
#if CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER
91+
#define SLOTS_PER_IMAGE 1
92+
#else
9093
#define SLOTS_PER_IMAGE 2
94+
#endif
9195

9296
LOG_MODULE_REGISTER(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
9397

@@ -360,7 +364,7 @@ img_mgmt_find_by_ver(struct image_version *find, uint8_t *hash)
360364
int i;
361365
struct image_version ver;
362366

363-
for (i = 0; i < 2 * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
367+
for (i = 0; i < SLOTS_PER_IMAGE * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
364368
if (img_mgmt_read_info(i, &ver, hash, NULL) != 0) {
365369
continue;
366370
}
@@ -381,7 +385,7 @@ img_mgmt_find_by_hash(uint8_t *find, struct image_version *ver)
381385
int i;
382386
uint8_t hash[IMAGE_HASH_LEN];
383387

384-
for (i = 0; i < 2 * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
388+
for (i = 0; i < SLOTS_PER_IMAGE * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
385389
if (img_mgmt_read_info(i, ver, hash, NULL) != 0) {
386390
continue;
387391
}
@@ -1087,7 +1091,8 @@ static const struct mgmt_handler img_mgmt_handlers[] = {
10871091
[IMG_MGMT_ID_STATE] = {
10881092
.mh_read = img_mgmt_state_read,
10891093
#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) || \
1090-
defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD)
1094+
defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD) || \
1095+
defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
10911096
.mh_write = NULL
10921097
#else
10931098
.mh_write = img_mgmt_state_write,

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
6161
/**
6262
* Collects information about the specified image slot.
6363
*/
64-
#ifndef CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP
64+
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \
65+
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
6566
uint8_t
6667
img_mgmt_state_flags(int query_slot)
6768
{
@@ -143,7 +144,8 @@ img_mgmt_state_flags(int query_slot)
143144
#endif
144145

145146
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \
146-
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
147+
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) && \
148+
!defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
147149
int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
148150
{
149151
const int active_slot = img_mgmt_active_slot(image);
@@ -300,7 +302,8 @@ int img_mgmt_get_next_boot_slot(int image, enum img_mgmt_next_boot_type *type)
300302
return return_slot;
301303
}
302304
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP) && \
303-
* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
305+
* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT) && \
306+
* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
304307
*/
305308

306309

@@ -322,6 +325,9 @@ img_mgmt_state_any_pending(void)
322325
int
323326
img_mgmt_slot_in_use(int slot)
324327
{
328+
#if defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
329+
return 0;
330+
#else
325331
int image = img_mgmt_slot_to_image(slot);
326332
int active_slot = img_mgmt_active_slot(image);
327333

@@ -348,6 +354,7 @@ img_mgmt_slot_in_use(int slot)
348354
#endif
349355

350356
return (active_slot == slot);
357+
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */
351358
}
352359

353360
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ img_mgmt_flash_area_id(int slot)
140140
fa_id = FIXED_PARTITION_ID(SLOT0_PARTITION);
141141
break;
142142

143+
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
143144
case 1:
144145
fa_id = FIXED_PARTITION_ID(SLOT1_PARTITION);
145146
break;
@@ -167,6 +168,7 @@ img_mgmt_flash_area_id(int slot)
167168
fa_id = FIXED_PARTITION_ID(SLOT5_PARTITION);
168169
break;
169170
#endif
171+
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */
170172

171173
default:
172174
fa_id = -1;

0 commit comments

Comments
 (0)