mgmt/mcumgr/lib: Fix loop when image write fails
The img_mgmt_upload was getting into loop with requesting offset 0 from mcumgr, when requested to re-try upload after write fails. Because it is not really possible to recover from write fail, at least currently, the commit changes code to reset upload state in a case of write error and return an error code. Now, when write fails, an error will be returned and upload process will be stopped and reset; upload re-try will behave as a new upload has been requested. Fixes #44219 Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
3d8960ffe3
commit
f52085dc54
|
@ -454,19 +454,22 @@ img_mgmt_upload(struct mgmt_ctxt *ctxt)
|
|||
|
||||
rc = img_mgmt_impl_write_image_data(req.off, req.img_data.value, action.write_bytes,
|
||||
last);
|
||||
if (rc != 0) {
|
||||
rc = MGMT_ERR_EUNKNOWN;
|
||||
if (rc == 0) {
|
||||
g_img_mgmt_state.off += action.write_bytes;
|
||||
} else {
|
||||
/* Write failed, currently not able to recover from this */
|
||||
cmd_status_arg.status = IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE;
|
||||
g_img_mgmt_state.area_id = -1;
|
||||
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(&action,
|
||||
img_mgmt_err_str_flash_write_failed);
|
||||
goto end;
|
||||
} else {
|
||||
g_img_mgmt_state.off += action.write_bytes;
|
||||
if (g_img_mgmt_state.off == g_img_mgmt_state.size) {
|
||||
/* Done */
|
||||
img_mgmt_dfu_pending();
|
||||
cmd_status_arg.status = IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE;
|
||||
g_img_mgmt_state.area_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_img_mgmt_state.off == g_img_mgmt_state.size) {
|
||||
/* Done */
|
||||
img_mgmt_dfu_pending();
|
||||
cmd_status_arg.status = IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE;
|
||||
g_img_mgmt_state.area_id = -1;
|
||||
}
|
||||
}
|
||||
end:
|
||||
|
|
Loading…
Reference in a new issue