blob: 1b724cc57090e7ab81eecf750c48157d1fa57ce8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
7/*
8 * Boot support
9 */
10#include <common.h>
11#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Simon Glass85f13782019-12-28 10:45:03 -070013#include <image.h>
wdenk38635852002-08-27 05:55:31 +000014#include <net.h>
15
Simon Glassd6c5f552011-10-24 18:00:02 +000016static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
wdenk38635852002-08-27 05:55:31 +000017
Joe Hershbergerb0429462018-04-13 15:26:30 -050018#ifdef CONFIG_CMD_BOOTP
Kim Phillipsdc00a682012-10-29 13:34:31 +000019static int do_bootp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000020{
Kim Phillipsdc00a682012-10-29 13:34:31 +000021 return netboot_common(BOOTP, cmdtp, argc, argv);
wdenk38635852002-08-27 05:55:31 +000022}
23
wdenkf287a242003-07-01 21:06:45 +000024U_BOOT_CMD(
25 bootp, 3, 1, do_bootp,
Peter Tyserdfb72b82009-01-27 18:03:12 -060026 "boot image via network using BOOTP/TFTP protocol",
Wolfgang Denkc54781c2009-05-24 17:06:54 +020027 "[loadAddress] [[hostIPaddr:]bootfilename]"
wdenk57b2d802003-06-27 21:31:46 +000028);
Joe Hershbergerb0429462018-04-13 15:26:30 -050029#endif
wdenk57b2d802003-06-27 21:31:46 +000030
Joe Hershbergerb0429462018-04-13 15:26:30 -050031#ifdef CONFIG_CMD_TFTPBOOT
Kim Phillipsdc00a682012-10-29 13:34:31 +000032int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000033{
Simon Glass768cbf02011-12-10 11:08:06 +000034 int ret;
35
36 bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
37 ret = netboot_common(TFTPGET, cmdtp, argc, argv);
38 bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
39 return ret;
wdenk38635852002-08-27 05:55:31 +000040}
41
wdenkf287a242003-07-01 21:06:45 +000042U_BOOT_CMD(
43 tftpboot, 3, 1, do_tftpb,
Peter Tyserdfb72b82009-01-27 18:03:12 -060044 "boot image via network using TFTP protocol",
Wolfgang Denkc54781c2009-05-24 17:06:54 +020045 "[loadAddress] [[hostIPaddr:]bootfilename]"
wdenk57b2d802003-06-27 21:31:46 +000046);
Joe Hershbergerb0429462018-04-13 15:26:30 -050047#endif
wdenk57b2d802003-06-27 21:31:46 +000048
Simon Glass85d96ec2011-10-24 18:00:08 +000049#ifdef CONFIG_CMD_TFTPPUT
Masahiro Yamada3dcd7142017-06-22 16:49:10 +090050static int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Simon Glass85d96ec2011-10-24 18:00:08 +000051{
Joe Hershbergerba867832015-03-22 17:09:09 -050052 return netboot_common(TFTPPUT, cmdtp, argc, argv);
Simon Glass85d96ec2011-10-24 18:00:08 +000053}
54
55U_BOOT_CMD(
56 tftpput, 4, 1, do_tftpput,
57 "TFTP put command, for uploading files to a server",
58 "Address Size [[hostIPaddr:]filename]"
59);
60#endif
61
Luca Ceresoli7aa81a42011-05-17 00:03:40 +000062#ifdef CONFIG_CMD_TFTPSRV
63static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
64{
65 return netboot_common(TFTPSRV, cmdtp, argc, argv);
66}
67
68U_BOOT_CMD(
69 tftpsrv, 2, 1, do_tftpsrv,
70 "act as a TFTP server and boot the first received file",
71 "[loadAddress]\n"
72 "Listen for an incoming TFTP transfer, receive a file and boot it.\n"
73 "The transfer is aborted if a transfer has not been started after\n"
74 "about 50 seconds or if Ctrl-C is pressed."
75);
76#endif
77
78
Peter Tyserf7a48ca2010-09-30 11:25:48 -050079#ifdef CONFIG_CMD_RARP
Kim Phillipsdc00a682012-10-29 13:34:31 +000080int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000081{
Kim Phillipsdc00a682012-10-29 13:34:31 +000082 return netboot_common(RARP, cmdtp, argc, argv);
wdenk38635852002-08-27 05:55:31 +000083}
84
wdenkf287a242003-07-01 21:06:45 +000085U_BOOT_CMD(
86 rarpboot, 3, 1, do_rarpb,
Peter Tyserdfb72b82009-01-27 18:03:12 -060087 "boot image via network using RARP/TFTP protocol",
Wolfgang Denkc54781c2009-05-24 17:06:54 +020088 "[loadAddress] [[hostIPaddr:]bootfilename]"
wdenk57b2d802003-06-27 21:31:46 +000089);
Peter Tyserf7a48ca2010-09-30 11:25:48 -050090#endif
wdenk57b2d802003-06-27 21:31:46 +000091
Jon Loeligerd76b5c12007-07-08 18:02:23 -050092#if defined(CONFIG_CMD_DHCP)
Kim Phillipsdc00a682012-10-29 13:34:31 +000093static int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk38635852002-08-27 05:55:31 +000094{
95 return netboot_common(DHCP, cmdtp, argc, argv);
96}
wdenk57b2d802003-06-27 21:31:46 +000097
wdenkf287a242003-07-01 21:06:45 +000098U_BOOT_CMD(
99 dhcp, 3, 1, do_dhcp,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600100 "boot image via network using DHCP/TFTP protocol",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200101 "[loadAddress] [[hostIPaddr:]bootfilename]"
wdenk57b2d802003-06-27 21:31:46 +0000102);
Jon Loeligerd704d912007-07-10 11:02:44 -0500103#endif
wdenk38635852002-08-27 05:55:31 +0000104
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500105#if defined(CONFIG_CMD_NFS)
Kim Phillipsdc00a682012-10-29 13:34:31 +0000106static int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkbe9c1cb2004-02-24 02:00:03 +0000107{
108 return netboot_common(NFS, cmdtp, argc, argv);
109}
110
111U_BOOT_CMD(
112 nfs, 3, 1, do_nfs,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600113 "boot image via network using NFS protocol",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200114 "[loadAddress] [[hostIPaddr:]bootfilename]"
wdenkbe9c1cb2004-02-24 02:00:03 +0000115);
Jon Loeligerd704d912007-07-10 11:02:44 -0500116#endif
wdenkbe9c1cb2004-02-24 02:00:03 +0000117
Kim Phillipsdc00a682012-10-29 13:34:31 +0000118static void netboot_update_env(void)
wdenk38635852002-08-27 05:55:31 +0000119{
wdenk05939202004-04-18 17:39:38 +0000120 char tmp[22];
wdenk38635852002-08-27 05:55:31 +0000121
Joe Hershberger5874dec2015-04-08 01:41:01 -0500122 if (net_gateway.s_addr) {
123 ip_to_string(net_gateway, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600124 env_set("gatewayip", tmp);
wdenk05939202004-04-18 17:39:38 +0000125 }
wdenk38635852002-08-27 05:55:31 +0000126
Joe Hershberger5874dec2015-04-08 01:41:01 -0500127 if (net_netmask.s_addr) {
128 ip_to_string(net_netmask, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600129 env_set("netmask", tmp);
wdenk05939202004-04-18 17:39:38 +0000130 }
wdenk38635852002-08-27 05:55:31 +0000131
Joe Hershberger6d236432015-04-08 01:41:03 -0500132 if (net_hostname[0])
Simon Glass6a38e412017-08-03 12:22:09 -0600133 env_set("hostname", net_hostname);
wdenk38635852002-08-27 05:55:31 +0000134
Joe Hershberger6d236432015-04-08 01:41:03 -0500135 if (net_root_path[0])
Simon Glass6a38e412017-08-03 12:22:09 -0600136 env_set("rootpath", net_root_path);
wdenk38635852002-08-27 05:55:31 +0000137
Joe Hershberger5874dec2015-04-08 01:41:01 -0500138 if (net_ip.s_addr) {
139 ip_to_string(net_ip, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600140 env_set("ipaddr", tmp);
wdenk05939202004-04-18 17:39:38 +0000141 }
Joe Hershbergerd4762042012-05-23 07:59:17 +0000142#if !defined(CONFIG_BOOTP_SERVERIP)
143 /*
Baruch Siachbc713252016-12-27 11:03:29 +0200144 * Only attempt to change serverip if net/bootp.c:store_net_params()
Joe Hershbergerd4762042012-05-23 07:59:17 +0000145 * could have set it
146 */
Joe Hershberger5874dec2015-04-08 01:41:01 -0500147 if (net_server_ip.s_addr) {
148 ip_to_string(net_server_ip, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600149 env_set("serverip", tmp);
wdenk05939202004-04-18 17:39:38 +0000150 }
Joe Hershbergerd4762042012-05-23 07:59:17 +0000151#endif
Joe Hershberger5874dec2015-04-08 01:41:01 -0500152 if (net_dns_server.s_addr) {
153 ip_to_string(net_dns_server, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600154 env_set("dnsip", tmp);
wdenk05939202004-04-18 17:39:38 +0000155 }
Jon Loeliger5336a762007-07-09 22:08:34 -0500156#if defined(CONFIG_BOOTP_DNS2)
Joe Hershberger5874dec2015-04-08 01:41:01 -0500157 if (net_dns_server2.s_addr) {
158 ip_to_string(net_dns_server2, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600159 env_set("dnsip2", tmp);
wdenk05939202004-04-18 17:39:38 +0000160 }
stroesee0aadfb2003-08-28 14:17:32 +0000161#endif
Joe Hershberger6d236432015-04-08 01:41:03 -0500162 if (net_nis_domain[0])
Simon Glass6a38e412017-08-03 12:22:09 -0600163 env_set("domain", net_nis_domain);
wdenkb4ad9622005-04-01 00:25:43 +0000164
Joe Hershberger013d3872015-04-08 01:41:17 -0500165#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500166 if (net_ntp_time_offset) {
167 sprintf(tmp, "%d", net_ntp_time_offset);
Simon Glass6a38e412017-08-03 12:22:09 -0600168 env_set("timeoffset", tmp);
wdenkb4ad9622005-04-01 00:25:43 +0000169 }
170#endif
Joe Hershberger013d3872015-04-08 01:41:17 -0500171#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
Joe Hershberger5874dec2015-04-08 01:41:01 -0500172 if (net_ntp_server.s_addr) {
173 ip_to_string(net_ntp_server, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600174 env_set("ntpserverip", tmp);
wdenkb4ad9622005-04-01 00:25:43 +0000175 }
176#endif
wdenk38635852002-08-27 05:55:31 +0000177}
wdenk05939202004-04-18 17:39:38 +0000178
Simon Glassd6c5f552011-10-24 18:00:02 +0000179static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
180 char * const argv[])
wdenk38635852002-08-27 05:55:31 +0000181{
182 char *s;
Peter Tyser24c297d2008-12-02 12:59:51 -0600183 char *end;
wdenk38635852002-08-27 05:55:31 +0000184 int rcode = 0;
185 int size;
Peter Tyser24c297d2008-12-02 12:59:51 -0600186 ulong addr;
wdenk38635852002-08-27 05:55:31 +0000187
Alexander Graff43bf5d2018-06-15 10:29:27 +0200188 net_boot_file_name_explicit = false;
189
Simon Glass892265d2019-12-28 10:45:02 -0700190 /* pre-set image_load_addr */
Simon Glass64b723f2017-08-03 12:22:12 -0600191 s = env_get("loadaddr");
Joe Hershberger013d3872015-04-08 01:41:17 -0500192 if (s != NULL)
Simon Glass892265d2019-12-28 10:45:02 -0700193 image_load_addr = simple_strtoul(s, NULL, 16);
wdenk38635852002-08-27 05:55:31 +0000194
195 switch (argc) {
196 case 1:
Joe Hershberger2e135272018-07-03 19:36:42 -0500197 /* refresh bootfile name from env */
198 copy_filename(net_boot_file_name, env_get("bootfile"),
199 sizeof(net_boot_file_name));
wdenk38635852002-08-27 05:55:31 +0000200 break;
201
Peter Tyser24c297d2008-12-02 12:59:51 -0600202 case 2: /*
203 * Only one arg - accept two forms:
204 * Just load address, or just boot file name. The latter
205 * form must be written in a format which can not be
206 * mis-interpreted as a valid number.
wdenk38635852002-08-27 05:55:31 +0000207 */
Peter Tyser24c297d2008-12-02 12:59:51 -0600208 addr = simple_strtoul(argv[1], &end, 16);
Alexander Graff43bf5d2018-06-15 10:29:27 +0200209 if (end == (argv[1] + strlen(argv[1]))) {
Simon Glass892265d2019-12-28 10:45:02 -0700210 image_load_addr = addr;
Joe Hershberger2e135272018-07-03 19:36:42 -0500211 /* refresh bootfile name from env */
212 copy_filename(net_boot_file_name, env_get("bootfile"),
213 sizeof(net_boot_file_name));
Alexander Graff43bf5d2018-06-15 10:29:27 +0200214 } else {
215 net_boot_file_name_explicit = true;
Joe Hershberger290c8992015-04-08 01:41:02 -0500216 copy_filename(net_boot_file_name, argv[1],
217 sizeof(net_boot_file_name));
Alexander Graff43bf5d2018-06-15 10:29:27 +0200218 }
wdenk38635852002-08-27 05:55:31 +0000219 break;
220
Joe Hershberger013d3872015-04-08 01:41:17 -0500221 case 3:
Simon Glass892265d2019-12-28 10:45:02 -0700222 image_load_addr = simple_strtoul(argv[1], NULL, 16);
Alexander Graff43bf5d2018-06-15 10:29:27 +0200223 net_boot_file_name_explicit = true;
Joe Hershberger290c8992015-04-08 01:41:02 -0500224 copy_filename(net_boot_file_name, argv[2],
225 sizeof(net_boot_file_name));
wdenk38635852002-08-27 05:55:31 +0000226
227 break;
228
Simon Glass85d96ec2011-10-24 18:00:08 +0000229#ifdef CONFIG_CMD_TFTPPUT
230 case 4:
Simon Glass892265d2019-12-28 10:45:02 -0700231 if (strict_strtoul(argv[1], 16, &image_save_addr) < 0 ||
232 strict_strtoul(argv[2], 16, &image_save_size) < 0) {
Simon Glass778fe692011-12-19 16:10:43 +0000233 printf("Invalid address/size\n");
Joe Hershbergerba867832015-03-22 17:09:09 -0500234 return CMD_RET_USAGE;
Simon Glass778fe692011-12-19 16:10:43 +0000235 }
Alexander Graff43bf5d2018-06-15 10:29:27 +0200236 net_boot_file_name_explicit = true;
Joe Hershberger290c8992015-04-08 01:41:02 -0500237 copy_filename(net_boot_file_name, argv[3],
238 sizeof(net_boot_file_name));
Simon Glass85d96ec2011-10-24 18:00:08 +0000239 break;
240#endif
Wolfgang Denk3b683112010-07-17 01:06:04 +0200241 default:
Simon Glass0169e6b2012-02-13 13:51:18 +0000242 bootstage_error(BOOTSTAGE_ID_NET_START);
Simon Glassa06dfc72011-12-10 08:44:01 +0000243 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +0000244 }
Simon Glass0169e6b2012-02-13 13:51:18 +0000245 bootstage_mark(BOOTSTAGE_ID_NET_START);
wdenk38635852002-08-27 05:55:31 +0000246
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500247 size = net_loop(proto);
Joe Hershberger013d3872015-04-08 01:41:17 -0500248 if (size < 0) {
Simon Glass0169e6b2012-02-13 13:51:18 +0000249 bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
Joe Hershbergerba867832015-03-22 17:09:09 -0500250 return CMD_RET_FAILURE;
Heiko Schocher633e03a2007-06-22 19:11:54 +0200251 }
Simon Glass0169e6b2012-02-13 13:51:18 +0000252 bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
wdenk38635852002-08-27 05:55:31 +0000253
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500254 /* net_loop ok, update environment */
wdenk38635852002-08-27 05:55:31 +0000255 netboot_update_env();
256
wdenkc217f6d2002-11-11 02:11:37 +0000257 /* done if no file was loaded (no errors though) */
Heiko Schocher633e03a2007-06-22 19:11:54 +0200258 if (size == 0) {
Simon Glass0169e6b2012-02-13 13:51:18 +0000259 bootstage_error(BOOTSTAGE_ID_NET_LOADED);
Joe Hershbergerba867832015-03-22 17:09:09 -0500260 return CMD_RET_SUCCESS;
Heiko Schocher633e03a2007-06-22 19:11:54 +0200261 }
wdenkc217f6d2002-11-11 02:11:37 +0000262
Simon Glass0169e6b2012-02-13 13:51:18 +0000263 bootstage_mark(BOOTSTAGE_ID_NET_LOADED);
Simon Glass964d1d42012-01-14 15:24:52 +0000264
Mike Frysinger194c2e82011-06-05 13:43:02 +0000265 rcode = bootm_maybe_autostart(cmdtp, argv[0]);
wdenk38635852002-08-27 05:55:31 +0000266
Joe Hershbergerba867832015-03-22 17:09:09 -0500267 if (rcode == CMD_RET_SUCCESS)
Simon Glass0169e6b2012-02-13 13:51:18 +0000268 bootstage_mark(BOOTSTAGE_ID_NET_DONE);
Joe Hershbergerba867832015-03-22 17:09:09 -0500269 else
270 bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR);
wdenk38635852002-08-27 05:55:31 +0000271 return rcode;
272}
wdenke6466f62003-06-05 19:27:42 +0000273
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500274#if defined(CONFIG_CMD_PING)
Kim Phillipsdc00a682012-10-29 13:34:31 +0000275static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenke6466f62003-06-05 19:27:42 +0000276{
277 if (argc < 2)
Joe Hershbergerba867832015-03-22 17:09:09 -0500278 return CMD_RET_USAGE;
wdenke6466f62003-06-05 19:27:42 +0000279
Joe Hershberger5874dec2015-04-08 01:41:01 -0500280 net_ping_ip = string_to_ip(argv[1]);
281 if (net_ping_ip.s_addr == 0)
Simon Glassa06dfc72011-12-10 08:44:01 +0000282 return CMD_RET_USAGE;
wdenke6466f62003-06-05 19:27:42 +0000283
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500284 if (net_loop(PING) < 0) {
wdenke6466f62003-06-05 19:27:42 +0000285 printf("ping failed; host %s is not alive\n", argv[1]);
Joe Hershbergerba867832015-03-22 17:09:09 -0500286 return CMD_RET_FAILURE;
wdenke6466f62003-06-05 19:27:42 +0000287 }
288
289 printf("host %s is alive\n", argv[1]);
290
Joe Hershbergerba867832015-03-22 17:09:09 -0500291 return CMD_RET_SUCCESS;
wdenke6466f62003-06-05 19:27:42 +0000292}
wdenkca9bc762003-07-15 07:45:49 +0000293
294U_BOOT_CMD(
295 ping, 2, 1, do_ping,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600296 "send ICMP ECHO_REQUEST to network host",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200297 "pingAddress"
wdenkca9bc762003-07-15 07:45:49 +0000298);
Jon Loeligerd704d912007-07-10 11:02:44 -0500299#endif
wdenk38635852002-08-27 05:55:31 +0000300
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500301#if defined(CONFIG_CMD_CDP)
wdenk145d2c12004-04-15 21:48:45 +0000302
303static void cdp_update_env(void)
304{
305 char tmp[16];
306
Joe Hershberger527336f2015-04-08 01:41:14 -0500307 if (cdp_appliance_vlan != htons(-1)) {
308 printf("CDP offered appliance VLAN %d\n",
309 ntohs(cdp_appliance_vlan));
Joe Hershberger013d3872015-04-08 01:41:17 -0500310 vlan_to_string(cdp_appliance_vlan, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600311 env_set("vlan", tmp);
Joe Hershberger013d3872015-04-08 01:41:17 -0500312 net_our_vlan = cdp_appliance_vlan;
wdenk145d2c12004-04-15 21:48:45 +0000313 }
314
Joe Hershberger527336f2015-04-08 01:41:14 -0500315 if (cdp_native_vlan != htons(-1)) {
316 printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan));
Joe Hershberger013d3872015-04-08 01:41:17 -0500317 vlan_to_string(cdp_native_vlan, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600318 env_set("nvlan", tmp);
Joe Hershberger013d3872015-04-08 01:41:17 -0500319 net_native_vlan = cdp_native_vlan;
wdenk145d2c12004-04-15 21:48:45 +0000320 }
wdenk145d2c12004-04-15 21:48:45 +0000321}
322
Kim Phillipsdc00a682012-10-29 13:34:31 +0000323int do_cdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk145d2c12004-04-15 21:48:45 +0000324{
325 int r;
326
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500327 r = net_loop(CDP);
wdenk145d2c12004-04-15 21:48:45 +0000328 if (r < 0) {
329 printf("cdp failed; perhaps not a CISCO switch?\n");
Joe Hershbergerba867832015-03-22 17:09:09 -0500330 return CMD_RET_FAILURE;
wdenk145d2c12004-04-15 21:48:45 +0000331 }
332
333 cdp_update_env();
334
Joe Hershbergerba867832015-03-22 17:09:09 -0500335 return CMD_RET_SUCCESS;
wdenk145d2c12004-04-15 21:48:45 +0000336}
337
338U_BOOT_CMD(
339 cdp, 1, 1, do_cdp,
Wolfgang Denkd29afc32010-10-26 23:42:23 +0200340 "Perform CDP network configuration",
Wolfgang Denkf003d922010-12-23 17:02:18 +0100341 "\n"
wdenk145d2c12004-04-15 21:48:45 +0000342);
Jon Loeligerd704d912007-07-10 11:02:44 -0500343#endif
wdenk145d2c12004-04-15 21:48:45 +0000344
Jon Loeligerd76b5c12007-07-08 18:02:23 -0500345#if defined(CONFIG_CMD_SNTP)
Kim Phillipsdc00a682012-10-29 13:34:31 +0000346int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkb4ad9622005-04-01 00:25:43 +0000347{
348 char *toff;
349
350 if (argc < 2) {
Simon Glassda1a1342017-08-03 12:22:15 -0600351 net_ntp_server = env_get_ip("ntpserverip");
Joe Hershberger5874dec2015-04-08 01:41:01 -0500352 if (net_ntp_server.s_addr == 0) {
Kim Phillipsdc00a682012-10-29 13:34:31 +0000353 printf("ntpserverip not set\n");
Joe Hershbergerba867832015-03-22 17:09:09 -0500354 return CMD_RET_FAILURE;
wdenkb4ad9622005-04-01 00:25:43 +0000355 }
356 } else {
Joe Hershberger5874dec2015-04-08 01:41:01 -0500357 net_ntp_server = string_to_ip(argv[1]);
358 if (net_ntp_server.s_addr == 0) {
Kim Phillipsdc00a682012-10-29 13:34:31 +0000359 printf("Bad NTP server IP address\n");
Joe Hershbergerba867832015-03-22 17:09:09 -0500360 return CMD_RET_FAILURE;
wdenkb4ad9622005-04-01 00:25:43 +0000361 }
362 }
363
Simon Glass64b723f2017-08-03 12:22:12 -0600364 toff = env_get("timeoffset");
Kim Phillipsdc00a682012-10-29 13:34:31 +0000365 if (toff == NULL)
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500366 net_ntp_time_offset = 0;
Kim Phillipsdc00a682012-10-29 13:34:31 +0000367 else
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500368 net_ntp_time_offset = simple_strtol(toff, NULL, 10);
wdenkb4ad9622005-04-01 00:25:43 +0000369
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500370 if (net_loop(SNTP) < 0) {
Luuk Paulussen7cb3f892011-05-16 18:27:11 +0000371 printf("SNTP failed: host %pI4 not responding\n",
Joe Hershberger013d3872015-04-08 01:41:17 -0500372 &net_ntp_server);
Joe Hershbergerba867832015-03-22 17:09:09 -0500373 return CMD_RET_FAILURE;
wdenkb4ad9622005-04-01 00:25:43 +0000374 }
375
Joe Hershbergerba867832015-03-22 17:09:09 -0500376 return CMD_RET_SUCCESS;
wdenkb4ad9622005-04-01 00:25:43 +0000377}
378
379U_BOOT_CMD(
380 sntp, 2, 1, do_sntp,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600381 "synchronize RTC via network",
wdenkb4ad9622005-04-01 00:25:43 +0000382 "[NTP server IP]\n"
383);
Jon Loeligerd704d912007-07-10 11:02:44 -0500384#endif
Robin Getz82f0d232009-07-20 14:53:54 -0400385
386#if defined(CONFIG_CMD_DNS)
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200387int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Robin Getz82f0d232009-07-20 14:53:54 -0400388{
Wolfgang Denk3b683112010-07-17 01:06:04 +0200389 if (argc == 1)
Simon Glassa06dfc72011-12-10 08:44:01 +0000390 return CMD_RET_USAGE;
Robin Getz82f0d232009-07-20 14:53:54 -0400391
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");
Joe Hershbergerba867832015-03-22 17:09:09 -0500406 return CMD_RET_FAILURE;
Robin Getz82f0d232009-07-20 14:53:54 -0400407 }
408
Joe Hershbergerf725e342015-04-08 01:41:15 -0500409 net_dns_resolve = argv[1];
Robin Getz82f0d232009-07-20 14:53:54 -0400410
411 if (argc == 3)
Joe Hershbergerf725e342015-04-08 01:41:15 -0500412 net_dns_env_var = argv[2];
Robin Getz82f0d232009-07-20 14:53:54 -0400413 else
Joe Hershbergerf725e342015-04-08 01:41:15 -0500414 net_dns_env_var = NULL;
Robin Getz82f0d232009-07-20 14:53:54 -0400415
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500416 if (net_loop(DNS) < 0) {
Robin Getz82f0d232009-07-20 14:53:54 -0400417 printf("dns lookup of %s failed, check setup\n", argv[1]);
Joe Hershbergerba867832015-03-22 17:09:09 -0500418 return CMD_RET_FAILURE;
Robin Getz82f0d232009-07-20 14:53:54 -0400419 }
420
Joe Hershbergerba867832015-03-22 17:09:09 -0500421 return CMD_RET_SUCCESS;
Robin Getz82f0d232009-07-20 14:53:54 -0400422}
423
424U_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 Hershbergerb35a3a62012-05-23 08:00:12 +0000431
432#if defined(CONFIG_CMD_LINK_LOCAL)
433static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
434 char * const argv[])
435{
436 char tmp[22];
437
Joe Hershbergerc80b41b02015-04-08 01:41:21 -0500438 if (net_loop(LINKLOCAL) < 0)
Joe Hershbergerba867832015-03-22 17:09:09 -0500439 return CMD_RET_FAILURE;
Joe Hershbergerb35a3a62012-05-23 08:00:12 +0000440
Joe Hershberger5874dec2015-04-08 01:41:01 -0500441 net_gateway.s_addr = 0;
442 ip_to_string(net_gateway, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600443 env_set("gatewayip", tmp);
Joe Hershbergerb35a3a62012-05-23 08:00:12 +0000444
Joe Hershberger5874dec2015-04-08 01:41:01 -0500445 ip_to_string(net_netmask, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600446 env_set("netmask", tmp);
Joe Hershbergerb35a3a62012-05-23 08:00:12 +0000447
Joe Hershberger5874dec2015-04-08 01:41:01 -0500448 ip_to_string(net_ip, tmp);
Simon Glass6a38e412017-08-03 12:22:09 -0600449 env_set("ipaddr", tmp);
450 env_set("llipaddr", tmp); /* store this for next time */
Joe Hershbergerb35a3a62012-05-23 08:00:12 +0000451
Joe Hershbergerba867832015-03-22 17:09:09 -0500452 return CMD_RET_SUCCESS;
Joe Hershbergerb35a3a62012-05-23 08:00:12 +0000453}
454
455U_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 */