int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { if (argc < 2) return -1; NetPingIP = string_to_ip(argv[1]); if (NetPingIP == 0) { printf ("Usage:\n%s\n", cmdtp->usage); return -1; } if (NetLoop(PING) < 0) { printf("ping failed; host %s is not alive\n", argv[1]); return 1; } printf("host %s is alive\n", argv[1]); return 0; }
void spl_eth_load_image(void) { int rv; env_init(); env_relocate(); setenv("autoload", "yes"); load_addr = CONFIG_SYS_TEXT_BASE - sizeof(struct image_header); rv = eth_initialize(gd->bd); if (rv == 0) { printf("No Ethernet devices found\n"); hang(); } rv = NetLoop(BOOTP); if (rv < 0) { printf("Problem booting with BOOTP\n"); hang(); } spl_parse_image_header((struct image_header *)load_addr); }
static int nc_getc(void) { uchar c; input_recursion = 1; net_timeout = 0; /* no timeout */ while (!input_size) NetLoop (NETCONS); input_recursion = 0; c = input_buffer[input_offset++]; if (input_offset >= sizeof input_buffer) input_offset -= sizeof input_buffer; input_size--; return c; }
static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char tmp[22]; if (NetLoop(LINKLOCAL) < 0) return 1; NetOurGatewayIP = 0; ip_to_string(NetOurGatewayIP, tmp); setenv("gatewayip", tmp); ip_to_string(NetOurSubnetMask, tmp); setenv("netmask", tmp); ip_to_string(NetOurIP, tmp); setenv("ipaddr", tmp); setenv("llipaddr", tmp); /* store this for next time */ return 0; }
int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { if (argc < 2) return -1; #ifdef UIP_CONF_IPV6 if (strcmp(argv[1], "-6") == 0) { uip_ipaddr_t DestIpv6; if (argc < 3) return -1; if (!inet_pton6(argv[2], (unsigned char*)&DestIpv6)) { printf("Invalid host address \n"); return -1; } if (!ping6(&DestIpv6)) { printf("ping failed; host %s is not alive\n", argv[2]); return 1; } printf("host %s is alive\n", argv[2]); return 0; } else { #endif NetPingIP = string_to_ip(argv[1]); if (NetPingIP == 0) { printf ("Usage:\n%s\n", cmdtp->usage); return -1; } if (NetLoop(PING) < 0) { printf("ping failed; host %s is not alive\n", argv[1]); return 1; } printf("host %s is alive\n", argv[1]); return 0; #ifdef UIP_CONF_IPV6 } #endif }
int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { if(argc < 2) { #ifdef CFG_LONGHELP if(cmdtp->help != NULL) { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help); } else { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); } #else printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); #endif return(-1); } NetPingIP = string_to_ip(argv[1]); if (NetPingIP == 0) { #ifdef CFG_LONGHELP if(cmdtp->help != NULL) { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help); } else { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); } #else printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); #endif return(-1); } if(NetLoop(PING) < 0) { printf("\n## Error: ping failed, host %s is not alive!\n\n", argv[1]); return(1); } printf("\nPing OK, host %s is alive!\n\n", argv[1]); return(0); }
static void nc_send_packet (const char *buf, int len) { DECLARE_GLOBAL_DATA_PTR; struct eth_device *eth; int inited = 0; uchar *pkt; uchar *ether; IPaddr_t ip; if ((eth = eth_get_dev ()) == NULL) { return; } if (!memcmp (nc_ether, NetEtherNullAddr, 6)) { if (eth->state == ETH_STATE_ACTIVE) return; /* inside net loop */ output_packet = buf; output_packet_len = len; NetLoop (NETCONS); /* wait for arp reply and send packet */ output_packet_len = 0; return; } if (eth->state != ETH_STATE_ACTIVE) { if (eth_init (gd->bd) < 0) return; inited = 1; } pkt = (uchar *) NetTxPacket + NetEthHdrSize () + IP_HDR_SIZE; memcpy (pkt, buf, len); ether = nc_ether; ip = nc_ip; NetSendUDPPacket (ether, ip, nc_port, nc_port, len); if (inited) eth_halt (); }
static int nc_tstc(void) { struct eth_device *eth; if (input_recursion) return 0; if (input_size) return 1; eth = eth_get_dev (); if (eth && eth->state == ETH_STATE_ACTIVE) return 0; /* inside net loop */ input_recursion = 1; net_timeout = 1; NetLoop (NETCONS); /* kind of poll */ input_recursion = 0; return input_size != 0; }
int network_update( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ) { int i; setup_pkt_recvd=0; NetSetTimeout(TIMEOUT * CFG_HZ, NbootTimeout); NetSetHandler(NBootHandler); dm9k_phy_retry_times=1000; eth_init(gd->bd); eth_rx(); if (setup_pkt_recvd) { front_puts("TFTP"); if (NetLoop (TFTP) <= 0) return 1; front_puts("BURN"); burn_flash_img( 0, 0, 0, 0); do_reset (NULL, 0, 0, NULL); } return 0; }
int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *toff; if(argc < 2) { #ifdef CFG_LONGHELP if(cmdtp->help != NULL) { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help); } else { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); } #else printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); #endif return(-1); } else { NetNtpServerIP = string_to_ip(argv[1]); if(NetNtpServerIP == 0) { printf("## Error: bad SNTP server IP address\n"); return(1); } } toff = getenv("timeoffset"); if(toff == NULL) { NetTimeOffset = 0; } else { NetTimeOffset = simple_strtol(toff, NULL, 10); } if(NetLoop(SNTP) < 0) { printf("## Error: SNTP host %s not responding\n", argv[1]); return(1); } return(0); }
int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { if (argc == 1) return cmd_usage(cmdtp); /* * We should check for a valid hostname: * - Each label must be between 1 and 63 characters long * - the entire hostname has a maximum of 255 characters * - only the ASCII letters 'a' through 'z' (case-insensitive), * the digits '0' through '9', and the hyphen * - cannot begin or end with a hyphen * - no other symbols, punctuation characters, or blank spaces are * permitted * but hey - this is a minimalist implmentation, so only check length * and let the name server deal with things. */ if (strlen(argv[1]) >= 255) { printf("dns error: hostname too long\n"); return 1; } NetDNSResolve = argv[1]; if (argc == 3) NetDNSenvvar = argv[2]; else NetDNSenvvar = NULL; if (NetLoop(DNS) < 0) { printf("dns lookup of %s failed, check setup\n", argv[1]); return 1; } return 0; }
int do_http (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int ret; printf("HTTP Start......\n"); if (argc > 1) http_debug = DEBUG; else http_debug = 0; http_state = HTTP_START; init_tcp(); if (ret = NetLoop(HTTP) < 0) { printf("HTTP Stop......%d\n",ret); return 1; } printf("HTTP Stop......%d\n",ret); return 0; }
int bootme_send_frame(const void *buf, size_t len) { int ret; struct eth_device *eth; int inited = 0; uchar *pkt; eth = eth_get_dev(); if (eth == NULL) return -EINVAL; if (bootme_state == BOOTME_INIT) check_net_config(); debug("%s: buf: %p len: %u from %pI4:%d to %pI4:%d\n", __func__, buf, len, &NetOurIP, bootme_src_port, &bootme_ip, bootme_dst_port); if (memcmp(bootme_ether, NetEtherNullAddr, ETH_ALEN) == 0) { if (eth->state == ETH_STATE_ACTIVE) return 0; /* inside net loop */ output_packet = buf; output_packet_len = len; /* wait for arp reply and send packet */ ret = NetLoop(BOOTME); if (ret < 0) { /* drop packet */ output_packet_len = 0; return ret; } if (bootme_timed_out) return -ETIMEDOUT; return 0; } if (eth->state != ETH_STATE_ACTIVE) { if (eth_is_on_demand_init()) { ret = eth_init(gd->bd); if (ret < 0) return ret; eth_set_last_protocol(BOOTME); } else { eth_init_state_only(gd->bd); } inited = 1; } assert(NetTxPacket != NULL); pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE; memcpy(pkt, buf, len); ret = NetSendUDPPacket(bootme_ether, bootme_ip, bootme_dst_port, bootme_src_port, len); if (inited) { debug("Stopping network\n"); if (eth_is_on_demand_init()) eth_halt(); else eth_halt_state_only(); } return ret; }
int do_diag(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *orig_ethact, *orig_ipaddr, ca_ethact[20], ca_ipaddr[20]; int i; switch (argc) { case 2: if (strncmp(argv[1],"cpu-bist", 8) == 0) { octeon_bist(); return 0; } else if (strncmp(argv[1],"ddr", 3) == 0) { return do_mem_mtest(NULL, 0, 1, "mtest"); } else if (strncmp(argv[1],"pci", 3) == 0) { #define MAX_ADV_PCI_BUS 13 char *local_args[4], busno[4]; int pci_busno; local_args[0] = "pci"; local_args[1] = busno; local_args[2] = "short"; local_args[3] = NULL; for (pci_busno = 0; pci_busno < MAX_ADV_PCI_BUS; pci_busno++) { sprintf (busno, "%x", pci_busno); do_pci(NULL, 0, 3, local_args); } return 0; } else if (strncmp(argv[1],"mmc-sensor", 10) == 0) { #define MON_3VSB_ID "0x02" #define MON_12V_ID "0x03" #define VDD_3V3_ID "0x06" #define TMP421_CORE_ID "0x0B" #define TMP275_BOARD_ID "0x0C" #define MON_3VSB(x) (0.016*x) #define MON_12V(x) ((68*x-5)*0.001) #define VDD_3V3(x) (0.016*x) #define TMP421_CORE(x) (x) #define TMP275_BOARD(x) (1.01*x+0.14) #define COMMAND_SUCCESS_OFFSET 6 #define VALUE_OFFSET (COMMAND_SUCCESS_OFFSET + 1) #define VALID_READ_OFFSET (COMMAND_SUCCESS_OFFSET + 2) #define INVALID_READ_MASK 0x20 const uchar *ret_val; char *argv[]={"ipmi", "raw", "0x04", "0x2D", "0x00"}; char *ids[]={MON_3VSB_ID, MON_12V_ID, VDD_3V3_ID, TMP421_CORE_ID, TMP275_BOARD_ID}; char *ids_name[]={"3.3V standby", "12V", "3.3V", "Core temperature", "Board temperature"}; int total_ids, argc, i, tmp; float fRet; total_ids = sizeof(ids) / sizeof(ids[0]); argc = sizeof(argv) / sizeof(argv[0]); for (i = 0; i < total_ids; i++) { sprintf(argv[argc-1], ids[i]); // replace the sensor ID to read ret_val = mmc_raw_command_access(argc, argv); if (ret_val[COMMAND_SUCCESS_OFFSET]) // 0 = success { printf("!FAIL IPMI Get %s return code 0x%02x\n", ids_name[i], ret_val[6]); continue; } if (ret_val[VALID_READ_OFFSET] & INVALID_READ_MASK) // bit 5: when set, this read is invalid { printf("%s: %s\n", ids_name[i], "Read failed!"); } else { switch (i) { case 0: fRet = MON_3VSB(ret_val[VALUE_OFFSET]); break; case 1: fRet = MON_12V(ret_val[VALUE_OFFSET]); break; case 2: fRet = VDD_3V3(ret_val[VALUE_OFFSET]); break; case 3: fRet = TMP421_CORE(ret_val[VALUE_OFFSET]); break; case 4: fRet = TMP275_BOARD(ret_val[VALUE_OFFSET]); break; default: printf("unkown to calculate\n"); break; } /* float to string, only 3 digits after '.'; Note: printf does not support float */ { tmp = fRet; printf("%s: %d.", ids_name[i], tmp); fRet -= tmp; fRet *= 1000; tmp = fRet; printf("%d\n", tmp); } } } return 0; } else if (strncmp(argv[1],"reset-type", 10) == 0) { uint8_t cause; mmc_get_hw_reset_reason(&cause); printf("reset-type: "); switch (cause) { case 0x1: printf("hard reset"); break; case 0x2: printf("soft reset"); break; case 0x4: printf("watchdog reset"); break; default: printf("unknown 0x%02x",cause); break; } printf("\n"); return 0; } else if (strncmp(argv[1],"i2c", 3) == 0) { char cmd[255], *subcmd[]={"speed", "dev", "probe"}; for (i = 0; i < sizeof(subcmd)/sizeof(subcmd[0]); i++) { sprintf(cmd, "i2c %s", subcmd[i]); run_command(cmd, 0); } return 0; } else if (strncmp(argv[1],"xaui", 4) == 0) { #define XAUI_INTERFACES 2 #define TEST_IP "192.168.4.1" int default_port[] = {2624, 3136}; /* save original env vars */ orig_ethact = getenv("ethact"); sprintf(ca_ethact, orig_ethact); // save to safety place orig_ipaddr = getenv("ipaddr"); sprintf(ca_ipaddr, orig_ipaddr); /* start to test */ setenv("ipaddr", TEST_IP); NetPingIP = string_to_ip(TEST_IP); // ping our self for (i = 0; i < XAUI_INTERFACES; i++) { char *new_ethact = "octeth "; sprintf(new_ethact, "octeth%d", i); setenv("ethact", new_ethact); /* enabling internal loopback */ if (cvmx_helper_configure_loopback(default_port[i], 1, 0)) { printf("enable %s loopback failed!\n", new_ethact); continue; } if (NetLoop(PING) < 0) { printf("%s loopback transmission failed!\n", new_ethact); } else { printf("%s loopback transmission test pass.\n", new_ethact); } /* disable loopback */ if (cvmx_helper_configure_loopback(default_port[i], 0, 0)) printf("disable %s loopback failed!\n", new_ethact); } /* restore env vars */ setenv("ethact", ca_ethact); setenv("ipaddr", orig_ipaddr ? ca_ipaddr : orig_ipaddr); return 0; } else if (strncmp(argv[1],"mii", 3) == 0) { int rc = 0; /* save original env vars */ orig_ethact = getenv("ethact"); sprintf(ca_ethact, orig_ethact); orig_ipaddr = getenv("ipaddr"); sprintf(ca_ipaddr, orig_ipaddr); /* enabling internal loopback */ run_command("mii write 0 0 6100", 0); /* start to test */ setenv("ethact", "octmgmt0"); setenv("ipaddr", TEST_IP); NetPingIP = string_to_ip(TEST_IP); // ping our self if (NetLoop(PING) < 0) { if (NetLoop(PING) < 0) // give another chance, the octmgmt0 may failed on first try rc = -1; } if (rc < 0) { printf("octmgmt0 loopback transmission failed!\n"); } else { printf("octmgmt0 loopback transmission test pass.\n"); } /* disable loopback */ run_command("mii write 0 0 2100", 0); /* restore env vars */ setenv("ethact", ca_ethact); setenv("ipaddr", orig_ipaddr ? ca_ipaddr : orig_ipaddr); return 0; } break; } return cmd_usage(cmdtp); }
static int do_fwupgrade(struct cmd_ctx *cmdctx, int argc, char * const argv[]) { struct mtd_info *mtd = NULL; const char *filename = NULL; int ret; int oob = 0; switch(argc) { case 4: oob = (argv[3][0] == 'y');; if (oob) printf("FWU: Will write oob data!\n"); /* pass through */ case 3: filename = argv[2]; /* pass through */ case 2: mtd = mtd_by_name(argv[1]); break; default: return cmd_usage(cmdctx->cmdtp); } if(mtd == NULL) { printf("FWU mtd device is not available (bad part name?)\n"); return -1; } if(mtd->erasesize > CONFIG_CMD_FWUPGRADE_BUFFER_SIZE) { printf("FWU internal buffer is smaller than size of eraseblock\n"); return -ENOMEM; }; u8 *block = (u8*)CONFIG_CMD_FWUPGRADE_BUFFER_ADDR; if(block == NULL) { printf("FWU unable to allocate memory\n"); return -ENOMEM; } struct fwu_tftp_ctx ctx; memset(&ctx, 0, sizeof(struct fwu_tftp_ctx)); ctx.mtd = mtd; ctx.block = block; ctx.flash_offset = 0; ctx.flash_end = mtd->size; ctx.oob = oob; struct NetTask task; net_init_task_def(&task, TFTP); task.u.tftp.data_cb = fwu_tftp_cb; task.u.tftp.data_ctx = &ctx; char dir[MAXPATH]; extract_dirname(dir, task.bootfile); if(filename) { if(filename[0] == '/') { strncpy_s(task.bootfile, filename, MAXPATH); } else { sprintf(task.bootfile, "%s%s", dir, filename); } } else { if(0 == strcmp(mtd->name, "boot")) { sprintf(task.bootfile, "%smboot.img", dir); } else if(0 == strcmp(mtd->name, "kernel")) { sprintf(task.bootfile, "%suImage", dir); } else { sprintf(task.bootfile, "%smboot-%s.bin", dir, mtd->name); } } ret = erase_part(mtd, 0, 1); if (ret) { printf("FW: Partition erase failed, aborting..."); goto out; } ret = NetLoop(&task); if (ret < 0) { printf("FWU net trasfer failed: ret %d\n", ret); goto out; } printf("FWU complete: tftp_bytes %lu hex 0x%08lX flash_area 0x%012llX flash_bb %d\n", task.out_filesize, task.out_filesize, ctx.flash_offset, ctx.bb); out: return 0; }
static int netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[]) { char *s; char *end; int rcode = 0; int size; ulong addr; /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: /* * Only one arg - accept two forms: * Just load address, or just boot file name. The latter * form must be written in a format which can not be * mis-interpreted as a valid number. */ addr = simple_strtoul(argv[1], &end, 16); /* use default loadaddr address is 0 */ if (!addr) addr = load_addr; else if (end == (argv[1] + strlen(argv[1]))) load_addr = addr; else copy_filename(BootFile, argv[1], sizeof(BootFile)); break; case 3: addr = simple_strtoul(argv[1], &end, 16); /* use default loadaddr address is 0 */ if (!addr) addr = load_addr; else if (end == (argv[1] + strlen(argv[1]))) load_addr = addr; copy_filename (BootFile, argv[2], sizeof(BootFile)); break; default: show_boot_progress (-80); return cmd_usage(cmdtp); } show_boot_progress (80); if ((size = NetLoop(proto)) < 0) { show_boot_progress (-81); return 1; } show_boot_progress (81); /* NetLoop ok, update environment */ netboot_update_env(); /* done if no file was loaded (no errors though) */ if (size == 0) { show_boot_progress (-82); return 0; } /* flush cache */ flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); show_boot_progress (82); rcode = do_bootm (cmdtp, 0, 1, local_args); } if (rcode < 0) show_boot_progress (-83); else show_boot_progress (84); return rcode; }
/* ====================================================================== * Interpreter command to boot VxWorks from a memory image. The image can * be either an ELF image or a raw binary. Will attempt to setup the * bootline and other parameters correctly. * ====================================================================== */ int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { unsigned long addr; /* Address of image */ unsigned long bootaddr; /* Address to put the bootline */ char *bootline; /* Text of the bootline */ char *tmp; /* Temporary char pointer */ #if defined(CONFIG_4xx) || defined(CONFIG_IOP480) char build_buf[80]; /* Buffer for building the bootline */ #endif /* -------------------------------------------------- */ /* * Check the loadaddr variable. * If we don't know where the image is then we're done. */ if (argc < 2) addr = load_addr; else addr = simple_strtoul (argv[1], NULL, 16); #if (CONFIG_COMMANDS & CFG_CMD_NET) /* Check to see if we need to tftp the image ourselves before starting */ if ((argc == 2) && (strcmp (argv[1], "tftp") == 0)) { if (NetLoop (TFTP) <= 0) return 1; printf ("Automatic boot of VxWorks image at address 0x%08lx ... \n", addr); } #endif /* This should equate * to NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET * from the VxWorks BSP header files. * This will vary from board to board */ #if defined(CONFIG_WALNUT) tmp = (char *) CFG_NVRAM_BASE_ADDR + 0x500; memcpy ((char *) tmp, (char *) &gd->bd->bi_enetaddr[3], 3); #elif defined(CFG_VXWORKS_MAC_PTR) tmp = (char *) CFG_VXWORKS_MAC_PTR; memcpy ((char *) tmp, (char *) &gd->bd->bi_enetaddr[0], 6); #else puts ("## Ethernet MAC address not copied to NV RAM\n"); #endif /* * Use bootaddr to find the location in memory that VxWorks * will look for the bootline string. The default value for * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which * defaults to 0x4200 */ if ((tmp = getenv ("bootaddr")) == NULL) bootaddr = 0x4200; else bootaddr = simple_strtoul (tmp, NULL, 16); /* * Check to see if the bootline is defined in the 'bootargs' * parameter. If it is not defined, we may be able to * construct the info */ if ((bootline = getenv ("bootargs")) != NULL) { memcpy ((void *) bootaddr, bootline, MAX(strlen(bootline), 255)); flush_cache (bootaddr, MAX(strlen(bootline), 255)); } else { #if defined(CONFIG_4xx) sprintf (build_buf, "ibmEmac(0,0)"); if ((tmp = getenv ("hostname")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "host:%s ", tmp); } else { sprintf (&build_buf[strlen (build_buf - 1)], ": "); } if ((tmp = getenv ("ipaddr")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "e=%s ", tmp); } memcpy ((void *)bootaddr, build_buf, MAX(strlen(build_buf), 255)); flush_cache (bootaddr, MAX(strlen(build_buf), 255)); #elif defined(CONFIG_IOP480) sprintf (build_buf, "dc(0,0)"); if ((tmp = getenv ("hostname")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "host:%s ", tmp); } else { sprintf (&build_buf[strlen (build_buf - 1)], ": "); } if ((tmp = getenv ("ipaddr")) != NULL) { sprintf (&build_buf[strlen (build_buf - 1)], "e=%s ", tmp); } memcpy ((void *) bootaddr, build_buf, MAX(strlen(build_buf), 255)); flush_cache (bootaddr, MAX(strlen(build_buf), 255)); #else /* * I'm not sure what the device should be for other * PPC flavors, the hostname and ipaddr should be ok * to just copy */ puts ("No bootargs defined\n"); return 1; #endif } /* * If the data at the load address is an elf image, then * treat it like an elf image. Otherwise, assume that it is a * binary image */ if (valid_elf_image (addr)) { addr = load_elf_image (addr); } else { puts ("## Not an ELF image, assuming binary\n"); /* leave addr as load_addr */ } printf ("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *) bootaddr); printf ("## Starting vxWorks at 0x%08lx ...\n", addr); ((void (*)(void)) addr) (); puts ("## vxWorks terminated\n"); return 1; }
/* ------------------------------------------------------------------------- */ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { uchar *addr, *save_addr; ulong size; int mezz, arg, result; switch (argc) { case 0: case 1: break; case 2: if (strcmp (argv[1], "info") == 0) { printf ("\nHymod FPGA Info...\n"); printf ("\t\t\t\tAddress\t\tSize\n"); printf ("\tMain Configuration:\t0x%08x\t%d\n", FPGA_MAIN_CFG_BASE, FPGA_MAIN_CFG_SIZE); printf ("\tMain Register:\t\t0x%08x\t%d\n", FPGA_MAIN_REG_BASE, FPGA_MAIN_REG_SIZE); printf ("\tMain Port:\t\t0x%08x\t%d\n", FPGA_MAIN_PORT_BASE, FPGA_MAIN_PORT_SIZE); printf ("\tMezz Configuration:\t0x%08x\t%d\n", FPGA_MEZZ_CFG_BASE, FPGA_MEZZ_CFG_SIZE); return 0; } break; case 3: if (strcmp (argv[1], "store") == 0) { addr = (uchar *) simple_strtoul (argv[2], NULL, 16); save_addr = addr; #if 0 /* fpga readback unimplemented */ while (more readback data) *addr++ = *fpga; result = error ? STORE_FAIL_XXX : STORE_SUCCESS; #else result = STORE_SUCCESS; #endif if (result == STORE_SUCCESS) { printf ("SUCCEEDED (%d bytes)\n", addr - save_addr); return 0; } else printf ("FAILED (%d bytes)\n", addr - save_addr); return 1; } break; case 4: if (strcmp (argv[1], "tftp") == 0) { copy_filename (BootFile, argv[2], sizeof (BootFile)); load_addr = simple_strtoul (argv[3], NULL, 16); NetBootFileXferSize = 0; if (NetLoop (TFTP) <= 0) { printf ("tftp transfer failed - aborting " "fgpa load\n"); return 1; } if (NetBootFileXferSize == 0) { printf ("can't determine file size - " "aborting fpga load\n"); return 1; } printf ("File transfer succeeded - " "beginning fpga load..."); result = fpga_load (0, (uchar *) load_addr, NetBootFileXferSize); if (result == LOAD_SUCCESS) { printf ("SUCCEEDED\n"); return 0; } else if (result == LOAD_FAIL_NOCONF) printf ("FAILED (no CONF)\n"); else if (result == LOAD_FAIL_NOINIT) printf ("FAILED (no INIT)\n"); else printf ("FAILED (no DONE)\n"); return 1; } /* fall through ... */ case 5: if (strcmp (argv[1], "load") == 0) { if (argc == 5) { if (strcmp (argv[2], "main") == 0) mezz = 0; else if (strcmp (argv[2], "mezz") == 0) mezz = 1; else { printf ("FPGA type must be either " "`main' or `mezz'\n"); return 1; } arg = 3; } else { mezz = 0; arg = 2; } addr = (uchar *) simple_strtoul (argv[arg++], NULL, 16); size = (ulong) simple_strtoul (argv[arg], NULL, 16); result = fpga_load (mezz, addr, size); if (result == LOAD_SUCCESS) { printf ("SUCCEEDED\n"); return 0; } else if (result == LOAD_FAIL_NOCONF) printf ("FAILED (no CONF)\n"); else if (result == LOAD_FAIL_NOINIT) printf ("FAILED (no INIT)\n"); else printf ("FAILED (no DONE)\n"); return 1; } break; default: break; } cmd_usage(cmdtp); return 1; }
/* ====================================================================== * Interpreter command to boot VxWorks from a memory image. The image can * be either an ELF image or a raw binary. Will attempt to setup the * bootline and other parameters correctly. * ====================================================================== */ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { unsigned long addr; /* Address of image */ unsigned long bootaddr; /* Address to put the bootline */ char *bootline; /* Text of the bootline */ char *tmp; /* Temporary char pointer */ char build_buf[128]; /* Buffer for building the bootline */ /* --------------------------------------------------- * * Check the loadaddr variable. * If we don't know where the image is then we're done. */ if (argc < 2) addr = load_addr; else addr = simple_strtoul(argv[1], NULL, 16); #if defined(CONFIG_CMD_NET) /* * Check to see if we need to tftp the image ourselves before starting */ if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) { if (NetLoop(TFTPGET) <= 0) return 1; printf("Automatic boot of VxWorks image at address 0x%08lx ...\n", addr); } #endif /* This should equate * to NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET * from the VxWorks BSP header files. * This will vary from board to board */ #if defined(CONFIG_WALNUT) tmp = (char *) CONFIG_SYS_NVRAM_BASE_ADDR + 0x500; eth_getenv_enetaddr("ethaddr", (uchar *)build_buf); memcpy(tmp, &build_buf[3], 3); #elif defined(CONFIG_SYS_VXWORKS_MAC_PTR) tmp = (char *) CONFIG_SYS_VXWORKS_MAC_PTR; eth_getenv_enetaddr("ethaddr", (uchar *)build_buf); memcpy(tmp, build_buf, 6); #else puts("## Ethernet MAC address not copied to NV RAM\n"); #endif /* * Use bootaddr to find the location in memory that VxWorks * will look for the bootline string. The default value for * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which * defaults to 0x4200 */ tmp = getenv("bootaddr"); if (tmp) bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR; else bootaddr = simple_strtoul(tmp, NULL, 16); /* * Check to see if the bootline is defined in the 'bootargs' * parameter. If it is not defined, we may be able to * construct the info */ bootline = getenv("bootargs"); if (bootline) { memcpy((void *) bootaddr, bootline, max(strlen(bootline), 255)); flush_cache(bootaddr, max(strlen(bootline), 255)); } else { sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE); tmp = getenv("bootfile"); if (tmp) sprintf(&build_buf[strlen(build_buf)], "%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp); else sprintf(&build_buf[strlen(build_buf)], "%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME); tmp = getenv("ipaddr"); if (tmp) sprintf(&build_buf[strlen(build_buf)], "e=%s ", tmp); tmp = getenv("serverip"); if (tmp) sprintf(&build_buf[strlen(build_buf)], "h=%s ", tmp); tmp = getenv("hostname"); if (tmp) sprintf(&build_buf[strlen(build_buf)], "tn=%s ", tmp); #ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS sprintf(&build_buf[strlen(build_buf)], CONFIG_SYS_VXWORKS_ADD_PARAMS); #endif memcpy((void *) bootaddr, build_buf, max(strlen(build_buf), 255)); flush_cache(bootaddr, max(strlen(build_buf), 255)); } /* * If the data at the load address is an elf image, then * treat it like an elf image. Otherwise, assume that it is a * binary image */ if (valid_elf_image(addr)) { addr = load_elf_image_shdr(addr); } else { puts("## Not an ELF image, assuming binary\n"); /* leave addr as load_addr */ } printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *) bootaddr); printf("## Starting vxWorks at 0x%08lx ...\n", addr); dcache_disable(); ((void (*)(int)) addr) (0); puts("## vxWorks terminated\n"); return 1; }
static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[]) { char *s; char *end; int rcode = 0; int size; ulong addr; /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: /* * Only one arg - accept two forms: * Just load address, or just boot file name. The latter * form must be written in a format which can not be * mis-interpreted as a valid number. */ addr = simple_strtoul(argv[1], &end, 16); if (end == (argv[1] + strlen(argv[1]))) load_addr = addr; else copy_filename(BootFile, argv[1], sizeof(BootFile)); break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); copy_filename(BootFile, argv[2], sizeof(BootFile)); break; #ifdef CONFIG_CMD_TFTPPUT case 4: if (strict_strtoul(argv[1], 16, &save_addr) < 0 || strict_strtoul(argv[2], 16, &save_size) < 0) { printf("Invalid address/size\n"); return cmd_usage(cmdtp); } copy_filename(BootFile, argv[3], sizeof(BootFile)); break; #endif default: bootstage_error(BOOTSTAGE_ID_NET_START); return CMD_RET_USAGE; } bootstage_mark(BOOTSTAGE_ID_NET_START); if ((size = NetLoop(proto)) < 0) { bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK); return 1; } bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK); /* NetLoop ok, update environment */ netboot_update_env(); /* done if no file was loaded (no errors though) */ if (size == 0) { bootstage_error(BOOTSTAGE_ID_NET_LOADED); return 0; } /* flush cache */ flush_cache(load_addr, size); bootstage_mark(BOOTSTAGE_ID_NET_LOADED); rcode = bootm_maybe_autostart(cmdtp, argv[0]); if (rcode < 0) bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR); else bootstage_mark(BOOTSTAGE_ID_NET_DONE); return rcode; }
int fetch_and_parse (char *fn, ulong addr, int (*cback)(uchar *, uchar *)) { char *ethaddr; uchar *fp, *efp; int rc, count = 0; while ((ethaddr = getenv ("ethaddr")) == NULL || *ethaddr == '\0') { printf ("*** Ethernet address is%s not set\n", count == 0 ? "" : " STILL"); if ((rc = hymod_get_ethaddr ()) < 0) { if (rc == -1) puts ("\n*** interrupted!"); else puts ("\n*** timeout!"); printf (" - fetch of '%s' aborted\n", fn); return (0); } count++; } copy_filename (BootFile, fn, sizeof (BootFile)); load_addr = addr; NetBootFileXferSize = 0; if (NetLoop(TFTPGET) == 0) { printf ("tftp transfer of file '%s' failed\n", fn); return (0); } if (NetBootFileXferSize == 0) { printf ("can't determine size of file '%s'\n", fn); return (0); } fp = (uchar *)load_addr; efp = fp + NetBootFileXferSize; do { uchar *name, *value; if (*fp == '#' || *fp == '\n') { /* skip this line */ while (fp < efp && *fp++ != '\n') ; continue; } name = fp; while (fp < efp && *fp != '=' && *fp != '\n') fp++; if (fp >= efp) break; if (*fp == '\n') { fp++; continue; } *fp++ = '\0'; value = fp; while (fp < efp && *fp != '\n') fp++; if (fp[-1] == '\r') fp[-1] = '\0'; *fp++ = '\0'; /* ok if we go off the end here */ if ((*cback)(name, value) == 0) return (0); } while (fp < efp); return (1); }
static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[]) { char *s; char *end; int rcode = 0; int size; ulong addr; /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: /* * Only one arg - accept two forms: * Just load address, or just boot file name. The latter * form must be written in a format which can not be * mis-interpreted as a valid number. */ addr = simple_strtoul(argv[1], &end, 16); if (end == (argv[1] + strlen(argv[1]))) load_addr = addr; else copy_filename(BootFile, argv[1], sizeof(BootFile)); break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); copy_filename (BootFile, argv[2], sizeof(BootFile)); break; #ifdef CONFIG_CMD_TFTPPUT case 4: save_addr = strict_strtoul(argv[1], NULL, 16); save_size = strict_strtoul(argv[2], NULL, 16); copy_filename(BootFile, argv[3], sizeof(BootFile)); break; #endif default: show_boot_progress (-80); return cmd_usage(cmdtp); } show_boot_progress (80); if ((size = NetLoop(proto)) < 0) { show_boot_progress (-81); return 1; } show_boot_progress (81); /* NetLoop ok, update environment */ netboot_update_env(); /* done if no file was loaded (no errors though) */ if (size == 0) { show_boot_progress (-82); return 0; } /* flush cache */ flush_cache(load_addr, size); show_boot_progress(82); rcode = bootm_maybe_autostart(cmdtp, argv[0]); if (rcode < 0) show_boot_progress (-83); else show_boot_progress (84); return rcode; }
static int netboot_common(proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[]) { char *s; int rcode = 0; int size; /* pre-set load_addr */ if((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch(argc) { case 1: break; case 2: /* only one arg - accept two forms: * just load address, or just boot file name. * The latter form must be written "filename" here. */ if(argv[1][0] == '"') { /* just boot filename */ copy_filename(BootFile, argv[1], sizeof(BootFile)); } else { /* load address */ load_addr = simple_strtoul(argv[1], NULL, 16); } break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); copy_filename(BootFile, argv[2], sizeof(BootFile)); break; default: #ifdef CFG_LONGHELP if(cmdtp->help != NULL) { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help); } else { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); } #else printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); #endif return 1; } if((size = NetLoop(proto)) < 0) { return(1); } /* NetLoop ok, update environment */ netboot_update_env(); /* done if no file was loaded (no errors though) */ if(size == 0) { return(0); } /* flush cache */ flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ if(((s = getenv("autostart")) != NULL) && (strcmp(s, "yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr); rcode = do_bootm(cmdtp, 0, 1, local_args); } #ifdef CONFIG_AUTOSCRIPT if(((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { printf("Running autoscript at addr 0x%08lX ...\n", load_addr); rcode = autoscript(load_addr); } #endif return rcode; }
static int netboot_common (int proto, cmd_tbl_t *cmdtp, int argc, char *argv[]) { char *s; int rcode = 0; int size; printf("\n netboot_common, argc= %d \n", argc); /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: /* only one arg - accept two forms: * just load address, or just boot file name. * The latter form must be written "filename" here. */ if (argv[1][0] == '"') { /* just boot filename */ copy_filename (BootFile, argv[1], sizeof(BootFile)); } else { /* load address */ load_addr = simple_strtoul(argv[1], NULL, 16); } break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); copy_filename (BootFile, argv[2], sizeof(BootFile)); #ifdef DEBUG printf("load addr= 0x%08x\n", load_addr); printf("boot file= %s\n", BootFile); #endif break; default: printf ("Usage:\n%s\n", cmdtp->usage); return 1; } if ((size = NetLoop(proto)) < 0) return 1; printf("NetBootFileXferSize= %08x\n", size); /* NetLoop ok, update environment */ #if (CONFIG_COMMANDS & CFG_CMD_ENV) netboot_update_env(); #endif /* done if no file was loaded (no errors though) */ if (size == 0) return 0; /* flush cache */ flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; if(modifies) { setenv("autostart", "no"); setenv ("bootfile", BootFile); #ifdef DEBUG s = getenv("bootfile"); printf("save bootfile= %s\n", s); #endif #if (CONFIG_COMMANDS & CFG_CMD_ENV) saveenv(); #endif } printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } #ifdef CONFIG_AUTOSCRIPT if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { printf("Running autoscript at addr 0x%08lX ...\n", load_addr); rcode = autoscript (load_addr); } #endif return rcode; }
/* Write u-boot image into the nand flash */ int nand_burn_uboot_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int filesize; MV_U32 ret = 0; extern char console_buffer[]; nand_info_t *nand = &nand_info[0]; nand_erase_options_t er_opts; nand_write_options_t wr_opts; load_addr = CFG_LOAD_ADDR; if(argc == 2) { copy_filename (BootFile, argv[1], sizeof(BootFile)); } else { copy_filename (BootFile, "u-boot.bin", sizeof(BootFile)); printf("using default file \"u-boot.bin\" \n"); } if ((filesize = NetLoop(TFTP)) < 0) return 0; printf("\n**Warning**\n"); printf("If U-Boot Endiannes is going to change (LE->BE or BE->LE), Then Env parameters should be overriden..\n"); printf("Override Env parameters? (y/n)"); readline(" "); if( strcmp(console_buffer,"Y") == 0 || strcmp(console_buffer,"yes") == 0 || strcmp(console_buffer,"y") == 0 ) { printf("Erase Env parameters sector %d... ",CFG_ENV_OFFSET); memset(&er_opts, 0, sizeof(er_opts)); er_opts.offset = CFG_ENV_OFFSET; er_opts.length = CFG_ENV_SECT_SIZE; er_opts.quiet = 1; nand_erase_opts(nand, &er_opts); //nand_erase(nand_dev_desc + 0, CFG_ENV_OFFSET, CFG_ENV_SECT_SIZE, 0); printf("\n"); } printf("Erase %d - %d ... ",CFG_MONITOR_BASE, CFG_MONITOR_LEN); memset(&er_opts, 0, sizeof(er_opts)); er_opts.offset = CFG_MONITOR_BASE; er_opts.length = CFG_MONITOR_LEN; er_opts.quiet = 1; nand_erase_opts(nand, &er_opts); //nand_erase(nand_dev_desc + 0, CFG_MONITOR_BASE, CFG_MONITOR_LEN, 0); printf("\nCopy to Nand Flash... "); memset(&wr_opts, 0, sizeof(wr_opts)); wr_opts.buffer = (u_char*) load_addr; wr_opts.length = CFG_MONITOR_LEN; wr_opts.offset = CFG_MONITOR_BASE; /* opts.forcejffs2 = 1; */ wr_opts.pad = 1; wr_opts.blockalign = 1; wr_opts.quiet = 1; ret = nand_write_opts(nand, &wr_opts); /* ret = nand_rw(nand_dev_desc + 0, NANDRW_WRITE | NANDRW_JFFS2, CFG_MONITOR_BASE, CFG_MONITOR_LEN, &total, (u_char*)0x100000 + CFG_MONITOR_IMAGE_OFFSET); */ if (ret) printf("Error - NAND burn faild!\n"); else printf("\ndone\n"); return 1; }
/* Boot from Nor flash */ int nor_burn_uboot_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int filesize; MV_U32 s_first,s_end,env_sec; extern char console_buffer[]; s_first = flash_in_which_sec(&flash_info[BOOT_FLASH_INDEX], CFG_MONITOR_BASE); s_end = flash_in_which_sec(&flash_info[BOOT_FLASH_INDEX], CFG_MONITOR_BASE + CFG_MONITOR_LEN -1); env_sec = flash_in_which_sec(&flash_info[BOOT_FLASH_INDEX], CFG_ENV_ADDR); load_addr = CFG_LOAD_ADDR; if(argc == 2) { copy_filename (BootFile, argv[1], sizeof(BootFile)); } else { copy_filename (BootFile, "u-boot.bin", sizeof(BootFile)); printf("using default file \"u-boot.bin\" \n"); } if ((filesize = NetLoop(TFTP)) < 0) return 0; printf("Un-Protect Flash Monitor space\n"); flash_protect (FLAG_PROTECT_CLEAR, CFG_MONITOR_BASE, CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[BOOT_FLASH_INDEX]); printf("\n**Warning**\n"); printf("If U-Boot Endiannes is going to change (LE->BE or BE->LE), Then Env parameters should be overriden..\n"); printf("Override Env parameters? (y/n)"); readline(" "); if( strcmp(console_buffer,"Y") == 0 || strcmp(console_buffer,"yes") == 0 || strcmp(console_buffer,"y") == 0 ) { flash_protect (FLAG_PROTECT_CLEAR, flash_info[BOOT_FLASH_INDEX].start[env_sec], flash_info[BOOT_FLASH_INDEX].start[env_sec] + CFG_ENV_SECT_SIZE - 1, &flash_info[BOOT_FLASH_INDEX]); printf("Erase Env parameters sector %d... ",env_sec); flash_erase(&flash_info[BOOT_FLASH_INDEX], env_sec, env_sec); if (MV_FALSE == mvBoardIsBootFromSpi()) flash_protect (FLAG_PROTECT_SET, flash_info[BOOT_FLASH_INDEX].start[env_sec], flash_info[BOOT_FLASH_INDEX].start[env_sec] + CFG_ENV_SECT_SIZE - 1, &flash_info[BOOT_FLASH_INDEX]); } printf("Erase %d - %d sectors... ",s_first,s_end); flash_erase(&flash_info[BOOT_FLASH_INDEX], s_first, s_end); printf("Copy to Flash... "); flash_write ( (uchar *)(CFG_LOAD_ADDR + CFG_MONITOR_IMAGE_OFFSET), (ulong)CFG_MONITOR_BASE, (ulong)(filesize - CFG_MONITOR_IMAGE_OFFSET)); printf("done\nProtect Flash Monitor space\n"); flash_protect (FLAG_PROTECT_SET, CFG_MONITOR_BASE, CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[BOOT_FLASH_INDEX]); return 1; }
//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); }