aboutsummaryrefslogtreecommitdiff
path: root/src/flash
diff options
context:
space:
mode:
authorMarc Schink <openocd-dev@marcschink.de>2016-11-04 09:19:21 +0100
committerFreddie Chopin <freddie.chopin@gmail.com>2017-06-17 12:45:56 +0100
commit1725abc3c0b69660cfe3e43ee3f3dbb479821b31 (patch)
treec0122676aaf88d54d94cc873745e6b6a33ffcb31 /src/flash
parent7112e5f57afffb3b387283f2f6048bf45f25c840 (diff)
downloadriscv-openocd-1725abc3c0b69660cfe3e43ee3f3dbb479821b31.zip
riscv-openocd-1725abc3c0b69660cfe3e43ee3f3dbb479821b31.tar.gz
riscv-openocd-1725abc3c0b69660cfe3e43ee3f3dbb479821b31.tar.bz2
flash/nor/tcl: Make read_bank parameters optional
Make 'offset' and 'length' parameters optional, if both are omitted simply read the whole flash bank. Additionally, check if the 'offset' and 'length' arguments are out of bounds of the flash bank. Change-Id: Ib9c1b0538a2c78ebcf702e2da11468dff407f8ff Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/3862 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/flash')
-rw-r--r--src/flash/nor/tcl.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index ab3b1ea..e5e2801 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -674,7 +674,7 @@ COMMAND_HANDLER(handle_flash_read_bank_command)
uint32_t length;
size_t written;
- if (CMD_ARGC != 4)
+ if (CMD_ARGC < 2 || CMD_ARGC > 4)
return ERROR_COMMAND_SYNTAX_ERROR;
struct duration bench;
@@ -682,11 +682,31 @@ COMMAND_HANDLER(handle_flash_read_bank_command)
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);
+ offset = 0;
+
+ if (CMD_ARGC > 2)
+ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], offset);
+
+ if (offset > p->size) {
+ LOG_ERROR("Offset 0x%8.8" PRIx32 " is out of range of the flash bank",
+ offset);
+ return ERROR_COMMAND_ARGUMENT_INVALID;
+ }
+
+ length = p->size - offset;
+
+ if (CMD_ARGC > 3)
+ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], length);
+
+ if (offset + length > p->size) {
+ LOG_ERROR("Length of %" PRIu32 " bytes with offset 0x%8.8" PRIx32
+ " is out of range of the flash bank", length, offset);
+ return ERROR_COMMAND_ARGUMENT_INVALID;
+ }
buffer = malloc(length);
if (buffer == NULL) {
@@ -966,10 +986,9 @@ static const struct command_registration flash_exec_command_handlers[] = {
.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.",
+ .usage = "bank_id filename [offset [length]]",
+ .help = "Read binary data from flash bank to file. Allow optional "
+ "offset from beginning of the bank (defaults to zero).",
},
{
.name = "verify_bank",