This is an automated email from Gerrit. Robert Jordens ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/2842
-- gerrit commit a08fb3fa54c064595006f75218a7be59912f72f4 Author: Robert Jordens <[email protected]> Date: Wed Jul 1 02:55:49 2015 -0600 flash/nor/tcl: add "flash read_bank" command Before the only read access to the flash was through the target's memory. Flashes like jtagspi do not expose a memory mapped interface to the flash. This command uses the flash_driver_read() driver API directly. Change-Id: I40b910de650114a3f676507f9f059a234377d862 Signed-off-by: Robert Jordens <[email protected]> diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 8f97ebd..812fd54 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -610,6 +610,70 @@ COMMAND_HANDLER(handle_flash_write_bank_command) return retval; } +COMMAND_HANDLER(handle_flash_read_bank_command) +{ + uint32_t offset; + uint8_t *buffer; + struct fileio fileio; + uint32_t length; + size_t written; + + if (CMD_ARGC != 4) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct duration bench; + duration_start(&bench); + + struct flash_bank *p; + int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &p); + if (ERROR_OK != retval) + return retval; + + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], offset); + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], length); + + buffer = malloc(length); + if (buffer == NULL) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + + retval = flash_driver_read(p, buffer, offset, length); + if (retval != ERROR_OK) { + LOG_ERROR("Read error"); + free(buffer); + return retval; + } + + retval = fileio_open(&fileio, CMD_ARGV[1], FILEIO_WRITE, FILEIO_BINARY); + if (retval != ERROR_OK) { + LOG_ERROR("Could not open file"); + free(buffer); + return retval; + } + + retval = fileio_write(&fileio, length, buffer, &written); + if (retval != ERROR_OK) { + LOG_ERROR("Could not write file"); + free(buffer); + fileio_close(&fileio); + return ERROR_FAIL; + } + + free(buffer); + fileio_close(&fileio); + + if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { + command_print(CMD_CTX, "wrote %ld bytes to file %s from flash bank %u" + " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", + (long)written, CMD_ARGV[1], p->bank_number, offset, + duration_elapsed(&bench), duration_kbps(&bench, written)); + } + + return retval; +} + + void flash_set_dirty(void) { struct flash_bank *c; @@ -727,6 +791,15 @@ static const struct command_registration flash_exec_command_handlers[] = { "offset from beginning of bank (defaults to zero)", }, { + .name = "read_bank", + .handler = handle_flash_read_bank_command, + .mode = COMMAND_EXEC, + .usage = "bank_id filename offset length", + .help = "Read binary data from flash bank to file, " + "starting at specified byte offset from the " + "beginning of the bank.", + }, + { .name = "protect", .handler = handle_flash_protect_command, .mode = COMMAND_EXEC, -- ------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/ _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
