int doWimaxDhcpRequest(int *ipaddr, int *gateway, int *mask, int *dns1, int *dns2, int *server, int *lease) { if (ifc_init() < 0) return -1; if (do_dhcp(iface) < 0) { ifc_close(); return -1; } ifc_close(); get_dhcp_info(ipaddr, gateway, mask, dns1, dns2, server, lease); return 0; }
int do_dhcp_client_request(const char *iface, int *ipaddr, int *gateway, int *mask, int *dns1, int *dns2, int *server, int *lease) { LOGD("[%s] do_dhcp_client_request\n", iface); if (ifc_init() < 0) return -1; if (do_dhcp(iface) < 0) { ifc_close(); return -1; } ifc_close(); get_dhcp_info(ipaddr, gateway, mask, dns1, dns2, server, lease); return 0; }
int do_dhcp_request(int *ipaddr, int *gateway, int *mask, int *dns1, int *dns2, int *server, int *lease) { /* For test driver, always report success */ if (strcmp(primary_iface, WIFI_TEST_INTERFACE) == 0) return 0; if (ifc_init() < 0) return -1; if (do_dhcp(primary_iface) < 0) { ifc_close(); return -1; } ifc_close(); get_dhcp_info(ipaddr, gateway, mask, dns1, dns2, server, lease); return 0; }
// return value: 1 => everything OK, no change. // 0 => close your connections, then call do_dhcp_halt() to halt the // interface(s) in question (it knows because the state will be NOTBOUND). // After that you can return to the start and use // init_all_network_interfaces(); as usual, or call do_dhcp_bind() by hand, // or whatever... int dhcp_bind( void ) { #ifdef CYGHWR_NET_DRIVER_ETH0 cyg_uint8 old_eth0_dhcpstate = eth0_dhcpstate; #endif #ifdef CYGHWR_NET_DRIVER_ETH1 cyg_uint8 old_eth1_dhcpstate = eth1_dhcpstate; #endif // If there are no interfaces at all, init it every time, doesn't // matter. In case we are called from elsewhere... if ( 1 #ifdef CYGHWR_NET_DRIVER_ETH0 && eth0_dhcpstate == 0 #endif #ifdef CYGHWR_NET_DRIVER_ETH1 && eth1_dhcpstate == 0 #endif ) cyg_semaphore_init( &dhcp_needs_attention, 0 ); // Run the state machine... #ifdef CYGHWR_NET_DRIVER_ETH0 if (eth0_up && DHCPSTATE_FAILED != eth0_dhcpstate ) eth0_up = do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease); #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if (eth1_up && DHCPSTATE_FAILED != eth1_dhcpstate ) eth1_up = do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease); #endif // If the interface newly came up, initialize it: // (this duplicates the code in init_all_network_interfaces() really). #ifdef CYGHWR_NET_DRIVER_ETH0 if ( eth0_up && eth0_dhcpstate == DHCPSTATE_BOUND && old_eth0_dhcpstate != eth0_dhcpstate ) { if (!init_net(eth0_name, ð0_bootp_data)) { eth0_up = false; } } #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if ( eth1_up && eth1_dhcpstate == DHCPSTATE_BOUND && old_eth1_dhcpstate != eth1_dhcpstate ) { if (!init_net(eth1_name, ð1_bootp_data)) { eth1_up = false; } } #endif #ifdef CYGHWR_NET_DRIVER_ETH0 if ( old_eth0_dhcpstate == DHCPSTATE_BOUND && eth0_dhcpstate == DHCPSTATE_NOTBOUND ) return 0; // a lease timed out; we became unbound #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if ( old_eth1_dhcpstate == DHCPSTATE_BOUND && eth1_dhcpstate == DHCPSTATE_NOTBOUND ) return 0; // a lease timed out; we became unbound #endif return 1; // all is well }
u8 Dhcp_Task(void) { //do_dhcp(); return do_dhcp(); }
void init_all_network_interfaces(void) { cyg_bool_t use_bootp; cyg_bool_t setup_network = false; in_addr_t local_ip_addr = 0; in_addr_t broadcast_addr = 0; in_addr_t server_addr = 0; in_addr_t gateway_addr = 0; in_addr_t network_mask = 0; char server_str[16]; char network_str[16]; char gateway_str[16]; char broadcast_str[16]; char ip_addr_str[16]; int i; int net_up = false; static volatile int in_init_all_network_interfaces = 0; cyg_scheduler_lock(); while ( in_init_all_network_interfaces ) { // Another thread is doing this... cyg_scheduler_unlock(); cyg_thread_delay( 10 ); cyg_scheduler_lock(); } in_init_all_network_interfaces = 1; cyg_scheduler_unlock(); #ifdef CYGHWR_NET_DRIVER_ETH0 // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootn", &setup_network, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); if (setup_network) { // Set defaults as appropriate use_bootp = true; // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp", &use_bootp, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_localip_addr", &local_ip_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_localip_mask", &network_mask, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_mygateway_addr", &gateway_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_ubroadcast_addr", &broadcast_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_serverip_addr", &server_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); if (use_bootp) { // Perform a complete initialization, using BOOTP/DHCP eth0_up = true; //#ifdef CYGHWR_NET_DRIVER_ETH0_DHCP eth0_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease)) //#else //#ifdef CYGPKG_NET_DHCP // eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called //#endif // if (do_bootp(eth0_name, ð0_bootp_data)) //#endif { #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } else { printf("BOOTP/DHCP failed on eth0\n"); eth0_up = false; } } else { eth0_up = true; strncpy(ip_addr_str, inet_ntoa(*(struct in_addr *) &local_ip_addr), 16); strncpy(broadcast_str, inet_ntoa(*(struct in_addr *) &broadcast_addr), 16); strncpy(gateway_str, inet_ntoa(*(struct in_addr *) &gateway_addr), 16); strncpy(network_str, inet_ntoa(*(struct in_addr *) &network_mask), 16); strncpy(server_str, inet_ntoa(*(struct in_addr *) &server_addr), 16); /* load flash configuration parameters */ build_bootp_record(ð0_bootp_data, eth0_name, ip_addr_str, network_str, broadcast_str, gateway_str, server_str); #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } } #endif #ifdef CYGHWR_NET_DRIVER_ETH1 setup_network = false; // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootn", &setup_network, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); if (setup_network) { // Set defaults as appropriate use_bootp = true; // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp", &use_bootp, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_localip_addr", &local_ip_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_localip_mask", &network_mask, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_mygateway_addr", &gateway_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_ubroadcast_addr", &broadcast_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_serverip_addr", &server_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); if (use_bootp) { // Perform a complete initialization, using BOOTP/DHCP eth1_up = true; //#ifdef CYGHWR_NET_DRIVER_ETH1_DHCP eth1_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease)) //#else //#ifdef CYGPKG_NET_DHCP // eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called //#endif // if (do_bootp(eth1_name, ð1_bootp_data)) //#endif { #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } else { printf("BOOTP/DHCP failed on eth1\n"); eth1_up = false; } } else { eth1_up = true; strncpy(ip_addr_str, inet_ntoa(*(struct in_addr *) &local_ip_addr), 16); strncpy(broadcast_str, inet_ntoa(*(struct in_addr *) &broadcast_addr), 16); strncpy(gateway_str, inet_ntoa(*(struct in_addr *) &gateway_addr), 16); strncpy(network_str, inet_ntoa(*(struct in_addr *) &network_mask), 16); strncpy(server_str, inet_ntoa(*(struct in_addr *) &server_addr), 16); /* load flash configuration parameters */ build_bootp_record(ð1_bootp_data, eth1_name, ip_addr_str, network_str, broadcast_str, gateway_str, server_str); #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } } #endif #ifdef CYGHWR_NET_DRIVER_ETH0 if (eth0_up) { if (!init_net(eth0_name, ð0_bootp_data)) { printf("Network initialization failed for eth0\n"); eth0_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX if (!init_net_IPv6(eth0_name, ð0_bootp_data, string(CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth0\n"); eth0_up = false; // ??? } #endif if (eth0_up) { unsigned int length = 4; struct in_addr temp; diag_printf("\nIP: %s", inet_ntoa(eth0_bootp_data.bp_yiaddr)); get_bootp_option(ð0_bootp_data, TAG_SUBNET_MASK, (void *)&temp, &length); diag_printf("/%s", inet_ntoa(temp)); get_bootp_option(ð0_bootp_data, TAG_GATEWAY, (void *)&temp, &length); // diag_printf(", Gateway: %s\n", inet_ntoa(eth0_bootp_data.bp_giaddr)); diag_printf(", Gateway: %s\n", inet_ntoa(temp)); diag_printf("Server: %s", inet_ntoa(eth0_bootp_data.bp_siaddr)); net_up = true; } } #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if (eth1_up) { if (!init_net(eth1_name, ð1_bootp_data)) { printf("Network initialization failed for eth1\n"); eth1_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX if (!init_net_IPv6(eth1_name, ð1_bootp_data, string(CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth1\n"); eth1_up = false; // ??? } #endif if (eth1_up) { unsigned int length = 4; struct in_addr temp; diag_printf("\nIP: %s", inet_ntoa(eth1_bootp_data.bp_yiaddr)); get_bootp_option(ð1_bootp_data, TAG_SUBNET_MASK, (void *)&temp, &length); diag_printf("/%s", inet_ntoa(temp)); get_bootp_option(ð1_bootp_data, TAG_GATEWAY, (void *)&temp, &length); // diag_printf(", Gateway: %s\n", inet_ntoa(eth1_bootp_data.bp_giaddr)); diag_printf(", Gateway: %s\n", inet_ntoa(temp)); diag_printf("Server: %s", inet_ntoa(eth1_bootp_data.bp_siaddr)); net_up = true; } } #endif #ifdef CYGPKG_NET_NLOOP #if 0 < CYGPKG_NET_NLOOP // Create a local IP Address for each of the DSP's */ for (i = 0; i < CYGPKG_NET_NLOOP; ++i) init_loopback_interface(i); #endif #endif #ifdef CYGOPT_NET_DHCP_DHCP_THREAD dhcp_start_dhcp_mgt_thread(); #endif #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD ipv6_start_routing_thread(); #endif #ifdef CYGPKG_NS_DNS_BUILD if (net_up) { struct in_addr dns_addr = {0}; int len; char *dns_domainname; CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_dns_ip", &dns_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); cyg_dns_res_init(&dns_addr); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_dns_domain_name", &dns_domainname, CYGNUM_FLASH_CFG_OP_CONFIG_STRING); len = strlen(dns_domainname); setdomainname(dns_domainname,len); diag_printf(", DNS server IP: %s", inet_ntoa(*(struct in_addr *)&dns_addr)); } #endif if (!net_up) { diag_printf("Network Disabled"); } diag_printf("\n\n"); }
// // Initialize network interface[s] using BOOTP/DHCP // void init_all_network_interfaces(void) { static volatile int in_init_all_network_interfaces = 0; #ifdef CYGPKG_IO_PCMCIA cyg_netdevtab_entry_t *t; #endif // CYGPKG_IO_PCMCIA #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD int rs_wait = 40; #endif cyg_scheduler_lock(); while ( in_init_all_network_interfaces ) { // Another thread is doing this... cyg_scheduler_unlock(); cyg_thread_delay( 10 ); cyg_scheduler_lock(); } in_init_all_network_interfaces = 1; cyg_scheduler_unlock(); #ifdef CYGHWR_NET_DRIVER_ETH0 if ( ! eth0_up ) { // Make this call idempotent #ifdef CYGPKG_IO_PCMCIA if ((t = eth_drv_netdev("eth0")) != (cyg_netdevtab_entry_t *)NULL) { int tries = 0; while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) { if (tries == 0) { diag_printf("... Waiting for PCMCIA device 'eth0'\n"); } if (++tries == 5) { diag_printf("... Giving up on PCMCIA device 'eth0'\n"); goto bail_eth0; } cyg_thread_delay(100); } } #endif // CYGPKG_IO_PCMCIA #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP // Perform a complete initialization, using BOOTP/DHCP eth0_up = true; #ifdef CYGHWR_NET_DRIVER_ETH0_DHCP eth0_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease)) #else #ifdef CYGPKG_NET_DHCP eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called #endif if (do_bootp(eth0_name, ð0_bootp_data)) #endif { #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } else { diag_printf("BOOTP/DHCP failed on eth0\n"); eth0_up = false; } #elif defined(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP) eth0_up = true; build_bootp_record(ð0_bootp_data, eth0_name, string(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_NETMASK), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_BROADCAST), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_GATEWAY), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_SERVER)); show_bootp(eth0_name, ð0_bootp_data); #endif #ifdef CYGPKG_IO_PCMCIA bail_eth0: #endif } #endif // CYGHWR_NET_DRIVER_ETH0 #ifdef CYGHWR_NET_DRIVER_ETH1 if ( ! eth1_up ) { // Make this call idempotent #ifdef CYGPKG_IO_PCMCIA if ((t = eth_drv_netdev("eth1")) != (cyg_netdevtab_entry_t *)NULL) { int tries = 0; while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) { if (tries == 0) { diag_printf("... Waiting for PCMCIA device 'eth1'\n"); } if (++tries == 5) { diag_printf("... Giving up on PCMCIA device 'eth1'\n"); goto bail_eth1; } cyg_thread_delay(100); } } #endif // CYGPKG_IO_PCMCIA #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP // Perform a complete initialization, using BOOTP/DHCP eth1_up = true; #ifdef CYGHWR_NET_DRIVER_ETH1_DHCP eth1_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease)) #else #ifdef CYGPKG_NET_DHCP eth1_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called #endif if (do_bootp(eth1_name, ð1_bootp_data)) #endif { #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } else { diag_printf("BOOTP/DHCP failed on eth1\n"); eth1_up = false; } #elif defined(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP) eth1_up = true; build_bootp_record(ð1_bootp_data, eth1_name, string(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_NETMASK), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_BROADCAST), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_GATEWAY), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_SERVER)); show_bootp(eth1_name, ð1_bootp_data); #endif #ifdef CYGPKG_IO_PCMCIA bail_eth1: #endif } #endif // CYGHWR_NET_DRIVER_ETH1 #ifdef CYGHWR_NET_DRIVER_ETH0 #ifndef CYGHWR_NET_DRIVER_ETH0_MANUAL if (eth0_up) { if (!init_net(eth0_name, ð0_bootp_data)) { diag_printf("Network initialization failed for eth0\n"); eth0_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX if (!init_net_IPv6(eth0_name, ð0_bootp_data, string(CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth0\n"); eth0_up = false; // ??? } #endif } #endif #endif #ifdef CYGHWR_NET_DRIVER_ETH1 #ifndef CYGHWR_NET_DRIVER_ETH1_MANUAL if (eth1_up) { if (!init_net(eth1_name, ð1_bootp_data)) { diag_printf("Network initialization failed for eth1\n"); eth1_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX if (!init_net_IPv6(eth1_name, ð1_bootp_data, string(CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth1\n"); eth1_up = false; // ??? } #endif } #endif #endif #ifdef CYGPKG_NET_NLOOP #if 0 < CYGPKG_NET_NLOOP { static int loop_init = 0; int i; if ( 0 == loop_init++ ) for ( i = 0; i < CYGPKG_NET_NLOOP; i++ ) init_loopback_interface( i ); } #endif #endif #ifdef CYGOPT_NET_DHCP_DHCP_THREAD dhcp_start_dhcp_mgt_thread(); #endif #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD ipv6_start_routing_thread(); // Wait for router solicit process to happen. while (rs_wait-- && !cyg_net_get_ipv6_advrouter(NULL)) { cyg_thread_delay(10); } if (rs_wait == 0 ) { diag_printf("No router solicit received\n"); } else { // Give Duplicate Address Detection time to work cyg_thread_delay(200); } #endif #ifdef CYGDAT_NS_DNS_DEFAULT_SERVER cyg_dns_res_start(string(CYGDAT_NS_DNS_DEFAULT_SERVER)); #endif #ifdef CYGDAT_NS_DNS_DOMAINNAME_NAME #define _NAME string(CYGDAT_NS_DNS_DOMAINNAME_NAME) { const char buf[] = _NAME; int len = strlen(_NAME); setdomainname(buf,len); } #endif // Open the monitor to other threads. in_init_all_network_interfaces = 0; }
int do_stage_boot(cmd_tbl_t * cmdtb, int flag, int argc, char *argv[]) { char *path_to_image, *path_to_scr, *path_to_initrd, *all_partions; ulong addr; int j,i=1,step=0,len,index,device,initrd=0; char * kernel_addr, *bootargs; char * args_to_func[5]; char device_prt[4]; if(argc < 2){ printf("No args, try help stage_boot\n"); return 0; } path_to_initrd = (char *)malloc((strlen(SCRIPT_PATH)+strlen(getenv("initrd_name")))*sizeof(char)); strcpy(path_to_initrd,SCRIPT_PATH); strcat(path_to_initrd,getenv("initrd_name")); path_to_image = (char *)malloc((strlen(SCRIPT_PATH)+strlen(getenv("image_name")))*sizeof(char)); strcpy(path_to_image,SCRIPT_PATH); strcat(path_to_image,getenv("image_name")); path_to_scr = (char *)malloc((strlen(SCRIPT_PATH)+strlen(getenv("script_name")))*sizeof(char)); strcpy(path_to_scr,SCRIPT_PATH); strcat(path_to_scr,getenv("script_name")); all_partions = (char *)malloc(strlen(getenv("device_partition"))*sizeof(char)); strcpy(all_partions,getenv("device_partition")); kernel_addr = getenv("kernel_addr_r"); #if !defined(CONFIG_MACH_AVANTA_LP_FPGA) ide_init(); #endif for(device=1;device<argc;device++) { #if !defined(CONFIG_MACH_AVANTA_LP_FPGA) /* step 1 load script from ide */ len=strlen(all_partions); for(index=0;index<len && i==1 && strcmp(argv[device],"hd_scr")==0 ;index++) { step=1; for(j=0;j<3;j++,index++) device_prt[j]=all_partions[index]; device_prt[3]='\0'; printf("\ntry to load script from ide %s\n",device_prt); args_to_func[0]="ext2load"; args_to_func[1]=INTERFACE_HD; args_to_func[2]=device_prt; args_to_func[3]=LOAD_ADDR; args_to_func[4]=path_to_scr; i = do_ext2load(cmdtb, 1, 5 , args_to_func); addr = simple_strtoul(args_to_func[3], NULL, 16); } /* finish step 1 */ /* step 2 boot PXE */ if (i== 1 && strcmp(argv[device],"pxe") == 0) { step = 2; save_env(); setenv("boot_from_pxe","1"); setenv("autoload","no"); setenv("pxefile_addr_r",LOAD_ADDR); args_to_func[0]="dhcp"; args_to_func[1]=getenv("pxefile_addr_r"); i = do_dhcp(cmdtb, 1, 1, args_to_func); if(i==0) i = do_pxe_get(cmdtb, 1 , 1, args_to_func); setenv("boot_from_pxe","0"); if(i==1) restore_env(); } /* finish step 2 */ /* step 3 load linux image from ide */ if( i == 1 && strcmp(argv[device],"hd_img")==0 ) { step = 3; len=strlen(all_partions); for(index=0;index<len && i==1 ;index++) { for(j=0;j<3;j++,index++) device_prt[j]=all_partions[index]; device_prt[3]='\0'; printf("\ntry to load image from ide %s\n", device_prt); args_to_func[0]="ext2load"; args_to_func[1]=INTERFACE_HD; args_to_func[2]=device_prt; args_to_func[3]=getenv("kernel_addr_r"); args_to_func[4]=path_to_image; i = do_ext2load(cmdtb, 1, 5 , args_to_func); addr = simple_strtoul(args_to_func[3], NULL, 16); if( i==0 ){ int temp; args_to_func[3]=getenv("ramdisk_addr_r"); args_to_func[4]=path_to_initrd; temp = do_ext2load(cmdtb, 1, 5 , args_to_func); if(temp == 0) { initrd = 1; args_to_func[1] = getenv("kernel_addr_r"); args_to_func[2] = getenv("ramdisk_addr_r"); } } } } /* finish step 3 */ /*step 4 load script from tftp */ if( i == 1 && strcmp(argv[device],"net_scr")==0 ) { printf("\ntry to load script from tftp\n"); step = 4; args_to_func[0]="tftp"; args_to_func[1]=LOAD_ADDR; args_to_func[2]=getenv("script_name"); i = do_tftpb(cmdtb, 1, 3,args_to_func); addr = simple_strtoul(args_to_func[1], NULL, 16); } #endif /* finish step 4 */ /*step 5 load linux image from tftp */ if( i == 1 && strcmp(argv[device],"net_img")==0 ) { printf("\ntry to load image from tftp\n"); step = 5; args_to_func[0]="tftp"; args_to_func[1]=getenv("kernel_addr_r"); args_to_func[2]=getenv("image_name"); i = do_tftpb(cmdtb, 1, 3,args_to_func); addr = simple_strtoul(args_to_func[1], NULL, 16); } /* finish step 5 */ } free(path_to_image); free(path_to_scr); path_to_image = getenv("bootargs_dflt"); if(!path_to_image) { printf("missing environment variable: bootargs_dflt\n"); return 0; } if (step == 3 && initrd ==1){ setenv("bootargs_dflt","console=ttyS0,115200 earlyprintk=ttyS0 root=/dev/sda2 ro pm_disable"); } bootargs = (char *)malloc(sizeof(char)*(strlen(getenv("bootargs_dflt"))+17)); strcpy(bootargs,"setenv bootargs "); #ifndef CONFIG_SYS_HUSH_PARSER if (run_command(strcat(bootargs,getenv("bootargs_dflt")), flag) < 0) { printf("missing environment variable: bootargs_dflt\n"); return 0; } #else marvell_recursive_parse = 1; if (parse_string_outer(strcat(bootargs,getenv("bootargs_dflt")), FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0){ printf("missing environment variable: bootargs_dflt\n"); marvell_recursive_parse = 0; return 0; } marvell_recursive_parse = 0; #endif if(i==0) { if(step == 1 || step == 4) source(addr,NULL); else if ((step == 3 && initrd ==0 )|| step == 5) do_bootm(cmdtb, 1,1,(char * const*)kernel_addr); else if (step ==2) do_pxe_boot(cmdtb, 2, 1,(char * const *)NULL); else if (step == 3 && initrd ==1){ do_bootm(cmdtb, 1,2,args_to_func); } } else { printf("Unable to load image/script\n"); } return 1; }