summaryrefslogtreecommitdiffstats
path: root/commands/mem.c
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2012-11-26 13:51:39 +0400
committerSascha Hauer <s.hauer@pengutronix.de>2012-11-26 11:14:40 +0100
commitf23198905c4e943a019acc0a7210d4e586650425 (patch)
tree16ae9b4663ddd3b48d6a62560a475dde79c773c7 /commands/mem.c
parent6a20c24644261c65cb9ca93313b6f51bafc87973 (diff)
downloadbarebox-f23198905c4e943a019acc0a7210d4e586650425.tar.gz
barebox-f23198905c4e943a019acc0a7210d4e586650425.tar.xz
mem: add the swab (swap bytes) option to memory_display()
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/mem.c')
-rw-r--r--commands/mem.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/commands/mem.c b/commands/mem.c
index 6fbc7cc4af..a42b7bacb3 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -51,7 +51,7 @@ static char *DEVMEM = "/dev/mem";
*/
#define DISP_LINE_LEN 16
-int memory_display(char *addr, loff_t offs, ulong nbytes, int size)
+int memory_display(char *addr, loff_t offs, ulong nbytes, int size, int swab)
{
ulong linebytes, i;
u_char *cp;
@@ -73,9 +73,17 @@ int memory_display(char *addr, loff_t offs, ulong nbytes, int size)
for (i = 0; i < linebytes; i += size) {
if (size == 4) {
- count -= printf(" %08x", (*uip++ = *((uint *)addr)));
+ u32 res;
+ res = (*uip++ = *((uint *)addr));
+ if (swab)
+ res = __swab32(res);
+ count -= printf(" %08x", res);
} else if (size == 2) {
- count -= printf(" %04x", (*usp++ = *((ushort *)addr)));
+ u16 res;
+ res = (*usp++ = *((ushort *)addr));
+ if (swab)
+ res = __swab16(res);
+ count -= printf(" %04x", res);
} else {
count -= printf(" %02x", (*ucp++ = *((u_char *)addr)));
}
@@ -195,7 +203,8 @@ static int do_mem_md(int argc, char *argv[])
if (!r)
goto out;
- if ((ret = memory_display(rw_buf, start, r, mode >> O_RWSIZE_SHIFT)))
+ if ((ret = memory_display(rw_buf, start, r,
+ mode >> O_RWSIZE_SHIFT, 0)))
goto out;
start += r;