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 extern int do_bootm (cmd_tbl_t *, int, int, char * const []);
33 static int netboot_common (proto_t, cmd_tbl_t *, int , char * const []);
35 int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
37 return netboot_common (BOOTP, cmdtp, argc, argv);
41 bootp, 3, 1, do_bootp,
42 "boot image via network using BOOTP/TFTP protocol",
43 "[loadAddress] [[hostIPaddr:]bootfilename]"
46 int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
48 return netboot_common (TFTP, cmdtp, argc, argv);
52 tftpboot, 3, 1, do_tftpb,
53 "boot image via network using TFTP protocol",
54 "[loadAddress] [[hostIPaddr:]bootfilename]"
57 #ifdef CONFIG_CMD_RARP
58 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
60 return netboot_common (RARP, cmdtp, argc, argv);
64 rarpboot, 3, 1, do_rarpb,
65 "boot image via network using RARP/TFTP protocol",
66 "[loadAddress] [[hostIPaddr:]bootfilename]"
70 #if defined(CONFIG_CMD_DHCP)
71 int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
73 return netboot_common(DHCP, cmdtp, argc, argv);
78 "boot image via network using DHCP/TFTP protocol",
79 "[loadAddress] [[hostIPaddr:]bootfilename]"
83 #if defined(CONFIG_CMD_NFS)
84 int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
86 return netboot_common(NFS, cmdtp, argc, argv);
91 "boot image via network using NFS protocol",
92 "[loadAddress] [[hostIPaddr:]bootfilename]"
96 static void netboot_update_env (void)
100 if (NetOurGatewayIP) {
101 ip_to_string (NetOurGatewayIP, tmp);
102 setenv ("gatewayip", tmp);
105 if (NetOurSubnetMask) {
106 ip_to_string (NetOurSubnetMask, tmp);
107 setenv ("netmask", tmp);
110 if (NetOurHostName[0])
111 setenv ("hostname", NetOurHostName);
113 if (NetOurRootPath[0])
114 setenv ("rootpath", NetOurRootPath);
117 ip_to_string (NetOurIP, tmp);
118 setenv ("ipaddr", tmp);
122 ip_to_string (NetServerIP, tmp);
123 setenv ("serverip", tmp);
127 ip_to_string (NetOurDNSIP, tmp);
128 setenv ("dnsip", tmp);
130 #if defined(CONFIG_BOOTP_DNS2)
132 ip_to_string (NetOurDNS2IP, tmp);
133 setenv ("dnsip2", tmp);
136 if (NetOurNISDomain[0])
137 setenv ("domain", NetOurNISDomain);
139 #if defined(CONFIG_CMD_SNTP) \
140 && defined(CONFIG_BOOTP_TIMEOFFSET)
142 sprintf (tmp, "%d", NetTimeOffset);
143 setenv ("timeoffset", tmp);
146 #if defined(CONFIG_CMD_SNTP) \
147 && defined(CONFIG_BOOTP_NTPSERVER)
148 if (NetNtpServerIP) {
149 ip_to_string (NetNtpServerIP, tmp);
150 setenv ("ntpserverip", tmp);
156 netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[])
164 /* pre-set load_addr */
165 if ((s = getenv("loadaddr")) != NULL) {
166 load_addr = simple_strtoul(s, NULL, 16);
174 * Only one arg - accept two forms:
175 * Just load address, or just boot file name. The latter
176 * form must be written in a format which can not be
177 * mis-interpreted as a valid number.
179 addr = simple_strtoul(argv[1], &end, 16);
180 if (end == (argv[1] + strlen(argv[1])))
183 copy_filename(BootFile, argv[1], sizeof(BootFile));
186 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
187 copy_filename (BootFile, argv[2], sizeof(BootFile));
192 show_boot_progress (-80);
193 return cmd_usage(cmdtp);
196 show_boot_progress (80);
197 if ((size = NetLoop(proto)) < 0) {
198 show_boot_progress (-81);
202 show_boot_progress (81);
203 /* NetLoop ok, update environment */
204 netboot_update_env();
206 /* done if no file was loaded (no errors though) */
208 show_boot_progress (-82);
213 flush_cache(load_addr, size);
215 /* Loading ok, check if we should attempt an auto-start */
216 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
218 local_args[0] = argv[0];
219 local_args[1] = NULL;
221 printf ("Automatic boot of image at addr 0x%08lX ...\n",
223 show_boot_progress (82);
224 rcode = do_bootm (cmdtp, 0, 1, local_args);
228 show_boot_progress (-83);
230 show_boot_progress (84);
234 #if defined(CONFIG_CMD_PING)
235 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
240 NetPingIP = string_to_ip(argv[1]);
242 return cmd_usage(cmdtp);
244 if (NetLoop(PING) < 0) {
245 printf("ping failed; host %s is not alive\n", argv[1]);
249 printf("host %s is alive\n", argv[1]);
256 "send ICMP ECHO_REQUEST to network host",
261 #if defined(CONFIG_CMD_CDP)
263 static void cdp_update_env(void)
267 if (CDPApplianceVLAN != htons(-1)) {
268 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN));
269 VLAN_to_string(CDPApplianceVLAN, tmp);
271 NetOurVLAN = CDPApplianceVLAN;
274 if (CDPNativeVLAN != htons(-1)) {
275 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN));
276 VLAN_to_string(CDPNativeVLAN, tmp);
277 setenv("nvlan", tmp);
278 NetOurNativeVLAN = CDPNativeVLAN;
283 int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
289 printf("cdp failed; perhaps not a CISCO switch?\n");
300 "Perform CDP network configuration",
304 #if defined(CONFIG_CMD_SNTP)
305 int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
310 NetNtpServerIP = getenv_IPaddr ("ntpserverip");
311 if (NetNtpServerIP == 0) {
312 printf ("ntpserverip not set\n");
316 NetNtpServerIP = string_to_ip(argv[1]);
317 if (NetNtpServerIP == 0) {
318 printf ("Bad NTP server IP address\n");
323 toff = getenv ("timeoffset");
324 if (toff == NULL) NetTimeOffset = 0;
325 else NetTimeOffset = simple_strtol (toff, NULL, 10);
327 if (NetLoop(SNTP) < 0) {
328 printf("SNTP failed: host %s not responding\n", argv[1]);
337 "synchronize RTC via network",
342 #if defined(CONFIG_CMD_DNS)
343 int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
346 return cmd_usage(cmdtp);
349 * We should check for a valid hostname:
350 * - Each label must be between 1 and 63 characters long
351 * - the entire hostname has a maximum of 255 characters
352 * - only the ASCII letters 'a' through 'z' (case-insensitive),
353 * the digits '0' through '9', and the hyphen
354 * - cannot begin or end with a hyphen
355 * - no other symbols, punctuation characters, or blank spaces are
357 * but hey - this is a minimalist implmentation, so only check length
358 * and let the name server deal with things.
360 if (strlen(argv[1]) >= 255) {
361 printf("dns error: hostname too long\n");
365 NetDNSResolve = argv[1];
368 NetDNSenvvar = argv[2];
372 if (NetLoop(DNS) < 0) {
373 printf("dns lookup of %s failed, check setup\n", argv[1]);
382 "lookup the IP of a hostname",
386 #endif /* CONFIG_CMD_DNS */