]>
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 defined(CONFIG_CMD_NET)
34 extern int do_bootm (cmd_tbl_t
*, int, int, char *[]);
36 static int netboot_common (proto_t
, cmd_tbl_t
*, int , char *[]);
38 int do_bootp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
40 return netboot_common (BOOTP
, cmdtp
, argc
, argv
);
44 bootp
, 3, 1, do_bootp
,
45 "bootp\t- boot image via network using BootP/TFTP protocol\n",
46 "[loadAddress] [bootfilename]\n"
49 int do_tftpb (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
51 return netboot_common (TFTP
, cmdtp
, argc
, argv
);
55 tftpboot
, 3, 1, do_tftpb
,
56 "tftpboot- boot image via network using TFTP protocol\n",
57 "[loadAddress] [bootfilename]\n"
60 int do_rarpb (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
62 return netboot_common (RARP
, cmdtp
, argc
, argv
);
66 rarpboot
, 3, 1, do_rarpb
,
67 "rarpboot- boot image via network using RARP/TFTP protocol\n",
68 "[loadAddress] [bootfilename]\n"
71 #if defined(CONFIG_CMD_DHCP)
72 int do_dhcp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
74 return netboot_common(DHCP
, cmdtp
, argc
, argv
);
79 "dhcp\t- invoke DHCP client to obtain IP/boot params\n",
82 #endif /* CFG_CMD_DHCP */
84 #if defined(CONFIG_CMD_NFS)
85 int do_nfs (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
87 return netboot_common(NFS
, cmdtp
, argc
, argv
);
92 "nfs\t- boot image via network using NFS protocol\n",
93 "[loadAddress] [host ip addr:bootfilename]\n"
95 #endif /* CFG_CMD_NFS */
97 static void netboot_update_env (void)
101 if (NetOurGatewayIP
) {
102 ip_to_string (NetOurGatewayIP
, tmp
);
103 setenv ("gatewayip", tmp
);
106 if (NetOurSubnetMask
) {
107 ip_to_string (NetOurSubnetMask
, tmp
);
108 setenv ("netmask", tmp
);
111 if (NetOurHostName
[0])
112 setenv ("hostname", NetOurHostName
);
114 if (NetOurRootPath
[0])
115 setenv ("rootpath", NetOurRootPath
);
118 ip_to_string (NetOurIP
, tmp
);
119 setenv ("ipaddr", tmp
);
123 ip_to_string (NetServerIP
, tmp
);
124 setenv ("serverip", tmp
);
128 ip_to_string (NetOurDNSIP
, tmp
);
129 setenv ("dnsip", tmp
);
131 #if defined(CONFIG_BOOTP_DNS2)
133 ip_to_string (NetOurDNS2IP
, tmp
);
134 setenv ("dnsip2", tmp
);
137 if (NetOurNISDomain
[0])
138 setenv ("domain", NetOurNISDomain
);
140 #if defined(CONFIG_CMD_SNTP) \
141 && defined(CONFIG_BOOTP_TIMEOFFSET)
143 sprintf (tmp
, "%d", NetTimeOffset
);
144 setenv ("timeoffset", tmp
);
147 #if defined(CONFIG_CMD_SNTP) \
148 && defined(CONFIG_BOOTP_NTPSERVER)
149 if (NetNtpServerIP
) {
150 ip_to_string (NetNtpServerIP
, tmp
);
151 setenv ("ntpserverip", tmp
);
157 netboot_common (proto_t proto
, cmd_tbl_t
*cmdtp
, int argc
, char *argv
[])
163 /* pre-set load_addr */
164 if ((s
= getenv("loadaddr")) != NULL
) {
165 load_addr
= simple_strtoul(s
, NULL
, 16);
172 case 2: /* only one arg - accept two forms:
173 * just load address, or just boot file name.
174 * The latter form must be written "filename" here.
176 if (argv
[1][0] == '"') { /* just boot filename */
177 copy_filename (BootFile
, argv
[1], sizeof(BootFile
));
178 } else { /* load address */
179 load_addr
= simple_strtoul(argv
[1], NULL
, 16);
183 case 3: load_addr
= simple_strtoul(argv
[1], NULL
, 16);
184 copy_filename (BootFile
, argv
[2], sizeof(BootFile
));
188 default: printf ("Usage:\n%s\n", cmdtp
->usage
);
192 if ((size
= NetLoop(proto
)) < 0)
195 /* NetLoop ok, update environment */
196 netboot_update_env();
198 /* done if no file was loaded (no errors though) */
203 flush_cache(load_addr
, size
);
205 /* Loading ok, check if we should attempt an auto-start */
206 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
,"yes") == 0)) {
208 local_args
[0] = argv
[0];
209 local_args
[1] = NULL
;
211 printf ("Automatic boot of image at addr 0x%08lX ...\n",
213 rcode
= do_bootm (cmdtp
, 0, 1, local_args
);
216 #ifdef CONFIG_AUTOSCRIPT
217 if (((s
= getenv("autoscript")) != NULL
) && (strcmp(s
,"yes") == 0)) {
218 printf("Running autoscript at addr 0x%08lX ...\n", load_addr
);
219 rcode
= autoscript (load_addr
);
225 #if defined(CONFIG_CMD_PING)
226 int do_ping (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
231 NetPingIP
= string_to_ip(argv
[1]);
232 if (NetPingIP
== 0) {
233 printf ("Usage:\n%s\n", cmdtp
->usage
);
237 if (NetLoop(PING
) < 0) {
238 printf("ping failed; host %s is not alive\n", argv
[1]);
242 printf("host %s is alive\n", argv
[1]);
249 "ping\t- send ICMP ECHO_REQUEST to network host\n",
252 #endif /* CFG_CMD_PING */
254 #if defined(CONFIG_CMD_CDP)
256 static void cdp_update_env(void)
260 if (CDPApplianceVLAN
!= htons(-1)) {
261 printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN
));
262 VLAN_to_string(CDPApplianceVLAN
, tmp
);
264 NetOurVLAN
= CDPApplianceVLAN
;
267 if (CDPNativeVLAN
!= htons(-1)) {
268 printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN
));
269 VLAN_to_string(CDPNativeVLAN
, tmp
);
270 setenv("nvlan", tmp
);
271 NetOurNativeVLAN
= CDPNativeVLAN
;
276 int do_cdp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
282 printf("cdp failed; perhaps not a CISCO switch?\n");
293 "cdp\t- Perform CDP network configuration\n",
295 #endif /* CFG_CMD_CDP */
297 #if defined(CONFIG_CMD_SNTP)
298 int do_sntp (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
303 NetNtpServerIP
= getenv_IPaddr ("ntpserverip");
304 if (NetNtpServerIP
== 0) {
305 printf ("ntpserverip not set\n");
309 NetNtpServerIP
= string_to_ip(argv
[1]);
310 if (NetNtpServerIP
== 0) {
311 printf ("Bad NTP server IP address\n");
316 toff
= getenv ("timeoffset");
317 if (toff
== NULL
) NetTimeOffset
= 0;
318 else NetTimeOffset
= simple_strtol (toff
, NULL
, 10);
320 if (NetLoop(SNTP
) < 0) {
321 printf("SNTP failed: host %s not responding\n", argv
[1]);
330 "sntp\t- synchronize RTC via network\n",
333 #endif /* CFG_CMD_SNTP */
335 #endif /* CFG_CMD_NET */