From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] mem: add the swab (swap bytes) option to memory_display()
Date: Mon, 26 Nov 2012 13:51:39 +0400 [thread overview]
Message-ID: <1353923501-13372-2-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1353923501-13372-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/mem.c | 17 +++++++++++++----
commands/spi.c | 4 ++--
fs/tftp.c | 2 +-
include/common.h | 2 +-
net/net.c | 2 +-
5 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/commands/mem.c b/commands/mem.c
index 6fbc7cc..a42b7ba 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;
diff --git a/commands/spi.c b/commands/spi.c
index 899bf62..2f6b430 100644
--- a/commands/spi.c
+++ b/commands/spi.c
@@ -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);
diff --git a/fs/tftp.c b/fs/tftp.c
index dff41e9..98cbb37 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -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;
diff --git a/include/common.h b/include/common.h
index e30774a..6256879 100644
--- a/include/common.h
+++ b/include/common.h
@@ -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
diff --git a/net/net.c b/net/net.c
index 3ac098f..639bc2d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -511,7 +511,7 @@ static void net_bad_packet(unsigned char *pkt, int len)
* We received a bad packet. for now just dump it.
* We could add more sophisticated debugging here
*/
- memory_display(pkt, 0, len, 1);
+ memory_display(pkt, 0, len, 1, 0);
#endif
}
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-11-26 9:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-26 9:51 commands: md, mw: add the '-x' option (swap bytes) Antony Pavlov
2012-11-26 9:51 ` Antony Pavlov [this message]
2012-11-26 9:51 ` [PATCH 2/3] commands: md: " Antony Pavlov
2012-11-26 9:51 ` [PATCH 3/3] commands: mw: " Antony Pavlov
2012-11-26 10:16 ` commands: md, " Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1353923501-13372-2-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox