target: add "phys" argument to mem2array, array2mem

Allow using physical addresses with mem2array and array2mem. In order
to minimize the impact on existing scripts, "phys" is added as an
optional 5th parameter to both commands.

This patch also adds "phys" variants to the memwrite/memread commands
in memory.tcl.

Change-Id: Ia6307f9d861789e7f3ccf1f98961d666bf8d85d6
Signed-off-by: Matthias Welwarsky <matthias.welwarsky@sysgo.com>
Reviewed-on: http://openocd.zylin.com/3387
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
__archive__
Matthias Welwarsky 2016-03-02 13:52:52 +01:00 committed by Andreas Fritiofson
parent 6f8cf930bc
commit 918de0be13
2 changed files with 86 additions and 6 deletions

View File

@ -3913,6 +3913,8 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
uint32_t count; uint32_t count;
uint32_t v; uint32_t v;
const char *varname; const char *varname;
const char *phys;
bool is_phys;
int n, e, retval; int n, e, retval;
uint32_t i; uint32_t i;
@ -3921,8 +3923,8 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
* argv[3] = memory address * argv[3] = memory address
* argv[4] = count of times to read * argv[4] = count of times to read
*/ */
if (argc != 4) { if (argc < 4 || argc > 5) {
Jim_WrongNumArgs(interp, 1, argv, "varname width addr nelems"); Jim_WrongNumArgs(interp, 1, argv, "varname width addr nelems [phys]");
return JIM_ERR; return JIM_ERR;
} }
varname = Jim_GetString(argv[0], &len); varname = Jim_GetString(argv[0], &len);
@ -3941,6 +3943,14 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
len = l; len = l;
if (e != JIM_OK) if (e != JIM_OK)
return e; return e;
is_phys = false;
if (argc > 4) {
phys = Jim_GetString(argv[4], &n);
if (!strncmp(phys, "phys", n))
is_phys = true;
else
return JIM_ERR;
}
switch (width) { switch (width) {
case 8: case 8:
width = 1; width = 1;
@ -4006,6 +4016,9 @@ static int target_mem2array(Jim_Interp *interp, struct target *target, int argc,
if (count > (buffersize / width)) if (count > (buffersize / width))
count = (buffersize / width); count = (buffersize / width);
if (is_phys)
retval = target_read_phys_memory(target, addr, width, count, buffer);
else
retval = target_read_memory(target, addr, width, count, buffer); retval = target_read_memory(target, addr, width, count, buffer);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
/* BOO !*/ /* BOO !*/
@ -4102,6 +4115,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target,
uint32_t count; uint32_t count;
uint32_t v; uint32_t v;
const char *varname; const char *varname;
const char *phys;
bool is_phys;
int n, e, retval; int n, e, retval;
uint32_t i; uint32_t i;
@ -4110,8 +4125,8 @@ static int target_array2mem(Jim_Interp *interp, struct target *target,
* argv[3] = memory address * argv[3] = memory address
* argv[4] = count to write * argv[4] = count to write
*/ */
if (argc != 4) { if (argc < 4 || argc > 5) {
Jim_WrongNumArgs(interp, 0, argv, "varname width addr nelems"); Jim_WrongNumArgs(interp, 0, argv, "varname width addr nelems [phys]");
return JIM_ERR; return JIM_ERR;
} }
varname = Jim_GetString(argv[0], &len); varname = Jim_GetString(argv[0], &len);
@ -4130,6 +4145,14 @@ static int target_array2mem(Jim_Interp *interp, struct target *target,
len = l; len = l;
if (e != JIM_OK) if (e != JIM_OK)
return e; return e;
is_phys = false;
if (argc > 4) {
phys = Jim_GetString(argv[4], &n);
if (!strncmp(phys, "phys", n))
is_phys = true;
else
return JIM_ERR;
}
switch (width) { switch (width) {
case 8: case 8:
width = 1; width = 1;
@ -4216,6 +4239,9 @@ static int target_array2mem(Jim_Interp *interp, struct target *target,
} }
len -= count; len -= count;
if (is_phys)
retval = target_write_phys_memory(target, addr, width, count, buffer);
else
retval = target_write_memory(target, addr, width, count, buffer); retval = target_write_memory(target, addr, width, count, buffer);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
/* BOO !*/ /* BOO !*/

View File

@ -131,3 +131,57 @@ proc memwrite8 {ADDR DATA} {
error "memwrite8: $msg" error "memwrite8: $msg"
} }
} }
proc memread32_phys {ADDR} {
set foo(0) 0
if ![ catch { mem2array foo 32 $ADDR 1 phys } msg ] {
return $foo(0)
} else {
error "memread32: $msg"
}
}
proc memread16_phys {ADDR} {
set foo(0) 0
if ![ catch { mem2array foo 16 $ADDR 1 phys } msg ] {
return $foo(0)
} else {
error "memread16: $msg"
}
}
proc memread8_phys {ADDR} {
set foo(0) 0
if ![ catch { mem2array foo 8 $ADDR 1 phys } msg ] {
return $foo(0)
} else {
error "memread8: $msg"
}
}
proc memwrite32_phys {ADDR DATA} {
set foo(0) $DATA
if ![ catch { array2mem foo 32 $ADDR 1 phys } msg ] {
return $foo(0)
} else {
error "memwrite32: $msg"
}
}
proc memwrite16_phys {ADDR DATA} {
set foo(0) $DATA
if ![ catch { array2mem foo 16 $ADDR 1 phys } msg ] {
return $foo(0)
} else {
error "memwrite16: $msg"
}
}
proc memwrite8_phys {ADDR DATA} {
set foo(0) $DATA
if ![ catch { array2mem foo 8 $ADDR 1 phys } msg ] {
return $foo(0)
} else {
error "memwrite8: $msg"
}
}