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 (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[])
46 return netboot_common (TFTP, cmdtp, argc, argv);
50 tftpboot, 3, 1, do_tftpb,
51 "boot image via network using TFTP protocol",
52 "[loadAddress] [[hostIPaddr:]bootfilename]"
55 #ifdef CONFIG_CMD_TFTPSRV
56 static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
58 return netboot_common(TFTPSRV, cmdtp, argc, argv);
62 tftpsrv, 2, 1, do_tftpsrv,
63 "act as a TFTP server and boot the first received file",
65 "Listen for an incoming TFTP transfer, receive a file and boot it.\n"
66 "The transfer is aborted if a transfer has not been started after\n"
67 "about 50 seconds or if Ctrl-C is pressed."
72 #ifdef CONFIG_CMD_RARP
73 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
75 return netboot_common (RARP, cmdtp, argc, argv);
79 rarpboot, 3, 1, do_rarpb,
80 "boot image via network using RARP/TFTP protocol",
81 "[loadAddress] [[hostIPaddr:]bootfilename]"
85 #if defined(CONFIG_CMD_DHCP)
86 int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
88 return netboot_common(DHCP, cmdtp, argc, argv);
93 "boot image via network using DHCP/TFTP protocol",
94 "[loadAddress] [[hostIPaddr:]bootfilename]"
98 #if defined(CONFIG_CMD_NFS)
99 int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
101 return netboot_common(NFS, cmdtp, argc, argv);
106 "boot image via network using NFS protocol",
107 "[loadAddress] [[hostIPaddr:]bootfilename]"
111 static void netboot_update_env (void)
115 if (NetOurGatewayIP) {
116 ip_to_string (NetOurGatewayIP, tmp);
117 setenv ("gatewayip", tmp);
120 if (NetOurSubnetMask) {
121 ip_to_string (NetOurSubnetMask, tmp);
122 setenv ("netmask", tmp);
125 if (NetOurHostName[0])
126 setenv ("hostname", NetOurHostName);
128 if (NetOurRootPath[0])
129 setenv ("rootpath", NetOurRootPath);
132 ip_to_string (NetOurIP, tmp);
133 setenv ("ipaddr", tmp);
137 ip_to_string (NetServerIP, tmp);
138 setenv ("serverip", tmp);
142 ip_to_string (NetOurDNSIP, tmp);
143 setenv ("dnsip", tmp);
145 #if defined(CONFIG_BOOTP_DNS2)
147 ip_to_string (NetOurDNS2IP, tmp);
148 setenv ("dnsip2", tmp);
151 if (NetOurNISDomain[0])
152 setenv ("domain", NetOurNISDomain);
154 #if defined(CONFIG_CMD_SNTP) \
155 && defined(CONFIG_BOOTP_TIMEOFFSET)
157 sprintf (tmp, "%d", NetTimeOffset);
158 setenv ("timeoffset", tmp);
161 #if defined(CONFIG_CMD_SNTP) \
162 && defined(CONFIG_BOOTP_NTPSERVER)
163 if (NetNtpServerIP) {
164 ip_to_string (NetNtpServerIP, tmp);
165 setenv ("ntpserverip", tmp);
171 netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[])
179 /* pre-set load_addr */
180 if ((s = getenv("loadaddr")) != NULL) {
181 load_addr = simple_strtoul(s, NULL, 16);
189 * Only one arg - accept two forms:
190 * Just load address, or just boot file name. The latter
191 * form must be written in a format which can not be
192 * mis-interpreted as a valid number.
194 addr = simple_strtoul(argv[1], &end, 16);
195 if (end == (argv[1] + strlen(argv[1])))
198 copy_filename(BootFile, argv[1], sizeof(BootFile));
201 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
202 copy_filename (BootFile, argv[2], sizeof(BootFile));
207 show_boot_progress (-80);
208 return cmd_usage(cmdtp);
211 show_boot_progress (80);
212 if ((size = NetLoop(proto)) < 0) {
213 show_boot_progress (-81);
217 show_boot_progress (81);
218 /* NetLoop ok, update environment */
219 netboot_update_env();
221 /* done if no file was loaded (no errors though) */
223 show_boot_progress (-82);
228 flush_cache(load_addr, size);
230 show_boot_progress(82);
231 rcode = bootm_maybe_autostart(cmdtp, argv[0]);
234 show_boot_progress (-83);
236 show_boot_progress (84);
240 #if defined(CONFIG_CMD_PING)
241 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
246 NetPingIP = string_to_ip(argv[1]);
248 return cmd_usage(cmdtp);
250 if (NetLoop(PING) < 0) {
251 printf("ping failed; host %s is not alive\n", argv[1]);
255 printf("host %s is alive\n", argv[1]);
262 "send ICMP ECHO_REQUEST to network host",
267 #if defined(CONFIG_CMD_CDP)
269 static void cdp_update_env(void)
273 if (CDPApplianceVLAN != htons(-1)) {
274 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN));
275 VLAN_to_string(CDPApplianceVLAN, tmp);
277 NetOurVLAN = CDPApplianceVLAN;
280 if (CDPNativeVLAN != htons(-1)) {
281 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN));
282 VLAN_to_string(CDPNativeVLAN, tmp);
283 setenv("nvlan", tmp);
284 NetOurNativeVLAN = CDPNativeVLAN;
289 int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
295 printf("cdp failed; perhaps not a CISCO switch?\n");
306 "Perform CDP network configuration",
311 #if defined(CONFIG_CMD_SNTP)
312 int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
317 NetNtpServerIP = getenv_IPaddr ("ntpserverip");
318 if (NetNtpServerIP == 0) {
319 printf ("ntpserverip not set\n");
323 NetNtpServerIP = string_to_ip(argv[1]);
324 if (NetNtpServerIP == 0) {
325 printf ("Bad NTP server IP address\n");
330 toff = getenv ("timeoffset");
331 if (toff == NULL) NetTimeOffset = 0;
332 else NetTimeOffset = simple_strtol (toff, NULL, 10);
334 if (NetLoop(SNTP) < 0) {
335 printf("SNTP failed: host %pI4 not responding\n",
345 "synchronize RTC via network",
350 #if defined(CONFIG_CMD_DNS)
351 int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
354 return cmd_usage(cmdtp);
357 * We should check for a valid hostname:
358 * - Each label must be between 1 and 63 characters long
359 * - the entire hostname has a maximum of 255 characters
360 * - only the ASCII letters 'a' through 'z' (case-insensitive),
361 * the digits '0' through '9', and the hyphen
362 * - cannot begin or end with a hyphen
363 * - no other symbols, punctuation characters, or blank spaces are
365 * but hey - this is a minimalist implmentation, so only check length
366 * and let the name server deal with things.
368 if (strlen(argv[1]) >= 255) {
369 printf("dns error: hostname too long\n");
373 NetDNSResolve = argv[1];
376 NetDNSenvvar = argv[2];
380 if (NetLoop(DNS) < 0) {
381 printf("dns lookup of %s failed, check setup\n", argv[1]);
390 "lookup the IP of a hostname",
394 #endif /* CONFIG_CMD_DNS */