ccollins476ad commented on a change in pull request #1301: kernel/os: Add debug 
mode syscfg setting
URL: https://github.com/apache/mynewt-core/pull/1301#discussion_r205947396
 
 

 ##########
 File path: hw/hal/src/hal_flash.c
 ##########
 @@ -91,11 +93,98 @@ hal_flash_read(uint8_t id, uint32_t address, void *dst, 
uint32_t num_bytes)
     return hf->hf_itf->hff_read(hf, address, dst, num_bytes);
 }
 
+#if MYNEWT_VAL(HAL_FLASH_VERIFY_ERASES)
+/**
+ * Verifies that the specified range of flash is erased.
+ *
+ * @return                      0 on success;
+ *                              nonzero on error or unexpected contents.
+ */
+static int
+hal_flash_cmp_erased(const struct hal_flash *hf, uint32_t address,
+  uint32_t num_bytes)
+{
+    uint8_t empty[MYNEWT_VAL(HAL_FLASH_VERIFY_BUF_SZ)];
+    uint8_t buf[MYNEWT_VAL(HAL_FLASH_VERIFY_BUF_SZ)];
+
+    uint32_t off;
+    uint32_t rem;
+    int chunk_sz;
+    int rc;
+
+    memset(empty, 0xff, sizeof empty);
+
+    for (off = 0; off < num_bytes; off += sizeof buf) {
+        rem = num_bytes - off;
+        if (rem >= sizeof buf) {
+            chunk_sz = sizeof buf;
+        } else {
+            chunk_sz = rem;
+        }
+
+        rc = hf->hf_itf->hff_read(hf, address + off, buf, chunk_sz);
+        if (rc != 0) {
+            return rc;
+        }
+
+        if (memcmp(buf, empty, chunk_sz) != 0) {
 
 Review comment:
   Good point.  I'm not sure why I didn't think of that.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to