int do_store(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { int i, init_flag=0,dev, ret = 0; uint64_t addr; loff_t off=0, size=0; char *cmd, *s, *area; char str[128]; unsigned char *tmp_buf= NULL; if (argc < 2) goto usage; cmd = argv[1]; if (strcmp(cmd, "erase") == 0){ area = argv[2]; if(strcmp(area, "boot") == 0){ if(POR_NAND_BOOT()){ off = simple_strtoul(argv[3], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); store_dbg("NAND BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); ret = run_command("amlnf deverase boot 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } return ret; }else if(POR_SPI_BOOT()){ off = simple_strtoul(argv[3], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); store_dbg("SPI BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); ret = run_command("sf probe 2",0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0 0x%x", CONFIG_ENV_IN_SPI_OFFSET);//store erase boot shoould NOT erase ENV in flash! ret = run_command(str,0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if(POR_EMMC_BOOT()){ off = simple_strtoul(argv[3], NULL, 16); size = simple_strtoul(argv[4], NULL, 16); store_dbg("MMC BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); sprintf(str, "mmc erase bootloader"); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for(i=0; i<2; i++){ //switch to boot partition here sprintf(str, "mmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret == -1){ //store_msg("mmc cmd %s failed \n",cmd); return 0; } else if(ret != 0){ store_msg("mmc cmd %s failed",cmd); //return -1; goto E_SWITCH_BACK; } //erase boot partition sprintf(str, "mmc erase bootloader"); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); //return -1; goto E_SWITCH_BACK; } } E_SWITCH_BACK: //switch back to urs partition sprintf(str, "mmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT,erase uboot : %s %d off =%llx ,size=%llx",__func__,__LINE__,off,size); return 0; } } else if(strcmp(area, "data") == 0){ if(POR_NAND_BOOT()){ store_dbg("NAND BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); ret = run_command("amlnf deverase data 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase code 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase cache 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } return ret; } else if(POR_SPI_BOOT()){ store_dbg("SPI BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); ret = run_command("amlnf deverase data 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase code 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } ret = run_command("amlnf deverase cache 0",0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); off = size =0; ret = run_command("mmc erase 1",0); // whole if(ret != 0){ store_msg("mmc cmd %s failed ",cmd); return -1; } } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); off = size =0; ret = run_command("mmc erase 1",0); //whole if(ret != 0){ store_msg("mmc cmd %s failed ",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT,erase data : %s %d off =%llx ,size=%llx",__func__,__LINE__, off, size); return 0; } } else { goto usage; } } else if(strcmp(cmd, "read") == 0){ if (argc < 6) goto usage; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (get_off_size(argc - 4, argv + 4, &off, &size) != 0) goto usage; store_dbg("addr = %llx off= 0x%llx size=0x%llx",addr,off,size); if((POR_NAND_BOOT())){ sprintf(str, "amlnf read_byte %s 0x%llx 0x%llx 0x%llx",s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } return ret; }else if((POR_SPI_BOOT())){ if(device_boot_flag == SPI_NAND_FLAG){ sprintf(str, "amlnf read_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed \n",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); sprintf(str, "mmc read %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } } return ret; } else if(POR_EMMC_BOOT()) { store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "mmc read %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "write") == 0){ if (argc < 6) goto usage; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (get_off_size(argc - 4, argv + 4, &off, &size) != 0) goto usage; if((POR_NAND_BOOT())){ sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed ",cmd); return -1; } }else if((POR_SPI_BOOT())){ if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed \n",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); sprintf(str, "mmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } } } else if(POR_EMMC_BOOT()) { store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "mmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return 0; } return ret; } else if(strcmp(cmd, "rom_write") == 0){ if (argc < 5) goto usage; addr = (ulong)simple_strtoul(argv[2], NULL, 16); if (get_off_size(argc - 3, argv + 3, &off, &size) != 0) goto usage; if(POR_NAND_BOOT()){ sprintf(str, "amlnf rom_write 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if (POR_SPI_BOOT()){ ret = run_command("sf probe 2",0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0x%llx 0x%llx ", off, size); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf write 0x%llx 0x%llx 0x%llx ",addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); tmp_buf= (unsigned char *)addr; #ifndef CONFIG_AML_SECU_BOOT_V2 #ifdef MMC_UBOOT_CLEAR_MBR //modify the 55 AA info for emmc uboot _mbrFlag[0] = tmp_buf[510]; _mbrFlag[1] = tmp_buf[511]; tmp_buf[510]=0; tmp_buf[511]=0; #endif #endif// #if defined(CONFIG_AML_SECU_BOOT_V2) sprintf(str, "mmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for(i=0; i<2; i++){ //switch to boot partition here sprintf(str, "mmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret == -1){ //store_msg("mmc cmd %s failed \n",cmd); ret = 0; return ret; } else if(ret != 0){ store_msg("mmc cmd %s failed",cmd); //return -1; goto W_SWITCH_BACK; } //write uboot to boot partition sprintf(str, "mmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); //return -1; goto W_SWITCH_BACK; } } W_SWITCH_BACK: //switch back to urs partition sprintf(str, "mmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "rom_read") == 0){ if (argc < 5) goto usage; addr = (ulong)simple_strtoul(argv[2], NULL, 16); if (get_off_size(argc - 3, argv + 3, &off, &size) != 0) goto usage; if(POR_NAND_BOOT()){ sprintf(str, "amlnf rom_read 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if (POR_SPI_BOOT()){ ret = run_command("sf probe 2",0); if(ret != 0){ return -1; } sprintf(str, "sf read 0x%llx 0x%llx 0x%llx ",addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if (POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "mmc read bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); tmp_buf= (unsigned char *)addr; ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for(i=0; i<2; i++){ //switch to boot partition here sprintf(str, "mmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret == -1){ //store_msg("mmc cmd %s failed \n",cmd); return 0; } else if(ret != 0){ store_msg("mmc cmd %s failed",cmd); goto R_SWITCH_BACK; //return -1; } //write uboot to boot partition sprintf(str, "mmc read bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); //return -1; goto R_SWITCH_BACK; } } R_SWITCH_BACK: //switch back to urs partition sprintf(str, "mmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } #endif #ifndef CONFIG_AML_SECU_BOOT_V2 #ifdef MMC_UBOOT_CLEAR_MBR tmp_buf[510]= _mbrFlag[0]; tmp_buf[511]= _mbrFlag[1]; #endif #endif// #ifndef CONFIG_AML_SECU_BOOT_V2 return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return 0; } } else if (strcmp(cmd, "rom_protect") == 0){ if (argc < 3) goto usage; area = argv[2]; if(POR_NAND_BOOT()){ sprintf(str, "amlnf rom_protect %s", area); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; } } else if (strcmp(cmd, "scrub") == 0){ off = (ulong)simple_strtoul(argv[2], NULL, 16); sprintf(str, "amlnf scrub %d", off); if((POR_NAND_BOOT()) ){ ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } }else if(POR_SPI_BOOT()){ if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } ret = run_command("sf probe 2", 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmc erase whole",0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } } }else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); device_boot_flag = EMMC_BOOT_FLAG; ret = run_command("mmcinfo 1", 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ MsgP("mmc key\n"); run_command("mmc key", 0); } MsgP("mmc erase 1"); ret = run_command("mmc erase 1", 0); } return ret; } else if(strcmp(cmd, "init") == 0){ init_flag = (argc > 2) ? (int)simple_strtoul(argv[2], NULL, 16) : 0; store_dbg("init_flag %d",init_flag); if(POR_NAND_BOOT()){ if((init_flag >=STORE_BOOT_ERASE_PROTECT_CACHE)&&(init_flag <=STORE_BOOT_SCRUB_ALL)){ sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",0); printf("command: %s -> %d\n", str, init_flag); device_boot_flag = NAND_BOOT_FLAG; ret = run_command(str, 0); if(ret != 0){ #if 0 if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } if(ret){ store_msg("nand cmd %s failed,ret=%d ",cmd,ret); return -1; } return 0; #else return -1; #endif } return ret; } else if(POR_SPI_BOOT()) { if(device_boot_flag == -1) { ret = run_command("sf probe 2", 0); if(ret){ store_msg(" cmd %s failed \n",cmd); return -1; } if((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)){ sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); /*nand erase!*/ sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",0); printf("command: %s -> %d\n", str, init_flag); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret < 0)//fail to init NAND flash { store_msg("nand cmd %s failed \n",cmd); device_boot_flag = SPI_EMMC_FLAG; store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmcinfo 1", 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -2; } if(init_flag == STORE_BOOT_ERASE_PROTECT_CACHE){ // OTA upgrade protect cache store_msg("mmc erase non_cache \n"); ret = run_command("mmc erase non_cache", 0); }else if(init_flag >= STORE_BOOT_ERASE_ALL){ // erase all except reserved area if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ MsgP("mmc key;\n"); run_command("mmc key", 0); } MsgP("mmc erase 1 \n"); ret = run_command("mmc erase 1", 0); } return 0; } else if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ #if 0 sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); #else return -1; #endif } device_boot_flag = SPI_NAND_FLAG; return 0; } if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); if((init_flag >=STORE_BOOT_ERASE_PROTECT_CACHE)&&(init_flag <=STORE_BOOT_SCRUB_ALL)){ sprintf(str, "amlnf init %d ",init_flag); run_command(str, 0); } sprintf(str, "amlnf init %d ",0); store_dbg("command: %s", str); ret = run_command(str, 0); #if 0 if((ret == NAND_INIT_FAILED)&&(init_flag == STORE_BOOT_ERASE_ALL)){ sprintf(str, "amlnf init %d ",4); ret = run_command(str, 0); } #else if(ret == NAND_INIT_FAILED){ return -1; } #endif if((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)){ ret = run_command("sf probe 2", 0); sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); ret = run_command("mmcinfo 1", 0); if(init_flag == STORE_BOOT_ERASE_PROTECT_CACHE){ // OTA upgrade protect cache store_msg("mmc erase non_cache \n"); ret = run_command("mmc erase non_cache", 0); }else if(init_flag == STORE_BOOT_ERASE_ALL){ // erase all except reserved area if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ run_command("mmc key", 0); } MsgP("mmc erase 1 \n"); ret = run_command("mmc erase 1", 0); } if((init_flag > STORE_BOOT_ERASE_PROTECT_CACHE) && (init_flag <= STORE_BOOT_SCRUB_ALL)){ ret = run_command("sf probe 2", 0); sprintf(str, "sf erase 0 0x%x", _SPI_FLASH_ERASE_SZ); ret = run_command(str,0); } } if(ret != 0){ store_msg("cmd %s failed \n",cmd); return -1; } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); device_boot_flag = EMMC_BOOT_FLAG; ret = run_command("mmcinfo 1", 0); if(ret != 0){ store_msg("mmc cmd %s failed \n",cmd); return -1; } if(init_flag == STORE_BOOT_ERASE_PROTECT_CACHE){ // OTA upgrade protect cache ret = run_command("mmc erase non_cache", 0); }else if(init_flag >= STORE_BOOT_ERASE_ALL){ // erase all except reserved area if(_info_disprotect_back_before_mmcinfo1 & DISPROTECT_KEY){ MsgP("mmc key\n"); run_command("mmc key", 0); } MsgP("mmc erase 1"); ret = run_command("mmc erase 1", 0); } return ret; }else{ store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "size") == 0){ if (argc < 4) goto usage; s = argv[2]; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if(POR_NAND_BOOT()){ sprintf(str, "amlnf size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } return ret; }else if(POR_SPI_BOOT()){ if(device_boot_flag == SPI_NAND_FLAG){ sprintf(str, "amlnf size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } } if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("MMC , %s %d ",__func__,__LINE__); sprintf(str, "mmc size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); return -1; } } return ret; } else if(POR_EMMC_BOOT()){ store_dbg("MMC , %s %d ",__func__,__LINE__); sprintf(str, "mmc size %s %llx",s,addr); store_dbg("command: %s", str); ret = run_command(str, 0); if(ret != 0){ store_msg("mmc cmd %s failed",cmd); return -1; } return ret; } else if(POR_CARD_BOOT()){ store_dbg("CARD BOOT , %s %d ",__func__,__LINE__); return 0; } } else if(strcmp(cmd, "disprotect") == 0){ area = argv[2]; if(strcmp(area, "key") == 0){ MsgP("disprotect key\n"); info_disprotect |= DISPROTECT_KEY; _info_disprotect_back_before_mmcinfo1 |= DISPROTECT_KEY; } if(strcmp(area, "secure") == 0){ store_msg("disprotect secure"); info_disprotect |= DISPROTECT_SECURE; } if(strcmp(area, "fbbt") == 0){ store_msg("disprotect fbbt"); info_disprotect |= DISPROTECT_FBBT; } if(strcmp(area, "hynix") == 0){ store_msg("disprotect hynix"); info_disprotect |= DISPROTECT_HYNIX; } return 0; } else if(strcmp(cmd, "exit") == 0){ if(POR_NAND_BOOT()){ ret = run_command("amlnf exit", 0); if(ret != 0){ store_msg("nand cmd %s failed",cmd); return -1; } } return 0; } else{ goto usage; } return ret; usage: cmd_usage(cmdtp); return 1; }
static int do_store_rom_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { uint64_t addr; loff_t off=0, size=0; char *cmd = NULL; char str[128]; int ret = 0; int i = 0; cpu_id_t cpu_id = get_cpu_id(); if (argc < 5) return CMD_RET_USAGE; addr = (ulong)simple_strtoul(argv[2], NULL, 16); if (get_off_size(argc - 3, (char **)(argv + 3), &off, &size) != 0) return CMD_RET_FAILURE; if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf rom_write 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if ((device_boot_flag==SPI_EMMC_FLAG)||(device_boot_flag==SPI_NAND_FLAG)){ ret = run_command("sf probe 2",0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf erase 0x%llx 0x%llx ", off, size); ret = run_command(str, 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } sprintf(str, "sf write 0x%llx 0x%llx 0x%llx ",addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); if (ret != 0) { store_msg("nand cmd %s failed",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); #ifndef CONFIG_AML_SECU_BOOT_V2 #ifdef MMC_UBOOT_CLEAR_MBR //modify the 55 AA info for emmc uboot unsigned char *tmp_buf= (unsigned char *)addr; _mbrFlag[0] = tmp_buf[510]; _mbrFlag[1] = tmp_buf[511]; tmp_buf[510]=0; tmp_buf[511]=0; #endif #endif// #if defined(CONFIG_AML_SECU_BOOT_V2) if (cpu_id.family_id >= MESON_CPU_MAJOR_ID_GXL) off += 512; sprintf(str, "amlmmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } #ifdef MMC_BOOT_PARTITION_SUPPORT for (i=0; i<2; i++) { //switch to boot partition here sprintf(str, "amlmmc switch 1 boot%d", i); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret == -1) { //store_msg("mmc cmd %s failed \n",cmd); ret = 0; return ret; } else if(ret != 0){ store_msg("amlmmc cmd %s failed",cmd); //return -1; goto W_SWITCH_BACK; } //write uboot to boot partition sprintf(str, "amlmmc write bootloader 0x%llx 0x%llx 0x%llx", addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); //return -1; goto W_SWITCH_BACK; } } W_SWITCH_BACK: //switch back to urs partition sprintf(str, "amlmmc switch 1 user"); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } #endif return ret; }else{ store_dbg("CARD BOOT, %s %d",__func__,__LINE__); return 0; } }
int do_data(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { int i, dev, ret = 0; ulong addr; loff_t off, size; char *cmd, *s; char str[128]; cmd = argv[1]; if (argc < 3) goto usage; if (get_off_size(argc - 2, argv + 2, &off, &size) != 0) return 1; printk("erase data : %s %d off =%llx ,size=%llx\n",__func__,__LINE__, off, size); if (strcmp(cmd, "erase") == 0){ printk(" %s %d\n",__func__,__LINE__); if(POR_NAND_BOOT()){ printk("NAND BOOT,nand_env_relocate_spec : %s %d \n",__func__,__LINE__); if(size == 0){ sprintf(str, "nand erase 0x%llx", off); printf("command: %s\n", str); run_command("nand device 1",0); run_command(str, 0); }else{ sprintf(str, "nand erase 0x%llx 0x%llx", off, size); printf("command: %s\n", str); run_command("nand device 1",0); run_command(str, 0); } printk("nand erase data \n"); }else if(POR_EMMC_BOOT()) { printk("MMC BOOT, %s %d \n",__func__,__LINE__); if(size == 0){ run_command("mmc erase 1", 0); } printk("mmc erase data \n"); }else{ ret = run_command("nand exist", 0); printk("do_data else: %s %d , nand exist ret %d\n",__func__,__LINE__, ret); if(!run_command("nand exist", 0)){ if(size == 0){ sprintf(str, "nand erase 0x%llx", off); printf("command: %s\n", str); run_command(str, 0); }else{ sprintf(str, "nand erase 0x%llx 0x%llx", off, size); printf("command: %s\n", str); run_command(str, 0); } printk("nand erase data \n"); }else if(!run_command("mmcinfo 1", 0)){ if(size == 0){ run_command("mmc erase 1", 0); } printk("mmc erase data \n"); } } }else{ goto usage; } return ret; usage: cmd_usage(cmdtp); return 1; }
static int do_store_write(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { uint64_t addr; loff_t off=0, size=0; char *cmd = NULL; char str[128]; int ret = 0; char * s = argv[2]; if (argc < 6) return CMD_RET_USAGE; addr = (ulong)simple_strtoul(argv[3], NULL, 16); if (get_off_size(argc - 4, (char **)(argv + 4), &off, &size) != 0) return CMD_RET_FAILURE; if (device_boot_flag == NAND_BOOT_FLAG) { #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed ",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_NAND_FLAG){ store_dbg("spi+nand , %s %d ",__func__,__LINE__); #if defined(CONFIG_AML_NAND) sprintf(str, "amlnf write_byte %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s", str); ret = run_command(str, 0); #else ret = -1; #endif if (ret != 0) { store_msg("nand cmd %s failed \n",cmd); return -1; } return ret; } else if(device_boot_flag == SPI_EMMC_FLAG){ store_dbg("spi+mmc , %s %d ",__func__,__LINE__); sprintf(str, "amlmmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } return ret; } else if(device_boot_flag==EMMC_BOOT_FLAG){ store_dbg("MMC BOOT, %s %d \n",__func__,__LINE__); sprintf(str, "amlmmc write %s 0x%llx 0x%llx 0x%llx", s, addr, off, size); store_dbg("command: %s\n", str); ret = run_command(str, 0); if (ret != 0) { store_msg("amlmmc cmd %s failed \n",cmd); return -1; } return ret; }else{ store_dbg("CARD BOOT, %s %d ",__func__,__LINE__); return CMD_RET_FAILURE; } return ret; }