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