Skip to content

nonblocking image upload#613

Merged
eivindj-nordic merged 3 commits intonrfconnect:mainfrom
michalek-no:rram_split_poc
Mar 25, 2026
Merged

nonblocking image upload#613
eivindj-nordic merged 3 commits intonrfconnect:mainfrom
michalek-no:rram_split_poc

Conversation

@michalek-no
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jan 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 13, 2026

You can find the documentation preview for this PR here.

@lemrey
Copy link
Copy Markdown
Contributor

lemrey commented Jan 16, 2026

@michalek-no it would help us to review this PR if you could point to the functionality that you changed/added from the Zephyr implementation, and fix the errors that GitHub is complaining about in the Files changed tab.

@michalek-no michalek-no force-pushed the rram_split_poc branch 5 times, most recently from 7e95fc5 to 7d19184 Compare January 20, 2026 11:42
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c Outdated
@lemrey
Copy link
Copy Markdown
Contributor

lemrey commented Jan 29, 2026

I have a PR for bm_storage where I add a flag to enable automatic padding of write operations #611, and a bunch of other stuff.

@michalek-no michalek-no force-pushed the rram_split_poc branch 2 times, most recently from 8a30e6c to f26f1a3 Compare February 5, 2026 14:37
@michalek-no michalek-no force-pushed the rram_split_poc branch 5 times, most recently from 1d5e92d to 62ca667 Compare February 16, 2026 10:44
Copy link
Copy Markdown
Contributor

@nvlsianpu nvlsianpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c
@michalek-no michalek-no force-pushed the rram_split_poc branch 7 times, most recently from 6a43719 to 3b7bbaf Compare February 23, 2026 12:25
@michalek-no
Copy link
Copy Markdown
Contributor Author

rebase

@michalek-no michalek-no force-pushed the rram_split_poc branch 2 times, most recently from ee821c2 to 05f0f3e Compare February 23, 2026 13:53
@@ -423,19 +478,63 @@ int img_mgmt_write_image_data(unsigned int offset, const void *data, unsigned in
int img_mgmt_write_image_data(unsigned int offset, const void *data, unsigned int num_bytes,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments in code on what is done? why? would be very helpfull.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is so much different then sdk-zephyr origin that I would:

  • move NCS-BM implementation of img_mgmt_read() & int img_mgmt_write_image_data() to a brand new file.
  • cut this fille content as you already did (+ removal of what the new file implements instead).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary in this PR.

@michalek-no michalek-no added the DNM Do not merge label Mar 10, 2026
@michalek-no michalek-no force-pushed the rram_split_poc branch 6 times, most recently from fbfe7c8 to 1cf28f0 Compare March 13, 2026 12:44
@michalek-no michalek-no removed the DNM Do not merge label Mar 13, 2026

ring_buf_put(&ring_buf, data, pad);
rb_size = ring_buf_get_claim(&ring_buf, &rb_data, PKTBUF_SZ);
ring_buf_get_finish(&ring_buf, rb_size);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's correct to call ring_buf_get_finish() here. That functions allows the data you claimed using ring_buf_get_claim() to be overwritten in the buffer, but at this point the data may not have been written yet. You need to keep this data unchanged while it is being written to NVM, meaning until you receive the event from bm_storage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not calling finish() causes size_get() to return incorrect values. 'ongoing' var keeps track on available space.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use value from ring_buf_get_claim() instead of size_get() here? Then we can release at the bm_event.

ring_buf_put(&ring_buf, data, num_bytes);
}

if (last) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When last, it seems you retrieve up to CHUNK_SZ bytes first, then write those bytes, then retrieve everything else that's left and write that. I don't think you need to write twice in this case; could you not simply retrieve everything that's left and write it at once?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles possibility we hit ring buffer wrap around

static uint8_t ongoing;
static int write_offset;

static void bm_storage_evt_handler_writes(struct bm_storage_evt *evt)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead you should inspect the event from bm_storage and free the data there.

@eivindj-nordic eivindj-nordic added this to the v2.0.0 milestone Mar 16, 2026
Copy link
Copy Markdown

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments left.

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c Outdated
}
}

struct bm_storage_config s0_config = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be static const?

},
};

struct bm_storage_config s1_config = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static const?

rb_data, rb_size, NULL);

if (err) {
rc = IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three places where we can get IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE here, shouldn't we at least have LOG_DBG, in all of them, with the err being reported?

if (ring_buf_size_get(&ring_buf)) {
rb_size = ring_buf_get_claim(&ring_buf, &rb_data, PKTBUF_SZ);
ring_buf_get_finish(&ring_buf, rb_size);
int err = bm_storage_write(&s0_storage,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eclipsing err variable declaration in upper scope.

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c Outdated
Copy link
Copy Markdown
Contributor

@eivindj-nordic eivindj-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nits.

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c Outdated
Comment on lines +145 to +146
int err = bm_storage_write(&s0_storage,
write_offset, rb_data, rb_size, NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unaligned

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still unaligned

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c Outdated
Comment thread subsys/storage/bm_storage/bm_storage.c
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c Outdated
@michalek-no
Copy link
Copy Markdown
Contributor Author

rebase

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment on lines +145 to +146
int err = bm_storage_write(&s0_storage,
write_offset, rb_data, rb_size, NULL);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still unaligned

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment on lines +215 to +219
int img_mgmt_find_by_hash(uint8_t *find, struct image_version *ver);
int img_mgmt_find_by_ver(struct image_version *find, uint8_t *hash);
int img_mgmt_state_read(struct smp_streamer *ctxt);
int img_mgmt_state_write(struct smp_streamer *njb);
int img_mgmt_flash_area_id(int slot);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Missing descriptions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the rest are removed, will be good with some description for img_mgmt_state_read().

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c Outdated

ring_buf_put(&ring_buf, data, pad);
rb_size = ring_buf_get_claim(&ring_buf, &rb_data, PKTBUF_SZ);
ring_buf_get_finish(&ring_buf, rb_size);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use value from ring_buf_get_claim() instead of size_get() here? Then we can release at the bm_event.

Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt.c Outdated
Comment thread doc/nrf-bm/release_notes/release_notes_changelog.rst Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/Kconfig Outdated
Comment on lines +204 to +205
struct zcbor_string img_data;
struct zcbor_string data_sha;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add descriptions here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave this minor stuff for the future

@eivindj-nordic
Copy link
Copy Markdown
Contributor

@nrfconnect/ncs-co-build-system Please review! We need to get this in this week.

Comment thread scripts/ci/license_allow_list.yaml
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/include/img_mgmt.h Outdated
Comment thread subsys/mgmt/mcumgr/grp/img_mgmt/src/bm_img_mgmt.c Outdated
* @param ver output buffer for image version
* @param hash output buffer for image hash
* @param flags output buffer for image flags
* @param image_slot Image slot number.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not fix these issues upstream and bring the fixed version in?

@nordicjm
Copy link
Copy Markdown
Contributor

Have not reviewed C code, first 3 comments mandatory, last one a suggestion

img_mgmt.h
img_mgmt_priv.h
img_mgmt.c
zephyr_img_mgmt.c
cherry-picked from sdk-zephyr dbcfb77ce3d20784406d4d73a1de3f7f1bcea07c

Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
@nvlsianpu
Copy link
Copy Markdown
Contributor

@nordicjm My comment to what you posted there:
comment 3rd- that maybe can be improved, comment 4th - no sens to procced. We did deep copy of this. comment 2nd - we can do a workaround for the thing - but this will be hack just for applying request.

access to slot0 and slot1 partitions are handled via
bm_storage subsystem

Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
removed bm unneeded stuff

Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants