wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Boot support |
| 26 | */ |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 29 | #include <net.h> |
| 30 | |
Simon Glass | d6c5f55 | 2011-10-24 18:00:02 +0000 | [diff] [blame] | 31 | static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 32 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 33 | int do_bootp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 34 | { |
| 35 | return netboot_common (BOOTP, cmdtp, argc, argv); |
| 36 | } |
| 37 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 38 | U_BOOT_CMD( |
| 39 | bootp, 3, 1, do_bootp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 40 | "boot image via network using BOOTP/TFTP protocol", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 41 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 42 | ); |
| 43 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 44 | int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 45 | { |
Simon Glass | 768cbf0 | 2011-12-10 11:08:06 +0000 | [diff] [blame] | 46 | int ret; |
| 47 | |
| 48 | bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start"); |
| 49 | ret = netboot_common(TFTPGET, cmdtp, argc, argv); |
| 50 | bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done"); |
| 51 | return ret; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 52 | } |
| 53 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 54 | U_BOOT_CMD( |
| 55 | tftpboot, 3, 1, do_tftpb, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 56 | "boot image via network using TFTP protocol", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 57 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 58 | ); |
| 59 | |
Simon Glass | 85d96ec | 2011-10-24 18:00:08 +0000 | [diff] [blame] | 60 | #ifdef CONFIG_CMD_TFTPPUT |
| 61 | int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 62 | { |
| 63 | int ret; |
| 64 | |
| 65 | ret = netboot_common(TFTPPUT, cmdtp, argc, argv); |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | U_BOOT_CMD( |
| 70 | tftpput, 4, 1, do_tftpput, |
| 71 | "TFTP put command, for uploading files to a server", |
| 72 | "Address Size [[hostIPaddr:]filename]" |
| 73 | ); |
| 74 | #endif |
| 75 | |
Luca Ceresoli | 7aa81a4 | 2011-05-17 00:03:40 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_CMD_TFTPSRV |
| 77 | static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 78 | { |
| 79 | return netboot_common(TFTPSRV, cmdtp, argc, argv); |
| 80 | } |
| 81 | |
| 82 | U_BOOT_CMD( |
| 83 | tftpsrv, 2, 1, do_tftpsrv, |
| 84 | "act as a TFTP server and boot the first received file", |
| 85 | "[loadAddress]\n" |
| 86 | "Listen for an incoming TFTP transfer, receive a file and boot it.\n" |
| 87 | "The transfer is aborted if a transfer has not been started after\n" |
| 88 | "about 50 seconds or if Ctrl-C is pressed." |
| 89 | ); |
| 90 | #endif |
| 91 | |
| 92 | |
Peter Tyser | f7a48ca | 2010-09-30 11:25:48 -0500 | [diff] [blame] | 93 | #ifdef CONFIG_CMD_RARP |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 94 | int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 95 | { |
| 96 | return netboot_common (RARP, cmdtp, argc, argv); |
| 97 | } |
| 98 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 99 | U_BOOT_CMD( |
| 100 | rarpboot, 3, 1, do_rarpb, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 101 | "boot image via network using RARP/TFTP protocol", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 102 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | ); |
Peter Tyser | f7a48ca | 2010-09-30 11:25:48 -0500 | [diff] [blame] | 104 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 105 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 106 | #if defined(CONFIG_CMD_DHCP) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 107 | int do_dhcp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 108 | { |
| 109 | return netboot_common(DHCP, cmdtp, argc, argv); |
| 110 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 111 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 112 | U_BOOT_CMD( |
| 113 | dhcp, 3, 1, do_dhcp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 114 | "boot image via network using DHCP/TFTP protocol", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 115 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 116 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 117 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 118 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 119 | #if defined(CONFIG_CMD_NFS) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 120 | int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | be9c1cb | 2004-02-24 02:00:03 +0000 | [diff] [blame] | 121 | { |
| 122 | return netboot_common(NFS, cmdtp, argc, argv); |
| 123 | } |
| 124 | |
| 125 | U_BOOT_CMD( |
| 126 | nfs, 3, 1, do_nfs, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 127 | "boot image via network using NFS protocol", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 128 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
wdenk | be9c1cb | 2004-02-24 02:00:03 +0000 | [diff] [blame] | 129 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 130 | #endif |
wdenk | be9c1cb | 2004-02-24 02:00:03 +0000 | [diff] [blame] | 131 | |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 132 | static void netboot_update_env (void) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 133 | { |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 134 | char tmp[22]; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 135 | |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 136 | if (NetOurGatewayIP) { |
| 137 | ip_to_string (NetOurGatewayIP, tmp); |
| 138 | setenv ("gatewayip", tmp); |
| 139 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 140 | |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 141 | if (NetOurSubnetMask) { |
| 142 | ip_to_string (NetOurSubnetMask, tmp); |
| 143 | setenv ("netmask", tmp); |
| 144 | } |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 145 | |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 146 | if (NetOurHostName[0]) |
| 147 | setenv ("hostname", NetOurHostName); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 148 | |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 149 | if (NetOurRootPath[0]) |
| 150 | setenv ("rootpath", NetOurRootPath); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 151 | |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 152 | if (NetOurIP) { |
| 153 | ip_to_string (NetOurIP, tmp); |
| 154 | setenv ("ipaddr", tmp); |
| 155 | } |
Joe Hershberger | d476204 | 2012-05-23 07:59:17 +0000 | [diff] [blame] | 156 | #if !defined(CONFIG_BOOTP_SERVERIP) |
| 157 | /* |
| 158 | * Only attempt to change serverip if net/bootp.c:BootpCopyNetParams() |
| 159 | * could have set it |
| 160 | */ |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 161 | if (NetServerIP) { |
| 162 | ip_to_string (NetServerIP, tmp); |
| 163 | setenv ("serverip", tmp); |
| 164 | } |
Joe Hershberger | d476204 | 2012-05-23 07:59:17 +0000 | [diff] [blame] | 165 | #endif |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 166 | if (NetOurDNSIP) { |
| 167 | ip_to_string (NetOurDNSIP, tmp); |
| 168 | setenv ("dnsip", tmp); |
| 169 | } |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 170 | #if defined(CONFIG_BOOTP_DNS2) |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 171 | if (NetOurDNS2IP) { |
| 172 | ip_to_string (NetOurDNS2IP, tmp); |
| 173 | setenv ("dnsip2", tmp); |
| 174 | } |
stroese | e0aadfb | 2003-08-28 14:17:32 +0000 | [diff] [blame] | 175 | #endif |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 176 | if (NetOurNISDomain[0]) |
| 177 | setenv ("domain", NetOurNISDomain); |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 178 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 179 | #if defined(CONFIG_CMD_SNTP) \ |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 180 | && defined(CONFIG_BOOTP_TIMEOFFSET) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 181 | if (NetTimeOffset) { |
| 182 | sprintf (tmp, "%d", NetTimeOffset); |
| 183 | setenv ("timeoffset", tmp); |
| 184 | } |
| 185 | #endif |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 186 | #if defined(CONFIG_CMD_SNTP) \ |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 187 | && defined(CONFIG_BOOTP_NTPSERVER) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 188 | if (NetNtpServerIP) { |
| 189 | ip_to_string (NetNtpServerIP, tmp); |
| 190 | setenv ("ntpserverip", tmp); |
| 191 | } |
| 192 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 193 | } |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 194 | |
Simon Glass | d6c5f55 | 2011-10-24 18:00:02 +0000 | [diff] [blame] | 195 | static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc, |
| 196 | char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 197 | { |
| 198 | char *s; |
Peter Tyser | 24c297d | 2008-12-02 12:59:51 -0600 | [diff] [blame] | 199 | char *end; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 200 | int rcode = 0; |
| 201 | int size; |
Peter Tyser | 24c297d | 2008-12-02 12:59:51 -0600 | [diff] [blame] | 202 | ulong addr; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 203 | |
| 204 | /* pre-set load_addr */ |
| 205 | if ((s = getenv("loadaddr")) != NULL) { |
| 206 | load_addr = simple_strtoul(s, NULL, 16); |
| 207 | } |
| 208 | |
| 209 | switch (argc) { |
| 210 | case 1: |
| 211 | break; |
| 212 | |
Peter Tyser | 24c297d | 2008-12-02 12:59:51 -0600 | [diff] [blame] | 213 | case 2: /* |
| 214 | * Only one arg - accept two forms: |
| 215 | * Just load address, or just boot file name. The latter |
| 216 | * form must be written in a format which can not be |
| 217 | * mis-interpreted as a valid number. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 218 | */ |
Peter Tyser | 24c297d | 2008-12-02 12:59:51 -0600 | [diff] [blame] | 219 | addr = simple_strtoul(argv[1], &end, 16); |
| 220 | if (end == (argv[1] + strlen(argv[1]))) |
| 221 | load_addr = addr; |
| 222 | else |
| 223 | copy_filename(BootFile, argv[1], sizeof(BootFile)); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 224 | break; |
| 225 | |
| 226 | case 3: load_addr = simple_strtoul(argv[1], NULL, 16); |
| 227 | copy_filename (BootFile, argv[2], sizeof(BootFile)); |
| 228 | |
| 229 | break; |
| 230 | |
Simon Glass | 85d96ec | 2011-10-24 18:00:08 +0000 | [diff] [blame] | 231 | #ifdef CONFIG_CMD_TFTPPUT |
| 232 | case 4: |
Simon Glass | 778fe69 | 2011-12-19 16:10:43 +0000 | [diff] [blame] | 233 | if (strict_strtoul(argv[1], 16, &save_addr) < 0 || |
| 234 | strict_strtoul(argv[2], 16, &save_size) < 0) { |
| 235 | printf("Invalid address/size\n"); |
| 236 | return cmd_usage(cmdtp); |
| 237 | } |
Simon Glass | 85d96ec | 2011-10-24 18:00:08 +0000 | [diff] [blame] | 238 | copy_filename(BootFile, argv[3], sizeof(BootFile)); |
| 239 | break; |
| 240 | #endif |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 241 | default: |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 242 | bootstage_error(BOOTSTAGE_ID_NET_START); |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 243 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 244 | } |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 245 | bootstage_mark(BOOTSTAGE_ID_NET_START); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 246 | |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 247 | if ((size = NetLoop(proto)) < 0) { |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 248 | bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 249 | return 1; |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 250 | } |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 251 | bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 252 | |
| 253 | /* NetLoop ok, update environment */ |
| 254 | netboot_update_env(); |
| 255 | |
wdenk | c217f6d | 2002-11-11 02:11:37 +0000 | [diff] [blame] | 256 | /* done if no file was loaded (no errors though) */ |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 257 | if (size == 0) { |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 258 | bootstage_error(BOOTSTAGE_ID_NET_LOADED); |
wdenk | c217f6d | 2002-11-11 02:11:37 +0000 | [diff] [blame] | 259 | return 0; |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 260 | } |
wdenk | c217f6d | 2002-11-11 02:11:37 +0000 | [diff] [blame] | 261 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 262 | /* flush cache */ |
| 263 | flush_cache(load_addr, size); |
| 264 | |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 265 | bootstage_mark(BOOTSTAGE_ID_NET_LOADED); |
Simon Glass | 964d1d4 | 2012-01-14 15:24:52 +0000 | [diff] [blame] | 266 | |
Mike Frysinger | 194c2e8 | 2011-06-05 13:43:02 +0000 | [diff] [blame] | 267 | rcode = bootm_maybe_autostart(cmdtp, argv[0]); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 268 | |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 269 | if (rcode < 0) |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 270 | bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR); |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 271 | else |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 272 | bootstage_mark(BOOTSTAGE_ID_NET_DONE); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 273 | return rcode; |
| 274 | } |
wdenk | e6466f6 | 2003-06-05 19:27:42 +0000 | [diff] [blame] | 275 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 276 | #if defined(CONFIG_CMD_PING) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 277 | int do_ping (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | e6466f6 | 2003-06-05 19:27:42 +0000 | [diff] [blame] | 278 | { |
| 279 | if (argc < 2) |
| 280 | return -1; |
| 281 | |
| 282 | NetPingIP = string_to_ip(argv[1]); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 283 | if (NetPingIP == 0) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 284 | return CMD_RET_USAGE; |
wdenk | e6466f6 | 2003-06-05 19:27:42 +0000 | [diff] [blame] | 285 | |
| 286 | if (NetLoop(PING) < 0) { |
| 287 | printf("ping failed; host %s is not alive\n", argv[1]); |
| 288 | return 1; |
| 289 | } |
| 290 | |
| 291 | printf("host %s is alive\n", argv[1]); |
| 292 | |
| 293 | return 0; |
| 294 | } |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 295 | |
| 296 | U_BOOT_CMD( |
| 297 | ping, 2, 1, do_ping, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 298 | "send ICMP ECHO_REQUEST to network host", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 299 | "pingAddress" |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 300 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 301 | #endif |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 302 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 303 | #if defined(CONFIG_CMD_CDP) |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 304 | |
| 305 | static void cdp_update_env(void) |
| 306 | { |
| 307 | char tmp[16]; |
| 308 | |
| 309 | if (CDPApplianceVLAN != htons(-1)) { |
| 310 | printf("CDP offered appliance VLAN %d\n", ntohs(CDPApplianceVLAN)); |
| 311 | VLAN_to_string(CDPApplianceVLAN, tmp); |
| 312 | setenv("vlan", tmp); |
| 313 | NetOurVLAN = CDPApplianceVLAN; |
| 314 | } |
| 315 | |
| 316 | if (CDPNativeVLAN != htons(-1)) { |
| 317 | printf("CDP offered native VLAN %d\n", ntohs(CDPNativeVLAN)); |
| 318 | VLAN_to_string(CDPNativeVLAN, tmp); |
| 319 | setenv("nvlan", tmp); |
| 320 | NetOurNativeVLAN = CDPNativeVLAN; |
| 321 | } |
| 322 | |
| 323 | } |
| 324 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 325 | int do_cdp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 326 | { |
| 327 | int r; |
| 328 | |
| 329 | r = NetLoop(CDP); |
| 330 | if (r < 0) { |
| 331 | printf("cdp failed; perhaps not a CISCO switch?\n"); |
| 332 | return 1; |
| 333 | } |
| 334 | |
| 335 | cdp_update_env(); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | U_BOOT_CMD( |
| 341 | cdp, 1, 1, do_cdp, |
Wolfgang Denk | d29afc3 | 2010-10-26 23:42:23 +0200 | [diff] [blame] | 342 | "Perform CDP network configuration", |
Wolfgang Denk | f003d92 | 2010-12-23 17:02:18 +0100 | [diff] [blame] | 343 | "\n" |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 344 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 345 | #endif |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 346 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 347 | #if defined(CONFIG_CMD_SNTP) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 348 | int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 349 | { |
| 350 | char *toff; |
| 351 | |
| 352 | if (argc < 2) { |
| 353 | NetNtpServerIP = getenv_IPaddr ("ntpserverip"); |
| 354 | if (NetNtpServerIP == 0) { |
| 355 | printf ("ntpserverip not set\n"); |
| 356 | return (1); |
| 357 | } |
| 358 | } else { |
| 359 | NetNtpServerIP = string_to_ip(argv[1]); |
| 360 | if (NetNtpServerIP == 0) { |
| 361 | printf ("Bad NTP server IP address\n"); |
| 362 | return (1); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | toff = getenv ("timeoffset"); |
| 367 | if (toff == NULL) NetTimeOffset = 0; |
| 368 | else NetTimeOffset = simple_strtol (toff, NULL, 10); |
| 369 | |
| 370 | if (NetLoop(SNTP) < 0) { |
Luuk Paulussen | 7cb3f89 | 2011-05-16 18:27:11 +0000 | [diff] [blame] | 371 | printf("SNTP failed: host %pI4 not responding\n", |
| 372 | &NetNtpServerIP); |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 373 | return 1; |
| 374 | } |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | U_BOOT_CMD( |
| 380 | sntp, 2, 1, do_sntp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 381 | "synchronize RTC via network", |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 382 | "[NTP server IP]\n" |
| 383 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 384 | #endif |
Robin Getz | 82f0d23 | 2009-07-20 14:53:54 -0400 | [diff] [blame] | 385 | |
| 386 | #if defined(CONFIG_CMD_DNS) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 387 | int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Robin Getz | 82f0d23 | 2009-07-20 14:53:54 -0400 | [diff] [blame] | 388 | { |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 389 | if (argc == 1) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 390 | return CMD_RET_USAGE; |
Robin Getz | 82f0d23 | 2009-07-20 14:53:54 -0400 | [diff] [blame] | 391 | |
| 392 | /* |
| 393 | * We should check for a valid hostname: |
| 394 | * - Each label must be between 1 and 63 characters long |
| 395 | * - the entire hostname has a maximum of 255 characters |
| 396 | * - only the ASCII letters 'a' through 'z' (case-insensitive), |
| 397 | * the digits '0' through '9', and the hyphen |
| 398 | * - cannot begin or end with a hyphen |
| 399 | * - no other symbols, punctuation characters, or blank spaces are |
| 400 | * permitted |
| 401 | * but hey - this is a minimalist implmentation, so only check length |
| 402 | * and let the name server deal with things. |
| 403 | */ |
| 404 | if (strlen(argv[1]) >= 255) { |
| 405 | printf("dns error: hostname too long\n"); |
| 406 | return 1; |
| 407 | } |
| 408 | |
| 409 | NetDNSResolve = argv[1]; |
| 410 | |
| 411 | if (argc == 3) |
| 412 | NetDNSenvvar = argv[2]; |
| 413 | else |
| 414 | NetDNSenvvar = NULL; |
| 415 | |
| 416 | if (NetLoop(DNS) < 0) { |
| 417 | printf("dns lookup of %s failed, check setup\n", argv[1]); |
| 418 | return 1; |
| 419 | } |
| 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | U_BOOT_CMD( |
| 425 | dns, 3, 1, do_dns, |
| 426 | "lookup the IP of a hostname", |
| 427 | "hostname [envvar]" |
| 428 | ); |
| 429 | |
| 430 | #endif /* CONFIG_CMD_DNS */ |
Joe Hershberger | b35a3a6 | 2012-05-23 08:00:12 +0000 | [diff] [blame] | 431 | |
| 432 | #if defined(CONFIG_CMD_LINK_LOCAL) |
| 433 | static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc, |
| 434 | char * const argv[]) |
| 435 | { |
| 436 | char tmp[22]; |
| 437 | |
| 438 | if (NetLoop(LINKLOCAL) < 0) |
| 439 | return 1; |
| 440 | |
| 441 | NetOurGatewayIP = 0; |
| 442 | ip_to_string(NetOurGatewayIP, tmp); |
| 443 | setenv("gatewayip", tmp); |
| 444 | |
| 445 | ip_to_string(NetOurSubnetMask, tmp); |
| 446 | setenv("netmask", tmp); |
| 447 | |
| 448 | ip_to_string(NetOurIP, tmp); |
| 449 | setenv("ipaddr", tmp); |
| 450 | setenv("llipaddr", tmp); /* store this for next time */ |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | U_BOOT_CMD( |
| 456 | linklocal, 1, 1, do_link_local, |
| 457 | "acquire a network IP address using the link-local protocol", |
| 458 | "" |
| 459 | ); |
| 460 | |
| 461 | #endif /* CONFIG_CMD_LINK_LOCAL */ |