]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_net.c
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 (CONFIG_COMMANDS & CFG_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 (CONFIG_COMMANDS & CFG_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",
89 #endif /* CFG_CMD_DHCP */
91 #if (CONFIG_COMMANDS & CFG_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"
102 #endif /* CFG_CMD_NFS */
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 (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
140 ip_to_string (NetOurDNS2IP
, tmp
);
141 setenv ("dnsip2", tmp
);
144 if (NetOurNISDomain
[0])
145 setenv ("domain", NetOurNISDomain
);
147 #if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
149 sprintf (tmp
, "%d", NetTimeOffset
);
150 setenv ("timeoffset", tmp
);
153 #if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
154 if (NetNtpServerIP
) {
155 ip_to_string (NetNtpServerIP
, tmp
);
156 setenv ("ntpserverip", tmp
);
162 netboot_common (proto_t proto
, cmd_tbl_t
*cmdtp
, int argc
, char *argv
[])
168 /* pre-set load_addr */
169 if ((s
= getenv("loadaddr")) != NULL
) {
170 load_addr
= simple_strtoul(s
, NULL
, 16);
177 case 2: /* only one arg - accept two forms:
178 * just load address, or just boot file name.
179 * The latter form must be written "filename" here.
181 if (argv
[1][0] == '"') { /* just boot filename */
182 copy_filename (BootFile
, argv
[1], sizeof(BootFile
));
183 } else { /* load address */
184 load_addr
= simple_strtoul(argv
[1], NULL
, 16);
188 case 3: load_addr
= simple_strtoul(argv
[1], NULL
, 16);
189 copy_filename (BootFile
, argv
[2], sizeof(BootFile
));
193 default: printf ("Usage:\n%s\n", cmdtp
->usage
);
194 SHOW_BOOT_PROGRESS(-80);
198 SHOW_BOOT_PROGRESS(80);
199 if ((size
= NetLoop(proto
)) < 0) {
200 SHOW_BOOT_PROGRESS(-81);
204 SHOW_BOOT_PROGRESS(81);
205 /* NetLoop ok, update environment */
206 netboot_update_env();
208 /* done if no file was loaded (no errors though) */
210 SHOW_BOOT_PROGRESS(-82);
215 flush_cache(load_addr
, size
);
217 /* Loading ok, check if we should attempt an auto-start */
218 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
,"yes") == 0)) {
220 local_args
[0] = argv
[0];
221 local_args
[1] = NULL
;
223 printf ("Automatic boot of image at addr 0x%08lX ...\n",
225 SHOW_BOOT_PROGRESS(82);
226 rcode
= do_bootm (cmdtp
, 0, 1, local_args
);
229 #ifdef CONFIG_AUTOSCRIPT
230 if (((s
= getenv("autoscript")) != NULL
) && (strcmp(s
,"yes") == 0)) {
231 printf("Running autoscript at addr 0x%08lX ...\n", load_addr
);
232 SHOW_BOOT_PROGRESS(83);
233 rcode
= autoscript (load_addr
);
236 #if defined(CONFIG_SHOW_BOOT_PROGRESS)
238 SHOW_BOOT_PROGRESS(-83);
240 SHOW_BOOT_PROGRESS(84);
245 #if (CONFIG_COMMANDS & CFG_CMD_PING)
246 int do_ping (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
251 NetPingIP
= string_to_ip(argv
[1]);
252 if (NetPingIP
== 0) {
253 printf ("Usage:\n%s\n", cmdtp
->usage
);
257 if (NetLoop(PING
) < 0) {
258 printf("ping failed; host %s is not alive\n", argv
[1]);
262 printf("host %s is alive\n", argv
[1]);
269 "ping\t- send ICMP ECHO_REQUEST to network host\n",
272 #endif /* CFG_CMD_PING */
274 #if (CONFIG_COMMANDS & CFG_CMD_CDP)
276 static void cdp_update_env(void)
280 if (CDPApplianceVLAN
!= htons(-1)) {
281 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN
));
282 VLAN_to_string(CDPApplianceVLAN
, tmp
);
284 NetOurVLAN
= CDPApplianceVLAN
;
287 if (CDPNativeVLAN
!= htons(-1)) {
288 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN
));
289 VLAN_to_string(CDPNativeVLAN
, tmp
);
290 setenv("nvlan", tmp
);
291 NetOurNativeVLAN
= CDPNativeVLAN
;
296 int do_cdp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
302 printf("cdp failed; perhaps not a CISCO switch?\n");
313 "cdp\t- Perform CDP network configuration\n",
315 #endif /* CFG_CMD_CDP */
317 #if (CONFIG_COMMANDS & CFG_CMD_SNTP)
318 int do_sntp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
323 NetNtpServerIP
= getenv_IPaddr ("ntpserverip");
324 if (NetNtpServerIP
== 0) {
325 printf ("ntpserverip not set\n");
329 NetNtpServerIP
= string_to_ip(argv
[1]);
330 if (NetNtpServerIP
== 0) {
331 printf ("Bad NTP server IP address\n");
336 toff
= getenv ("timeoffset");
337 if (toff
== NULL
) NetTimeOffset
= 0;
338 else NetTimeOffset
= simple_strtol (toff
, NULL
, 10);
340 if (NetLoop(SNTP
) < 0) {
341 printf("SNTP failed: host %s not responding\n", argv
[1]);
350 "sntp\t- synchronize RTC via network\n",
353 #endif /* CFG_CMD_SNTP */
355 #endif /* CFG_CMD_NET */