From 54e2cd704fb44b8e87bc4507ee852f22eeedfbe9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 8 Nov 2020 09:35:05 -0600 Subject: Teach devmem about nommu and 0x prefix on address. Print hex or decimal output depending on whether address was hex or decimal. --- toys/other/devmem.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'toys/other') diff --git a/toys/other/devmem.c b/toys/other/devmem.c index ced6c518..920d8563 100644 --- a/toys/other/devmem.c +++ b/toys/other/devmem.c @@ -10,9 +10,8 @@ config DEVMEM help usage: devmem ADDR [WIDTH [DATA]] - Read/write physical address via /dev/mem. - - WIDTH is 1, 2, 4, or 8 bytes (default 4). + Read/write physical address. WIDTH is 1, 2, 4, or 8 bytes (default 4). + Prefix ADDR with 0x for hexadecimal, output is in same base as address. */ #define FOR_devmem @@ -21,14 +20,15 @@ config DEVMEM void devmem_main(void) { int writing = toys.optc == 3, page_size = sysconf(_SC_PAGESIZE), bytes = 4,fd; - unsigned long long addr = atolx(toys.optargs[0]), data = 0, map_off, map_len; + unsigned long long data = 0, map_off, map_len; + unsigned long addr = atolx(*toys.optargs); void *map, *p; // WIDTH? if (toys.optc>1) { int i; - if (strlen(toys.optargs[1])!=1 || (i=stridx("1248", *toys.optargs[1]))==-1) + if ((i=stridx("1248", *toys.optargs[1]))==-1 || toys.optargs[1][1]) error_exit("bad width: %s", toys.optargs[1]); bytes = 1<