target: Add verify_image_checksum command 69/2869/6
authorMatthias Welwarsky <matthias.welwarsky@sysgo.com>
Thu, 10 Nov 2016 19:53:26 +0000 (20:53 +0100)
committerPaul Fertser <fercerpav@gmail.com>
Thu, 8 Dec 2016 12:28:37 +0000 (12:28 +0000)
This avoids the secondary binary search if the checksum is different

Change-Id: I986ba7687cea76f30e37a6bca58aabde18198263
Signed-off-by: Evan Hunter <ehunter@broadcom.com>
Signed-off-by: Matthias Welwarsky <matthias.welwarsky@sysgo.com>
Reviewed-on: http://openocd.zylin.com/2869
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
doc/openocd.texi
src/target/target.c

index 4ce61871b9b5036221344e01033e0fb29ae0dced..497a20b5b138a79cf1315fc211347285046c6e0f 100644 (file)
@@ -6984,6 +6984,13 @@ The file format may optionally be specified
 This will first attempt a comparison using a CRC checksum, if this fails it will try a binary compare.
 @end deffn
 
 This will first attempt a comparison using a CRC checksum, if this fails it will try a binary compare.
 @end deffn
 
+@deffn Command {verify_image_checksum} filename address [@option{bin}|@option{ihex}|@option{elf}]
+Verify @var{filename} against target memory starting at @var{address}.
+The file format may optionally be specified
+(@option{bin}, @option{ihex}, or @option{elf})
+This perform a comparison using a CRC checksum only
+@end deffn
+
 
 @section Breakpoint and Watchpoint commands
 @cindex breakpoint
 
 @section Breakpoint and Watchpoint commands
 @cindex breakpoint
index 4c5ddd3e03043512b6ec2334411c6df280afd02c..26bae4b69a5ed13907f2b1833d5dff085dc2520e 100644 (file)
@@ -3299,7 +3299,13 @@ COMMAND_HANDLER(handle_dump_image_command)
        return retval;
 }
 
        return retval;
 }
 
-static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
+enum verify_mode {
+       IMAGE_TEST = 0,
+       IMAGE_VERIFY = 1,
+       IMAGE_CHECKSUM_ONLY = 2
+};
+
+static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode verify)
 {
        uint8_t *buffer;
        size_t buf_cnt;
 {
        uint8_t *buffer;
        size_t buf_cnt;
@@ -3357,7 +3363,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
                        break;
                }
 
                        break;
                }
 
-               if (verify) {
+               if (verify >= IMAGE_VERIFY) {
                        /* calculate checksum of image */
                        retval = image_calculate_checksum(buffer, buf_cnt, &checksum);
                        if (retval != ERROR_OK) {
                        /* calculate checksum of image */
                        retval = image_calculate_checksum(buffer, buf_cnt, &checksum);
                        if (retval != ERROR_OK) {
@@ -3370,7 +3376,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
                                free(buffer);
                                break;
                        }
                                free(buffer);
                                break;
                        }
-
+                       if ((checksum != mem_checksum) && (verify == IMAGE_CHECKSUM_ONLY)) {
+                               LOG_ERROR("checksum mismatch");
+                               free(buffer);
+                               retval = ERROR_FAIL;
+                               goto done;
+                       }
                        if (checksum != mem_checksum) {
                                /* failed crc checksum, fall back to a binary compare */
                                uint8_t *data;
                        if (checksum != mem_checksum) {
                                /* failed crc checksum, fall back to a binary compare */
                                uint8_t *data;
@@ -3435,14 +3446,19 @@ done:
        return retval;
 }
 
        return retval;
 }
 
+COMMAND_HANDLER(handle_verify_image_checksum_command)
+{
+       return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, IMAGE_CHECKSUM_ONLY);
+}
+
 COMMAND_HANDLER(handle_verify_image_command)
 {
 COMMAND_HANDLER(handle_verify_image_command)
 {
-       return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, 1);
+       return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, IMAGE_VERIFY);
 }
 
 COMMAND_HANDLER(handle_test_image_command)
 {
 }
 
 COMMAND_HANDLER(handle_test_image_command)
 {
-       return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, 0);
+       return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, IMAGE_TEST);
 }
 
 static int handle_bp_command_list(struct command_context *cmd_ctx)
 }
 
 static int handle_bp_command_list(struct command_context *cmd_ctx)
@@ -6218,6 +6234,12 @@ static const struct command_registration target_exec_command_handlers[] = {
                .mode = COMMAND_EXEC,
                .usage = "filename address size",
        },
                .mode = COMMAND_EXEC,
                .usage = "filename address size",
        },
+       {
+               .name = "verify_image_checksum",
+               .handler = handle_verify_image_checksum_command,
+               .mode = COMMAND_EXEC,
+               .usage = "filename [offset [type]]",
+       },
        {
                .name = "verify_image",
                .handler = handle_verify_image_command,
        {
                .name = "verify_image",
                .handler = handle_verify_image_command,

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)