Advertisement
Guest User

Untitled

a guest
Jun 6th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <sys/mman.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7.  
  8. typedef unsigned int u32;
  9.  
  10.  
  11. #define set_wbit(addr, v)   (*((volatile unsigned long  *)(addr)) |= (unsigned long)(v))
  12. #define readl(addr)     (*((volatile unsigned long  *)(addr)))
  13. #define writel(v, addr)     (*((volatile unsigned long  *)(addr)) = (unsigned long)(v))
  14.  
  15. #define VER_REG         (AW_SRAMCTRL_BASE + 0x24)
  16. #define H6_VER_REG      (H6_SRAMCTRL_BASE + 0x24)
  17. #define SUN4I_SID_BASE      0x01C23800
  18. #define SUN8I_SID_BASE      0x01C14000
  19.  
  20. #define SID_PRCTL   0x40    /* SID program/read control register */
  21. #define SID_RDKEY   0x60    /* SID read key value register */
  22.  
  23. #define SID_OP_LOCK 0xAC    /* Efuse operation lock value */
  24. #define SID_READ_START  (1 << 1) /* bit 1 of SID_PRCTL, Software Read Start */
  25.  
  26.  
  27. static const unsigned char rotpk_bin[] = {
  28.     0x01, 0x23, 0x45, 0x67,
  29.     0x89, 0xab, 0xcd, 0xef,
  30.     0x11, 0x22, 0x33, 0x44,
  31.     0x55, 0x66, 0x77, 0x88,
  32.     0x99, 0xaa, 0xbb, 0xcc,
  33.     0xdd, 0xee, 0xff, 0xff,
  34.     0xff, 0xff, 0xff, 0xff,
  35.     0xff, 0xff, 0xff, 0xff
  36. };
  37.  
  38. int main(int argc, char *argv[]) {
  39.  
  40.     off_t offset = SUN8I_SID_BASE;
  41.     size_t len = 4096;
  42.  
  43.     // Truncate offset to a multiple of the page size, or mmap will fail.
  44.     size_t pagesize = sysconf(_SC_PAGE_SIZE);
  45.     off_t page_base = (offset / pagesize) * pagesize;
  46.     off_t page_offset = offset - page_base;
  47.  
  48.     printf("ps: %d, base: %08x, off: %08x\r\n", pagesize, page_base, page_offset);
  49.  
  50.     int fd = open("/dev/mem", O_RDWR);
  51.     unsigned char *mem = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, page_base);
  52.     if (mem == MAP_FAILED) {
  53.         perror("Can't map memory");
  54.         return -1;
  55.     }
  56.     close(fd);
  57.  
  58.     u32 *checkRotpk = mem+0x120;
  59.     u32 *trigger = mem+0x140;
  60.     u32 *rotpk32 = (u32*) rotpk_bin;
  61.    
  62.     for(int i=0; i<8; i++){
  63.         checkRotpk[i] = rotpk32[i];
  64.         printf("%08x\n\r", rotpk32[i]);
  65.     }
  66.     *trigger = 0x80000000;
  67.  
  68.     sleep(1);
  69.     printf("%08x\n\r", *trigger);
  70.  
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement