deadbat-alternate.patch
[u-boot-openmoko/mini2440.git] / board / hymod / input.c
blob63aa13c4a977e2fa20952e07725fa8a9c0a6a6c7
1 /*
2 * (C) Copyright 2003
3 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
5 * See file CREDITS for list of people who contributed to this
6 * project.
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.
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.
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
24 #include <common.h>
26 /* imports from common/main.c */
27 extern char console_buffer[CFG_CBSIZE];
29 int
30 hymod_get_serno (const char *prompt)
32 for (;;) {
33 int n, serno;
34 char *p;
36 #ifdef CONFIG_BOOT_RETRY_TIME
37 reset_cmd_timeout ();
38 #endif
40 n = readline (prompt);
42 if (n < 0)
43 return (n);
45 if (n == 0)
46 continue;
48 serno = (int) simple_strtol (console_buffer, &p, 10);
50 if (p > console_buffer && *p == '\0' && serno > 0)
51 return (serno);
53 printf ("Invalid number (%s) - please re-enter\n",
54 console_buffer);
58 int
59 hymod_get_ethaddr (void)
61 for (;;) {
62 int n;
64 #ifdef CONFIG_BOOT_RETRY_TIME
65 reset_cmd_timeout ();
66 #endif
68 n = readline ("Enter board ethernet address: ");
70 if (n < 0)
71 return (n);
73 if (n == 0)
74 continue;
76 if (n == 17) {
77 int i;
78 char *p, *q;
79 uchar ea[6];
81 /* see if it looks like an ethernet address */
83 p = console_buffer;
85 for (i = 0; i < 6; i++) {
86 char term = (i == 5 ? '\0' : ':');
88 ea[i] = simple_strtol (p, &q, 16);
90 if ((q - p) != 2 || *q++ != term)
91 break;
93 p = q;
96 if (i == 6) {
97 /* it looks ok - set it */
98 printf ("Setting ethernet addr to %s\n",
99 console_buffer);
101 setenv ("ethaddr", console_buffer);
103 puts ("Remember to do a 'saveenv' to "
104 "make it permanent\n");
106 return (0);
110 printf ("Invalid ethernet addr (%s) - please re-enter\n",
111 console_buffer);