int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { printf("Saving Environment to %s...\n", env_name_spec); return saveenv() ? 1 : 0; }
//extern int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); void recoveryHandle(void) { char cmd[256]; char img[10]; char * argv[3]; char *env; MV_32 imagAddr, imagSize = 0, netflag = 1; char ip[16]= {"dhcp"}; char* usbload[5]; unsigned int netwait = 3000; int upgrade = -1; /* get the loadaddr env var */ if (!getenv("loadaddr")) { printf("Missing loadaddr environment variable assuming default (%s)!\n", RCVR_LOAD_ADDR); setenv("loadaddr",RCVR_LOAD_ADDR); saveenv(); } #ifdef CONFIG_USB_STORAGE /* First try to perform recovery from USB DOK*/ /* try to recognize storage devices immediately */ if (usb_init() >= 0) { if (usb_stor_scan(1) >= 0) { netflag = 0; usbload[0] = "usbload"; usbload[1] = "usb"; usbload[2] = "0:1"; usbload[3] = getenv("loadaddr"); usbload[4] = "/multiware.img"; printf("Trying to load image from USB flash drive using FAT FS\n"); if (do_fat_fsload(0, 0, 5, usbload) == 1) { printf("Trying to load image from USB flash drive using ext2 FS partition 0\n"); usbload[2] = "0:0"; if(do_ext2load(0, 0, 5, usbload) == 1) { printf("Trying to load image from USB flash drive using ext2 FS partition 1\n"); usbload[2] = "0:1"; if(do_ext2load(0, 0, 5, usbload) == 1) { printf("Couldn't load recovery image from USB flash drive, Trying network interface\n"); netflag = 1; } else { env = getenv("filesize"); usbload[3] = getenv("loadaddr"); imagSize = simple_strtoul(env, NULL, 16); /* get the filesize env var */ /* Trying to check if we forced to upgrade by placing upgrade.me */ usbload[4] = "/upgrade.me"; usbload[3] = "0x000000000"; env=getenv("loadaddr"); imagAddr=simple_strtoul(env, NULL, 16); sprintf(usbload[3], "0x%x", imagAddr + imagSize + 1); printf("dummyaddr:%s\n", usbload[3]); upgrade=do_ext2load(0, 0, 5, usbload); } } else { env = getenv("filesize"); imagSize = simple_strtoul(env, NULL, 16); /* get the filesize env var */ /* Trying to check if we forced to upgrade by placing upgrade.me */ usbload[4] = "/upgrade.me"; usbload[3] = "0x000000000"; env=getenv("loadaddr"); imagAddr=simple_strtoul(env, NULL, 16); sprintf(usbload[3], "0x%x", imagAddr + imagSize + 1); printf("dummyaddr:%s\n", usbload[3]); upgrade=do_ext2load(0, 0, 5, usbload); } } else { env = getenv("filesize"); imagSize = simple_strtoul(env, NULL, 16); /* get the filesize env var */ /* Trying to check if we forced to upgrade by placing upgrade.me */ usbload[4] = "/upgrade.me"; usbload[3] = "0x000000000"; env=getenv("loadaddr"); imagAddr=simple_strtoul(env, NULL, 16); sprintf(usbload[3], "0x%x", imagAddr + imagSize + 1); printf("dummyaddr:%s\n", usbload[3]); upgrade=do_fat_fsload(0, 0, 5, usbload); } // Decide on upgrade/init mode if (upgrade == 0) sprintf(ip, "usb_upgrade"); else sprintf(ip, "usb"); printf("USB mode:%s\n", ip); } } #endif if(netflag == 1) { /* if recovery ip set same as our ip then skip dhcp */ while ( strcmp(getenv("rcvrip"), getenv("ipaddr")) && (netwait > 0) ) { /* Perform the DHCP */ printf("Aquiring an IP address using DHCP after delay...\n"); mvOsDelay(netwait); netwait-=1000; if (NetLoop(DHCP) != -1) { /* We'vev got DHCP progressing with recovery */ printf("DHCP should be ready for Recovery.\n"); break; } } /* No DHCP after timeout or forced */ if ( !strcmp(getenv("rcvrip"), getenv("ipaddr")) || (netwait <= 0) ) { ulong tmpip; printf("No DHCP after timeout or manual IP address configured, switching to static IP address (%s)!\n", getenv("rcvrip")); tmpip = getenv_IPaddr ("rcvrip"); NetCopyIP(&NetOurIP, &tmpip); sprintf(ip, "static"); } /* Perform the recovery */ printf("Starting retrieval of recovery image over network...\n"); if ((imagSize = NetLoop(RCVR)) == -1) { printf("Failed\n"); return; } } switch (mvBoardIdGet()) { case RD_88F6510_SFU_ID: case RD_88F6560_GW_ID: case DB_88F6535_BP_ID: setenv("bootcmd","setenv bootargs ${console} ubi.mtd=2 root=ubi0:rootfsU rootfstype=ubifs ${mvNetConfig} ${mvPhoneConfig}; nand read.e ${loadaddr} 0x200000 0x400000; bootm ${loadaddr};"); setenv("console","console=ttyS0,115200"); saveenv(); break; } printf("\nPermanent bootcmd: %s\n", getenv("bootcmd")); printf("\nPermanent console: %s\n", getenv("console")); /* This assignment to cmd should execute prior to the RD setenv and saveenv below*/ sprintf(cmd,"setenv bootargs ${console} root=/dev/ram0 ${mvNetConfig} recovery=%s rcvrip=%s:%s%s ethact=${ethact} ethaddr=%s eth1addr=%s; bootm ${loadaddr};", ip, getenv("rcvrip"), getenv("serverip"), getenv("bootargs_end"), getenv("ethaddr"), getenv("eth1addr")); setenv("bootcmd", cmd); printf("\nRecovery bootcmd: %s\n", cmd); printf("Booting recovery image at: [%s]...\n", getenv("loadaddr")); sprintf(cmd, "boot"); sprintf(img, "%s", getenv("loadaddr")); argv[0] = cmd; argv[1] = img; do_bootd(NULL, 0, 2, argv); }
void emmc_env_relocate_spec(void) { #if !defined(ENV_IS_EMBEDDED) int dev_num; int ret; env_t * env_buf = NULL; u64 cnt = CONFIG_ENV_SIZE; u64 blk = 0; uint32_t crc; struct mmc *mmc = NULL; char *name = "env"; struct partitions *part_info = NULL; int blk_shift = 0; env_buf = (env_t *)malloc(CONFIG_ENV_SIZE); if(!env_buf) { printf("malloc failed \n"); return ; } memset(env_buf->data, 0, ENV_SIZE); #ifdef CONFIG_STORE_COMPATIBLE part_info = find_mmc_partition_by_name(name); if(part_info == NULL) { printf("get partition info failed !!\n"); return ; } dev_num = find_dev_num_by_partition_name (name); if(dev_num < 0) { printf("get mmc dev failed !!\n"); return ; } store_dbg(" read env: dev_num %d",dev_num); mmc = find_mmc_device(dev_num); if (!mmc) { set_default_env("!No MMC device"); return; } if ((cnt % 512) || (blk % 512)) { set_default_env("!addr or blk count notalign"); return ; } blk_shift = ffs(mmc->read_bl_len) - 1; blk = part_info->offset >> blk_shift; cnt = cnt >> blk_shift; #endif store_dbg(" read env: blk_shift %d blk %d cnt %llx",blk_shift,blk,cnt); ret =(cnt == mmc->block_dev.block_read(dev_num, blk, cnt, env_buf)); if(!ret) { set_default_env("!readenv() failed"); saveenv(); return; } crc = env_buf->crc; if (crc32(0, env_buf->data, ENV_SIZE) != crc) { set_default_env("!bad CRC"); saveenv(); } env_import(env_buf, 1); #endif }