Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- #include <unistd.h>
- #include <string.h>
- typedef unsigned int u32;
- #define set_wbit(addr, v) (*((volatile unsigned long *)(addr)) |= (unsigned long)(v))
- #define readl(addr) (*((volatile unsigned long *)(addr)))
- #define writel(v, addr) (*((volatile unsigned long *)(addr)) = (unsigned long)(v))
- #define VER_REG (AW_SRAMCTRL_BASE + 0x24)
- #define H6_VER_REG (H6_SRAMCTRL_BASE + 0x24)
- #define SUN4I_SID_BASE 0x01C23800
- #define SUN8I_SID_BASE 0x01C14000
- #define SID_PRCTL 0x40 /* SID program/read control register */
- #define SID_RDKEY 0x60 /* SID read key value register */
- #define SID_OP_LOCK 0xAC /* Efuse operation lock value */
- #define SID_READ_START (1 << 1) /* bit 1 of SID_PRCTL, Software Read Start */
- static const unsigned char rotpk_bin[] = {
- 0x01, 0x23, 0x45, 0x67,
- 0x89, 0xab, 0xcd, 0xef,
- 0x11, 0x22, 0x33, 0x44,
- 0x55, 0x66, 0x77, 0x88,
- 0x99, 0xaa, 0xbb, 0xcc,
- 0xdd, 0xee, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff
- };
- int main(int argc, char *argv[]) {
- off_t offset = SUN8I_SID_BASE;
- size_t len = 4096;
- // Truncate offset to a multiple of the page size, or mmap will fail.
- size_t pagesize = sysconf(_SC_PAGE_SIZE);
- off_t page_base = (offset / pagesize) * pagesize;
- off_t page_offset = offset - page_base;
- printf("ps: %d, base: %08x, off: %08x\r\n", pagesize, page_base, page_offset);
- int fd = open("/dev/mem", O_RDWR);
- unsigned char *mem = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, page_base);
- if (mem == MAP_FAILED) {
- perror("Can't map memory");
- return -1;
- }
- close(fd);
- u32 *checkRotpk = mem+0x120;
- u32 *trigger = mem+0x140;
- u32 *rotpk32 = (u32*) rotpk_bin;
- for(int i=0; i<8; i++){
- checkRotpk[i] = rotpk32[i];
- printf("%08x\n\r", rotpk32[i]);
- }
- *trigger = 0x80000000;
- sleep(1);
- printf("%08x\n\r", *trigger);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement