From 55f2fe830a541a297d6bf3906c6a28df81acbf05 Mon Sep 17 00:00:00 2001 From: ntfreak Date: Thu, 20 Dec 2007 16:19:10 +0000 Subject: - removed flash write_image - binary compare function has been moved to verify_image command - minor code reformat and cleanup - updated docs to include new commands git-svn-id: svn://svn.berlios.de/openocd/trunk@243 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/target/target.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'src/target/target.c') diff --git a/src/target/target.c b/src/target/target.c index 0874010c..53022dff 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -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); -- cgit v1.2.3