You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/01/25 00:53:31 UTC

[GitHub] andrzej-kaczmarek commented on a change in pull request #1613: Fix disconnect during OTA by spacing out erases

andrzej-kaczmarek 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_r250833190
 
 

 ##########
 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:
   such `if`s split by `#ifdef` are quite confusing so I'd prefer to avoid this by either using `goto` or perhaps just moving this into its own `if (rc == 0 && req.data_len != 0)` and `#ifdef` as a whole

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services