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 #ifdef CONFIG_SHOW_BOOT_PROGRESS
34 # include <status_led.h>
35 extern void show_boot_progress (int val);
36 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress (arg)
38 # define SHOW_BOOT_PROGRESS(arg)
41 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
43 static int netboot_common (proto_t, cmd_tbl_t *, int , char *[]);
45 int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
47 return netboot_common (BOOTP, cmdtp, argc, argv);
51 bootp, 3, 1, do_bootp,
52 "bootp\t- boot image via network using BootP/TFTP protocol\n",
53 "[loadAddress] [bootfilename]\n"
56 int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
58 return netboot_common (TFTP, cmdtp, argc, argv);
62 tftpboot, 3, 1, do_tftpb,
63 "tftpboot- boot image via network using TFTP protocol\n",
64 "[loadAddress] [bootfilename]\n"
67 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
69 return netboot_common (RARP, cmdtp, argc, argv);
73 rarpboot, 3, 1, do_rarpb,
74 "rarpboot- boot image via network using RARP/TFTP protocol\n",
75 "[loadAddress] [bootfilename]\n"
78 #if defined(CONFIG_CMD_DHCP)
79 int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
81 return netboot_common(DHCP, cmdtp, argc, argv);
86 "dhcp\t- invoke DHCP client to obtain IP/boot params\n",
91 #if defined(CONFIG_CMD_NFS)
92 int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
94 return netboot_common(NFS, cmdtp, argc, argv);
99 "nfs\t- boot image via network using NFS protocol\n",
100 "[loadAddress] [host ip addr:bootfilename]\n"
104 static void netboot_update_env (void)
108 if (NetOurGatewayIP) {
109 ip_to_string (NetOurGatewayIP, tmp);
110 setenv ("gatewayip", tmp);
113 if (NetOurSubnetMask) {
114 ip_to_string (NetOurSubnetMask, tmp);
115 setenv ("netmask", tmp);
118 if (NetOurHostName[0])
119 setenv ("hostname", NetOurHostName);
121 if (NetOurRootPath[0])
122 setenv ("rootpath", NetOurRootPath);
125 ip_to_string (NetOurIP, tmp);
126 setenv ("ipaddr", tmp);
130 ip_to_string (NetServerIP, tmp);
131 setenv ("serverip", tmp);
135 ip_to_string (NetOurDNSIP, tmp);
136 setenv ("dnsip", tmp);
138 #if defined(CONFIG_BOOTP_DNS2)
140 ip_to_string (NetOurDNS2IP, tmp);
141 setenv ("dnsip2", tmp);
144 if (NetOurNISDomain[0])
145 setenv ("domain", NetOurNISDomain);
147 #if defined(CONFIG_CMD_SNTP) \
148 && defined(CONFIG_BOOTP_TIMEOFFSET)
150 sprintf (tmp, "%d", NetTimeOffset);
151 setenv ("timeoffset", tmp);
154 #if defined(CONFIG_CMD_SNTP) \
155 && defined(CONFIG_BOOTP_NTPSERVER)
156 if (NetNtpServerIP) {
157 ip_to_string (NetNtpServerIP, tmp);
158 setenv ("ntpserverip", tmp);
164 netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
170 /* pre-set load_addr */
171 if ((s = getenv("loadaddr")) != NULL) {
172 load_addr = simple_strtoul(s, NULL, 16);
179 case 2: /* only one arg - accept two forms:
180 * just load address, or just boot file name.
181 * The latter form must be written "filename" here.
183 if (argv[1][0] == '"') { /* just boot filename */
184 copy_filename (BootFile, argv[1], sizeof(BootFile));
185 } else { /* load address */
186 load_addr = simple_strtoul(argv[1], NULL, 16);
190 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
191 copy_filename (BootFile, argv[2], sizeof(BootFile));
195 default: printf ("Usage:\n%s\n", cmdtp->usage);
196 SHOW_BOOT_PROGRESS(-80);
200 SHOW_BOOT_PROGRESS(80);
201 if ((size = NetLoop(proto)) < 0) {
202 SHOW_BOOT_PROGRESS(-81);
206 SHOW_BOOT_PROGRESS(81);
207 /* NetLoop ok, update environment */
208 netboot_update_env();
210 /* done if no file was loaded (no errors though) */
212 SHOW_BOOT_PROGRESS(-82);
217 flush_cache(load_addr, size);
219 /* Loading ok, check if we should attempt an auto-start */
220 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
222 local_args[0] = argv[0];
223 local_args[1] = NULL;
225 printf ("Automatic boot of image at addr 0x%08lX ...\n",
227 SHOW_BOOT_PROGRESS(82);
228 rcode = do_bootm (cmdtp, 0, 1, local_args);
231 #ifdef CONFIG_AUTOSCRIPT
232 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
233 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
234 SHOW_BOOT_PROGRESS(83);
235 rcode = autoscript (load_addr);
238 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
240 SHOW_BOOT_PROGRESS(-83);
242 SHOW_BOOT_PROGRESS(84);
247 #if defined(CONFIG_CMD_PING)
248 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
253 NetPingIP = string_to_ip(argv[1]);
254 if (NetPingIP == 0) {
255 printf ("Usage:\n%s\n", cmdtp->usage);
259 if (NetLoop(PING) < 0) {
260 printf("ping failed; host %s is not alive\n", argv[1]);
264 printf("host %s is alive\n", argv[1]);
271 "ping\t- send ICMP ECHO_REQUEST to network host\n",
276 #if defined(CONFIG_CMD_CDP)
278 static void cdp_update_env(void)
282 if (CDPApplianceVLAN != htons(-1)) {
283 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN));
284 VLAN_to_string(CDPApplianceVLAN, tmp);
286 NetOurVLAN = CDPApplianceVLAN;
289 if (CDPNativeVLAN != htons(-1)) {
290 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN));
291 VLAN_to_string(CDPNativeVLAN, tmp);
292 setenv("nvlan", tmp);
293 NetOurNativeVLAN = CDPNativeVLAN;
298 int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
304 printf("cdp failed; perhaps not a CISCO switch?\n");
315 "cdp\t- Perform CDP network configuration\n",
319 #if defined(CONFIG_CMD_SNTP)
320 int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
325 NetNtpServerIP = getenv_IPaddr ("ntpserverip");
326 if (NetNtpServerIP == 0) {
327 printf ("ntpserverip not set\n");
331 NetNtpServerIP = string_to_ip(argv[1]);
332 if (NetNtpServerIP == 0) {
333 printf ("Bad NTP server IP address\n");
338 toff = getenv ("timeoffset");
339 if (toff == NULL) NetTimeOffset = 0;
340 else NetTimeOffset = simple_strtol (toff, NULL, 10);
342 if (NetLoop(SNTP) < 0) {
343 printf("SNTP failed: host %s not responding\n", argv[1]);
352 "sntp\t- synchronize RTC via network\n",