sandbox: Change memory commands to use map_physmem
Sandbox wants to support commands which use memory. The map_sysmen() call provides this feature, so use this in the memory commands. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
4213fc2913
commit
0628ab8ec5
122
common/cmd_mem.c
122
common/cmd_mem.c
|
@ -33,6 +33,7 @@
|
||||||
#include <dataflash.h>
|
#include <dataflash.h>
|
||||||
#endif
|
#endif
|
||||||
#include <watchdog.h>
|
#include <watchdog.h>
|
||||||
|
#include <asm/io.h>
|
||||||
#include <linux/compiler.h>
|
#include <linux/compiler.h>
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
@ -138,9 +139,13 @@ static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
{
|
{
|
||||||
|
ulong bytes = size * length;
|
||||||
|
const void *buf = map_sysmem(addr, bytes);
|
||||||
|
|
||||||
/* Print the lines. */
|
/* Print the lines. */
|
||||||
print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
|
print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
|
||||||
addr += size*length;
|
addr += bytes;
|
||||||
|
unmap_sysmem(buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -163,6 +168,8 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
ulong addr, writeval, count;
|
ulong addr, writeval, count;
|
||||||
int size;
|
int size;
|
||||||
|
void *buf;
|
||||||
|
ulong bytes;
|
||||||
|
|
||||||
if ((argc < 3) || (argc > 4))
|
if ((argc < 3) || (argc > 4))
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -188,15 +195,18 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
count = 1;
|
count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bytes = size * count;
|
||||||
|
buf = map_sysmem(addr, bytes);
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
if (size == 4)
|
if (size == 4)
|
||||||
*((ulong *)addr) = (ulong )writeval;
|
*((ulong *)buf) = (ulong)writeval;
|
||||||
else if (size == 2)
|
else if (size == 2)
|
||||||
*((ushort *)addr) = (ushort)writeval;
|
*((ushort *)buf) = (ushort)writeval;
|
||||||
else
|
else
|
||||||
*((u_char *)addr) = (u_char)writeval;
|
*((u_char *)buf) = (u_char)writeval;
|
||||||
addr += size;
|
buf += size;
|
||||||
}
|
}
|
||||||
|
unmap_sysmem(buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,10 +268,11 @@ int do_mem_mwc ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
|
||||||
static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
ulong addr1, addr2, count, ngood;
|
ulong addr1, addr2, count, ngood, bytes;
|
||||||
int size;
|
int size;
|
||||||
int rcode = 0;
|
int rcode = 0;
|
||||||
const char *type;
|
const char *type;
|
||||||
|
const void *buf1, *buf2, *base;
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -294,33 +305,40 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bytes = size * count;
|
||||||
|
base = buf1 = map_sysmem(addr1, bytes);
|
||||||
|
buf2 = map_sysmem(addr2, bytes);
|
||||||
for (ngood = 0; ngood < count; ++ngood) {
|
for (ngood = 0; ngood < count; ++ngood) {
|
||||||
ulong word1, word2;
|
ulong word1, word2;
|
||||||
if (size == 4) {
|
if (size == 4) {
|
||||||
word1 = *(ulong *)addr1;
|
word1 = *(ulong *)buf1;
|
||||||
word2 = *(ulong *)addr2;
|
word2 = *(ulong *)buf2;
|
||||||
} else if (size == 2) {
|
} else if (size == 2) {
|
||||||
word1 = *(ushort *)addr1;
|
word1 = *(ushort *)buf1;
|
||||||
word2 = *(ushort *)addr2;
|
word2 = *(ushort *)buf2;
|
||||||
} else {
|
} else {
|
||||||
word1 = *(u_char *)addr1;
|
word1 = *(u_char *)buf1;
|
||||||
word2 = *(u_char *)addr2;
|
word2 = *(u_char *)buf2;
|
||||||
}
|
}
|
||||||
if (word1 != word2) {
|
if (word1 != word2) {
|
||||||
|
ulong offset = buf1 - base;
|
||||||
|
|
||||||
printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
|
printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
|
||||||
type, addr1, size, word1,
|
type, (ulong)(addr1 + offset), size, word1,
|
||||||
type, addr2, size, word2);
|
type, (ulong)(addr2 + offset), size, word2);
|
||||||
rcode = 1;
|
rcode = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr1 += size;
|
buf1 += size;
|
||||||
addr2 += size;
|
buf2 += size;
|
||||||
|
|
||||||
/* reset watchdog from time to time */
|
/* reset watchdog from time to time */
|
||||||
if ((ngood % (64 << 10)) == 0)
|
if ((ngood % (64 << 10)) == 0)
|
||||||
WATCHDOG_RESET();
|
WATCHDOG_RESET();
|
||||||
}
|
}
|
||||||
|
unmap_sysmem(buf1);
|
||||||
|
unmap_sysmem(buf2);
|
||||||
|
|
||||||
printf("Total of %ld %s(s) were the same\n", ngood, type);
|
printf("Total of %ld %s(s) were the same\n", ngood, type);
|
||||||
return rcode;
|
return rcode;
|
||||||
|
@ -328,8 +346,10 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
|
|
||||||
static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
ulong addr, dest, count;
|
ulong addr, dest, count, bytes;
|
||||||
int size;
|
int size;
|
||||||
|
const void *src;
|
||||||
|
void *buf;
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -419,15 +439,18 @@ static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bytes = size * count;
|
||||||
|
buf = map_sysmem(addr, bytes);
|
||||||
|
src = map_sysmem(addr, bytes);
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
if (size == 4)
|
if (size == 4)
|
||||||
*((ulong *)dest) = *((ulong *)addr);
|
*((ulong *)buf) = *((ulong *)src);
|
||||||
else if (size == 2)
|
else if (size == 2)
|
||||||
*((ushort *)dest) = *((ushort *)addr);
|
*((ushort *)buf) = *((ushort *)src);
|
||||||
else
|
else
|
||||||
*((u_char *)dest) = *((u_char *)addr);
|
*((u_char *)buf) = *((u_char *)src);
|
||||||
addr += size;
|
src += size;
|
||||||
dest += size;
|
buf += size;
|
||||||
|
|
||||||
/* reset watchdog from time to time */
|
/* reset watchdog from time to time */
|
||||||
if ((count % (64 << 10)) == 0)
|
if ((count % (64 << 10)) == 0)
|
||||||
|
@ -453,11 +476,12 @@ static int do_mem_base(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
|
static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
char * const argv[])
|
char * const argv[])
|
||||||
{
|
{
|
||||||
ulong addr, length, i;
|
ulong addr, length, i, bytes;
|
||||||
int size;
|
int size;
|
||||||
volatile uint *longp;
|
volatile uint *longp;
|
||||||
volatile ushort *shortp;
|
volatile ushort *shortp;
|
||||||
volatile u_char *cp;
|
volatile u_char *cp;
|
||||||
|
const void *buf;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -477,28 +501,31 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
*/
|
*/
|
||||||
length = simple_strtoul(argv[2], NULL, 16);
|
length = simple_strtoul(argv[2], NULL, 16);
|
||||||
|
|
||||||
|
bytes = size * length;
|
||||||
|
buf = map_sysmem(addr, bytes);
|
||||||
|
|
||||||
/* We want to optimize the loops to run as fast as possible.
|
/* We want to optimize the loops to run as fast as possible.
|
||||||
* If we have only one object, just run infinite loops.
|
* If we have only one object, just run infinite loops.
|
||||||
*/
|
*/
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
if (size == 4) {
|
if (size == 4) {
|
||||||
longp = (uint *)addr;
|
longp = (uint *)buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
i = *longp;
|
i = *longp;
|
||||||
}
|
}
|
||||||
if (size == 2) {
|
if (size == 2) {
|
||||||
shortp = (ushort *)addr;
|
shortp = (ushort *)buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
i = *shortp;
|
i = *shortp;
|
||||||
}
|
}
|
||||||
cp = (u_char *)addr;
|
cp = (u_char *)buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
i = *cp;
|
i = *cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 4) {
|
if (size == 4) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
longp = (uint *)addr;
|
longp = (uint *)buf;
|
||||||
i = length;
|
i = length;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*longp++;
|
*longp++;
|
||||||
|
@ -506,28 +533,30 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||||
}
|
}
|
||||||
if (size == 2) {
|
if (size == 2) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
shortp = (ushort *)addr;
|
shortp = (ushort *)buf;
|
||||||
i = length;
|
i = length;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*shortp++;
|
*shortp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
cp = (u_char *)addr;
|
cp = (u_char *)buf;
|
||||||
i = length;
|
i = length;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*cp++;
|
*cp++;
|
||||||
}
|
}
|
||||||
|
unmap_sysmem(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LOOPW
|
#ifdef CONFIG_LOOPW
|
||||||
int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
ulong addr, length, i, data;
|
ulong addr, length, i, data, bytes;
|
||||||
int size;
|
int size;
|
||||||
volatile uint *longp;
|
volatile uint *longp;
|
||||||
volatile ushort *shortp;
|
volatile ushort *shortp;
|
||||||
volatile u_char *cp;
|
volatile u_char *cp;
|
||||||
|
void *buf;
|
||||||
|
|
||||||
if (argc < 4)
|
if (argc < 4)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -550,28 +579,31 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
/* data to write */
|
/* data to write */
|
||||||
data = simple_strtoul(argv[3], NULL, 16);
|
data = simple_strtoul(argv[3], NULL, 16);
|
||||||
|
|
||||||
|
bytes = size * length;
|
||||||
|
buf = map_sysmem(addr, bytes);
|
||||||
|
|
||||||
/* We want to optimize the loops to run as fast as possible.
|
/* We want to optimize the loops to run as fast as possible.
|
||||||
* If we have only one object, just run infinite loops.
|
* If we have only one object, just run infinite loops.
|
||||||
*/
|
*/
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
if (size == 4) {
|
if (size == 4) {
|
||||||
longp = (uint *)addr;
|
longp = (uint *)buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
*longp = data;
|
*longp = data;
|
||||||
}
|
}
|
||||||
if (size == 2) {
|
if (size == 2) {
|
||||||
shortp = (ushort *)addr;
|
shortp = (ushort *)buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
*shortp = data;
|
*shortp = data;
|
||||||
}
|
}
|
||||||
cp = (u_char *)addr;
|
cp = (u_char *)buf;
|
||||||
for (;;)
|
for (;;)
|
||||||
*cp = data;
|
*cp = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size == 4) {
|
if (size == 4) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
longp = (uint *)addr;
|
longp = (uint *)buf;
|
||||||
i = length;
|
i = length;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*longp++ = data;
|
*longp++ = data;
|
||||||
|
@ -579,14 +611,14 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
}
|
}
|
||||||
if (size == 2) {
|
if (size == 2) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
shortp = (ushort *)addr;
|
shortp = (ushort *)buf;
|
||||||
i = length;
|
i = length;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*shortp++ = data;
|
*shortp++ = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
cp = (u_char *)addr;
|
cp = (u_char *)buf;
|
||||||
i = length;
|
i = length;
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
*cp++ = data;
|
*cp++ = data;
|
||||||
|
@ -962,6 +994,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
ulong addr, i;
|
ulong addr, i;
|
||||||
int nbytes, size;
|
int nbytes, size;
|
||||||
|
void *ptr = NULL;
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
@ -1006,13 +1039,14 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
|
||||||
* the next value. A non-converted value exits.
|
* the next value. A non-converted value exits.
|
||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
|
ptr = map_sysmem(addr, size);
|
||||||
printf("%08lx:", addr);
|
printf("%08lx:", addr);
|
||||||
if (size == 4)
|
if (size == 4)
|
||||||
printf(" %08x", *((uint *)addr));
|
printf(" %08x", *((uint *)ptr));
|
||||||
else if (size == 2)
|
else if (size == 2)
|
||||||
printf(" %04x", *((ushort *)addr));
|
printf(" %04x", *((ushort *)ptr));
|
||||||
else
|
else
|
||||||
printf(" %02x", *((u_char *)addr));
|
printf(" %02x", *((u_char *)ptr));
|
||||||
|
|
||||||
nbytes = readline (" ? ");
|
nbytes = readline (" ? ");
|
||||||
if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
|
if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
|
||||||
|
@ -1042,16 +1076,18 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
|
||||||
reset_cmd_timeout();
|
reset_cmd_timeout();
|
||||||
#endif
|
#endif
|
||||||
if (size == 4)
|
if (size == 4)
|
||||||
*((uint *)addr) = i;
|
*((uint *)ptr) = i;
|
||||||
else if (size == 2)
|
else if (size == 2)
|
||||||
*((ushort *)addr) = i;
|
*((ushort *)ptr) = i;
|
||||||
else
|
else
|
||||||
*((u_char *)addr) = i;
|
*((u_char *)ptr) = i;
|
||||||
if (incrflag)
|
if (incrflag)
|
||||||
addr += size;
|
addr += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (nbytes);
|
} while (nbytes);
|
||||||
|
if (ptr)
|
||||||
|
unmap_sysmem(ptr);
|
||||||
|
|
||||||
mm_last_addr = addr;
|
mm_last_addr = addr;
|
||||||
mm_last_size = size;
|
mm_last_size = size;
|
||||||
|
|
Loading…
Reference in New Issue