[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] devmem: Add COUNT support
From: Marek Vasut <marex () denx ! de>
Date: 2016-06-27 18:39:26
Message-ID: 1467052766-5944-1-git-send-email-marex () denx ! de
[Download RAW message or body]
Add additional parameter to allow dumping subsequent addresses.
Signed-off-by: Marek Vasut <marex@denx.de>
---
miscutils/devmem.c | 122 +++++++++++++++++++++++++++++------------------------
1 file changed, 67 insertions(+), 55 deletions(-)
diff --git a/miscutils/devmem.c b/miscutils/devmem.c
index 786a21b..cbde0ef 100644
--- a/miscutils/devmem.c
+++ b/miscutils/devmem.c
@@ -5,12 +5,13 @@
*/
//usage:#define devmem_trivial_usage
-//usage: "ADDRESS [WIDTH [VALUE]]"
+//usage: "ADDRESS [WIDTH [VALUE [COUNT]]]"
//usage:#define devmem_full_usage "\n\n"
//usage: "Read/write from physical address\n"
//usage: "\n ADDRESS Address to act upon"
//usage: "\n WIDTH Width (8/16/...)"
//usage: "\n VALUE Data to be written"
+//usage: "\n COUNT Number of elements"
#include "libbb.h"
@@ -20,10 +21,12 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
void *map_base, *virt_addr;
uint64_t read_result;
uint64_t writeval = writeval; /* for compiler */
+ uint64_t count = 1;
off_t target;
unsigned page_size, mapped_size, offset_in_page;
int fd;
unsigned width = 8 * sizeof(int);
+ int write = 0;
/* devmem ADDRESS [WIDTH [VALUE]] */
// TODO: options?
@@ -55,26 +58,32 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
width = sizes[width];
}
/* VALUE */
- if (argv[3])
- writeval = bb_strtoull(argv[3], NULL, 0);
- } else { /* argv[2] == NULL */
- /* make argv[3] to be a valid thing to fetch */
- argv--;
+ if (argv[3]) {
+ if (strcmp(argv[3], "-")) {
+ write = 1;
+ writeval = bb_strtoull(argv[3], NULL, 0);
+ }
+
+ /* COUNT */
+ if (argv[4])
+ count = bb_strtoull(argv[4], NULL, 0);
+ }
}
if (errno)
bb_show_usage(); /* one of bb_strtouXX failed */
- fd = xopen("/dev/mem", argv[3] ? (O_RDWR | O_SYNC) : (O_RDONLY | O_SYNC));
- mapped_size = page_size = getpagesize();
+ fd = xopen("/dev/mem", write ? (O_RDWR | O_SYNC) : (O_RDONLY | O_SYNC));
+ page_size = getpagesize();
+ mapped_size = roundup(count, page_size);
offset_in_page = (unsigned)target & (page_size - 1);
if (offset_in_page + width > page_size) {
/* This access spans pages.
* Must map two pages to make it possible: */
- mapped_size *= 2;
+ mapped_size += page_size;
}
map_base = mmap(NULL,
mapped_size,
- argv[3] ? (PROT_READ | PROT_WRITE) : PROT_READ,
+ write ? (PROT_READ | PROT_WRITE) : PROT_READ,
MAP_SHARED,
fd,
target & ~(off_t)(page_size - 1));
@@ -85,52 +94,55 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
virt_addr = (char*)map_base + offset_in_page;
- if (!argv[3]) {
- switch (width) {
- case 8:
- read_result = *(volatile uint8_t*)virt_addr;
- break;
- case 16:
- read_result = *(volatile uint16_t*)virt_addr;
- break;
- case 32:
- read_result = *(volatile uint32_t*)virt_addr;
- break;
- case 64:
- read_result = *(volatile uint64_t*)virt_addr;
- break;
- default:
- bb_error_msg_and_die("bad width");
- }
-// printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n",
-// target, virt_addr,
-// (unsigned long long)read_result);
- /* Zero-padded output shows the width of access just done */
- printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result);
- } else {
- switch (width) {
- case 8:
- *(volatile uint8_t*)virt_addr = writeval;
-// read_result = *(volatile uint8_t*)virt_addr;
- break;
- case 16:
- *(volatile uint16_t*)virt_addr = writeval;
-// read_result = *(volatile uint16_t*)virt_addr;
- break;
- case 32:
- *(volatile uint32_t*)virt_addr = writeval;
-// read_result = *(volatile uint32_t*)virt_addr;
- break;
- case 64:
- *(volatile uint64_t*)virt_addr = writeval;
-// read_result = *(volatile uint64_t*)virt_addr;
- break;
- default:
- bb_error_msg_and_die("bad width");
- }
-// printf("Written 0x%llX; readback 0x%llX\n",
-// (unsigned long long)writeval,
+ while (count--) {
+ if (!write) {
+ switch (width) {
+ case 8:
+ read_result = *(volatile uint8_t*)virt_addr;
+ break;
+ case 16:
+ read_result = *(volatile uint16_t*)virt_addr;
+ break;
+ case 32:
+ read_result = *(volatile uint32_t*)virt_addr;
+ break;
+ case 64:
+ read_result = *(volatile uint64_t*)virt_addr;
+ break;
+ default:
+ bb_error_msg_and_die("bad width");
+ }
+// printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n",
+// target, virt_addr,
// (unsigned long long)read_result);
+ /* Zero-padded output shows the width of access just done */
+ printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result);
+ } else {
+ switch (width) {
+ case 8:
+ *(volatile uint8_t*)virt_addr = writeval;
+// read_result = *(volatile uint8_t*)virt_addr;
+ break;
+ case 16:
+ *(volatile uint16_t*)virt_addr = writeval;
+// read_result = *(volatile uint16_t*)virt_addr;
+ break;
+ case 32:
+ *(volatile uint32_t*)virt_addr = writeval;
+// read_result = *(volatile uint32_t*)virt_addr;
+ break;
+ case 64:
+ *(volatile uint64_t*)virt_addr = writeval;
+// read_result = *(volatile uint64_t*)virt_addr;
+ break;
+ default:
+ bb_error_msg_and_die("bad width");
+ }
+// printf("Written 0x%llX; readback 0x%llX\n",
+// (unsigned long long)writeval,
+// (unsigned long long)read_result);
+ }
+ virt_addr += width / 8;
}
if (ENABLE_FEATURE_CLEAN_UP) {
--
2.7.0
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic