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>
This commit is contained in:
parent
6a20c24644
commit
f23198905c
|
@ -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;
|
||||
|
|
|
@ -101,12 +101,12 @@ static int do_spi(int argc, char *argv[])
|
|||
printf("\n");
|
||||
|
||||
printf("wrote %i bytes\n", count);
|
||||
memory_display(tx_buf, 0, count, byte_per_word);
|
||||
memory_display(tx_buf, 0, count, byte_per_word, 0);
|
||||
|
||||
printf("read %i bytes\n", read);
|
||||
}
|
||||
|
||||
memory_display(rx_buf, 0, read, byte_per_word);
|
||||
memory_display(rx_buf, 0, read, byte_per_word, 0);
|
||||
|
||||
out:
|
||||
free(rx_buf);
|
||||
|
|
|
@ -227,7 +227,7 @@ static void tftp_parse_oack(struct file_priv *priv, unsigned char *pkt, int len)
|
|||
|
||||
debug("got OACK\n");
|
||||
#ifdef DEBUG
|
||||
memory_display(pkt, 0, len, 1);
|
||||
memory_display(pkt, 0, len, 1, 0);
|
||||
#endif
|
||||
|
||||
s = pkt;
|
||||
|
|
|
@ -226,7 +226,7 @@ int run_shell(void);
|
|||
#define PAGE_SIZE 4096
|
||||
#define PAGE_SHIFT 12
|
||||
|
||||
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);
|
||||
|
||||
extern const char version_string[];
|
||||
#ifdef CONFIG_BANNER
|
||||
|
|
Loading…
Reference in New Issue