target: Add verify_image_checksum command

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>
gitignore-build
Matthias Welwarsky 2016-11-10 20:53:26 +01:00 committed by Paul Fertser
parent 420c15de6c
commit 29964c7984
2 changed files with 34 additions and 5 deletions

View 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. This will first attempt a comparison using a CRC checksum, if this fails it will try a binary compare.
@end deffn @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 @section Breakpoint and Watchpoint commands
@cindex breakpoint @cindex breakpoint

View 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; uint8_t *buffer;
size_t buf_cnt; 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 */ /* calculate checksum of image */
retval = image_calculate_checksum(buffer, buf_cnt, &checksum); retval = image_calculate_checksum(buffer, buf_cnt, &checksum);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
@ -3370,7 +3376,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
free(buffer); free(buffer);
break; break;
} }
if ((checksum != mem_checksum) && (verify == IMAGE_CHECKSUM_ONLY)) {
LOG_ERROR("checksum mismatch");
free(buffer);
retval = ERROR_FAIL;
goto done;
}
if (checksum != mem_checksum) { if (checksum != mem_checksum) {
/* failed crc checksum, fall back to a binary compare */ /* failed crc checksum, fall back to a binary compare */
uint8_t *data; 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, .mode = COMMAND_EXEC,
.usage = "filename address size", .usage = "filename address size",
}, },
{
.name = "verify_image_checksum",
.handler = handle_verify_image_checksum_command,
.mode = COMMAND_EXEC,
.usage = "filename [offset [type]]",
},
{ {
.name = "verify_image", .name = "verify_image",
.handler = handle_verify_image_command, .handler = handle_verify_image_command,