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