mkiiskila commented on a change in pull request #281: imgmgr: add erase 
command, remove erase from upload command
URL: 
https://github.com/apache/incubator-mynewt-core/pull/281#discussion_r119241026
 
 

 ##########
 File path: sys/flash_map/src/flash_map.c
 ##########
 @@ -131,6 +132,40 @@ flash_area_align(const struct flash_area *fa)
     return hal_flash_align(fa->fa_device_id);
 }
 
+int
+flash_area_is_empty(const struct flash_area *fa, bool *empty)
+{
+    uint32_t data[64 >> 2];
+    uint32_t data_off = 0;
+    int8_t bytes_to_read;
+    uint8_t i;
+    int rc;
+
+    while(data_off < fa->fa_size)
+    {
+        bytes_to_read = min(64, fa->fa_size - data_off);
+        rc = flash_area_read(fa, data_off, data, bytes_to_read);
+        if (rc) {
+            return rc;
+        }
+        for (i = 0; i < bytes_to_read >> 2; i++){
+          if (data[i] != (uint32_t) -1) {
+            goto not_empty;
+          }
+        }
+        for (i = i << 2; i < bytes_to_read; i++) {
+          if (*(((uint8_t *) data) + i) != (uint8_t) -1) {
+            goto not_empty;
+          }
+        }
 
 Review comment:
   I don't think this 2nd for loop is needed. I have not encountered a flash 
sector which would not be a multiple of minimally 4 bytes.
 
----------------------------------------------------------------
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

Reply via email to