forked from MichaelBell/rp1-hacking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmio_dump.c
More file actions
78 lines (58 loc) · 1.57 KB
/
mmio_dump.c
File metadata and controls
78 lines (58 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdint.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
//#define MMIOADDR 0x601100000
//#define MMIOADDR 0x1f00178000
#define MMIOADDR 0x1f00400000
#define MMIOLEN 0x10000
#define BASE 0x70a0
#define LEN (1024*32)
volatile unsigned int *mmio;
#define REG32(m,x) ((volatile uint64_t *)((uint64_t)(m)+(uint64_t)(x)))
static void setup_io() {
int fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd < 0) {
printf("Unable to open /dev/mem. Run as root using sudo?\n");
exit(-1);
}
void *gpio_map =
mmap(NULL, // Any adddress in our space will do
MMIOLEN, // Map length
PROT_READ | PROT_WRITE, // Enable reading & writting to mapped memory
MAP_SHARED, // Shared with other processes
fd, // File to map
MMIOADDR // Offset to GPIO peripheral
);
close(fd);
if (gpio_map == MAP_FAILED) {
perror("mmap failed, errno");
exit(-1);
}
mmio = ((volatile unsigned *)gpio_map) + BASE/4;
}
volatile unsigned int test;
int main(void) {
setup_io();
printf("Read mmio address: %10lx \n", MMIOADDR + BASE);
unsigned int a=0;
unsigned int b=0;
unsigned int i = 0;
FILE* f = fopen("bootrom.bin", "wb");
for(a=0; a<LEN/4; a++) {
b= *(mmio + a);
fwrite(&b, 4, 1, f);
}
}