saulpw commented on a change in pull request #1613: Fix disconnect during OTA by spacing out erases URL: https://github.com/apache/mynewt-core/pull/1613#discussion_r250837466
########## File path: mgmt/imgmgr/src/imgmgr.c ########## @@ -739,19 +784,32 @@ imgr_upload(struct mgmt_cbuf *cb) } #endif +#if MYNEWT_VAL(IMGMGR_LAZY_ERASE) + /* setup for lazy sector by sector erase */ + imgr_state.sector_id = -1; + imgr_state.sector_end = 0; +#else + /* erase the entire req.size all at once */ if (action.erase) { rc = flash_area_erase(fa, 0, req.size); if (rc != 0) { rc = MGMT_ERR_EUNKNOWN; errstr = imgmgr_err_str_flash_erase_failed; } } +#endif } /* Write the image data to flash. */ if (rc == 0 && req.data_len != 0) { - rc = flash_area_write(fa, req.off, req.img_data, action.write_bytes); - if (rc != 0) { +#if MYNEWT_VAL(IMGMGR_LAZY_ERASE) + /* erase as we cross sector boundaries */ + if (imgr_erase_if_needed(fa, req.off, action.write_bytes) != 0) { + rc = MGMT_ERR_EUNKNOWN; + errstr = imgmgr_err_str_flash_erase_failed; + } else Review comment: Ironically we had a `goto` in the first place and I argued that we should match the surrounding code style and remove it. Looks like @jerobi was right in the first place :) Fixed now. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services