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)
34 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
36 static int netboot_common (int, 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 - 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 (CONFIG_COMMANDS & CFG_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 - invoke DHCP client to obtain IP/boot params\n",
82 #endif /* CFG_CMD_DHCP */
84 static void netboot_update_env(void)
88 if (NetOurGatewayIP) {
89 ip_to_string (NetOurGatewayIP, tmp);
90 setenv("gatewayip", tmp);
93 if (NetOurSubnetMask) {
94 ip_to_string (NetOurSubnetMask, tmp);
95 setenv("netmask", tmp);
98 if (NetOurHostName[0])
99 setenv("hostname", NetOurHostName);
101 if (NetOurRootPath[0])
102 setenv("rootpath", NetOurRootPath);
105 ip_to_string (NetOurIP, tmp);
106 setenv("ipaddr", tmp);
110 ip_to_string (NetServerIP, tmp);
111 setenv("serverip", tmp);
115 ip_to_string (NetOurDNSIP, tmp);
116 setenv("dnsip", tmp);
119 if (NetOurNISDomain[0])
120 setenv("domain", NetOurNISDomain);
124 netboot_common (int proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
130 /* pre-set load_addr */
131 if ((s = getenv("loadaddr")) != NULL) {
132 load_addr = simple_strtoul(s, NULL, 16);
139 case 2: /* only one arg - accept two forms:
140 * just load address, or just boot file name.
141 * The latter form must be written "filename" here.
143 if (argv[1][0] == '"') { /* just boot filename */
144 copy_filename (BootFile, argv[1], sizeof(BootFile));
145 } else { /* load address */
146 load_addr = simple_strtoul(argv[1], NULL, 16);
150 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
151 copy_filename (BootFile, argv[2], sizeof(BootFile));
155 default: printf ("Usage:\n%s\n", cmdtp->usage);
159 if ((size = NetLoop(proto)) < 0)
162 /* NetLoop ok, update environment */
163 netboot_update_env();
165 /* done if no file was loaded (no errors though) */
170 flush_cache(load_addr, size);
172 /* Loading ok, check if we should attempt an auto-start */
173 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
175 local_args[0] = argv[0];
176 local_args[1] = NULL;
178 printf ("Automatic boot of image at addr 0x%08lX ...\n",
180 rcode = do_bootm (cmdtp, 0, 1, local_args);
183 #ifdef CONFIG_AUTOSCRIPT
184 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
185 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
186 rcode = autoscript (load_addr);
192 #if (CONFIG_COMMANDS & CFG_CMD_PING)
193 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
198 NetPingIP = string_to_ip(argv[1]);
199 if (NetPingIP == 0) {
200 printf ("Usage:\n%s\n", cmdtp->usage);
204 if (NetLoop(PING) < 0) {
205 printf("ping failed; host %s is not alive\n", argv[1]);
209 printf("host %s is alive\n", argv[1]);
213 #endif /* CFG_CMD_PING */
215 #endif /* CFG_CMD_NET */