]>
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 "boot image via network using BOOTP/TFTP protocol",
43 "[loadAddress] [[hostIPaddr:]bootfilename]"
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 "boot image via network using TFTP protocol",
54 "[loadAddress] [[hostIPaddr:]bootfilename]"
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 "boot image via network using RARP/TFTP protocol",
65 "[loadAddress] [[hostIPaddr:]bootfilename]"
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 "boot image via network using DHCP/TFTP protocol",
77 "[loadAddress] [[hostIPaddr:]bootfilename]"
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 "boot image via network using NFS protocol",
90 "[loadAddress] [[hostIPaddr:]bootfilename]"
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
[])
162 /* pre-set load_addr */
163 if ((s
= getenv("loadaddr")) != NULL
) {
164 load_addr
= simple_strtoul(s
, NULL
, 16);
172 * Only one arg - accept two forms:
173 * Just load address, or just boot file name. The latter
174 * form must be written in a format which can not be
175 * mis-interpreted as a valid number.
177 addr
= simple_strtoul(argv
[1], &end
, 16);
178 if (end
== (argv
[1] + strlen(argv
[1])))
181 copy_filename(BootFile
, argv
[1], sizeof(BootFile
));
184 case 3: load_addr
= simple_strtoul(argv
[1], NULL
, 16);
185 copy_filename (BootFile
, argv
[2], sizeof(BootFile
));
189 default: cmd_usage(cmdtp
);
190 show_boot_progress (-80);
194 show_boot_progress (80);
195 if ((size
= NetLoop(proto
)) < 0) {
196 show_boot_progress (-81);
200 show_boot_progress (81);
201 /* NetLoop ok, update environment */
202 netboot_update_env();
204 /* done if no file was loaded (no errors though) */
206 show_boot_progress (-82);
211 flush_cache(load_addr
, size
);
213 /* Loading ok, check if we should attempt an auto-start */
214 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
,"yes") == 0)) {
216 local_args
[0] = argv
[0];
217 local_args
[1] = NULL
;
219 printf ("Automatic boot of image at addr 0x%08lX ...\n",
221 show_boot_progress (82);
222 rcode
= do_bootm (cmdtp
, 0, 1, local_args
);
226 if (((s
= getenv("autoscript")) != NULL
) && (strcmp(s
,"yes") == 0)) {
227 printf ("Running \"source\" command at addr 0x%08lX",
230 s
= getenv ("autoscript_uname");
232 printf (":%s ...\n", s
);
236 show_boot_progress (83);
237 rcode
= source (load_addr
, s
);
241 show_boot_progress (-83);
243 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) {
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 "send ICMP ECHO_REQUEST to network host",
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 "Perform CDP network configuration",
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 "synchronize RTC via network",
357 #if defined(CONFIG_CMD_DNS)
358 int do_dns(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
366 * We should check for a valid hostname:
367 * - Each label must be between 1 and 63 characters long
368 * - the entire hostname has a maximum of 255 characters
369 * - only the ASCII letters 'a' through 'z' (case-insensitive),
370 * the digits '0' through '9', and the hyphen
371 * - cannot begin or end with a hyphen
372 * - no other symbols, punctuation characters, or blank spaces are
374 * but hey - this is a minimalist implmentation, so only check length
375 * and let the name server deal with things.
377 if (strlen(argv
[1]) >= 255) {
378 printf("dns error: hostname too long\n");
382 NetDNSResolve
= argv
[1];
385 NetDNSenvvar
= argv
[2];
389 if (NetLoop(DNS
) < 0) {
390 printf("dns lookup of %s failed, check setup\n", argv
[1]);
399 "lookup the IP of a hostname",
403 #endif /* CONFIG_CMD_DNS */