aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Welwarsky <matthias.welwarsky@sysgo.com>2016-11-10 20:53:26 +0100
committerPaul Fertser <fercerpav@gmail.com>2016-12-08 12:28:37 +0000
commit29964c79846ea419e113dc90c0d74f1a7e16e70a (patch)
tree9fdf610b62fd2fd8b8449aee9160428d3c452b0c /src
parent420c15de6c3e423d2e1cb717f2210d0d13be9578 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/target/target.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 4c5ddd3e..26bae4b6 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3299,7 +3299,13 @@ COMMAND_HANDLER(handle_dump_image_command)
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;
@@ -3357,7 +3363,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
break;
}
- if (verify) {
+ if (verify >= IMAGE_VERIFY) {
/* 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;
}
-
+ 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;
@@ -3435,14 +3446,19 @@ done:
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)
{
- 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)
{
- 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)
@@ -6219,6 +6235,12 @@ static const struct command_registration target_exec_command_handlers[] = {
.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,
.mode = COMMAND_EXEC,