2f857c06ae92683bd515fedaf60db2ac5f408d3a
[oweals/u-boot.git] / board / hymod / input.c
1 /*
2  * (C) Copyright 2003
3  * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <bootretry.h>
10 #include <cli.h>
11
12 int
13 hymod_get_serno (const char *prompt)
14 {
15         for (;;) {
16                 int n, serno;
17                 char *p;
18
19 #ifdef CONFIG_BOOT_RETRY_TIME
20                 reset_cmd_timeout ();
21 #endif
22
23                 n = cli_readline(prompt);
24
25                 if (n < 0)
26                         return (n);
27
28                 if (n == 0)
29                         continue;
30
31                 serno = (int) simple_strtol (console_buffer, &p, 10);
32
33                 if (p > console_buffer && *p == '\0' && serno > 0)
34                         return (serno);
35
36                 printf ("Invalid number (%s) - please re-enter\n",
37                         console_buffer);
38         }
39 }
40
41 int
42 hymod_get_ethaddr (void)
43 {
44         for (;;) {
45                 int n;
46
47 #ifdef CONFIG_BOOT_RETRY_TIME
48                 reset_cmd_timeout ();
49 #endif
50
51                 n = cli_readline("Enter board ethernet address: ");
52
53                 if (n < 0)
54                         return (n);
55
56                 if (n == 0)
57                         continue;
58
59                 if (n == 17) {
60                         int i;
61                         char *p, *q;
62
63                         /* see if it looks like an ethernet address */
64
65                         p = console_buffer;
66
67                         for (i = 0; i < 6; i++) {
68                                 char term = (i == 5 ? '\0' : ':');
69
70                                 (void)simple_strtol (p, &q, 16);
71
72                                 if ((q - p) != 2 || *q++ != term)
73                                         break;
74
75                                 p = q;
76                         }
77
78                         if (i == 6) {
79                                 /* it looks ok - set it */
80                                 printf ("Setting ethernet addr to %s\n",
81                                         console_buffer);
82
83                                 setenv ("ethaddr", console_buffer);
84
85                                 puts ("Remember to do a 'saveenv' to "
86                                         "make it permanent\n");
87
88                                 return (0);
89                         }
90                 }
91
92                 printf ("Invalid ethernet addr (%s) - please re-enter\n",
93                         console_buffer);
94         }
95 }