Skip to content

Commit 1d5e92d

Browse files
committed
wip
1 parent b843e6f commit 1d5e92d

3 files changed

Lines changed: 20 additions & 72 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
387387
}
388388

389389
rc = img_mgmt_read(image_slot,
390-
boot_get_image_start_offset(img_mgmt_flash_area_id(image_slot)),
390+
0,
391391
&hdr, sizeof(hdr));
392+
LOG_ERR("read info - %d", rc);
392393

393394
if (rc != 0) {
394395
return rc;
@@ -417,8 +418,7 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
417418
* TLV. All images are required to have a hash TLV. If the hash is missing, the image
418419
* is considered invalid.
419420
*/
420-
data_off = hdr.ih_hdr_size + hdr.ih_img_size +
421-
boot_get_image_start_offset(img_mgmt_flash_area_id(image_slot));
421+
data_off = hdr.ih_hdr_size + hdr.ih_img_size;
422422

423423
rc = img_mgmt_find_tlvs(image_slot, &data_off, &data_end, IMAGE_TLV_PROT_INFO_MAGIC);
424424
if (!rc) {

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

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -505,68 +505,6 @@ static bool img_mgmt_state_encode_slot(struct smp_streamer *ctxt, uint32_t slot,
505505
/**
506506
* Command handler: image state read
507507
*/
508-
#if !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER)
509-
int
510-
img_mgmt_state_read(struct smp_streamer *ctxt)
511-
{
512-
LOG_ERR("state read");
513-
return MGMT_ERR_EOK;
514-
zcbor_state_t *zse = ctxt->writer->zs;
515-
uint32_t i;
516-
bool ok;
517-
518-
519-
ok = zcbor_tstr_put_lit(zse, "images") &&
520-
zcbor_list_start_encode(zse, 2 * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER);
521-
522-
img_mgmt_take_lock();
523-
524-
for (i = 0; ok && i < CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
525-
/* _a is active slot, _o is opposite slot */
526-
enum img_mgmt_next_boot_type type = NEXT_BOOT_TYPE_NORMAL;
527-
int next_boot_slot = img_mgmt_get_next_boot_slot(i, &type);
528-
int slot_a = img_mgmt_active_slot(i);
529-
int slot_o = img_mgmt_get_opposite_slot(slot_a);
530-
int flags_a = REPORT_SLOT_ACTIVE;
531-
int flags_o = 0;
532-
533-
if (type != NEXT_BOOT_TYPE_REVERT) {
534-
flags_a |= REPORT_SLOT_CONFIRMED;
535-
}
536-
537-
if (next_boot_slot != slot_a) {
538-
if (type == NEXT_BOOT_TYPE_NORMAL) {
539-
flags_o = REPORT_SLOT_PENDING | REPORT_SLOT_PERMANENT;
540-
} else if (type == NEXT_BOOT_TYPE_REVERT) {
541-
flags_o = REPORT_SLOT_CONFIRMED;
542-
} else if (type == NEXT_BOOT_TYPE_TEST) {
543-
flags_o = REPORT_SLOT_PENDING;
544-
}
545-
}
546-
547-
/* Need to report slots in proper order */
548-
if (slot_a < slot_o) {
549-
ok = img_mgmt_state_encode_slot(ctxt, slot_a, flags_a) &&
550-
img_mgmt_state_encode_slot(ctxt, slot_o, flags_o);
551-
} else {
552-
ok = img_mgmt_state_encode_slot(ctxt, slot_o, flags_o) &&
553-
img_mgmt_state_encode_slot(ctxt, slot_a, flags_a);
554-
}
555-
}
556-
557-
/* Ending list encoding for two slots per image */
558-
ok = ok && zcbor_list_end_encode(zse, 2 * CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER);
559-
/* splitStatus is always 0 so in frugal list it is not present at all */
560-
if (!IS_ENABLED(CONFIG_MCUMGR_GRP_IMG_FRUGAL_LIST) && ok) {
561-
ok = zcbor_tstr_put_lit(zse, "splitStatus") &&
562-
zcbor_int32_put(zse, 0);
563-
}
564-
565-
img_mgmt_release_lock();
566-
567-
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
568-
}
569-
#else
570508
int
571509
img_mgmt_state_read(struct smp_streamer *ctxt)
572510
{
@@ -580,6 +518,7 @@ img_mgmt_state_read(struct smp_streamer *ctxt)
580518
img_mgmt_take_lock();
581519

582520
for (i = 0; ok && i < CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER; i++) {
521+
LOG_ERR("state read %d", i);
583522
/* _a is active slot, _o is opposite slot */
584523
int slot_a = img_mgmt_active_slot(i);
585524
int slot_o = img_mgmt_get_opposite_slot(slot_a);
@@ -602,7 +541,6 @@ img_mgmt_state_read(struct smp_streamer *ctxt)
602541

603542
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
604543
}
605-
#endif /* !defined(CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER) */
606544

607545
static int img_mgmt_set_next_boot_slot_common(int slot, int active_slot, bool confirm)
608546
{

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
3636
#define S0_SIZE DT_REG_SIZE(S0_PARTITION)
3737

3838
static struct bm_storage s0_storage;
39+
static int storage_init;
3940

4041
/* SLOT0_PARTITION and SLOT1_PARTITION are not checked because
4142
* there is not conditional code that depends on them. If they do
@@ -61,6 +62,12 @@ static void bm_storage_evt_handler_a(struct bm_storage_evt *evt)
6162
ongoing--;
6263
}
6364
}
65+
struct bm_storage_config storage_config_a = {
66+
.evt_handler = bm_storage_evt_handler_a,
67+
.start_addr = S0_START,
68+
.end_addr = S0_START+S0_SIZE,
69+
};
70+
6471

6572
/**
6673
* Get flash_area ID for a image number; actually the slots are images
@@ -178,6 +185,11 @@ int img_mgmt_vercmp(const struct image_version *a, const struct image_version *b
178185
int img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_bytes)
179186
{
180187

188+
if(!storage_init){
189+
LOG_ERR("init");
190+
bm_storage_init(&s0_storage, &storage_config_a);
191+
storage_init=1;
192+
}
181193
return bm_storage_read(&s0_storage, s0_storage.start_addr + offset,
182194
dst, num_bytes);
183195
}
@@ -191,12 +203,10 @@ int img_mgmt_write_image_data(unsigned int offset, const void *data, unsigned in
191203
uint8_t *rb_data;
192204

193205
if (offset == 0) {
194-
struct bm_storage_config storage_config_a = {
195-
.evt_handler = bm_storage_evt_handler_a,
196-
.start_addr = S0_START,
197-
.end_addr = S0_START+S0_SIZE,
198-
};
199-
bm_storage_init(&s0_storage, &storage_config_a);
206+
if(!storage_init){
207+
bm_storage_init(&s0_storage, &storage_config_a);
208+
storage_init=1;
209+
}
200210
}
201211
int rb_freespace = ring_buf_space_get(&ring_buf);
202212

0 commit comments

Comments
 (0)