- removed flash write_image - binary compare function has been moved to verify_image...
[openocd.git] / src / target / target.c
index 0874010c03e5d0e26cd54c881cc8fca7ab872c6c..53022dffd52a85a9ac7b9846ed57ca7891712fb8 100644 (file)
@@ -1876,7 +1876,7 @@ int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, ch
        if (!target)
        {
                ERROR("no target selected");
-       return ERROR_OK;
+               return ERROR_OK;
        }
        
        duration_start_measure(&duration);
@@ -1915,27 +1915,59 @@ int handle_verify_image_command(struct command_context_s *cmd_ctx, char *cmd, ch
                
                /* calculate checksum of image */
                image_calculate_checksum( buffer, buf_cnt, &checksum );
-               free(buffer);
                
                retval = target_checksum_memory(target, image.sections[i].base_address, buf_cnt, &mem_checksum);
                
                if( retval != ERROR_OK )
                {
                        command_print(cmd_ctx, "image verify failed, verify aborted");
+                       free(buffer);
                        image_close(&image);
                        return ERROR_OK;
                }
                
                if( checksum != mem_checksum )
                {
-                       command_print(cmd_ctx, "image verify failed, verify aborted");
-                       image_close(&image);
-                       return ERROR_OK;
-               }
+                       /* failed crc checksum, fall back to a binary compare */
+                       u8 *data;
+                       
+                       command_print(cmd_ctx, "image verify checksum failed - attempting binary compare");
                        
+                       data = (u8*)malloc(buf_cnt);
+                       
+                       /* Can we use 32bit word accesses? */
+                       int size = 1;
+                       int count = buf_cnt;
+                       if ((count % 4) == 0)
+                       {
+                               size *= 4;
+                               count /= 4;
+                       }
+                       retval = target->type->read_memory(target, image.sections[i].base_address, size, count, data);
+       
+                       if (retval == ERROR_OK)
+                       {
+                               int t;
+                               for (t = 0; t < buf_cnt; t++)
+                               {
+                                       if (data[t] != buffer[t])
+                                       {
+                                               command_print(cmd_ctx, "Verify operation failed address 0x%08x. Was 0x%02x instead of 0x%02x\n", t + image.sections[i].base_address, data[t], buffer[t]);
+                                               free(data);
+                                               free(buffer);
+                                               image_close(&image);
+                                               return ERROR_OK;
+                                       }
+                               }
+                       }
+                       
+                       free(data);
+               }
+               
+               free(buffer);
                image_size += buf_cnt;
        }
-
+       
        duration_stop_measure(&duration, &duration_text);
        command_print(cmd_ctx, "verified %u bytes in %s", image_size, duration_text);
        free(duration_text);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)