]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/hymod/input.c
Merge branch 'master' of git://git.denx.de/u-boot-mpc83xx
[karo-tx-uboot.git] / board / hymod / input.c
1 /*
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 int
27 hymod_get_serno (const char *prompt)
28 {
29         for (;;) {
30                 int n, serno;
31                 char *p;
32
33 #ifdef CONFIG_BOOT_RETRY_TIME
34                 reset_cmd_timeout ();
35 #endif
36
37                 n = readline (prompt);
38
39                 if (n < 0)
40                         return (n);
41
42                 if (n == 0)
43                         continue;
44
45                 serno = (int) simple_strtol (console_buffer, &p, 10);
46
47                 if (p > console_buffer && *p == '\0' && serno > 0)
48                         return (serno);
49
50                 printf ("Invalid number (%s) - please re-enter\n",
51                         console_buffer);
52         }
53 }
54
55 int
56 hymod_get_ethaddr (void)
57 {
58         for (;;) {
59                 int n;
60
61 #ifdef CONFIG_BOOT_RETRY_TIME
62                 reset_cmd_timeout ();
63 #endif
64
65                 n = readline ("Enter board ethernet address: ");
66
67                 if (n < 0)
68                         return (n);
69
70                 if (n == 0)
71                         continue;
72
73                 if (n == 17) {
74                         int i;
75                         char *p, *q;
76
77                         /* see if it looks like an ethernet address */
78
79                         p = console_buffer;
80
81                         for (i = 0; i < 6; i++) {
82                                 char term = (i == 5 ? '\0' : ':');
83
84                                 (void)simple_strtol (p, &q, 16);
85
86                                 if ((q - p) != 2 || *q++ != term)
87                                         break;
88
89                                 p = q;
90                         }
91
92                         if (i == 6) {
93                                 /* it looks ok - set it */
94                                 printf ("Setting ethernet addr to %s\n",
95                                         console_buffer);
96
97                                 setenv ("ethaddr", console_buffer);
98
99                                 puts ("Remember to do a 'saveenv' to "
100                                         "make it permanent\n");
101
102                                 return (0);
103                         }
104                 }
105
106                 printf ("Invalid ethernet addr (%s) - please re-enter\n",
107                         console_buffer);
108         }
109 }