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,
29 #include <cmd_autoscript.h>
32 #if (CONFIG_COMMANDS & CFG_CMD_NET)
35 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
37 static int netboot_common (int, cmd_tbl_t *, int , char *[]);
39 int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
41 return netboot_common (BOOTP, cmdtp, argc, argv);
44 cmd_tbl_t U_BOOT_CMD(BOOTP) = MK_CMD_ENTRY(
45 "bootp", 3, 1, do_bootp,
46 "bootp - boot image via network using BootP/TFTP protocol\n",
47 "[loadAddress] [bootfilename]\n"
50 int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
52 return netboot_common (TFTP, cmdtp, argc, argv);
55 cmd_tbl_t U_BOOT_CMD(TFTPB) = MK_CMD_ENTRY(
56 "tftpboot", 3, 1, do_tftpb,
57 "tftpboot- boot image via network using TFTP protocol\n",
58 "[loadAddress] [bootfilename]\n"
61 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
63 return netboot_common (RARP, cmdtp, argc, argv);
66 cmd_tbl_t U_BOOT_CMD(RARPB) = MK_CMD_ENTRY(
67 "rarpboot", 3, 1, do_rarpb,
68 "rarpboot- boot image via network using RARP/TFTP protocol\n",
69 "[loadAddress] [bootfilename]\n"
72 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
73 int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
75 return netboot_common(DHCP, cmdtp, argc, argv);
78 cmd_tbl_t U_BOOT_CMD(DHCP) = MK_CMD_ENTRY(
79 "dhcp", 3, 1, do_dhcp,
80 "dhcp - invoke DHCP client to obtain IP/boot params\n",
83 #endif /* CFG_CMD_DHCP */
85 static void netboot_update_env(void)
89 if (NetOurGatewayIP) {
90 ip_to_string (NetOurGatewayIP, tmp);
91 setenv("gatewayip", tmp);
94 if (NetOurSubnetMask) {
95 ip_to_string (NetOurSubnetMask, tmp);
96 setenv("netmask", tmp);
99 if (NetOurHostName[0])
100 setenv("hostname", NetOurHostName);
102 if (NetOurRootPath[0])
103 setenv("rootpath", NetOurRootPath);
106 ip_to_string (NetOurIP, tmp);
107 setenv("ipaddr", tmp);
111 ip_to_string (NetServerIP, tmp);
112 setenv("serverip", tmp);
116 ip_to_string (NetOurDNSIP, tmp);
117 setenv("dnsip", tmp);
120 if (NetOurNISDomain[0])
121 setenv("domain", NetOurNISDomain);
125 netboot_common (int proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
131 /* pre-set load_addr */
132 if ((s = getenv("loadaddr")) != NULL) {
133 load_addr = simple_strtoul(s, NULL, 16);
140 case 2: /* only one arg - accept two forms:
141 * just load address, or just boot file name.
142 * The latter form must be written "filename" here.
144 if (argv[1][0] == '"') { /* just boot filename */
145 copy_filename (BootFile, argv[1], sizeof(BootFile));
146 } else { /* load address */
147 load_addr = simple_strtoul(argv[1], NULL, 16);
151 case 3: load_addr = simple_strtoul(argv[1], NULL, 16);
152 copy_filename (BootFile, argv[2], sizeof(BootFile));
156 default: printf ("Usage:\n%s\n", cmdtp->usage);
160 if ((size = NetLoop(proto)) < 0)
163 /* NetLoop ok, update environment */
164 netboot_update_env();
166 /* done if no file was loaded (no errors though) */
171 flush_cache(load_addr, size);
173 /* Loading ok, check if we should attempt an auto-start */
174 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
176 local_args[0] = argv[0];
177 local_args[1] = NULL;
179 printf ("Automatic boot of image at addr 0x%08lX ...\n",
181 rcode = do_bootm (cmdtp, 0, 1, local_args);
184 #ifdef CONFIG_AUTOSCRIPT
185 if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) {
186 printf("Running autoscript at addr 0x%08lX ...\n", load_addr);
187 rcode = autoscript (load_addr);
193 #if (CONFIG_COMMANDS & CFG_CMD_PING)
194 int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
199 NetPingIP = string_to_ip(argv[1]);
200 if (NetPingIP == 0) {
201 printf ("Usage:\n%s\n", cmdtp->usage);
205 if (NetLoop(PING) < 0) {
206 printf("ping failed; host %s is not alive\n", argv[1]);
210 printf("host %s is alive\n", argv[1]);
214 #endif /* CFG_CMD_PING */
216 #endif /* CFG_CMD_NET */