flash/nor: add flash mdw/h/b commands

Some flash banks are not mapped in the target memory
(e.g. SPI flash, some special pages).

Add flash version of mdw/h/b which reads data using
the flash driver.

Change-Id: I66910e0a69cf523fe5ca1ed6ce7b9e8e176aef4a
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4776
Tested-by: jenkins
Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek 2018-11-22 19:05:04 +01:00
parent 73a5f58adb
commit 6e86ad6166
2 changed files with 95 additions and 0 deletions

View File

@ -5121,6 +5121,19 @@ each block, and the specified length must stay within that bank.
@end deffn @end deffn
@comment no current checks for errors if fill blocks touch multiple banks! @comment no current checks for errors if fill blocks touch multiple banks!
@deffn Command {flash mdw} addr [count]
@deffnx Command {flash mdh} addr [count]
@deffnx Command {flash mdb} addr [count]
Display contents of address @var{addr}, as
32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
or 8-bit bytes (@command{mdb}).
If @var{count} is specified, displays that many units.
Reads from flash using the flash driver, therefore it enables reading
from a bank not mapped in target address space.
The flash bank to use is inferred from the @var{address} of
each block, and the specified length must stay within that bank.
@end deffn
@deffn Command {flash write_bank} num filename [offset] @deffn Command {flash write_bank} num filename [offset]
Write the binary @file{filename} to flash bank @var{num}, Write the binary @file{filename} to flash bank @var{num},
starting at @var{offset} bytes from the beginning of the bank. If @var{offset} starting at @var{offset} bytes from the beginning of the bank. If @var{offset}

View File

@ -628,6 +628,67 @@ done:
return retval; return retval;
} }
COMMAND_HANDLER(handle_flash_md_command)
{
int retval;
if (CMD_ARGC < 1 || CMD_ARGC > 2)
return ERROR_COMMAND_SYNTAX_ERROR;
target_addr_t address;
COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
uint32_t count = 1;
if (CMD_ARGC == 2)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], count);
unsigned int wordsize;
switch (CMD_NAME[2]) {
case 'w':
wordsize = 4;
break;
case 'h':
wordsize = 2;
break;
case 'b':
wordsize = 1;
break;
default:
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (count == 0)
return ERROR_OK;
struct target *target = get_current_target(CMD_CTX);
struct flash_bank *bank;
retval = get_flash_bank_by_addr(target, address, true, &bank);
if (retval != ERROR_OK)
return retval;
uint32_t offset = address - bank->base;
uint32_t sizebytes = count * wordsize;
if (offset + sizebytes > bank->size) {
command_print(CMD, "Cannot cross flash bank borders");
return ERROR_FAIL;
}
uint8_t *buffer = calloc(count, wordsize);
if (buffer == NULL) {
command_print(CMD, "No memory for flash read buffer");
return ERROR_FAIL;
}
retval = flash_driver_read(bank, buffer, offset, sizebytes);
if (retval == ERROR_OK)
target_handle_md_output(CMD, target, address, wordsize, count, buffer);
free(buffer);
return retval;
}
COMMAND_HANDLER(handle_flash_write_bank_command) COMMAND_HANDLER(handle_flash_write_bank_command)
{ {
uint32_t offset; uint32_t offset;
@ -1049,6 +1110,27 @@ static const struct command_registration flash_exec_command_handlers[] = {
.help = "Fill n bytes with 8-bit value, starting at " .help = "Fill n bytes with 8-bit value, starting at "
"word address. (No autoerase.)", "word address. (No autoerase.)",
}, },
{
.name = "mdb",
.handler = handle_flash_md_command,
.mode = COMMAND_EXEC,
.usage = "address [count]",
.help = "Display bytes from flash.",
},
{
.name = "mdh",
.handler = handle_flash_md_command,
.mode = COMMAND_EXEC,
.usage = "address [count]",
.help = "Display half-words from flash.",
},
{
.name = "mdw",
.handler = handle_flash_md_command,
.mode = COMMAND_EXEC,
.usage = "address [count]",
.help = "Display words from flash.",
},
{ {
.name = "write_bank", .name = "write_bank",
.handler = handle_flash_write_bank_command, .handler = handle_flash_write_bank_command,