3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #if (CONFIG_COMMANDS & CFG_CMD_NET)
33 extern int do_bootm(cmd_tbl_t *, int, int, char *[]);
34 static int netboot_common(proto_t, cmd_tbl_t *, int, char *[]);
36 int do_httpd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
37 return NetLoopHttpd();
39 U_BOOT_CMD(httpd, 1, 1, do_httpd, "start www server for firmware recovery\n", NULL);
41 int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
42 return netboot_common(TFTP, cmdtp, argc, argv);
44 U_BOOT_CMD(tftpboot, 3, 1, do_tftpb, "boot image via network using TFTP protocol\n", "[loadAddress] [bootfilename]\n");
46 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
47 int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
48 return netboot_common(DHCP, cmdtp, argc, argv);
50 U_BOOT_CMD(dhcp, 3, 1, do_dhcp, "invoke DHCP client to obtain IP/boot params\n", NULL);
51 #endif /* CFG_CMD_DHCP */
53 #if (CONFIG_COMMANDS & CFG_CMD_NFS)
54 int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
55 return netboot_common(NFS, cmdtp, argc, argv);
57 U_BOOT_CMD(nfs, 3, 1, do_nfs, "boot image via network using NFS protocol\n", "[loadAddress] [host ip addr:bootfilename]\n");
58 #endif /* CFG_CMD_NFS */
60 static void netboot_update_env(void){
64 ip_to_string(NetOurGatewayIP, tmp);
65 setenv("gatewayip", tmp);
69 ip_to_string(NetOurSubnetMask, tmp);
70 setenv("netmask", tmp);
73 if(NetOurHostName[0]){
74 setenv("hostname", NetOurHostName);
77 if(NetOurRootPath[0]){
78 setenv("rootpath", NetOurRootPath);
82 ip_to_string(NetOurIP, tmp);
83 setenv("ipaddr", tmp);
87 ip_to_string(NetServerIP, tmp);
88 setenv("serverip", tmp);
92 ip_to_string(NetOurDNSIP, tmp);
96 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
98 ip_to_string (NetOurDNS2IP, tmp);
99 setenv("dnsip2", tmp);
103 if(NetOurNISDomain[0]){
104 setenv("domain", NetOurNISDomain);
107 #if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
109 sprintf(tmp, "%d", NetTimeOffset);
110 setenv("timeoffset", tmp);
114 #if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
116 ip_to_string(NetNtpServerIP, tmp);
117 setenv("ntpserverip", tmp);
122 static int netboot_common(proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[]){
127 /* pre-set load_addr */
128 if((s = getenv("loadaddr")) != NULL){
129 load_addr = simple_strtoul(s, NULL, 16);
137 /* only one arg - accept two forms:
138 * just load address, or just boot file name.
139 * The latter form must be written "filename" here.
141 if(argv[1][0] == '"'){ /* just boot filename */
142 copy_filename(BootFile, argv[1], sizeof(BootFile));
143 } else { /* load address */
144 load_addr = simple_strtoul(argv[1], NULL, 16);
150 load_addr = simple_strtoul(argv[1], NULL, 16);
151 copy_filename(BootFile, argv[2], sizeof(BootFile));
158 if(cmdtp->help != NULL){
159 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
161 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
164 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
169 if((size = NetLoop(proto)) < 0){
173 /* NetLoop ok, update environment */
174 netboot_update_env();
176 /* done if no file was loaded (no errors though) */
182 flush_cache(load_addr, size);
184 /* Loading ok, check if we should attempt an auto-start */
185 if(((s = getenv("autostart")) != NULL) && (strcmp(s, "yes") == 0)){
187 local_args[0] = argv[0];
188 local_args[1] = NULL;
190 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
191 rcode = do_bootm(cmdtp, 0, 1, local_args);
194 #ifdef CONFIG_AUTOSCRIPT
195 if(((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)){
196 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
197 rcode = autoscript(load_addr);
203 #if (CONFIG_COMMANDS & CFG_CMD_PING)
204 int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
208 if(cmdtp->help != NULL){
209 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
211 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
214 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
219 NetPingIP = string_to_ip(argv[1]);
223 if(cmdtp->help != NULL){
224 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
226 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
229 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
234 if(NetLoop(PING) < 0){
235 printf("\n## Error: ping failed, host %s is not alive!\n\n", argv[1]);
239 printf("\nPing OK, host %s is alive!\n\n", argv[1]);
244 U_BOOT_CMD(ping, 2, 1, do_ping, "send ICMP ECHO_REQUEST to network host\n", "host IP\n"
245 "\t- sends ping to IP 'host IP'\n");
246 #endif /* CFG_CMD_PING */
248 #if (CONFIG_COMMANDS & CFG_CMD_SNTP)
249 int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){
254 if(cmdtp->help != NULL){
255 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help);
257 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
260 printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage);
264 NetNtpServerIP = string_to_ip(argv[1]);
265 if(NetNtpServerIP == 0){
266 printf("## Error: bad SNTP server IP address\n");
271 toff = getenv("timeoffset");
276 NetTimeOffset = simple_strtol(toff, NULL, 10);
279 if(NetLoop(SNTP) < 0){
280 printf("## Error: SNTP host %s not responding\n", argv[1]);
287 U_BOOT_CMD(sntp, 2, 1, do_sntp, "send NTP request to NTP server\n", "ntpserverip\n"
288 "\t- sends NTP request to NTP server 'ntpserverip'\n");
289 #endif /* CFG_CMD_SNTP */
291 #endif /* CFG_CMD_NET */