Skip to content

Commit f52085d

Browse files
de-nordiccarlescufi
authored andcommitted
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 <[email protected]>
1 parent 3d8960f commit f52085d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

subsys/mgmt/mcumgr/lib/cmd/img_mgmt/src/img_mgmt.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,19 +454,22 @@ img_mgmt_upload(struct mgmt_ctxt *ctxt)
454454

455455
rc = img_mgmt_impl_write_image_data(req.off, req.img_data.value, action.write_bytes,
456456
last);
457-
if (rc != 0) {
458-
rc = MGMT_ERR_EUNKNOWN;
457+
if (rc == 0) {
458+
g_img_mgmt_state.off += action.write_bytes;
459+
} else {
460+
/* Write failed, currently not able to recover from this */
461+
cmd_status_arg.status = IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE;
462+
g_img_mgmt_state.area_id = -1;
459463
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(&action,
460464
img_mgmt_err_str_flash_write_failed);
461465
goto end;
462-
} else {
463-
g_img_mgmt_state.off += action.write_bytes;
464-
if (g_img_mgmt_state.off == g_img_mgmt_state.size) {
465-
/* Done */
466-
img_mgmt_dfu_pending();
467-
cmd_status_arg.status = IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE;
468-
g_img_mgmt_state.area_id = -1;
469-
}
466+
}
467+
468+
if (g_img_mgmt_state.off == g_img_mgmt_state.size) {
469+
/* Done */
470+
img_mgmt_dfu_pending();
471+
cmd_status_arg.status = IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE;
472+
g_img_mgmt_state.area_id = -1;
470473
}
471474
}
472475
end:

0 commit comments

Comments
 (0)