summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kralevich2016-11-29 17:43:17 -0600
committerNick Kralevich2016-11-29 17:45:11 -0600
commit8a475f7e4ae72db0a6cfe31ab46f588e89e0fc34 (patch)
tree0942a93641ba00bec048635078e1bde0ff7e05b7 /toolbox
parent9bfd9f558b116e208aef7bdeef887ca37fcd2007 (diff)
downloadplatform-system-core-8a475f7e4ae72db0a6cfe31ab46f588e89e0fc34.tar.gz
platform-system-core-8a475f7e4ae72db0a6cfe31ab46f588e89e0fc34.tar.xz
platform-system-core-8a475f7e4ae72db0a6cfe31ab46f588e89e0fc34.zip
delete toolbox/r.c
/dev/mem has been turned off on all Android kernels (b/19549480). This utility cannot be used. Test: android compiles. Change-Id: I500021f224febb15dd8bfe6e1f6e5c398fe6f552
Diffstat (limited to 'toolbox')
-rw-r--r--toolbox/Android.mk9
-rw-r--r--toolbox/r.c102
2 files changed, 0 insertions, 111 deletions
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index 5319ff4ab..d6ead1a09 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -81,15 +81,6 @@ $(INPUT_H_LABELS_H): $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/generate-input.h-lab
81$(INPUT_H_LABELS_H): 81$(INPUT_H_LABELS_H):
82 $(transform-generated-source) 82 $(transform-generated-source)
83 83
84# We only want 'r' on userdebug and eng builds.
85include $(CLEAR_VARS)
86LOCAL_SRC_FILES := r.c
87LOCAL_CFLAGS += $(common_cflags)
88LOCAL_C_INCLUDES += $(LOCAL_PATH)/upstream-netbsd/include/
89LOCAL_MODULE := r
90LOCAL_MODULE_TAGS := debug
91include $(BUILD_EXECUTABLE)
92
93 84
94# We build BSD grep separately, so it can provide egrep and fgrep too. 85# We build BSD grep separately, so it can provide egrep and fgrep too.
95include $(CLEAR_VARS) 86include $(CLEAR_VARS)
diff --git a/toolbox/r.c b/toolbox/r.c
deleted file mode 100644
index b96cdb279..000000000
--- a/toolbox/r.c
+++ /dev/null
@@ -1,102 +0,0 @@
1#include <fcntl.h>
2#include <inttypes.h>
3#include <stdbool.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <sys/mman.h>
8#include <unistd.h>
9
10#if __LP64__
11#define strtoptr strtoull
12#else
13#define strtoptr strtoul
14#endif
15
16static int usage()
17{
18 fprintf(stderr,"r [-b|-s] <address> [<value>]\n");
19 return -1;
20}
21
22int main(int argc, char *argv[])
23{
24 if(argc < 2) return usage();
25
26 int width = 4;
27 if(!strcmp(argv[1], "-b")) {
28 width = 1;
29 argc--;
30 argv++;
31 } else if(!strcmp(argv[1], "-s")) {
32 width = 2;
33 argc--;
34 argv++;
35 }
36
37 if(argc < 2) return usage();
38 uintptr_t addr = strtoptr(argv[1], 0, 16);
39
40 uintptr_t endaddr = 0;
41 char* end = strchr(argv[1], '-');
42 if (end)
43 endaddr = strtoptr(end + 1, 0, 16);
44
45 if (!endaddr)
46 endaddr = addr + width - 1;
47
48 if (endaddr <= addr) {
49 fprintf(stderr, "end address <= start address\n");
50 return -1;
51 }
52
53 bool set = false;
54 uint32_t value = 0;
55 if(argc > 2) {
56 set = true;
57 value = strtoul(argv[2], 0, 16);
58 }
59
60 int fd = open("/dev/mem", O_RDWR | O_SYNC);
61 if(fd < 0) {
62 fprintf(stderr,"cannot open /dev/mem\n");
63 return -1;
64 }
65
66 off64_t mmap_start = addr & ~(PAGE_SIZE - 1);
67 size_t mmap_size = endaddr - mmap_start + 1;
68 mmap_size = (mmap_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
69
70 void* page = mmap64(0, mmap_size, PROT_READ | PROT_WRITE,
71 MAP_SHARED, fd, mmap_start);
72
73 if(page == MAP_FAILED){
74 fprintf(stderr,"cannot mmap region\n");
75 return -1;
76 }
77
78 while (addr <= endaddr) {
79 switch(width){
80 case 4: {
81 uint32_t* x = (uint32_t*) (((uintptr_t) page) + (addr & 4095));
82 if(set) *x = value;
83 fprintf(stderr,"%08"PRIxPTR": %08x\n", addr, *x);
84 break;
85 }
86 case 2: {
87 uint16_t* x = (uint16_t*) (((uintptr_t) page) + (addr & 4095));
88 if(set) *x = value;
89 fprintf(stderr,"%08"PRIxPTR": %04x\n", addr, *x);
90 break;
91 }
92 case 1: {
93 uint8_t* x = (uint8_t*) (((uintptr_t) page) + (addr & 4095));
94 if(set) *x = value;
95 fprintf(stderr,"%08"PRIxPTR": %02x\n", addr, *x);
96 break;
97 }
98 }
99 addr += width;
100 }
101 return 0;
102}