-
-
Save smaeul/8148daa39ac47dfea2c0bb3170aa9995 to your computer and use it in GitHub Desktop.
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> | |
static inline uint32_t | |
readl(uintptr_t addr) | |
{ | |
volatile uint32_t *ptr = (void *)addr; | |
return *ptr; | |
} | |
static inline void | |
writel(uintptr_t val, uint32_t addr) | |
{ | |
volatile uint32_t *ptr = (void *)addr; | |
*ptr = val; | |
} | |
#if 1 | |
// H6 | |
#define SUNXI_SID_BASE 0x03006000 | |
#define EFUSE_LCJS (0x48) | |
#else | |
// A64/H5 | |
#define SUNXI_SID_BASE 0x1c14000 | |
#define EFUSE_LCJS (0xF4) | |
#endif | |
#define SID_PRCTL (SUNXI_SID_BASE + 0x40) | |
#define SID_PRKEY (SUNXI_SID_BASE + 0x50) | |
// WARNING: Executing this code will PERMANENTLY switch your device to secure mode. | |
// Secure mode requires a special file to boot (TOC0) and is mostly unsupported by tools. | |
// If your device has a ROTPK hash programmed, and you do not have the PRIVATE key, | |
// running this code will BRICK your device. | |
// | |
// If you are unsure about ANY part of the above warning, DO NOT RUN THIS CODE. | |
// | |
// By uncommenting the line below, YOU are taking responsibility for the consequences. | |
// | |
// #define SID_OP_LOCK (0xAC) | |
void sid_program_key(void) | |
{ | |
uint32_t key_index = EFUSE_LCJS; | |
uint32_t key_value = 0x1 << 11; | |
uint32_t reg_val; | |
writel(key_value, SID_PRKEY); | |
reg_val = readl(SID_PRCTL); | |
reg_val &= ~((0x1ff<<16)|0x3); | |
reg_val |= key_index<<16; | |
writel(reg_val, SID_PRCTL); | |
reg_val &= ~((0xff<<8)|0x3); | |
reg_val |= (SID_OP_LOCK<<8) | 0x1; | |
writel(reg_val, SID_PRCTL); | |
while(readl(SID_PRCTL)&0x1){}; | |
reg_val &= ~((0x1ff<<16)|(0xff<<8)|0x3); | |
writel(reg_val, SID_PRCTL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment