]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
3863585b WD |
2 | /* |
3 | * (C) Copyright 2000 | |
4 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
3863585b WD |
5 | */ |
6 | ||
7 | /* | |
8 | * Boot support | |
9 | */ | |
10 | #include <common.h> | |
52f24238 | 11 | #include <bootstage.h> |
3863585b | 12 | #include <command.h> |
8a3987f4 | 13 | #include <dm.h> |
9fb625ce | 14 | #include <env.h> |
8e8ccfe1 | 15 | #include <image.h> |
3863585b | 16 | #include <net.h> |
912ece4c PR |
17 | #include <net/udp.h> |
18 | #include <net/sntp.h> | |
4b290d4a | 19 | #include <net/ncsi.h> |
3863585b | 20 | |
09140113 | 21 | static int netboot_common(enum proto_t, struct cmd_tbl *, int, char * const []); |
3863585b | 22 | |
d7a45eaf | 23 | #ifdef CONFIG_CMD_BOOTP |
09140113 SG |
24 | static int do_bootp(struct cmd_tbl *cmdtp, int flag, int argc, |
25 | char *const argv[]) | |
3863585b | 26 | { |
088f1b19 | 27 | return netboot_common(BOOTP, cmdtp, argc, argv); |
3863585b WD |
28 | } |
29 | ||
0d498393 WD |
30 | U_BOOT_CMD( |
31 | bootp, 3, 1, do_bootp, | |
2fb2604d | 32 | "boot image via network using BOOTP/TFTP protocol", |
a89c33db | 33 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
8bde7f77 | 34 | ); |
d7a45eaf | 35 | #endif |
8bde7f77 | 36 | |
d7a45eaf | 37 | #ifdef CONFIG_CMD_TFTPBOOT |
09140113 | 38 | int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
3863585b | 39 | { |
573f14fe SG |
40 | int ret; |
41 | ||
42 | bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start"); | |
43 | ret = netboot_common(TFTPGET, cmdtp, argc, argv); | |
44 | bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done"); | |
45 | return ret; | |
3863585b WD |
46 | } |
47 | ||
0d498393 WD |
48 | U_BOOT_CMD( |
49 | tftpboot, 3, 1, do_tftpb, | |
651031ef | 50 | "load file via network using TFTP protocol", |
a89c33db | 51 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
8bde7f77 | 52 | ); |
d7a45eaf | 53 | #endif |
8bde7f77 | 54 | |
2d46cf29 | 55 | #ifdef CONFIG_CMD_TFTPPUT |
09140113 SG |
56 | static int do_tftpput(struct cmd_tbl *cmdtp, int flag, int argc, |
57 | char *const argv[]) | |
2d46cf29 | 58 | { |
85848f03 | 59 | return netboot_common(TFTPPUT, cmdtp, argc, argv); |
2d46cf29 SG |
60 | } |
61 | ||
62 | U_BOOT_CMD( | |
63 | tftpput, 4, 1, do_tftpput, | |
64 | "TFTP put command, for uploading files to a server", | |
65 | "Address Size [[hostIPaddr:]filename]" | |
66 | ); | |
67 | #endif | |
68 | ||
7a83af07 | 69 | #ifdef CONFIG_CMD_TFTPSRV |
09140113 SG |
70 | static int do_tftpsrv(struct cmd_tbl *cmdtp, int flag, int argc, |
71 | char *const argv[]) | |
7a83af07 LC |
72 | { |
73 | return netboot_common(TFTPSRV, cmdtp, argc, argv); | |
74 | } | |
75 | ||
76 | U_BOOT_CMD( | |
77 | tftpsrv, 2, 1, do_tftpsrv, | |
78 | "act as a TFTP server and boot the first received file", | |
79 | "[loadAddress]\n" | |
80 | "Listen for an incoming TFTP transfer, receive a file and boot it.\n" | |
81 | "The transfer is aborted if a transfer has not been started after\n" | |
82 | "about 50 seconds or if Ctrl-C is pressed." | |
83 | ); | |
84 | #endif | |
85 | ||
86 | ||
bf6cb247 | 87 | #ifdef CONFIG_CMD_RARP |
09140113 | 88 | int do_rarpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
3863585b | 89 | { |
088f1b19 | 90 | return netboot_common(RARP, cmdtp, argc, argv); |
3863585b WD |
91 | } |
92 | ||
0d498393 WD |
93 | U_BOOT_CMD( |
94 | rarpboot, 3, 1, do_rarpb, | |
2fb2604d | 95 | "boot image via network using RARP/TFTP protocol", |
a89c33db | 96 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
8bde7f77 | 97 | ); |
bf6cb247 | 98 | #endif |
8bde7f77 | 99 | |
c76fe474 | 100 | #if defined(CONFIG_CMD_DHCP) |
09140113 SG |
101 | static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, |
102 | char *const argv[]) | |
3863585b WD |
103 | { |
104 | return netboot_common(DHCP, cmdtp, argc, argv); | |
105 | } | |
8bde7f77 | 106 | |
0d498393 WD |
107 | U_BOOT_CMD( |
108 | dhcp, 3, 1, do_dhcp, | |
2fb2604d | 109 | "boot image via network using DHCP/TFTP protocol", |
a89c33db | 110 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
8bde7f77 | 111 | ); |
90253178 | 112 | #endif |
3863585b | 113 | |
c76fe474 | 114 | #if defined(CONFIG_CMD_NFS) |
09140113 SG |
115 | static int do_nfs(struct cmd_tbl *cmdtp, int flag, int argc, |
116 | char *const argv[]) | |
cbd8a35c WD |
117 | { |
118 | return netboot_common(NFS, cmdtp, argc, argv); | |
119 | } | |
120 | ||
121 | U_BOOT_CMD( | |
122 | nfs, 3, 1, do_nfs, | |
2fb2604d | 123 | "boot image via network using NFS protocol", |
a89c33db | 124 | "[loadAddress] [[hostIPaddr:]bootfilename]" |
cbd8a35c | 125 | ); |
90253178 | 126 | #endif |
cbd8a35c | 127 | |
088f1b19 | 128 | static void netboot_update_env(void) |
3863585b | 129 | { |
6e592385 | 130 | char tmp[22]; |
3863585b | 131 | |
049a95a7 JH |
132 | if (net_gateway.s_addr) { |
133 | ip_to_string(net_gateway, tmp); | |
382bee57 | 134 | env_set("gatewayip", tmp); |
6e592385 | 135 | } |
3863585b | 136 | |
049a95a7 JH |
137 | if (net_netmask.s_addr) { |
138 | ip_to_string(net_netmask, tmp); | |
382bee57 | 139 | env_set("netmask", tmp); |
6e592385 | 140 | } |
3863585b | 141 | |
808f13d8 | 142 | #ifdef CONFIG_CMD_BOOTP |
586cbe51 | 143 | if (net_hostname[0]) |
382bee57 | 144 | env_set("hostname", net_hostname); |
808f13d8 | 145 | #endif |
3863585b | 146 | |
808f13d8 | 147 | #ifdef CONFIG_CMD_BOOTP |
586cbe51 | 148 | if (net_root_path[0]) |
382bee57 | 149 | env_set("rootpath", net_root_path); |
808f13d8 | 150 | #endif |
3863585b | 151 | |
049a95a7 JH |
152 | if (net_ip.s_addr) { |
153 | ip_to_string(net_ip, tmp); | |
382bee57 | 154 | env_set("ipaddr", tmp); |
6e592385 | 155 | } |
a3e1a727 | 156 | /* |
ff78ad28 | 157 | * Only attempt to change serverip if net/bootp.c:store_net_params() |
a3e1a727 JH |
158 | * could have set it |
159 | */ | |
43407539 | 160 | if (!IS_ENABLED(CONFIG_BOOTP_SERVERIP) && net_server_ip.s_addr) { |
049a95a7 | 161 | ip_to_string(net_server_ip, tmp); |
382bee57 | 162 | env_set("serverip", tmp); |
6e592385 | 163 | } |
049a95a7 JH |
164 | if (net_dns_server.s_addr) { |
165 | ip_to_string(net_dns_server, tmp); | |
382bee57 | 166 | env_set("dnsip", tmp); |
6e592385 | 167 | } |
1fe80d79 | 168 | #if defined(CONFIG_BOOTP_DNS2) |
049a95a7 JH |
169 | if (net_dns_server2.s_addr) { |
170 | ip_to_string(net_dns_server2, tmp); | |
382bee57 | 171 | env_set("dnsip2", tmp); |
6e592385 | 172 | } |
fe389a82 | 173 | #endif |
808f13d8 | 174 | #ifdef CONFIG_CMD_BOOTP |
586cbe51 | 175 | if (net_nis_domain[0]) |
382bee57 | 176 | env_set("domain", net_nis_domain); |
808f13d8 | 177 | #endif |
ea287deb | 178 | |
4fd5055f | 179 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) |
bc0571fc JH |
180 | if (net_ntp_time_offset) { |
181 | sprintf(tmp, "%d", net_ntp_time_offset); | |
382bee57 | 182 | env_set("timeoffset", tmp); |
ea287deb WD |
183 | } |
184 | #endif | |
4fd5055f | 185 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) |
049a95a7 JH |
186 | if (net_ntp_server.s_addr) { |
187 | ip_to_string(net_ntp_server, tmp); | |
382bee57 | 188 | env_set("ntpserverip", tmp); |
ea287deb WD |
189 | } |
190 | #endif | |
3863585b | 191 | } |
6e592385 | 192 | |
5f46c6eb HS |
193 | /** |
194 | * parse_addr_size() - parse address and size arguments for tftpput | |
195 | * | |
196 | * @argv: command line arguments | |
197 | * Return: 0 on success | |
198 | */ | |
199 | static int parse_addr_size(char * const argv[]) | |
3863585b | 200 | { |
5f46c6eb HS |
201 | if (strict_strtoul(argv[1], 16, &image_save_addr) < 0 || |
202 | strict_strtoul(argv[2], 16, &image_save_size) < 0) { | |
203 | printf("Invalid address/size\n"); | |
204 | return CMD_RET_USAGE; | |
205 | } | |
206 | return 0; | |
207 | } | |
449312c1 | 208 | |
5f46c6eb HS |
209 | /** |
210 | * parse_args() - parse command line arguments | |
211 | * | |
212 | * @proto: command prototype | |
213 | * @argc: number of arguments | |
214 | * @argv: command line arguments | |
215 | * Return: 0 on success | |
216 | */ | |
217 | static int parse_args(enum proto_t proto, int argc, char *const argv[]) | |
218 | { | |
219 | ulong addr; | |
220 | char *end; | |
3863585b WD |
221 | |
222 | switch (argc) { | |
223 | case 1: | |
5f46c6eb HS |
224 | if (CONFIG_IS_ENABLED(CMD_TFTPPUT) && proto == TFTPPUT) |
225 | return 1; | |
226 | ||
f43308fa JH |
227 | /* refresh bootfile name from env */ |
228 | copy_filename(net_boot_file_name, env_get("bootfile"), | |
229 | sizeof(net_boot_file_name)); | |
3863585b WD |
230 | break; |
231 | ||
5f46c6eb HS |
232 | case 2: |
233 | if (CONFIG_IS_ENABLED(CMD_TFTPPUT) && proto == TFTPPUT) | |
234 | return 1; | |
235 | /* | |
2e4970d8 PT |
236 | * Only one arg - accept two forms: |
237 | * Just load address, or just boot file name. The latter | |
238 | * form must be written in a format which can not be | |
239 | * mis-interpreted as a valid number. | |
3863585b | 240 | */ |
7e5f460e | 241 | addr = hextoul(argv[1], &end); |
449312c1 | 242 | if (end == (argv[1] + strlen(argv[1]))) { |
bb872dd9 | 243 | image_load_addr = addr; |
f43308fa JH |
244 | /* refresh bootfile name from env */ |
245 | copy_filename(net_boot_file_name, env_get("bootfile"), | |
246 | sizeof(net_boot_file_name)); | |
449312c1 AG |
247 | } else { |
248 | net_boot_file_name_explicit = true; | |
1411157d JH |
249 | copy_filename(net_boot_file_name, argv[1], |
250 | sizeof(net_boot_file_name)); | |
449312c1 | 251 | } |
3863585b WD |
252 | break; |
253 | ||
4fd5055f | 254 | case 3: |
5f46c6eb HS |
255 | if (CONFIG_IS_ENABLED(CMD_TFTPPUT) && proto == TFTPPUT) { |
256 | if (parse_addr_size(argv)) | |
257 | return 1; | |
258 | } else { | |
259 | image_load_addr = hextoul(argv[1], NULL); | |
260 | net_boot_file_name_explicit = true; | |
261 | copy_filename(net_boot_file_name, argv[2], | |
262 | sizeof(net_boot_file_name)); | |
263 | } | |
3863585b WD |
264 | break; |
265 | ||
2d46cf29 SG |
266 | #ifdef CONFIG_CMD_TFTPPUT |
267 | case 4: | |
5f46c6eb HS |
268 | if (parse_addr_size(argv)) |
269 | return 1; | |
449312c1 | 270 | net_boot_file_name_explicit = true; |
1411157d JH |
271 | copy_filename(net_boot_file_name, argv[3], |
272 | sizeof(net_boot_file_name)); | |
2d46cf29 SG |
273 | break; |
274 | #endif | |
47e26b1b | 275 | default: |
5f46c6eb HS |
276 | return 1; |
277 | } | |
278 | return 0; | |
279 | } | |
280 | ||
281 | static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc, | |
282 | char *const argv[]) | |
283 | { | |
284 | char *s; | |
285 | int rcode = 0; | |
286 | int size; | |
287 | ||
288 | net_boot_file_name_explicit = false; | |
289 | *net_boot_file_name = '\0'; | |
290 | ||
291 | /* pre-set image_load_addr */ | |
292 | s = env_get("loadaddr"); | |
293 | if (s != NULL) | |
294 | image_load_addr = hextoul(s, NULL); | |
295 | ||
296 | if (parse_args(proto, argc, argv)) { | |
770605e4 | 297 | bootstage_error(BOOTSTAGE_ID_NET_START); |
4c12eeb8 | 298 | return CMD_RET_USAGE; |
3863585b | 299 | } |
5f46c6eb | 300 | |
770605e4 | 301 | bootstage_mark(BOOTSTAGE_ID_NET_START); |
3863585b | 302 | |
bc0571fc | 303 | size = net_loop(proto); |
4fd5055f | 304 | if (size < 0) { |
770605e4 | 305 | bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK); |
85848f03 | 306 | return CMD_RET_FAILURE; |
566a494f | 307 | } |
770605e4 | 308 | bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK); |
3863585b | 309 | |
bc0571fc | 310 | /* net_loop ok, update environment */ |
3863585b WD |
311 | netboot_update_env(); |
312 | ||
eb9401e3 | 313 | /* done if no file was loaded (no errors though) */ |
566a494f | 314 | if (size == 0) { |
770605e4 | 315 | bootstage_error(BOOTSTAGE_ID_NET_LOADED); |
85848f03 | 316 | return CMD_RET_SUCCESS; |
566a494f | 317 | } |
eb9401e3 | 318 | |
770605e4 | 319 | bootstage_mark(BOOTSTAGE_ID_NET_LOADED); |
c8e66db7 | 320 | |
67d668bf | 321 | rcode = bootm_maybe_autostart(cmdtp, argv[0]); |
3863585b | 322 | |
85848f03 | 323 | if (rcode == CMD_RET_SUCCESS) |
770605e4 | 324 | bootstage_mark(BOOTSTAGE_ID_NET_DONE); |
85848f03 JH |
325 | else |
326 | bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR); | |
3863585b WD |
327 | return rcode; |
328 | } | |
329 | ||
c76fe474 | 330 | #if defined(CONFIG_CMD_PING) |
09140113 SG |
331 | static int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, |
332 | char *const argv[]) | |
73a8b27c WD |
333 | { |
334 | if (argc < 2) | |
85848f03 | 335 | return CMD_RET_USAGE; |
73a8b27c | 336 | |
049a95a7 JH |
337 | net_ping_ip = string_to_ip(argv[1]); |
338 | if (net_ping_ip.s_addr == 0) | |
4c12eeb8 | 339 | return CMD_RET_USAGE; |
73a8b27c | 340 | |
bc0571fc | 341 | if (net_loop(PING) < 0) { |
73a8b27c | 342 | printf("ping failed; host %s is not alive\n", argv[1]); |
85848f03 | 343 | return CMD_RET_FAILURE; |
73a8b27c WD |
344 | } |
345 | ||
346 | printf("host %s is alive\n", argv[1]); | |
347 | ||
85848f03 | 348 | return CMD_RET_SUCCESS; |
73a8b27c | 349 | } |
6dff5529 WD |
350 | |
351 | U_BOOT_CMD( | |
352 | ping, 2, 1, do_ping, | |
2fb2604d | 353 | "send ICMP ECHO_REQUEST to network host", |
a89c33db | 354 | "pingAddress" |
6dff5529 | 355 | ); |
90253178 | 356 | #endif |
73a8b27c | 357 | |
c76fe474 | 358 | #if defined(CONFIG_CMD_CDP) |
a3d991bd WD |
359 | |
360 | static void cdp_update_env(void) | |
361 | { | |
362 | char tmp[16]; | |
363 | ||
6aede5b7 JH |
364 | if (cdp_appliance_vlan != htons(-1)) { |
365 | printf("CDP offered appliance VLAN %d\n", | |
366 | ntohs(cdp_appliance_vlan)); | |
4fd5055f | 367 | vlan_to_string(cdp_appliance_vlan, tmp); |
382bee57 | 368 | env_set("vlan", tmp); |
4fd5055f | 369 | net_our_vlan = cdp_appliance_vlan; |
a3d991bd WD |
370 | } |
371 | ||
6aede5b7 JH |
372 | if (cdp_native_vlan != htons(-1)) { |
373 | printf("CDP offered native VLAN %d\n", ntohs(cdp_native_vlan)); | |
4fd5055f | 374 | vlan_to_string(cdp_native_vlan, tmp); |
382bee57 | 375 | env_set("nvlan", tmp); |
4fd5055f | 376 | net_native_vlan = cdp_native_vlan; |
a3d991bd | 377 | } |
a3d991bd WD |
378 | } |
379 | ||
09140113 | 380 | int do_cdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
a3d991bd WD |
381 | { |
382 | int r; | |
383 | ||
bc0571fc | 384 | r = net_loop(CDP); |
a3d991bd WD |
385 | if (r < 0) { |
386 | printf("cdp failed; perhaps not a CISCO switch?\n"); | |
85848f03 | 387 | return CMD_RET_FAILURE; |
a3d991bd WD |
388 | } |
389 | ||
390 | cdp_update_env(); | |
391 | ||
85848f03 | 392 | return CMD_RET_SUCCESS; |
a3d991bd WD |
393 | } |
394 | ||
395 | U_BOOT_CMD( | |
396 | cdp, 1, 1, do_cdp, | |
ec5c04cd | 397 | "Perform CDP network configuration", |
4b58266e | 398 | "\n" |
a3d991bd | 399 | ); |
90253178 | 400 | #endif |
a3d991bd | 401 | |
c76fe474 | 402 | #if defined(CONFIG_CMD_SNTP) |
912ece4c PR |
403 | static struct udp_ops sntp_ops = { |
404 | .prereq = sntp_prereq, | |
405 | .start = sntp_start, | |
406 | .data = NULL, | |
407 | }; | |
408 | ||
09140113 | 409 | int do_sntp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
ea287deb WD |
410 | { |
411 | char *toff; | |
412 | ||
413 | if (argc < 2) { | |
723806cc | 414 | net_ntp_server = env_get_ip("ntpserverip"); |
049a95a7 | 415 | if (net_ntp_server.s_addr == 0) { |
088f1b19 | 416 | printf("ntpserverip not set\n"); |
85848f03 | 417 | return CMD_RET_FAILURE; |
ea287deb WD |
418 | } |
419 | } else { | |
049a95a7 JH |
420 | net_ntp_server = string_to_ip(argv[1]); |
421 | if (net_ntp_server.s_addr == 0) { | |
088f1b19 | 422 | printf("Bad NTP server IP address\n"); |
85848f03 | 423 | return CMD_RET_FAILURE; |
ea287deb WD |
424 | } |
425 | } | |
426 | ||
00caae6d | 427 | toff = env_get("timeoffset"); |
088f1b19 | 428 | if (toff == NULL) |
bc0571fc | 429 | net_ntp_time_offset = 0; |
088f1b19 | 430 | else |
bc0571fc | 431 | net_ntp_time_offset = simple_strtol(toff, NULL, 10); |
ea287deb | 432 | |
912ece4c | 433 | if (udp_loop(&sntp_ops) < 0) { |
d6840e3d | 434 | printf("SNTP failed: host %pI4 not responding\n", |
4fd5055f | 435 | &net_ntp_server); |
85848f03 | 436 | return CMD_RET_FAILURE; |
ea287deb WD |
437 | } |
438 | ||
85848f03 | 439 | return CMD_RET_SUCCESS; |
ea287deb WD |
440 | } |
441 | ||
442 | U_BOOT_CMD( | |
443 | sntp, 2, 1, do_sntp, | |
2fb2604d | 444 | "synchronize RTC via network", |
ea287deb WD |
445 | "[NTP server IP]\n" |
446 | ); | |
90253178 | 447 | #endif |
1a32bf41 RG |
448 | |
449 | #if defined(CONFIG_CMD_DNS) | |
09140113 | 450 | int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
1a32bf41 | 451 | { |
47e26b1b | 452 | if (argc == 1) |
4c12eeb8 | 453 | return CMD_RET_USAGE; |
1a32bf41 RG |
454 | |
455 | /* | |
456 | * We should check for a valid hostname: | |
457 | * - Each label must be between 1 and 63 characters long | |
458 | * - the entire hostname has a maximum of 255 characters | |
459 | * - only the ASCII letters 'a' through 'z' (case-insensitive), | |
460 | * the digits '0' through '9', and the hyphen | |
461 | * - cannot begin or end with a hyphen | |
462 | * - no other symbols, punctuation characters, or blank spaces are | |
463 | * permitted | |
464 | * but hey - this is a minimalist implmentation, so only check length | |
465 | * and let the name server deal with things. | |
466 | */ | |
467 | if (strlen(argv[1]) >= 255) { | |
468 | printf("dns error: hostname too long\n"); | |
85848f03 | 469 | return CMD_RET_FAILURE; |
1a32bf41 RG |
470 | } |
471 | ||
786eac5f | 472 | net_dns_resolve = argv[1]; |
1a32bf41 RG |
473 | |
474 | if (argc == 3) | |
786eac5f | 475 | net_dns_env_var = argv[2]; |
1a32bf41 | 476 | else |
786eac5f | 477 | net_dns_env_var = NULL; |
1a32bf41 | 478 | |
bc0571fc | 479 | if (net_loop(DNS) < 0) { |
1a32bf41 | 480 | printf("dns lookup of %s failed, check setup\n", argv[1]); |
85848f03 | 481 | return CMD_RET_FAILURE; |
1a32bf41 RG |
482 | } |
483 | ||
85848f03 | 484 | return CMD_RET_SUCCESS; |
1a32bf41 RG |
485 | } |
486 | ||
487 | U_BOOT_CMD( | |
488 | dns, 3, 1, do_dns, | |
489 | "lookup the IP of a hostname", | |
490 | "hostname [envvar]" | |
491 | ); | |
492 | ||
493 | #endif /* CONFIG_CMD_DNS */ | |
d22c338e JH |
494 | |
495 | #if defined(CONFIG_CMD_LINK_LOCAL) | |
09140113 SG |
496 | static int do_link_local(struct cmd_tbl *cmdtp, int flag, int argc, |
497 | char *const argv[]) | |
d22c338e JH |
498 | { |
499 | char tmp[22]; | |
500 | ||
bc0571fc | 501 | if (net_loop(LINKLOCAL) < 0) |
85848f03 | 502 | return CMD_RET_FAILURE; |
d22c338e | 503 | |
049a95a7 JH |
504 | net_gateway.s_addr = 0; |
505 | ip_to_string(net_gateway, tmp); | |
382bee57 | 506 | env_set("gatewayip", tmp); |
d22c338e | 507 | |
049a95a7 | 508 | ip_to_string(net_netmask, tmp); |
382bee57 | 509 | env_set("netmask", tmp); |
d22c338e | 510 | |
049a95a7 | 511 | ip_to_string(net_ip, tmp); |
382bee57 SG |
512 | env_set("ipaddr", tmp); |
513 | env_set("llipaddr", tmp); /* store this for next time */ | |
d22c338e | 514 | |
85848f03 | 515 | return CMD_RET_SUCCESS; |
d22c338e JH |
516 | } |
517 | ||
518 | U_BOOT_CMD( | |
519 | linklocal, 1, 1, do_link_local, | |
520 | "acquire a network IP address using the link-local protocol", | |
521 | "" | |
522 | ); | |
523 | ||
524 | #endif /* CONFIG_CMD_LINK_LOCAL */ | |
8a3987f4 TH |
525 | |
526 | #ifdef CONFIG_DM_ETH | |
527 | static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) | |
528 | { | |
529 | const struct udevice *current = eth_get_dev(); | |
530 | unsigned char env_enetaddr[ARP_HLEN]; | |
531 | const struct udevice *dev; | |
532 | struct uclass *uc; | |
533 | ||
534 | uclass_id_foreach_dev(UCLASS_ETH, dev, uc) { | |
535 | eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); | |
536 | printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr, | |
537 | current == dev ? "active" : ""); | |
538 | } | |
539 | return CMD_RET_SUCCESS; | |
540 | } | |
541 | ||
542 | static struct cmd_tbl cmd_net[] = { | |
543 | U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""), | |
544 | }; | |
545 | ||
546 | static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) | |
547 | { | |
548 | struct cmd_tbl *cp; | |
549 | ||
550 | cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net)); | |
551 | ||
552 | /* Drop the net command */ | |
553 | argc--; | |
554 | argv++; | |
555 | ||
556 | if (!cp || argc > cp->maxargs) | |
557 | return CMD_RET_USAGE; | |
558 | if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) | |
559 | return CMD_RET_SUCCESS; | |
560 | ||
561 | return cp->cmd(cmdtp, flag, argc, argv); | |
562 | } | |
563 | ||
564 | U_BOOT_CMD( | |
565 | net, 2, 1, do_net, | |
566 | "NET sub-system", | |
567 | "list - list available devices\n" | |
568 | ); | |
569 | #endif // CONFIG_DM_ETH | |
4b290d4a SMJ |
570 | |
571 | #if defined(CONFIG_CMD_NCSI) | |
572 | static int do_ncsi(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) | |
573 | { | |
574 | if (!phy_interface_is_ncsi() || !ncsi_active()) { | |
575 | printf("Device not configured for NC-SI\n"); | |
576 | return CMD_RET_FAILURE; | |
577 | } | |
578 | ||
579 | if (net_loop(NCSI) < 0) | |
580 | return CMD_RET_FAILURE; | |
581 | ||
582 | return CMD_RET_SUCCESS; | |
583 | } | |
584 | ||
585 | U_BOOT_CMD( | |
586 | ncsi, 1, 1, do_ncsi, | |
587 | "Configure attached NIC via NC-SI", | |
588 | "" | |
589 | ); | |
590 | #endif /* CONFIG_CMD_NCSI */ |