Example #1
0
static int key_efuse_query(char *keyname,unsigned int *keystate)
{
	int err=-EINVAL;
#ifdef CONFIG_EFUSE
	int i;
	char *title = keyname;
	efuseinfo_item_t info;
	char *buf;
	if(efuse_getinfo(title, &info) < 0)
		return -EINVAL;
	buf = malloc(info.data_len);
	if(buf == NULL){
		printf("%s:%d,malloc mem fail\n",__func__,__LINE__);
		return -ENOMEM;
	}
	memset(buf,0,info.data_len);
	err = efuse_read_usr(buf, info.data_len, (loff_t *)&info.offset);
	*keystate = KEY_NO_EXIST;
	if(err >0){
		for(i=0;i<info.data_len;i++){
			if(buf[i] != 0){
				*keystate = KEY_BURNED;
				break;
			}
		}
	}
	free(buf);
#endif
	return err;
}
Example #2
0
static int key_efuse_read(char *keyname,unsigned char *keydata,unsigned int datalen,unsigned int *reallen,enum key_manager_df_e flag)
{
#ifdef CONFIG_EFUSE
	char *title = keyname;
	efuseinfo_item_t info;
	int err=0;
	char *buf;
	if(flag >= KEY_M_MAX_DF){
		printf("%s:%d,%s key config[%x] err\n",__func__,__LINE__,keyname, flag);
		return -EINVAL;
	}

	if(efuse_getinfo(title, &info) < 0)
		return -EINVAL;
	
	buf = malloc(info.data_len);
	if(buf == NULL){
		printf("%s:%d,malloc mem fail\n",__func__,__LINE__);
		return -ENOMEM;
	}
	//err = efuse_read_usr((char*)keydata, datalen, (loff_t *)&info.offset);
	err = efuse_read_usr((char*)buf, info.data_len, (loff_t *)&info.offset);
	if(err>=0){
		*reallen = info.data_len;
		if(datalen > info.data_len){
			datalen = info.data_len;
		}
		memcpy(keydata,buf,datalen);
	}
	free(buf);
	return err;
#else
	return -EINVAL;
#endif
}
Example #3
0
// Prefetch the usid data from nand, efuse, etc
static int do_usid_prefetch(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
	int i,j,count=1,ret = 0,prefetch_flag = 0;
	char tmpbuf[1024]={0},str[1024]={0};
#ifdef CONFIG_AML_NAND_KEY
	run_command("secukey nand",0);
#endif

#ifdef CONFIG_AML_EMMC_KEY
	run_command("secukey emmc",0);
#endif

#ifdef CONFIG_STORE_COMPATIBLE && defined(CONFIG_SECURITYKEY)
    if (is_nand_exist()) {
        run_command("secukey nand",0);
    } else if (is_emmc_exist()) {
        run_command("secukey emmc",0);
    }
#endif

	ret=uboot_key_read("usid",usid_prefetch);
    if(ret >= 0) {
#ifdef CONFIG_AML_NAND_KEY
		printf("usid keys read from nand success!\n");
#endif

#ifdef CONFIG_AML_EMMC_KEY
		printf("usid keys read from emmc success!\n");
#endif

#ifdef CONFIG_STORE_COMPATIBLE && defined(CONFIG_SECURITYKEY)
    if (is_nand_exist()) {
		printf("usid keys read from nand success!\n");
    } else if (is_emmc_exist()) {
		printf("usid keys read from emmc success!\n");
    }
#endif
		char outputdata[2];
		memset(outputdata,0,2);
		for(i=0;i<USID_SIZE;i++){
			outputdata[0]=usid_prefetch[i];
			if(outputdata[0] == 00){
				count++;
				//printf("the data is 0!\n");
			}
		}	
		if(count >= USID_SIZE){					
			prefetch_flag = 0;
			printf("prefetch usid verify keys from %s failed\n", argv[1]);
#ifdef CONFIG_AML_NAND_KEY
			printf("nand key read usid fail,usid valid\n");
#endif

#ifdef CONFIG_AML_EMMC_KEY
			printf("emmc key read usid fail,usid valid\n");
#endif

#ifdef CONFIG_STORE_COMPATIBLE && defined(CONFIG_SECURITYKEY)
            if (is_nand_exist()) {
                printf("nand key read usid fail,usid valid\n");
            } else if (is_emmc_exist()) {
                printf("emmc key read usid fail,usid valid\n");
            }
#endif
		}else{
			for(i=0,j=0;i<ret;j++){
				tmpbuf[j] = twoASCByteToByte(usid_prefetch[i],usid_prefetch[i+1]);
				i += 2;
			}
#ifdef CONFIG_AML_NAND_KEY
			printf("nand usid read OK,write to bootargs now...\n");
#endif

#ifdef CONFIG_AML_EMMC_KEY
			printf("emmc usid read OK,write to bootargs now...\n");
#endif

#ifdef CONFIG_STORE_COMPATIBLE && defined(CONFIG_SECURITYKEY)
            if (is_nand_exist()) {
                printf("nand usid read OK,write to bootargs now...\n");
            } else if (is_emmc_exist()) {
                printf("emmc usid read OK,write to bootargs now...\n");
            }
#endif
			strcpy(str, getenv("bootargs"));
			if(strstr(str,"androidboot.serialno") == NULL){
				strcat(str, " androidboot.serialno=");
				strcat(str, tmpbuf);
				setenv("bootargs", str);
			}
				prefetch_flag = 1;
			} 
		}else {
			efuseinfo_item_t info;
			int efuse_ret;
			char *argv[3]={"efuse","read","usid"};
			printf("usid keys not in nand,read from efuse\n");
			if((!strncmp(argv[1],"read",sizeof("read"))) &&  (!strncmp(argv[2],"usid",sizeof("usid")))){
				efuse_getinfo("usid", &info);
				efuse_ret = efuse_read_usr(usid_prefetch, info.data_len, (loff_t*)&info.offset);
			}
			printf("efuse_ret=%d\n",efuse_ret);
			if(efuse_ret >= 0){
				usid_prefetch[info.data_len] = 0x00;
				printf("efuse read usid ok,write to bootargs now...\n");
				strcpy(str, getenv("bootargs"));
				if(strstr(str,"androidboot.serialno") == NULL){
					strcat(str, " androidboot.serialno=");
					strcat(str, usid_prefetch);
					setenv("bootargs", str);
				}
				prefetch_flag = 1;
			}
			else{
				printf("usid read usid fail,usid valid\n");
				prefetch_flag = 0;
			}    
		}
		if(prefetch_flag == 0)
			printf("fetch usid fail\n");
	return 1;
}
Example #4
0
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;
    unsigned long tag;
	#ifdef CONFIG_EFUSE
		char *barg_addr;
		char *r_efus;
		char addr[20];
		char bootargs[384];
	#endif
	
    tag = simple_strtoul (getenv ("tag"), NULL, 16);
    printf("tag = %d    !!!!!!!!!!!!!!!!!!\n", tag);

    if(tag == 3)
    {
        switch(get_kernel_cmd())
        {
            case SYSTEM_REBOOT:
            {
                printf("SYSTEM_REBOOT...\n");
                return  1;
            }
            default:
            {
                printf("NORMAL_BOOT...\n");
                break;
            }
        }
    }
    else
    {
        printf("Upgrade step %d...\n", tag);
    }

    if(tag == 0)
    {
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        else
        {
            printf("### ERROR:  u-boot write failed!!!\n");
            return  -1;
        }
    }
    else if((tag >0) && (tag < 3))
    {
        if(tag == 1)
        {
            if(upgrade_env())
            {
                run_command ("set tag 2", 0);
                run_command ("save", 0);
                run_command ("reset", 0);
                hang();
            }
            else
            {
                run_command ("defenv", 0);
                run_command ("save", 0);
            }
        }
        run_command ("set tag 3", 0);
        
        #ifdef CONFIG_EFUSE
			//r_addr = getenv ("ethaddr");
			if(efuse_chk_written(2)){
				r_efus = efuse_read_usr(2);
				memset(addr,0,sizeof(addr));
				sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
				printf("efuse mac is : %s \n", addr);
				//setenv ("ethaddr", addr);
				barg_addr = getenv ("bootargs");
				sprintf(bootargs,"set bootargs '%s mac=%s'",barg_addr,addr);
				run_command (bootargs, 0);
			}
		#endif
        run_command ("save", 0);
        
        upgrade_partition();
        return  1;
    }

    saradc_enable();

    //added by Elvis for added fool idle
    get_key();
    get_key();
    
    while(hold_time > 0)
    {
        udelay(polling_time);
        tmp = get_key();
        printf("get_key(): %d\n", tmp);
        if(!tmp)  break;
        hold_time -= polling_time;
    }

    if(hold_time > 0)
    {
        printf("Normal Start...\n");
        return  1;
    }
    else
    {
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        if(upgrade_env())
        {
            run_command ("set tag 2", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        run_command ("set tag 3", 0);
        run_command ("save", 0);
        upgrade_partition();
    }
}
Example #5
0
// Prefetch the uuid data from nand, efuse, etc
static int do_uuid_prefetch(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
	int i,j,count=1,ret = 0,prefetch_flag = 0;
	char tmpbuf[1024],str[1024];
	//if (argc >= 1)
	//	return cmd_usage(cmdtp);
	run_command("secukey nand",0);
    //ret = uboot_key_get(argv[1], "uuid", uuid_prefetch, 16, 0);
	ret=uboot_key_read("uuid",uuid_prefetch);
    //printf("ret=%d\n",ret);
    if(ret >= 0) {
		printf("uuid keys read from nand success!\n");
		char outputdata[2];
		memset(outputdata,0,2);
		for(i=0;i<UUID_SIZE;i++){
			outputdata[0]=uuid_prefetch[i];
			//printf("%02x\n",outputdata[0]);
			if(outputdata[0] == 00){
				count++;
				//printf("the data is 0!\n");
			}
		}	
		if(count >= UUID_SIZE){					
			prefetch_flag = 0;
			printf("prefetch uuid verify keys from %s failed\n", argv[1]);
			printf("nand key read uuid fail,uuid valid\n");
		}else{
#if 0	/* do not convert,because it writes uuid(0~f) datas directly */
			for(i=0,j=0;i<ret;j++){
				tmpbuf[j] = twoASCByteToByte(uuid_prefetch[i],uuid_prefetch[i+1]);
				i += 2;
			}
#endif        
                printf("nand uuid read uuid=%s\n", uuid_prefetch);
			printf("nand uuid read OK,write to bootargs now...\n");
			strcpy(str, getenv("bootargs"));
			if(strstr(str,"androidboot.serialno") == NULL){
				strcat(str, " androidboot.serialno=");
				strcat(str, uuid_prefetch);
				setenv("bootargs", str);
			}
				prefetch_flag = 1;
			} 
		}
#if 0 /* no uuid key in efuse */
          else {
			efuseinfo_item_t info;
			int efuse_ret;
			char *argv[3]={"efuse","read","uuid"};
			printf("uuid keys not in nand,read from efuse\n");
			if((!strncmp(argv[1],"read",sizeof("read"))) &&  (!strncmp(argv[2],"uuid",sizeof("uuid")))){
				efuse_getinfo("uuid", &info);
				efuse_ret = efuse_read_usr(uuid_prefetch, info.data_len, (loff_t*)&info.offset);
			}
			printf("efuse_ret=%d\n",efuse_ret);
			if(efuse_ret >= 0){
				uuid_prefetch[info.data_len] = 0x00;
				printf("efuse read uuid ok,write to bootargs now...\n");
				strcpy(str, getenv("bootargs"));
				if(strstr(str,"androidboot.serialno") == NULL){
					strcat(str, " androidboot.serialno=");
					strcat(str, uuid_prefetch);
					setenv("bootargs", str);
				}
				prefetch_flag = 1;
			}
			else{
				printf("uuid read uuid fail,uuid valid\n");
				prefetch_flag = 0;
			}    
		}
#endif        
		if(prefetch_flag == 0)
			printf("fetch uuid fail\n");
	return 1;
}
Example #6
0
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;
#ifdef CONFIG_SWITCH_BOOT_MODE
    printf("ENTER U-BOOT SWITCH MODE !!!!\n");
#else
    unsigned long tag;
	#ifdef CONFIG_EFUSE
		char *barg_addr;
		char *r_efus;
		char addr[20];
		char bootargs[384];
	#endif
	
    tag = simple_strtoul (getenv ("tag"), NULL, 16);
    printf("tag = %d    !!!!!!!!!!!!!!!!!!\n", tag);

    if(tag == 3)
    {
        switch(get_kernel_cmd())
        {
            case SYSTEM_REBOOT:
            {
                printf("SYSTEM_REBOOT...\n");
                return  1;
            }
            default:
            {
                printf("NORMAL_BOOT...\n");
                break;
            }
        }
    }
    else
    {
        printf("Upgrade step %d...\n", tag);
    }

    if(tag == 0)
    {
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        else
        {
            printf("### ERROR:  u-boot write failed!!!\n");
            return  -1;
        }
    }
    else if((tag >0) && (tag < 3))
    {
        if(tag == 1)
        {
            if(upgrade_env())
            {
                run_command ("set tag 2", 0);
                run_command ("save", 0);
                run_command ("reset", 0);
                hang();
            }
            else
            {
                run_command ("defenv", 0);
                run_command ("save", 0);
            }
        }
        run_command ("set tag 3", 0);
        
        #ifdef CONFIG_EFUSE
			//r_addr = getenv ("ethaddr");
			if(efuse_chk_written(2)){
				r_efus = efuse_read_usr(2);
				memset(addr,0,sizeof(addr));
				sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
				printf("efuse mac is : %s \n", addr);
				//setenv ("ethaddr", addr);
				barg_addr = getenv ("bootargs");
				sprintf(bootargs,"set bootargs '%s mac=%s'",barg_addr,addr);
				run_command (bootargs, 0);
			}
		#endif
        run_command ("save", 0);
        
        upgrade_partition();
        return  1;
    }
#endif
	
		//add by steven for version info
		char verubt[64],verrec[64];
		char *r_verubt,*r_verrec;
		const char* pVer = 0x82000020;
		const unsigned int* pMark = 0x8200005c;
		
		r_verubt = getenv("verubt");
		r_verrec = getenv("verrec");
		sprintf(verubt,"%s(%s.%s)",U_BOOT_VERSION,U_BOOT_DATE,U_BOOT_TIME);
		
		run_command("sf probe 0;sf read 82000000 40000 1000;",0);
		if(*pMark==0xbc690000)
		{
			sprintf(verrec,"%s",pVer);
		}
				
		if(strcmp(r_verubt,verubt) || strcmp(r_verrec,verrec)){
			setenv("verubt",verubt);
			if(*pMark==0xbc690000){
				setenv("verrec",verrec);
			}
			run_command("sav",0);
		}
		//end: add by steven for version info
		
		
#ifdef CONFIG_EFUSE //add by steven for mac in efuse.
		char *barg_addr;
		char *r_efus,*r_emac;
		char addr[20];
		
		r_emac = getenv ("emac");		
		if((efuse_chk_written(2)) && (strcmp(r_emac,"efuse")==0)){
			r_efus = efuse_read_usr(2);
			memset(addr,0,sizeof(addr));
			sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
			printf("efuse mac is : %s \n", addr);
			setenv ("ethaddr", addr);
			run_command("sav",0);
		}
#endif
		
    saradc_enable();

    //added by Elvis for added fool idle
    get_key();
    get_key();
    
    while(hold_time > 0)
    {
        udelay(polling_time);
        tmp = get_key();
        printf("get_key(): %d\n", tmp);
        if(!tmp)  break;
        hold_time -= polling_time;
    }

    if(hold_time > 0)
    {
        printf("Normal Start...\n");
        return  1;
    }
    else
    {
#ifdef CONFIG_RECOVERY
       	printf("Recovery Start...\n");
        run_command ("run recoveryboot", 0);
        hang();
#else
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        if(upgrade_env())
        {
            run_command ("set tag 2", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        run_command ("set tag 3", 0);
        run_command ("save", 0);
        upgrade_partition();
#endif
    }
}