static int key_efuse_init(char *buf,unsigned int len) { #ifdef CONFIG_EFUSE char ver; int ret; char title[] = "version"; efuseinfo_item_t info; loff_t pos; if(efuse_getinfo(title, &info) < 0) return -EINVAL; pos = info.offset; ret = efuse_chk_written(pos, info.data_len); if(ret < 0){ return -EINVAL; } if(ret > 0){ return 0;// efuse version was written } if(!(info.we)){ printf("%s write unsupport now. \n", title); return -EACCES; } ver = unifykey_get_efuse_version(); if(ver == 0){ printf("not config efuse version\n"); return 0; } else{ if(efuse_write_usr((char*)&ver, 1, &pos)<0){ printf("error: efuse write fail.\n"); return -1; } else{ printf("%s written done.\n", info.title); return 0; } } #else return 0; #endif }
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(); } }
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 } }