diff options
author | Colin Cross <ccross@android.com> | 2011-01-19 17:49:18 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-01-19 17:49:18 -0800 |
commit | 0f951a4fb85c29c4aebef123e8e247316ee13c5b (patch) | |
tree | ae1265524bf64dae6e3460f8cd14897a94b3d62f /toolbox | |
parent | a6f502683bb75e3864e8445291e559502a9edddd (diff) | |
parent | 618eca4ed91af2d2a2c618168327ca4a6a496669 (diff) | |
download | system_core-0f951a4fb85c29c4aebef123e8e247316ee13c5b.zip system_core-0f951a4fb85c29c4aebef123e8e247316ee13c5b.tar.gz system_core-0f951a4fb85c29c4aebef123e8e247316ee13c5b.tar.bz2 |
am 618eca4e: am 6fa54fa2: Merge "Accept address ranges in r" into honeycomb
* commit '618eca4ed91af2d2a2c618168327ca4a6a496669':
Accept address ranges in r
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/r.c | 65 |
1 files changed, 43 insertions, 22 deletions
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 @@ static int usage() 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 @@ int r_main(int argc, char *argv[]) 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 @@ int r_main(int argc, char *argv[]) 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; - } - 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; + 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; } - } return 0; } |