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