[U-Boot] [PATCH 05/20] sandbox: Change memory commands to use map_physmem
Simon Glass
sjg at chromium.org
Wed Dec 26 19:56:58 CET 2012
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 at chromium.org>
---
common/cmd_mem.c | 122 +++++++++++++++++++++++++++++++++++-------------------
1 files changed, 79 insertions(+), 43 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 4d64cff..e2adea9 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -33,6 +33,7 @@
#include <dataflash.h>
#endif
#include <watchdog.h>
+#include <asm/io.h>
static int mod_mem(cmd_tbl_t *, int, int, int, char * const []);
@@ -135,9 +136,13 @@ static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
# endif
{
+ ulong bytes = size * length;
+ const void *buf = map_sysmem(addr, bytes);
+
/* Print the lines. */
- print_buffer(addr, (void*)addr, size, length, DISP_LINE_LEN/size);
- addr += size*length;
+ print_buffer(addr, buf, size, length, DISP_LINE_LEN / size);
+ addr += bytes;
+ unmap_sysmem(buf);
}
#endif
@@ -160,6 +165,8 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
ulong addr, writeval, count;
int size;
+ void *buf;
+ ulong bytes;
if ((argc < 3) || (argc > 4))
return CMD_RET_USAGE;
@@ -185,15 +192,18 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
count = 1;
}
+ bytes = size * count;
+ buf = map_sysmem(addr, bytes);
while (count-- > 0) {
if (size == 4)
- *((ulong *)addr) = (ulong )writeval;
+ *((ulong *)buf) = (ulong)writeval;
else if (size == 2)
- *((ushort *)addr) = (ushort)writeval;
+ *((ushort *)buf) = (ushort)writeval;
else
- *((u_char *)addr) = (u_char)writeval;
- addr += size;
+ *((u_char *)buf) = (u_char)writeval;
+ buf += size;
}
+ unmap_sysmem(buf);
return 0;
}
@@ -255,10 +265,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[])
{
- ulong addr1, addr2, count, ngood;
+ ulong addr1, addr2, count, ngood, bytes;
int size;
int rcode = 0;
const char *type;
+ const void *buf1, *buf2, *base;
if (argc != 4)
return CMD_RET_USAGE;
@@ -291,33 +302,40 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
#endif
+ bytes = size * count;
+ base = buf1 = map_sysmem(addr1, bytes);
+ buf2 = map_sysmem(addr2, bytes);
for (ngood = 0; ngood < count; ++ngood) {
ulong word1, word2;
if (size == 4) {
- word1 = *(ulong *)addr1;
- word2 = *(ulong *)addr2;
+ word1 = *(ulong *)buf1;
+ word2 = *(ulong *)buf2;
} else if (size == 2) {
- word1 = *(ushort *)addr1;
- word2 = *(ushort *)addr2;
+ word1 = *(ushort *)buf1;
+ word2 = *(ushort *)buf2;
} else {
- word1 = *(u_char *)addr1;
- word2 = *(u_char *)addr2;
+ word1 = *(u_char *)buf1;
+ word2 = *(u_char *)buf2;
}
if (word1 != word2) {
+ ulong offset = buf1 - base;
+
printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n",
- type, addr1, size, word1,
- type, addr2, size, word2);
+ type, (ulong)(addr1 + offset), size, word1,
+ type, (ulong)(addr2 + offset), size, word2);
rcode = 1;
break;
}
- addr1 += size;
- addr2 += size;
+ buf1 += size;
+ buf2 += size;
/* reset watchdog from time to time */
if ((ngood % (64 << 10)) == 0)
WATCHDOG_RESET();
}
+ unmap_sysmem(buf1);
+ unmap_sysmem(buf2);
printf("Total of %ld %s(s) were the same\n", ngood, type);
return rcode;
@@ -325,8 +343,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[])
{
- ulong addr, dest, count;
+ ulong addr, dest, count, bytes;
int size;
+ const void *src;
+ void *buf;
if (argc != 4)
return CMD_RET_USAGE;
@@ -416,15 +436,18 @@ static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
#endif
+ bytes = size * count;
+ buf = map_sysmem(addr, bytes);
+ src = map_sysmem(addr, bytes);
while (count-- > 0) {
if (size == 4)
- *((ulong *)dest) = *((ulong *)addr);
+ *((ulong *)buf) = *((ulong *)src);
else if (size == 2)
- *((ushort *)dest) = *((ushort *)addr);
+ *((ushort *)buf) = *((ushort *)src);
else
- *((u_char *)dest) = *((u_char *)addr);
- addr += size;
- dest += size;
+ *((u_char *)buf) = *((u_char *)src);
+ src += size;
+ buf += size;
/* reset watchdog from time to time */
if ((count % (64 << 10)) == 0)
@@ -450,11 +473,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,
char * const argv[])
{
- ulong addr, length, i;
+ ulong addr, length, i, bytes;
int size;
volatile uint *longp;
volatile ushort *shortp;
volatile u_char *cp;
+ const void *buf;
if (argc < 3)
return CMD_RET_USAGE;
@@ -473,28 +497,31 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
*/
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.
* If we have only one object, just run infinite loops.
*/
if (length == 1) {
if (size == 4) {
- longp = (uint *)addr;
+ longp = (uint *)buf;
for (;;)
i = *longp;
}
if (size == 2) {
- shortp = (ushort *)addr;
+ shortp = (ushort *)buf;
for (;;)
i = *shortp;
}
- cp = (u_char *)addr;
+ cp = (u_char *)buf;
for (;;)
i = *cp;
}
if (size == 4) {
for (;;) {
- longp = (uint *)addr;
+ longp = (uint *)buf;
i = length;
while (i-- > 0)
*longp++;
@@ -502,28 +529,30 @@ static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc,
}
if (size == 2) {
for (;;) {
- shortp = (ushort *)addr;
+ shortp = (ushort *)buf;
i = length;
while (i-- > 0)
*shortp++;
}
}
for (;;) {
- cp = (u_char *)addr;
+ cp = (u_char *)buf;
i = length;
while (i-- > 0)
*cp++;
}
+ unmap_sysmem(buf);
}
#ifdef CONFIG_LOOPW
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;
volatile uint *longp;
volatile ushort *shortp;
volatile u_char *cp;
+ void *buf;
if (argc < 4)
return CMD_RET_USAGE;
@@ -545,28 +574,31 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* data to write */
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.
* If we have only one object, just run infinite loops.
*/
if (length == 1) {
if (size == 4) {
- longp = (uint *)addr;
+ longp = (uint *)buf;
for (;;)
*longp = data;
}
if (size == 2) {
- shortp = (ushort *)addr;
+ shortp = (ushort *)buf;
for (;;)
*shortp = data;
}
- cp = (u_char *)addr;
+ cp = (u_char *)buf;
for (;;)
*cp = data;
}
if (size == 4) {
for (;;) {
- longp = (uint *)addr;
+ longp = (uint *)buf;
i = length;
while (i-- > 0)
*longp++ = data;
@@ -574,14 +606,14 @@ int do_mem_loopw (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
if (size == 2) {
for (;;) {
- shortp = (ushort *)addr;
+ shortp = (ushort *)buf;
i = length;
while (i-- > 0)
*shortp++ = data;
}
}
for (;;) {
- cp = (u_char *)addr;
+ cp = (u_char *)buf;
i = length;
while (i-- > 0)
*cp++ = data;
@@ -957,6 +989,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
{
ulong addr, i;
int nbytes, size;
+ void *ptr = NULL;
if (argc != 2)
return CMD_RET_USAGE;
@@ -1001,13 +1034,14 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
* the next value. A non-converted value exits.
*/
do {
+ ptr = map_sysmem(addr, size);
printf("%08lx:", addr);
if (size == 4)
- printf(" %08x", *((uint *)addr));
+ printf(" %08x", *((uint *)ptr));
else if (size == 2)
- printf(" %04x", *((ushort *)addr));
+ printf(" %04x", *((ushort *)ptr));
else
- printf(" %02x", *((u_char *)addr));
+ printf(" %02x", *((u_char *)ptr));
nbytes = readline (" ? ");
if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
@@ -1037,16 +1071,18 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
reset_cmd_timeout();
#endif
if (size == 4)
- *((uint *)addr) = i;
+ *((uint *)ptr) = i;
else if (size == 2)
- *((ushort *)addr) = i;
+ *((ushort *)ptr) = i;
else
- *((u_char *)addr) = i;
+ *((u_char *)ptr) = i;
if (incrflag)
addr += size;
}
}
} while (nbytes);
+ if (ptr)
+ unmap_sysmem(ptr);
mm_last_addr = addr;
mm_last_size = size;
--
1.7.7.3
More information about the U-Boot
mailing list