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