STM32L: Validate flash writes
authorKeith Packard <keithp@keithp.com>
Tue, 3 Apr 2012 03:48:41 +0000 (20:48 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 13 Apr 2013 06:23:35 +0000 (23:23 -0700)
Read-back flash data and make sure it is byte-for-byte the same as the
source data.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/flash/nor/stm32lx.c

index 17ac6f080093b0f5e6f6c36d90e4688c3da35928..6c3063fc8a9a70b08dbcfdef4559e2969d072174 100644 (file)
@@ -377,6 +377,12 @@ static int stm32lx_write(struct flash_bank *bank, uint8_t *buffer,
        uint32_t bytes_written = 0;
        int retval;
 
+       uint8_t  *start = buffer;
+       uint32_t start_address = address;
+       uint32_t start_count = count;
+       uint8_t  *validate;
+       uint32_t check;
+
        if (bank->target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
@@ -451,7 +457,26 @@ static int stm32lx_write(struct flash_bank *bank, uint8_t *buffer,
        if (retval != ERROR_OK)
                return retval;
 
-       return ERROR_OK;
+       validate = malloc (start_count);
+
+       retval = target_read_buffer(target, start_address, start_count, validate);
+       if (retval != ERROR_OK) {
+               free (validate);
+               return retval;
+       }
+
+       for (check = 0; check < start_count; check++) {
+               if (validate[check] != start[check]) {
+                       LOG_ERROR ("flash corrupted at 0x%08x (%02x != %02x)\n",
+                                  start_address + check, start[check], validate[check]);
+                       retval = ERROR_FAIL;
+                       break;
+               }
+       }
+
+       free (validate);
+
+       return retval;
 }
 
 static int stm32lx_probe(struct flash_bank *bank)