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 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
35 static int netboot_common (proto_t, cmd_tbl_t *, int , char *[]);
37 int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
39 return netboot_common (BOOTP, cmdtp, argc, argv);
43 bootp, 3, 1, do_bootp,
44 "bootp\t- boot image via network using BootP/TFTP protocol\n",
45 "[loadAddress] [bootfilename]\n"
48 int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
50 return netboot_common (TFTP, cmdtp, argc, argv);
54 tftpboot, 3, 1, do_tftpb,
55 "tftpboot- boot image via network using TFTP protocol\n",
56 "[loadAddress] [bootfilename]\n"
59 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
61 return netboot_common (RARP, cmdtp, argc, argv);
65 rarpboot, 3, 1, do_rarpb,
66 "rarpboot- boot image via network using RARP/TFTP protocol\n",
67 "[loadAddress] [bootfilename]\n"
70 #if defined(CONFIG_CMD_DHCP)
71 int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
73 return netboot_common(DHCP, cmdtp, argc, argv);
78 "dhcp\t- invoke DHCP client to obtain IP/boot params\n",
83 #if defined(CONFIG_CMD_NFS)
84 int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
86 return netboot_common(NFS, cmdtp, argc, argv);
91 "nfs\t- boot image via network using NFS protocol\n",
92 "[loadAddress] [host ip addr:bootfilename]\n"
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 *argv[])
162 /* pre-set load_addr */
163 if ((s = getenv("loadaddr")) != NULL) {
164 load_addr = simple_strtoul(s, NULL, 16);
171 case 2: /* only one arg - accept two forms:
172 * just load address, or just boot file name.
173 * The latter form must be written "filename" here.
175 if (argv[1][0] == '"') { /* just boot filename */
176 copy_filename (BootFile, argv[1], sizeof(BootFile));
177 } else { /* load address */
178 load_addr = simple_strtoul(argv[1], NULL, 16);
182 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
183 copy_filename (BootFile, argv[2], sizeof(BootFile));
187 default: printf ("Usage:\n%s\n", cmdtp->usage);
188 show_boot_progress (-80);
192 show_boot_progress (80);
193 if ((size = NetLoop(proto)) < 0) {
194 show_boot_progress (-81);
198 show_boot_progress (81);
199 /* NetLoop ok, update environment */
200 netboot_update_env();
202 /* done if no file was loaded (no errors though) */
204 show_boot_progress (-82);
209 flush_cache(load_addr, size);
211 /* Loading ok, check if we should attempt an auto-start */
212 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
214 local_args[0] = argv[0];
215 local_args[1] = NULL;
217 printf ("Automatic boot of image at addr 0x%08lX ...\n",
219 show_boot_progress (82);
220 rcode = do_bootm (cmdtp, 0, 1, local_args);
223 #ifdef CONFIG_AUTOSCRIPT
224 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
225 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
226 show_boot_progress (83);
227 rcode = autoscript (load_addr);
231 show_boot_progress (-83);
233 show_boot_progress (84);
237 #if defined(CONFIG_CMD_PING)
238 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
243 NetPingIP = string_to_ip(argv[1]);
244 if (NetPingIP == 0) {
245 printf ("Usage:\n%s\n", cmdtp->usage);
249 if (NetLoop(PING) < 0) {
250 printf("ping failed; host %s is not alive\n", argv[1]);
254 printf("host %s is alive\n", argv[1]);
261 "ping\t- send ICMP ECHO_REQUEST to network host\n",
266 #if defined(CONFIG_CMD_CDP)
268 static void cdp_update_env(void)
272 if (CDPApplianceVLAN != htons(-1)) {
273 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN));
274 VLAN_to_string(CDPApplianceVLAN, tmp);
276 NetOurVLAN = CDPApplianceVLAN;
279 if (CDPNativeVLAN != htons(-1)) {
280 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN));
281 VLAN_to_string(CDPNativeVLAN, tmp);
282 setenv("nvlan", tmp);
283 NetOurNativeVLAN = CDPNativeVLAN;
288 int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
294 printf("cdp failed; perhaps not a CISCO switch?\n");
305 "cdp\t- Perform CDP network configuration\n",
309 #if defined(CONFIG_CMD_SNTP)
310 int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
315 NetNtpServerIP = getenv_IPaddr ("ntpserverip");
316 if (NetNtpServerIP == 0) {
317 printf ("ntpserverip not set\n");
321 NetNtpServerIP = string_to_ip(argv[1]);
322 if (NetNtpServerIP == 0) {
323 printf ("Bad NTP server IP address\n");
328 toff = getenv ("timeoffset");
329 if (toff == NULL) NetTimeOffset = 0;
330 else NetTimeOffset = simple_strtol (toff, NULL, 10);
332 if (NetLoop(SNTP) < 0) {
333 printf("SNTP failed: host %s not responding\n", argv[1]);
342 "sntp\t- synchronize RTC via network\n",