Blame view

common/cmd_net.c 9.3 KB
3863585bb   wdenk   Initial revision
1
2
3
4
  /*
   * (C) Copyright 2000
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
5
   * SPDX-License-Identifier:	GPL-2.0+
3863585bb   wdenk   Initial revision
6
7
8
9
10
11
12
   */
  
  /*
   * Boot support
   */
  #include <common.h>
  #include <command.h>
3863585bb   wdenk   Initial revision
13
  #include <net.h>
e4bf0c5cf   Simon Glass   net: tftpput: Ren...
14
  static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
3863585bb   wdenk   Initial revision
15

088f1b199   Kim Phillips   common/cmd_*.c: s...
16
  static int do_bootp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
17
  {
088f1b199   Kim Phillips   common/cmd_*.c: s...
18
  	return netboot_common(BOOTP, cmdtp, argc, argv);
3863585bb   wdenk   Initial revision
19
  }
0d4983930   wdenk   Patch by Kenneth ...
20
21
  U_BOOT_CMD(
  	bootp,	3,	1,	do_bootp,
2fb2604d5   Peter Tyser   Command usage cle...
22
  	"boot image via network using BOOTP/TFTP protocol",
a89c33db9   Wolfgang Denk   General help mess...
23
  	"[loadAddress] [[hostIPaddr:]bootfilename]"
8bde7f776   wdenk   * Code cleanup:
24
  );
088f1b199   Kim Phillips   common/cmd_*.c: s...
25
  int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
26
  {
573f14fe4   Simon Glass   bootstage: Plumb ...
27
28
29
30
31
32
  	int ret;
  
  	bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
  	ret = netboot_common(TFTPGET, cmdtp, argc, argv);
  	bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
  	return ret;
3863585bb   wdenk   Initial revision
33
  }
0d4983930   wdenk   Patch by Kenneth ...
34
35
  U_BOOT_CMD(
  	tftpboot,	3,	1,	do_tftpb,
2fb2604d5   Peter Tyser   Command usage cle...
36
  	"boot image via network using TFTP protocol",
a89c33db9   Wolfgang Denk   General help mess...
37
  	"[loadAddress] [[hostIPaddr:]bootfilename]"
8bde7f776   wdenk   * Code cleanup:
38
  );
2d46cf291   Simon Glass   net: tftpput: add...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  #ifdef CONFIG_CMD_TFTPPUT
  int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	int ret;
  
  	ret = netboot_common(TFTPPUT, cmdtp, argc, argv);
  	return ret;
  }
  
  U_BOOT_CMD(
  	tftpput,	4,	1,	do_tftpput,
  	"TFTP put command, for uploading files to a server",
  	"Address Size [[hostIPaddr:]filename]"
  );
  #endif
7a83af07a   Luca Ceresoli   TFTP: add tftpsrv...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  #ifdef CONFIG_CMD_TFTPSRV
  static int do_tftpsrv(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  {
  	return netboot_common(TFTPSRV, cmdtp, argc, argv);
  }
  
  U_BOOT_CMD(
  	tftpsrv,	2,	1,	do_tftpsrv,
  	"act as a TFTP server and boot the first received file",
  	"[loadAddress]
  "
  	"Listen for an incoming TFTP transfer, receive a file and boot it.
  "
  	"The transfer is aborted if a transfer has not been started after
  "
  	"about 50 seconds or if Ctrl-C is pressed."
  );
  #endif
bf6cb247a   Peter Tyser   rarp: Condtionall...
72
  #ifdef CONFIG_CMD_RARP
088f1b199   Kim Phillips   common/cmd_*.c: s...
73
  int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
74
  {
088f1b199   Kim Phillips   common/cmd_*.c: s...
75
  	return netboot_common(RARP, cmdtp, argc, argv);
3863585bb   wdenk   Initial revision
76
  }
0d4983930   wdenk   Patch by Kenneth ...
77
78
  U_BOOT_CMD(
  	rarpboot,	3,	1,	do_rarpb,
2fb2604d5   Peter Tyser   Command usage cle...
79
  	"boot image via network using RARP/TFTP protocol",
a89c33db9   Wolfgang Denk   General help mess...
80
  	"[loadAddress] [[hostIPaddr:]bootfilename]"
8bde7f776   wdenk   * Code cleanup:
81
  );
bf6cb247a   Peter Tyser   rarp: Condtionall...
82
  #endif
8bde7f776   wdenk   * Code cleanup:
83

c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
84
  #if defined(CONFIG_CMD_DHCP)
088f1b199   Kim Phillips   common/cmd_*.c: s...
85
  static int do_dhcp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3863585bb   wdenk   Initial revision
86
87
88
  {
  	return netboot_common(DHCP, cmdtp, argc, argv);
  }
8bde7f776   wdenk   * Code cleanup:
89

0d4983930   wdenk   Patch by Kenneth ...
90
91
  U_BOOT_CMD(
  	dhcp,	3,	1,	do_dhcp,
2fb2604d5   Peter Tyser   Command usage cle...
92
  	"boot image via network using DHCP/TFTP protocol",
a89c33db9   Wolfgang Denk   General help mess...
93
  	"[loadAddress] [[hostIPaddr:]bootfilename]"
8bde7f776   wdenk   * Code cleanup:
94
  );
902531788   Jon Loeliger   common/: Remove l...
95
  #endif
3863585bb   wdenk   Initial revision
96

c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
97
  #if defined(CONFIG_CMD_NFS)
088f1b199   Kim Phillips   common/cmd_*.c: s...
98
  static int do_nfs(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
cbd8a35c6   wdenk   * Patch by Masami...
99
100
101
102
103
104
  {
  	return netboot_common(NFS, cmdtp, argc, argv);
  }
  
  U_BOOT_CMD(
  	nfs,	3,	1,	do_nfs,
2fb2604d5   Peter Tyser   Command usage cle...
105
  	"boot image via network using NFS protocol",
a89c33db9   Wolfgang Denk   General help mess...
106
  	"[loadAddress] [[hostIPaddr:]bootfilename]"
cbd8a35c6   wdenk   * Patch by Masami...
107
  );
902531788   Jon Loeliger   common/: Remove l...
108
  #endif
cbd8a35c6   wdenk   * Patch by Masami...
109

088f1b199   Kim Phillips   common/cmd_*.c: s...
110
  static void netboot_update_env(void)
3863585bb   wdenk   Initial revision
111
  {
6e5923851   wdenk   * Cleanup, minor ...
112
  	char tmp[22];
3863585bb   wdenk   Initial revision
113

6e5923851   wdenk   * Cleanup, minor ...
114
  	if (NetOurGatewayIP) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
115
116
  		ip_to_string(NetOurGatewayIP, tmp);
  		setenv("gatewayip", tmp);
6e5923851   wdenk   * Cleanup, minor ...
117
  	}
3863585bb   wdenk   Initial revision
118

6e5923851   wdenk   * Cleanup, minor ...
119
  	if (NetOurSubnetMask) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
120
121
  		ip_to_string(NetOurSubnetMask, tmp);
  		setenv("netmask", tmp);
6e5923851   wdenk   * Cleanup, minor ...
122
  	}
3863585bb   wdenk   Initial revision
123

6e5923851   wdenk   * Cleanup, minor ...
124
  	if (NetOurHostName[0])
088f1b199   Kim Phillips   common/cmd_*.c: s...
125
  		setenv("hostname", NetOurHostName);
3863585bb   wdenk   Initial revision
126

6e5923851   wdenk   * Cleanup, minor ...
127
  	if (NetOurRootPath[0])
088f1b199   Kim Phillips   common/cmd_*.c: s...
128
  		setenv("rootpath", NetOurRootPath);
3863585bb   wdenk   Initial revision
129

6e5923851   wdenk   * Cleanup, minor ...
130
  	if (NetOurIP) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
131
132
  		ip_to_string(NetOurIP, tmp);
  		setenv("ipaddr", tmp);
6e5923851   wdenk   * Cleanup, minor ...
133
  	}
a3e1a727f   Joe Hershberger   net: Don't write ...
134
135
136
137
138
  #if !defined(CONFIG_BOOTP_SERVERIP)
  	/*
  	 * Only attempt to change serverip if net/bootp.c:BootpCopyNetParams()
  	 * could have set it
  	 */
6e5923851   wdenk   * Cleanup, minor ...
139
  	if (NetServerIP) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
140
141
  		ip_to_string(NetServerIP, tmp);
  		setenv("serverip", tmp);
6e5923851   wdenk   * Cleanup, minor ...
142
  	}
a3e1a727f   Joe Hershberger   net: Don't write ...
143
  #endif
6e5923851   wdenk   * Cleanup, minor ...
144
  	if (NetOurDNSIP) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
145
146
  		ip_to_string(NetOurDNSIP, tmp);
  		setenv("dnsip", tmp);
6e5923851   wdenk   * Cleanup, minor ...
147
  	}
1fe80d79c   Jon Loeliger   Finally retire cm...
148
  #if defined(CONFIG_BOOTP_DNS2)
6e5923851   wdenk   * Cleanup, minor ...
149
  	if (NetOurDNS2IP) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
150
151
  		ip_to_string(NetOurDNS2IP, tmp);
  		setenv("dnsip2", tmp);
6e5923851   wdenk   * Cleanup, minor ...
152
  	}
fe389a82c   stroese   - Added CONFIG_BO...
153
  #endif
6e5923851   wdenk   * Cleanup, minor ...
154
  	if (NetOurNISDomain[0])
088f1b199   Kim Phillips   common/cmd_*.c: s...
155
  		setenv("domain", NetOurNISDomain);
ea287debe   wdenk   * Patch by Masami...
156

c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
157
  #if defined(CONFIG_CMD_SNTP) \
1fe80d79c   Jon Loeliger   Finally retire cm...
158
      && defined(CONFIG_BOOTP_TIMEOFFSET)
ea287debe   wdenk   * Patch by Masami...
159
  	if (NetTimeOffset) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
160
161
  		sprintf(tmp, "%d", NetTimeOffset);
  		setenv("timeoffset", tmp);
ea287debe   wdenk   * Patch by Masami...
162
163
  	}
  #endif
c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
164
  #if defined(CONFIG_CMD_SNTP) \
1fe80d79c   Jon Loeliger   Finally retire cm...
165
      && defined(CONFIG_BOOTP_NTPSERVER)
ea287debe   wdenk   * Patch by Masami...
166
  	if (NetNtpServerIP) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
167
168
  		ip_to_string(NetNtpServerIP, tmp);
  		setenv("ntpserverip", tmp);
ea287debe   wdenk   * Patch by Masami...
169
170
  	}
  #endif
3863585bb   wdenk   Initial revision
171
  }
6e5923851   wdenk   * Cleanup, minor ...
172

e4bf0c5cf   Simon Glass   net: tftpput: Ren...
173
174
  static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
  		char * const argv[])
3863585bb   wdenk   Initial revision
175
176
  {
  	char *s;
2e4970d81   Peter Tyser   net: Fix download...
177
  	char *end;
3863585bb   wdenk   Initial revision
178
179
  	int   rcode = 0;
  	int   size;
2e4970d81   Peter Tyser   net: Fix download...
180
  	ulong addr;
3863585bb   wdenk   Initial revision
181
182
183
184
185
186
187
188
189
  
  	/* pre-set load_addr */
  	if ((s = getenv("loadaddr")) != NULL) {
  		load_addr = simple_strtoul(s, NULL, 16);
  	}
  
  	switch (argc) {
  	case 1:
  		break;
2e4970d81   Peter Tyser   net: Fix download...
190
191
192
193
194
  	case 2:	/*
  		 * Only one arg - accept two forms:
  		 * Just load address, or just boot file name. The latter
  		 * form must be written in a format which can not be
  		 * mis-interpreted as a valid number.
3863585bb   wdenk   Initial revision
195
  		 */
2e4970d81   Peter Tyser   net: Fix download...
196
197
198
199
200
  		addr = simple_strtoul(argv[1], &end, 16);
  		if (end == (argv[1] + strlen(argv[1])))
  			load_addr = addr;
  		else
  			copy_filename(BootFile, argv[1], sizeof(BootFile));
3863585bb   wdenk   Initial revision
201
202
203
  		break;
  
  	case 3:	load_addr = simple_strtoul(argv[1], NULL, 16);
088f1b199   Kim Phillips   common/cmd_*.c: s...
204
  		copy_filename(BootFile, argv[2], sizeof(BootFile));
3863585bb   wdenk   Initial revision
205
206
  
  		break;
2d46cf291   Simon Glass   net: tftpput: add...
207
208
  #ifdef CONFIG_CMD_TFTPPUT
  	case 4:
38bd80b48   Simon Glass   net: Fix argument...
209
210
211
212
213
214
  		if (strict_strtoul(argv[1], 16, &save_addr) < 0 ||
  			strict_strtoul(argv[2], 16, &save_size) < 0) {
  			printf("Invalid address/size
  ");
  			return cmd_usage(cmdtp);
  		}
2d46cf291   Simon Glass   net: tftpput: add...
215
216
217
  		copy_filename(BootFile, argv[3], sizeof(BootFile));
  		break;
  #endif
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
218
  	default:
770605e4f   Simon Glass   bootstage: Replac...
219
  		bootstage_error(BOOTSTAGE_ID_NET_START);
4c12eeb8b   Simon Glass   Convert cmd_usage...
220
  		return CMD_RET_USAGE;
3863585bb   wdenk   Initial revision
221
  	}
770605e4f   Simon Glass   bootstage: Replac...
222
  	bootstage_mark(BOOTSTAGE_ID_NET_START);
3863585bb   wdenk   Initial revision
223

566a494f5   Heiko Schocher   [PCS440EP] u...
224
  	if ((size = NetLoop(proto)) < 0) {
770605e4f   Simon Glass   bootstage: Replac...
225
  		bootstage_error(BOOTSTAGE_ID_NET_NETLOOP_OK);
3863585bb   wdenk   Initial revision
226
  		return 1;
566a494f5   Heiko Schocher   [PCS440EP] u...
227
  	}
770605e4f   Simon Glass   bootstage: Replac...
228
  	bootstage_mark(BOOTSTAGE_ID_NET_NETLOOP_OK);
3863585bb   wdenk   Initial revision
229
230
231
  
  	/* NetLoop ok, update environment */
  	netboot_update_env();
eb9401e3e   wdenk   * Patch by Andrea...
232
  	/* done if no file was loaded (no errors though) */
566a494f5   Heiko Schocher   [PCS440EP] u...
233
  	if (size == 0) {
770605e4f   Simon Glass   bootstage: Replac...
234
  		bootstage_error(BOOTSTAGE_ID_NET_LOADED);
eb9401e3e   wdenk   * Patch by Andrea...
235
  		return 0;
566a494f5   Heiko Schocher   [PCS440EP] u...
236
  	}
eb9401e3e   wdenk   * Patch by Andrea...
237

3863585bb   wdenk   Initial revision
238
239
  	/* flush cache */
  	flush_cache(load_addr, size);
770605e4f   Simon Glass   bootstage: Replac...
240
  	bootstage_mark(BOOTSTAGE_ID_NET_LOADED);
c8e66db78   Simon Glass   bootstage: Conver...
241

67d668bf9   Mike Frysinger   autostart: unify ...
242
  	rcode = bootm_maybe_autostart(cmdtp, argv[0]);
3863585bb   wdenk   Initial revision
243

566a494f5   Heiko Schocher   [PCS440EP] u...
244
  	if (rcode < 0)
770605e4f   Simon Glass   bootstage: Replac...
245
  		bootstage_error(BOOTSTAGE_ID_NET_DONE_ERR);
566a494f5   Heiko Schocher   [PCS440EP] u...
246
  	else
770605e4f   Simon Glass   bootstage: Replac...
247
  		bootstage_mark(BOOTSTAGE_ID_NET_DONE);
3863585bb   wdenk   Initial revision
248
249
  	return rcode;
  }
c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
250
  #if defined(CONFIG_CMD_PING)
088f1b199   Kim Phillips   common/cmd_*.c: s...
251
  static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
73a8b27c5   wdenk   * Add support for...
252
253
254
255
256
  {
  	if (argc < 2)
  		return -1;
  
  	NetPingIP = string_to_ip(argv[1]);
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
257
  	if (NetPingIP == 0)
4c12eeb8b   Simon Glass   Convert cmd_usage...
258
  		return CMD_RET_USAGE;
73a8b27c5   wdenk   * Add support for...
259
260
261
262
263
264
265
266
267
268
269
270
  
  	if (NetLoop(PING) < 0) {
  		printf("ping failed; host %s is not alive
  ", argv[1]);
  		return 1;
  	}
  
  	printf("host %s is alive
  ", argv[1]);
  
  	return 0;
  }
6dff55297   wdenk   * Patches by Mart...
271
272
273
  
  U_BOOT_CMD(
  	ping,	2,	1,	do_ping,
2fb2604d5   Peter Tyser   Command usage cle...
274
  	"send ICMP ECHO_REQUEST to network host",
a89c33db9   Wolfgang Denk   General help mess...
275
  	"pingAddress"
6dff55297   wdenk   * Patches by Mart...
276
  );
902531788   Jon Loeliger   common/: Remove l...
277
  #endif
73a8b27c5   wdenk   * Add support for...
278

c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
279
  #if defined(CONFIG_CMD_CDP)
a3d991bd0   wdenk   Patches by Pantel...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
  
  static void cdp_update_env(void)
  {
  	char tmp[16];
  
  	if (CDPApplianceVLAN != htons(-1)) {
  		printf("CDP offered appliance VLAN %d
  ", ntohs(CDPApplianceVLAN));
  		VLAN_to_string(CDPApplianceVLAN, tmp);
  		setenv("vlan", tmp);
  		NetOurVLAN = CDPApplianceVLAN;
  	}
  
  	if (CDPNativeVLAN != htons(-1)) {
  		printf("CDP offered native VLAN %d
  ", ntohs(CDPNativeVLAN));
  		VLAN_to_string(CDPNativeVLAN, tmp);
  		setenv("nvlan", tmp);
  		NetOurNativeVLAN = CDPNativeVLAN;
  	}
  
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
302
  int do_cdp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
a3d991bd0   wdenk   Patches by Pantel...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
  {
  	int r;
  
  	r = NetLoop(CDP);
  	if (r < 0) {
  		printf("cdp failed; perhaps not a CISCO switch?
  ");
  		return 1;
  	}
  
  	cdp_update_env();
  
  	return 0;
  }
  
  U_BOOT_CMD(
  	cdp,	1,	1,	do_cdp,
ec5c04cdb   Wolfgang Denk   Revert "cmd_net: ...
320
  	"Perform CDP network configuration",
4b58266e9   Wolfgang Denk   cmd_net.c: fix bu...
321
322
  	"
  "
a3d991bd0   wdenk   Patches by Pantel...
323
  );
902531788   Jon Loeliger   common/: Remove l...
324
  #endif
a3d991bd0   wdenk   Patches by Pantel...
325

c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
326
  #if defined(CONFIG_CMD_SNTP)
088f1b199   Kim Phillips   common/cmd_*.c: s...
327
  int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ea287debe   wdenk   * Patch by Masami...
328
329
330
331
  {
  	char *toff;
  
  	if (argc < 2) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
332
  		NetNtpServerIP = getenv_IPaddr("ntpserverip");
ea287debe   wdenk   * Patch by Masami...
333
  		if (NetNtpServerIP == 0) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
334
335
  			printf("ntpserverip not set
  ");
ea287debe   wdenk   * Patch by Masami...
336
337
338
339
340
  			return (1);
  		}
  	} else {
  		NetNtpServerIP = string_to_ip(argv[1]);
  		if (NetNtpServerIP == 0) {
088f1b199   Kim Phillips   common/cmd_*.c: s...
341
342
  			printf("Bad NTP server IP address
  ");
ea287debe   wdenk   * Patch by Masami...
343
344
345
  			return (1);
  		}
  	}
088f1b199   Kim Phillips   common/cmd_*.c: s...
346
347
348
349
350
  	toff = getenv("timeoffset");
  	if (toff == NULL)
  		NetTimeOffset = 0;
  	else
  		NetTimeOffset = simple_strtol(toff, NULL, 10);
ea287debe   wdenk   * Patch by Masami...
351
352
  
  	if (NetLoop(SNTP) < 0) {
d6840e3d7   Luuk Paulussen   sntp: avoid use o...
353
354
355
  		printf("SNTP failed: host %pI4 not responding
  ",
  			&NetNtpServerIP);
ea287debe   wdenk   * Patch by Masami...
356
357
358
359
360
361
362
363
  		return 1;
  	}
  
  	return 0;
  }
  
  U_BOOT_CMD(
  	sntp,	2,	1,	do_sntp,
2fb2604d5   Peter Tyser   Command usage cle...
364
  	"synchronize RTC via network",
ea287debe   wdenk   * Patch by Masami...
365
366
367
  	"[NTP server IP]
  "
  );
902531788   Jon Loeliger   common/: Remove l...
368
  #endif
1a32bf418   Robin Getz   Add DNS support
369
370
  
  #if defined(CONFIG_CMD_DNS)
54841ab50   Wolfgang Denk   Make sure that ar...
371
  int do_dns(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1a32bf418   Robin Getz   Add DNS support
372
  {
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
373
  	if (argc == 1)
4c12eeb8b   Simon Glass   Convert cmd_usage...
374
  		return CMD_RET_USAGE;
1a32bf418   Robin Getz   Add DNS support
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
  
  	/*
  	 * We should check for a valid hostname:
  	 * - Each label must be between 1 and 63 characters long
  	 * - the entire hostname has a maximum of 255 characters
  	 * - only the ASCII letters 'a' through 'z' (case-insensitive),
  	 *   the digits '0' through '9', and the hyphen
  	 * - cannot begin or end with a hyphen
  	 * - no other symbols, punctuation characters, or blank spaces are
  	 *   permitted
  	 * but hey - this is a minimalist implmentation, so only check length
  	 * and let the name server deal with things.
  	 */
  	if (strlen(argv[1]) >= 255) {
  		printf("dns error: hostname too long
  ");
  		return 1;
  	}
  
  	NetDNSResolve = argv[1];
  
  	if (argc == 3)
  		NetDNSenvvar = argv[2];
  	else
  		NetDNSenvvar = NULL;
  
  	if (NetLoop(DNS) < 0) {
  		printf("dns lookup of %s failed, check setup
  ", argv[1]);
  		return 1;
  	}
  
  	return 0;
  }
  
  U_BOOT_CMD(
  	dns,	3,	1,	do_dns,
  	"lookup the IP of a hostname",
  	"hostname [envvar]"
  );
  
  #endif	/* CONFIG_CMD_DNS */
d22c338e0   Joe Hershberger   net: Add link-loc...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
  
  #if defined(CONFIG_CMD_LINK_LOCAL)
  static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
  			char * const argv[])
  {
  	char tmp[22];
  
  	if (NetLoop(LINKLOCAL) < 0)
  		return 1;
  
  	NetOurGatewayIP = 0;
  	ip_to_string(NetOurGatewayIP, tmp);
  	setenv("gatewayip", tmp);
  
  	ip_to_string(NetOurSubnetMask, tmp);
  	setenv("netmask", tmp);
  
  	ip_to_string(NetOurIP, tmp);
  	setenv("ipaddr", tmp);
  	setenv("llipaddr", tmp); /* store this for next time */
  
  	return 0;
  }
  
  U_BOOT_CMD(
  	linklocal,	1,	1,	do_link_local,
  	"acquire a network IP address using the link-local protocol",
  	""
  );
  
  #endif  /* CONFIG_CMD_LINK_LOCAL */