Accept address ranges in r
Change-Id: Ifece1b37d018216462844cc89e0f2f6a2b7d287d
diff --git a/toolbox/r.c b/toolbox/r.c
index 5a82e20..eb8ea0b 100644
--- a/toolbox/r.c
+++ b/toolbox/r.c
@@ -13,8 +13,10 @@
int r_main(int argc, char *argv[])
{
int width = 4, set = 0, fd;
- unsigned addr, value;
+ unsigned addr, value, endaddr = 0;
+ unsigned long mmap_start, mmap_size;
void *page;
+ char *end;
if(argc < 2) return usage();
@@ -31,6 +33,18 @@
if(argc < 2) return usage();
addr = strtoul(argv[1], 0, 16);
+ end = strchr(argv[1], '-');
+ if (end)
+ endaddr = strtoul(end + 1, 0, 16);
+
+ if (!endaddr)
+ endaddr = addr + width - 1;
+
+ if (endaddr <= addr) {
+ fprintf(stderr, "invalid end address\n");
+ return -1;
+ }
+
if(argc > 2) {
set = 1;
value = strtoul(argv[2], 0, 16);
@@ -42,33 +56,40 @@
return -1;
}
- page = mmap(0, 8192, PROT_READ | PROT_WRITE,
- MAP_SHARED, fd, addr & (~4095));
+ mmap_start = addr & ~(PAGE_SIZE - 1);
+ mmap_size = endaddr - mmap_start + 1;
+ mmap_size = (mmap_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+
+ page = mmap(0, mmap_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, mmap_start);
if(page == MAP_FAILED){
fprintf(stderr,"cannot mmap region\n");
return -1;
}
- switch(width){
- case 4: {
- unsigned *x = (unsigned*) (((unsigned) page) + (addr & 4095));
- if(set) *x = value;
- fprintf(stderr,"%08x: %08x\n", addr, *x);
- break;
+ while (addr <= endaddr) {
+ switch(width){
+ case 4: {
+ unsigned *x = (unsigned*) (((unsigned) page) + (addr & 4095));
+ if(set) *x = value;
+ fprintf(stderr,"%08x: %08x\n", addr, *x);
+ break;
+ }
+ case 2: {
+ unsigned short *x = (unsigned short*) (((unsigned) page) + (addr & 4095));
+ if(set) *x = value;
+ fprintf(stderr,"%08x: %04x\n", addr, *x);
+ break;
+ }
+ case 1: {
+ unsigned char *x = (unsigned char*) (((unsigned) page) + (addr & 4095));
+ if(set) *x = value;
+ fprintf(stderr,"%08x: %02x\n", addr, *x);
+ break;
+ }
+ }
+ addr += width;
}
- case 2: {
- unsigned short *x = (unsigned short*) (((unsigned) page) + (addr & 4095));
- if(set) *x = value;
- fprintf(stderr,"%08x: %04x\n", addr, *x);
- break;
- }
- case 1: {
- unsigned char *x = (unsigned char*) (((unsigned) page) + (addr & 4095));
- if(set) *x = value;
- fprintf(stderr,"%08x: %02x\n", addr, *x);
- break;
- }
- }
return 0;
}