/* ********************************************************************************************************************** * * the Embedded Secure Bootloader System * * * Copyright(C), 2006-2014, Allwinnertech Co., Ltd. * All Rights Reserved * * File : * * By : * * Version : V2.00 * * Date : * * Descript: ********************************************************************************************************************** */ #include #include "efuse.h" #include #define readl(addr) mmio_read_32(addr) #define writel(value, addr) mmio_write_32(addr, value) #define SID_OP_LOCK (0xAC) /* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ void sid_program_key(unsigned int key_index, unsigned int key_value) { unsigned int 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); return; } /* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ unsigned int sid_read_key(unsigned int key_index) { unsigned int reg_val; 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) | 0x2; writel(reg_val, SID_PRCTL); while(readl(SID_PRCTL)&0x2){}; reg_val &= ~((0x1ff<<16)|(0xff<<8)|0x3); writel(reg_val, SID_PRCTL); reg_val = readl(SID_RDKEY); return reg_val; } /* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ void sid_set_security_mode(void) { unsigned int reg_val; reg_val = sid_read_key(EFUSE_LCJS); reg_val |= (0x1<<11); //使能securebit sid_program_key(EFUSE_LCJS, reg_val); reg_val = (sid_read_key(EFUSE_LCJS) >> 11) & 1; return; } /* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ int sid_probe_security_mode(void) { return ((sid_read_key(EFUSE_LCJS)>>11) & 1); }