]>
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 extern int do_bootm (cmd_tbl_t
*, int, int, char *[]);
33 static int netboot_common (proto_t
, cmd_tbl_t
*, int , char *[]);
35 int do_bootp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
37 return netboot_common (BOOTP
, cmdtp
, argc
, argv
);
41 bootp
, 3, 1, do_bootp
,
42 "bootp\t- boot image via network using BootP/TFTP protocol\n",
43 "[loadAddress] [bootfilename]\n"
46 int do_tftpb (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
48 return netboot_common (TFTP
, cmdtp
, argc
, argv
);
52 tftpboot
, 3, 1, do_tftpb
,
53 "tftpboot- boot image via network using TFTP protocol\n",
54 "[loadAddress] [bootfilename]\n"
57 int do_rarpb (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
59 return netboot_common (RARP
, cmdtp
, argc
, argv
);
63 rarpboot
, 3, 1, do_rarpb
,
64 "rarpboot- boot image via network using RARP/TFTP protocol\n",
65 "[loadAddress] [bootfilename]\n"
68 #if defined(CONFIG_CMD_DHCP)
69 int do_dhcp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
71 return netboot_common(DHCP
, cmdtp
, argc
, argv
);
76 "dhcp\t- invoke DHCP client to obtain IP/boot params\n",
81 #if defined(CONFIG_CMD_NFS)
82 int do_nfs (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
84 return netboot_common(NFS
, cmdtp
, argc
, argv
);
89 "nfs\t- boot image via network using NFS protocol\n",
90 "[loadAddress] [host ip addr:bootfilename]\n"
94 static void netboot_update_env (void)
98 if (NetOurGatewayIP
) {
99 ip_to_string (NetOurGatewayIP
, tmp
);
100 setenv ("gatewayip", tmp
);
103 if (NetOurSubnetMask
) {
104 ip_to_string (NetOurSubnetMask
, tmp
);
105 setenv ("netmask", tmp
);
108 if (NetOurHostName
[0])
109 setenv ("hostname", NetOurHostName
);
111 if (NetOurRootPath
[0])
112 setenv ("rootpath", NetOurRootPath
);
115 ip_to_string (NetOurIP
, tmp
);
116 setenv ("ipaddr", tmp
);
120 ip_to_string (NetServerIP
, tmp
);
121 setenv ("serverip", tmp
);
125 ip_to_string (NetOurDNSIP
, tmp
);
126 setenv ("dnsip", tmp
);
128 #if defined(CONFIG_BOOTP_DNS2)
130 ip_to_string (NetOurDNS2IP
, tmp
);
131 setenv ("dnsip2", tmp
);
134 if (NetOurNISDomain
[0])
135 setenv ("domain", NetOurNISDomain
);
137 #if defined(CONFIG_CMD_SNTP) \
138 && defined(CONFIG_BOOTP_TIMEOFFSET)
140 sprintf (tmp
, "%d", NetTimeOffset
);
141 setenv ("timeoffset", tmp
);
144 #if defined(CONFIG_CMD_SNTP) \
145 && defined(CONFIG_BOOTP_NTPSERVER)
146 if (NetNtpServerIP
) {
147 ip_to_string (NetNtpServerIP
, tmp
);
148 setenv ("ntpserverip", tmp
);
154 netboot_common (proto_t proto
, cmd_tbl_t
*cmdtp
, int argc
, char *argv
[])
160 /* pre-set load_addr */
161 if ((s
= getenv("loadaddr")) != NULL
) {
162 load_addr
= simple_strtoul(s
, NULL
, 16);
169 case 2: /* only one arg - accept two forms:
170 * just load address, or just boot file name.
171 * The latter form must be written "filename" here.
173 if (argv
[1][0] == '"') { /* just boot filename */
174 copy_filename (BootFile
, argv
[1], sizeof(BootFile
));
175 } else { /* load address */
176 load_addr
= simple_strtoul(argv
[1], NULL
, 16);
180 case 3: load_addr
= simple_strtoul(argv
[1], NULL
, 16);
181 copy_filename (BootFile
, argv
[2], sizeof(BootFile
));
185 default: printf ("Usage:\n%s\n", cmdtp
->usage
);
186 show_boot_progress (-80);
190 show_boot_progress (80);
191 if ((size
= NetLoop(proto
)) < 0) {
192 show_boot_progress (-81);
196 show_boot_progress (81);
197 /* NetLoop ok, update environment */
198 netboot_update_env();
200 /* done if no file was loaded (no errors though) */
202 show_boot_progress (-82);
207 flush_cache(load_addr
, size
);
209 /* Loading ok, check if we should attempt an auto-start */
210 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
,"yes") == 0)) {
212 local_args
[0] = argv
[0];
213 local_args
[1] = NULL
;
215 printf ("Automatic boot of image at addr 0x%08lX ...\n",
217 show_boot_progress (82);
218 rcode
= do_bootm (cmdtp
, 0, 1, local_args
);
221 #ifdef CONFIG_AUTOSCRIPT
222 if (((s
= getenv("autoscript")) != NULL
) && (strcmp(s
,"yes") == 0)) {
223 printf("Running autoscript at addr 0x%08lX ...\n", load_addr
);
224 show_boot_progress (83);
225 rcode
= autoscript (load_addr
);
229 show_boot_progress (-83);
231 show_boot_progress (84);
235 #if defined(CONFIG_CMD_PING)
236 int do_ping (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
241 NetPingIP
= string_to_ip(argv
[1]);
242 if (NetPingIP
== 0) {
243 printf ("Usage:\n%s\n", cmdtp
->usage
);
247 if (NetLoop(PING
) < 0) {
248 printf("ping failed; host %s is not alive\n", argv
[1]);
252 printf("host %s is alive\n", argv
[1]);
259 "ping\t- send ICMP ECHO_REQUEST to network host\n",
264 #if defined(CONFIG_CMD_CDP)
266 static void cdp_update_env(void)
270 if (CDPApplianceVLAN
!= htons(-1)) {
271 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN
));
272 VLAN_to_string(CDPApplianceVLAN
, tmp
);
274 NetOurVLAN
= CDPApplianceVLAN
;
277 if (CDPNativeVLAN
!= htons(-1)) {
278 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN
));
279 VLAN_to_string(CDPNativeVLAN
, tmp
);
280 setenv("nvlan", tmp
);
281 NetOurNativeVLAN
= CDPNativeVLAN
;
286 int do_cdp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
292 printf("cdp failed; perhaps not a CISCO switch?\n");
303 "cdp\t- Perform CDP network configuration\n",
307 #if defined(CONFIG_CMD_SNTP)
308 int do_sntp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
313 NetNtpServerIP
= getenv_IPaddr ("ntpserverip");
314 if (NetNtpServerIP
== 0) {
315 printf ("ntpserverip not set\n");
319 NetNtpServerIP
= string_to_ip(argv
[1]);
320 if (NetNtpServerIP
== 0) {
321 printf ("Bad NTP server IP address\n");
326 toff
= getenv ("timeoffset");
327 if (toff
== NULL
) NetTimeOffset
= 0;
328 else NetTimeOffset
= simple_strtol (toff
, NULL
, 10);
330 if (NetLoop(SNTP
) < 0) {
331 printf("SNTP failed: host %s not responding\n", argv
[1]);
340 "sntp\t- synchronize RTC via network\n",