blob: 1a2b8d23a7be380c6ce7c9bd3f5dc83ee678487c [file] [log] [blame]
wdenk6dd652f2003-06-19 23:40:20 +00001/*
2 * (C) Copyright 2003
3 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
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#include <common.h>
25
26/* imports from common/main.c */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020027extern char console_buffer[CONFIG_SYS_CBSIZE];
wdenk6dd652f2003-06-19 23:40:20 +000028
29int
30hymod_get_serno (const char *prompt)
31{
32 for (;;) {
33 int n, serno;
34 char *p;
35
36#ifdef CONFIG_BOOT_RETRY_TIME
37 reset_cmd_timeout ();
38#endif
39
40 n = readline (prompt);
41
42 if (n < 0)
43 return (n);
44
45 if (n == 0)
46 continue;
47
48 serno = (int) simple_strtol (console_buffer, &p, 10);
49
50 if (p > console_buffer && *p == '\0' && serno > 0)
51 return (serno);
52
53 printf ("Invalid number (%s) - please re-enter\n",
54 console_buffer);
55 }
56}
57
58int
59hymod_get_ethaddr (void)
60{
61 for (;;) {
62 int n;
63
64#ifdef CONFIG_BOOT_RETRY_TIME
65 reset_cmd_timeout ();
66#endif
67
68 n = readline ("Enter board ethernet address: ");
69
70 if (n < 0)
71 return (n);
72
73 if (n == 0)
74 continue;
75
76 if (n == 17) {
77 int i;
78 char *p, *q;
wdenk6dd652f2003-06-19 23:40:20 +000079
80 /* see if it looks like an ethernet address */
81
82 p = console_buffer;
83
84 for (i = 0; i < 6; i++) {
85 char term = (i == 5 ? '\0' : ':');
86
Wolfgang Denk48fddf62011-11-05 05:13:10 +000087 (void)simple_strtol (p, &q, 16);
wdenk6dd652f2003-06-19 23:40:20 +000088
89 if ((q - p) != 2 || *q++ != term)
90 break;
91
92 p = q;
93 }
94
95 if (i == 6) {
96 /* it looks ok - set it */
97 printf ("Setting ethernet addr to %s\n",
98 console_buffer);
99
100 setenv ("ethaddr", console_buffer);
101
102 puts ("Remember to do a 'saveenv' to "
103 "make it permanent\n");
104
105 return (0);
106 }
107 }
108
109 printf ("Invalid ethernet addr (%s) - please re-enter\n",
110 console_buffer);
111 }
112}