-
-
Save cleverca22/58784f67690bfb97492f3f439ff00ed7 to your computer and use it in GitHub Desktop.
rpi firmware load time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@raspberrypi:~# gcc uptime.c -o uptime && ./uptime | |
uptime.c: In function ‘main’: | |
uptime.c:11:11: warning: comparison between pointer and integer | |
if (addr == -1) { | |
^~ | |
305.825899 | |
4593.07 14749.79 | |
root@raspberrypi:~# cat uptime.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <sys/mman.h> | |
#include <stdio.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
int main(int argc, char **argv) { | |
int fd = open("/dev/mem", O_RDONLY); | |
void *addr = mmap(NULL, 16 * 1024 * 1024, PROT_READ, MAP_SHARED, fd, 0xfe000000); | |
if (addr == -1) { | |
perror("unable to mmap"); | |
return 1; | |
} | |
volatile uint32_t *st_clo = (volatile uint32_t*)(addr + 0x3004); | |
uint32_t snapshot = *st_clo; | |
printf("%3ld.%06ld\n", snapshot / 1000000, snapshot % 1000000); | |
munmap(addr, 16 * 1024 * 1024); | |
close(fd); | |
fd = open("/proc/uptime", O_RDONLY); | |
char buffer[1024]; | |
int size = read(fd, buffer, 1024); | |
write(0, buffer, size); | |
close(fd); | |
return 0; | |
} |
can this program be adapted for rpi3?
just change the peripheral base addr from 0xfe to 0x3f
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
moved to https://github.com/librerpi/rpi-tools/blob/97c895e9977ae767538bf1c877fe32ec90df05c6/boottime.c