Unable to continue image upload via SMP if device disconnects/restarts

Hello,

we've successfuly been using SMP to update our peripherals so far. Now we've come upon an issue. If the software has a bug, and the device disconnects or reboots during the upload, the device is unable to continue the upload at the point it last left off.

I've followed to error to the file in zephyr/subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/zephyr_img_mgmt.c

There, in the function img_mgmt_impl_upload_inspect, the device will check if it already has data written to it and if it does, it will continue the upload via the sending of the last offset.

The function fails at line 540:

/*
* If request includes proper data hash we can check whether there is
* upload in progress (interrupted due to e.g. link disconnection) with
* the same data hash so we can just resume it by simply including
* current upload offset in response.
*/
if ((req->data_sha.len > 0) && (g_img_mgmt_state.area_id != -1)) {
if ((g_img_mgmt_state.data_sha_len == req->data_sha.len) &&
!memcmp(g_img_mgmt_state.data_sha, req->data_sha.value,
req->data_sha.len)) {
return 0;
}
}

The problem seems to be that g_img_mgmt_state has no data behind it's entry. so g_img_mgmt_state.data_sha_len is 0 and g_img_mgmt_state.data_sha is empty.
The sha256 is being sent with the first package on our side. And it is the correct sha256 entry, so the one you have to extract from the TLV of the image and not one that you calculate yourself.

I'm stuck now at this issue and would love some help regarding this.
If this is not an issue directly involving nordic, I can seek help on the zephyr discord as well.

Related