* [PATCH 1/3] mem: add the swab (swap bytes) option to memory_display()
2012-11-26 9:51 commands: md, mw: add the '-x' option (swap bytes) Antony Pavlov
@ 2012-11-26 9:51 ` Antony Pavlov
2012-11-26 9:51 ` [PATCH 2/3] commands: md: add the '-x' option (swap bytes) Antony Pavlov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2012-11-26 9:51 UTC (permalink / raw)
To: barebox
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] commands: md: add the '-x' option (swap bytes)
2012-11-26 9:51 commands: md, mw: add the '-x' option (swap bytes) Antony Pavlov
2012-11-26 9:51 ` [PATCH 1/3] mem: add the swab (swap bytes) option to memory_display() Antony Pavlov
@ 2012-11-26 9:51 ` Antony Pavlov
2012-11-26 9:51 ` [PATCH 3/3] commands: mw: " Antony Pavlov
2012-11-26 10:16 ` commands: md, " Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2012-11-26 9:51 UTC (permalink / raw)
To: barebox
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/mem.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/commands/mem.c b/commands/mem.c
index a42b7ba..9873e52 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -136,7 +136,7 @@ static int open_and_lseek(const char *filename, int mode, loff_t pos)
}
static int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
- char **sourcefile, char **destfile)
+ char **sourcefile, char **destfile, int *swab)
{
int opt;
@@ -157,6 +157,9 @@ static int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
case 'd':
*destfile = optarg;
break;
+ case 'x':
+ *swab = 1;
+ break;
default:
return -1;
}
@@ -173,11 +176,13 @@ static int do_mem_md(int argc, char *argv[])
int fd;
char *filename = DEVMEM;
int mode = O_RWSIZE_4;
+ int swab = 0;
if (argc < 2)
return COMMAND_ERROR_USAGE;
- if (mem_parse_options(argc, argv, "bwls:", &mode, &filename, NULL) < 0)
+ if (mem_parse_options(argc, argv, "bwls:x", &mode, &filename, NULL,
+ &swab) < 0)
return 1;
if (optind < argc) {
@@ -204,7 +209,7 @@ static int do_mem_md(int argc, char *argv[])
goto out;
if ((ret = memory_display(rw_buf, start, r,
- mode >> O_RWSIZE_SHIFT, 0)))
+ mode >> O_RWSIZE_SHIFT, swab)))
goto out;
start += r;
@@ -225,6 +230,7 @@ static const __maybe_unused char cmd_md_help[] =
" -b output in bytes\n"
" -w output in halfwords (16bit)\n"
" -l output in words (32bit)\n"
+" -x swap bytes at output\n"
"\n"
"Memory regions:\n"
"Memory regions can be specified in two different forms: start+size\n"
@@ -250,7 +256,8 @@ static int do_mem_mw(int argc, char *argv[])
int mode = O_RWSIZE_4;
loff_t adr;
- if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &filename) < 0)
+ if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &filename,
+ NULL) < 0)
return 1;
if (optind + 1 >= argc)
@@ -318,7 +325,8 @@ static int do_mem_cmp(int argc, char *argv[])
int offset = 0;
struct stat statbuf;
- if (mem_parse_options(argc, argv, "bwls:d:", &mode, &sourcefile, &destfile) < 0)
+ if (mem_parse_options(argc, argv, "bwls:d:", &mode, &sourcefile,
+ &destfile, NULL) < 0)
return 1;
if (optind + 2 > argc)
@@ -425,7 +433,8 @@ static int do_mem_cp(int argc, char *argv[])
struct stat statbuf;
int ret = 0;
- if (mem_parse_options(argc, argv, "bwls:d:", &mode, &sourcefile, &destfile) < 0)
+ if (mem_parse_options(argc, argv, "bwls:d:", &mode, &sourcefile,
+ &destfile, NULL) < 0)
return 1;
if (optind + 2 > argc)
@@ -530,7 +539,8 @@ static int do_memset(int argc, char *argv[])
int ret = 1;
char *file = DEVMEM;
- if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &file) < 0)
+ if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &file,
+ NULL) < 0)
return 1;
if (optind + 3 > argc)
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] commands: mw: add the '-x' option (swap bytes)
2012-11-26 9:51 commands: md, mw: add the '-x' option (swap bytes) Antony Pavlov
2012-11-26 9:51 ` [PATCH 1/3] mem: add the swab (swap bytes) option to memory_display() Antony Pavlov
2012-11-26 9:51 ` [PATCH 2/3] commands: md: add the '-x' option (swap bytes) Antony Pavlov
@ 2012-11-26 9:51 ` Antony Pavlov
2012-11-26 10:16 ` commands: md, " Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Antony Pavlov @ 2012-11-26 9:51 UTC (permalink / raw)
To: barebox
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/mem.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/commands/mem.c b/commands/mem.c
index 9873e52..51aa04d 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -255,9 +255,10 @@ static int do_mem_mw(int argc, char *argv[])
char *filename = DEVMEM;
int mode = O_RWSIZE_4;
loff_t adr;
+ int swab = 0;
- if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &filename,
- NULL) < 0)
+ if (mem_parse_options(argc, argv, "bwld:x", &mode, NULL, &filename,
+ &swab) < 0)
return 1;
if (optind + 1 >= argc)
@@ -280,10 +281,14 @@ static int do_mem_mw(int argc, char *argv[])
break;
case O_RWSIZE_2:
val16 = simple_strtoul(argv[optind], NULL, 0);
+ if (swab)
+ val16 = __swab16(val16);
ret = write(fd, &val16, 2);
break;
case O_RWSIZE_4:
val32 = simple_strtoul(argv[optind], NULL, 0);
+ if (swab)
+ val32 = __swab32(val32);
ret = write(fd, &val32, 4);
break;
}
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: commands: md, mw: add the '-x' option (swap bytes)
2012-11-26 9:51 commands: md, mw: add the '-x' option (swap bytes) Antony Pavlov
` (2 preceding siblings ...)
2012-11-26 9:51 ` [PATCH 3/3] commands: mw: " Antony Pavlov
@ 2012-11-26 10:16 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-11-26 10:16 UTC (permalink / raw)
To: Antony Pavlov; +Cc: barebox
On Mon, Nov 26, 2012 at 01:51:38PM +0400, Antony Pavlov wrote:
> Most of my MIPS boards run barebox in big-endian mode, but
> sometimes I need see state of little-endian registers
> (e.g. registers of PCI-connected peripherals) and it is not
> very handy to swap bytes manually.
>
> This patch series adds to memory commands md and mw the ability
> to swap bytes "on the fly".
Applied, thanks
Sascha
>
> [PATCH 1/3] mem: add the swab (swap bytes) option to
> [PATCH 2/3] commands: md: add the '-x' option (swap bytes)
> [PATCH 3/3] commands: mw: add the '-x' option (swap bytes)
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread