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 static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
33 int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
35 return netboot_common (BOOTP, cmdtp, argc, argv);
39 bootp, 3, 1, do_bootp,
40 "boot image via network using BOOTP/TFTP protocol",
41 "[loadAddress] [[hostIPaddr:]bootfilename]"
44 int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
48 bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
49 ret = netboot_common(TFTPGET, cmdtp, argc, argv);
50 bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
55 tftpboot, 3, 1, do_tftpb,
56 "boot image via network using TFTP protocol",
57 "[loadAddress] [[hostIPaddr:]bootfilename]"
60 #ifdef CONFIG_CMD_TFTPPUT
61 int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
65 ret = netboot_common(TFTPPUT, cmdtp, argc, argv);
70 tftpput, 4, 1, do_tftpput,
71 "TFTP put command, for uploading files to a server",
72 "Address Size [[hostIPaddr:]filename]"
76 #ifdef CONFIG_CMD_TFTPSRV
77 static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
79 return netboot_common(TFTPSRV, cmdtp, argc, argv);
83 tftpsrv, 2, 1, do_tftpsrv,
84 "act as a TFTP server and boot the first received file",
86 "Listen for an incoming TFTP transfer, receive a file and boot it.\n"
87 "The transfer is aborted if a transfer has not been started after\n"
88 "about 50 seconds or if Ctrl-C is pressed."
93 #ifdef CONFIG_CMD_RARP
94 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
96 return netboot_common (RARP, cmdtp, argc, argv);
100 rarpboot, 3, 1, do_rarpb,
101 "boot image via network using RARP/TFTP protocol",
102 "[loadAddress] [[hostIPaddr:]bootfilename]"
106 #if defined(CONFIG_CMD_DHCP)
107 int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
109 return netboot_common(DHCP, cmdtp, argc, argv);
114 "boot image via network using DHCP/TFTP protocol",
115 "[loadAddress] [[hostIPaddr:]bootfilename]"
119 #if defined(CONFIG_CMD_NFS)
120 int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
122 return netboot_common(NFS, cmdtp, argc, argv);
127 "boot image via network using NFS protocol",
128 "[loadAddress] [[hostIPaddr:]bootfilename]"
132 static void netboot_update_env (void)
136 if (NetOurGatewayIP) {
137 ip_to_string (NetOurGatewayIP, tmp);
138 setenv ("gatewayip", tmp);
141 if (NetOurSubnetMask) {
142 ip_to_string (NetOurSubnetMask, tmp);
143 setenv ("netmask", tmp);
146 if (NetOurHostName[0])
147 setenv ("hostname", NetOurHostName);
149 if (NetOurRootPath[0])
150 setenv ("rootpath", NetOurRootPath);
153 ip_to_string (NetOurIP, tmp);
154 setenv ("ipaddr", tmp);
158 ip_to_string (NetServerIP, tmp);
159 setenv ("serverip", tmp);
163 ip_to_string (NetOurDNSIP, tmp);
164 setenv ("dnsip", tmp);
166 #if defined(CONFIG_BOOTP_DNS2)
168 ip_to_string (NetOurDNS2IP, tmp);
169 setenv ("dnsip2", tmp);
172 if (NetOurNISDomain[0])
173 setenv ("domain", NetOurNISDomain);
175 #if defined(CONFIG_CMD_SNTP) \
176 && defined(CONFIG_BOOTP_TIMEOFFSET)
178 sprintf (tmp, "%d", NetTimeOffset);
179 setenv ("timeoffset", tmp);
182 #if defined(CONFIG_CMD_SNTP) \
183 && defined(CONFIG_BOOTP_NTPSERVER)
184 if (NetNtpServerIP) {
185 ip_to_string (NetNtpServerIP, tmp);
186 setenv ("ntpserverip", tmp);
191 static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
200 /* pre-set load_addr */
201 if ((s = getenv("loadaddr")) != NULL) {
202 load_addr = simple_strtoul(s, NULL, 16);
210 * Only one arg - accept two forms:
211 * Just load address, or just boot file name. The latter
212 * form must be written in a format which can not be
213 * mis-interpreted as a valid number.
215 addr = simple_strtoul(argv[1], &end, 16);
216 if (end == (argv[1] + strlen(argv[1])))
219 copy_filename(BootFile, argv[1], sizeof(BootFile));
222 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
223 copy_filename (BootFile, argv[2], sizeof(BootFile));
227 #ifdef CONFIG_CMD_TFTPPUT
229 if (strict_strtoul(argv[1], 16, &save_addr) < 0 ||
230 strict_strtoul(argv[2], 16, &save_size) < 0) {
231 printf("Invalid address/size\n");
232 return cmd_usage(cmdtp);
234 copy_filename(BootFile, argv[3], sizeof(BootFile));
238 bootstage_error(BOOTSTAGE_ID_NET_START);
239 return CMD_RET_USAGE;
241 bootstage_mark(BOOTSTAGE_ID_NET_START);
243 if ((size = NetLoop(proto)) < 0) {
244 bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
247 bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
249 /* NetLoop ok, update environment */
250 netboot_update_env();
252 /* done if no file was loaded (no errors though) */
254 bootstage_error(BOOTSTAGE_ID_NET_LOADED);
259 flush_cache(load_addr, size);
261 bootstage_mark(BOOTSTAGE_ID_NET_LOADED);
263 rcode = bootm_maybe_autostart(cmdtp, argv[0]);
266 bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR);
268 bootstage_mark(BOOTSTAGE_ID_NET_DONE);
272 #if defined(CONFIG_CMD_PING)
273 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
278 NetPingIP = string_to_ip(argv[1]);
280 return CMD_RET_USAGE;
282 if (NetLoop(PING) < 0) {
283 printf("ping failed; host %s is not alive\n", argv[1]);
287 printf("host %s is alive\n", argv[1]);
294 "send ICMP ECHO_REQUEST to network host",
299 #if defined(CONFIG_CMD_CDP)
301 static void cdp_update_env(void)
305 if (CDPApplianceVLAN != htons(-1)) {
306 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN));
307 VLAN_to_string(CDPApplianceVLAN, tmp);
309 NetOurVLAN = CDPApplianceVLAN;
312 if (CDPNativeVLAN != htons(-1)) {
313 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN));
314 VLAN_to_string(CDPNativeVLAN, tmp);
315 setenv("nvlan", tmp);
316 NetOurNativeVLAN = CDPNativeVLAN;
321 int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
327 printf("cdp failed; perhaps not a CISCO switch?\n");
338 "Perform CDP network configuration",
343 #if defined(CONFIG_CMD_SNTP)
344 int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
349 NetNtpServerIP = getenv_IPaddr ("ntpserverip");
350 if (NetNtpServerIP == 0) {
351 printf ("ntpserverip not set\n");
355 NetNtpServerIP = string_to_ip(argv[1]);
356 if (NetNtpServerIP == 0) {
357 printf ("Bad NTP server IP address\n");
362 toff = getenv ("timeoffset");
363 if (toff == NULL) NetTimeOffset = 0;
364 else NetTimeOffset = simple_strtol (toff, NULL, 10);
366 if (NetLoop(SNTP) < 0) {
367 printf("SNTP failed: host %pI4 not responding\n",
377 "synchronize RTC via network",
382 #if defined(CONFIG_CMD_DNS)
383 int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
386 return CMD_RET_USAGE;
389 * We should check for a valid hostname:
390 * - Each label must be between 1 and 63 characters long
391 * - the entire hostname has a maximum of 255 characters
392 * - only the ASCII letters 'a' through 'z' (case-insensitive),
393 * the digits '0' through '9', and the hyphen
394 * - cannot begin or end with a hyphen
395 * - no other symbols, punctuation characters, or blank spaces are
397 * but hey - this is a minimalist implmentation, so only check length
398 * and let the name server deal with things.
400 if (strlen(argv[1]) >= 255) {
401 printf("dns error: hostname too long\n");
405 NetDNSResolve = argv[1];
408 NetDNSenvvar = argv[2];
412 if (NetLoop(DNS) < 0) {
413 printf("dns lookup of %s failed, check setup\n", argv[1]);
422 "lookup the IP of a hostname",
426 #endif /* CONFIG_CMD_DNS */