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 defined(CONFIG_CMD_NET)
33 u32 save_addr; /* Default save address for TFTPPUT */
34 u32 save_size; /* Default save size (in bytes) for TFTPPUT */
36 extern int do_bootm(cmd_tbl_t *, int, int, char *[]);
37 static int netboot_common(proto_t, cmd_tbl_t *, int, char *[]);
39 #if defined(CONFIG_CMD_HTTPD)
40 int do_httpd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
42 return NetLoopHttpd();
45 U_BOOT_CMD(httpd, 1, 1, do_httpd,
46 "start web server for firmware recovery\n",
48 #endif /* CONFIG_CMD_HTTPD */
50 #if defined(CONFIG_CMD_DHCP)
51 int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
53 return netboot_common(DHCP, cmdtp, argc, argv);
56 U_BOOT_CMD(dhcp, 3, 1, do_dhcp,
57 "invoke DHCP client to obtain IP/boot params\n",
59 #endif /* CONFIG_CMD_DHCP */
61 #if defined(CONFIG_CMD_NFS)
62 int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
64 return netboot_common(NFS, cmdtp, argc, argv);
66 U_BOOT_CMD(nfs, 3, 1, do_nfs,
67 "boot image via network using NFS protocol\n",
68 "[address] [host ip addr:filename]\n"
69 "\t- loads 'filename' at 'address' using NFS protocol");
70 #endif /* CONFIG_CMD_NFS */
72 #if defined(CONFIG_CMD_PING)
73 int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
76 print_cmd_help(cmdtp);
80 NetPingIP = string_to_ip(argv[1]);
83 print_cmd_help(cmdtp);
87 if (NetLoop(PING) < 0) {
89 printf_err("ping failed, host %s is not alive!\n\n", argv[1]);
93 printf("\nPing OK, host %s is alive!\n\n", argv[1]);
98 U_BOOT_CMD(ping, 2, 1, do_ping,
99 "send ICMP ECHO_REQUEST to network host\n",
101 "\t- sends ping to IP 'host IP'\n");
102 #endif /* CONFIG_CMD_PING */
104 #if defined(CONFIG_CMD_SNTP)
105 int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
110 print_cmd_help(cmdtp);
113 NetNtpServerIP = string_to_ip(argv[1]);
115 if (NetNtpServerIP == 0) {
116 printf_err("bad SNTP server IP address\n");
121 toff = getenv("timeoffset");
126 NetTimeOffset = simple_strtol(toff, NULL, 10);
128 if (NetLoop(SNTP) < 0) {
129 printf_err("SNTP host %s not responding\n", argv[1]);
136 U_BOOT_CMD(sntp, 2, 1, do_sntp,
137 "send NTP request to NTP server\n",
139 "\t- sends NTP request to NTP server 'ntpserverip'\n");
140 #endif /* CONFIG_CMD_SNTP */
142 int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
144 return netboot_common(TFTPGET, cmdtp, argc, argv);
147 U_BOOT_CMD(tftpboot, 3, 1, do_tftpb,
148 "boot image via network using TFTP protocol\n",
149 "[address] [filename]\n"
150 "\t- loads 'filename' at 'address' from TFTP server");
152 int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
155 print_cmd_help(cmdtp);
159 return netboot_common(TFTPPUT, cmdtp, argc, argv);
162 U_BOOT_CMD(tftpput, 4, 1, do_tftpput,
163 "send file to TFTP server\n",
164 "address size filename\n"
165 "\t- sends 'size' of data from 'address' as 'filename' to TFTP server");
167 static void netboot_update_env(void)
171 if (NetOurGatewayIP) {
172 ip_to_string(NetOurGatewayIP, tmp);
173 setenv("gatewayip", tmp);
176 if (NetOurSubnetMask) {
177 ip_to_string(NetOurSubnetMask, tmp);
178 setenv("netmask", tmp);
181 if (NetOurHostName[0])
182 setenv("hostname", NetOurHostName);
184 if (NetOurRootPath[0])
185 setenv("rootpath", NetOurRootPath);
188 ip_to_string(NetOurIP, tmp);
189 setenv("ipaddr", tmp);
193 ip_to_string(NetServerIP, tmp);
194 setenv("serverip", tmp);
198 ip_to_string(NetOurDNSIP, tmp);
199 setenv("dnsip", tmp);
202 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
204 ip_to_string(NetOurDNS2IP, tmp);
205 setenv("dnsip2", tmp);
209 if (NetOurNISDomain[0])
210 setenv("domain", NetOurNISDomain);
212 #if defined(CONFIG_CMD_SNTP)
213 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
215 sprintf(tmp, "%d", NetTimeOffset);
216 setenv("timeoffset", tmp);
220 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
221 if (NetNtpServerIP) {
222 ip_to_string(NetNtpServerIP, tmp);
223 setenv("ntpserverip", tmp);
226 #endif /* CONFIG_CMD_SNTP */
229 static int netboot_common(proto_t proto,
239 /* Pre-set load_addr */
240 if ((s = getenv("loadaddr")) != NULL)
241 load_addr = simple_strtoul(s, NULL, 16);
248 * Don't allow to use loading address
249 * lower than RAM/FLASH base
251 tmp = simple_strtoul(argv[1], NULL, 16);
253 #if defined(CFG_DIRECT_FLASH_TFTP)
254 if ((tmp < CFG_SDRAM_BASE && tmp < CFG_FLASH_BASE) || tmp == 0)
256 if (tmp < CFG_SDRAM_BASE || tmp == 0)
258 copy_filename(BootFile, argv[1], sizeof(BootFile));
264 load_addr = simple_strtoul(argv[1], NULL, 16);
265 copy_filename(BootFile, argv[2], sizeof(BootFile));
268 save_addr = simple_strtoul(argv[1], NULL, 16);
269 save_size = simple_strtoul(argv[2], NULL, 16);
270 copy_filename(BootFile, argv[3], sizeof(BootFile));
273 print_cmd_help(cmdtp);
277 if ((size = NetLoop(proto)) < 0)
280 /* NetLoop ok, update environment */
281 netboot_update_env();
283 /* Done if no file was loaded (no errors though) */
288 flush_cache(load_addr, size);
290 /* Loading ok, check if we should attempt an auto-start */
291 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "yes") == 0)) {
293 local_args[0] = argv[0];
294 local_args[1] = NULL;
296 printf("Automatic boot of image at addr 0x%08lX ...\n",
299 rcode = do_bootm(cmdtp, 0, 1, local_args);
302 #if defined(CONFIG_AUTOSCRIPT)
303 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
304 printf("Running autoscript at addr 0x%08lX ...\n",
307 rcode = autoscript(load_addr);
313 #endif /* CONFIG_CMD_NET */