blob: a9035d340591042d4113b1af0b3019b53d3f8e9d [file] [log] [blame]
wdenkb00ec162003-06-19 23:40:20 +00001/*
2 * (C) Copyright 2003
3 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkb00ec162003-06-19 23:40:20 +00006 */
7
8#include <common.h>
Simon Glass399ed9a2014-04-10 20:01:30 -06009#include <bootretry.h>
Simon Glassdec3c012014-04-10 20:01:25 -060010#include <cli.h>
wdenkb00ec162003-06-19 23:40:20 +000011
wdenkb00ec162003-06-19 23:40:20 +000012int
13hymod_get_serno (const char *prompt)
14{
15 for (;;) {
16 int n, serno;
17 char *p;
18
Simon Glass09007c42014-04-10 20:01:31 -060019 bootretry_reset_cmd_timeout();
wdenkb00ec162003-06-19 23:40:20 +000020
Simon Glassbe6aafc2014-04-10 20:01:27 -060021 n = cli_readline(prompt);
wdenkb00ec162003-06-19 23:40:20 +000022
23 if (n < 0)
24 return (n);
25
26 if (n == 0)
27 continue;
28
29 serno = (int) simple_strtol (console_buffer, &p, 10);
30
31 if (p > console_buffer && *p == '\0' && serno > 0)
32 return (serno);
33
34 printf ("Invalid number (%s) - please re-enter\n",
35 console_buffer);
36 }
37}
38
39int
40hymod_get_ethaddr (void)
41{
42 for (;;) {
43 int n;
44
Simon Glass09007c42014-04-10 20:01:31 -060045 bootretry_reset_cmd_timeout();
wdenkb00ec162003-06-19 23:40:20 +000046
Simon Glassbe6aafc2014-04-10 20:01:27 -060047 n = cli_readline("Enter board ethernet address: ");
wdenkb00ec162003-06-19 23:40:20 +000048
49 if (n < 0)
50 return (n);
51
52 if (n == 0)
53 continue;
54
55 if (n == 17) {
56 int i;
57 char *p, *q;
wdenkb00ec162003-06-19 23:40:20 +000058
59 /* see if it looks like an ethernet address */
60
61 p = console_buffer;
62
63 for (i = 0; i < 6; i++) {
64 char term = (i == 5 ? '\0' : ':');
65
Wolfgang Denk6f1cf052011-11-05 05:13:10 +000066 (void)simple_strtol (p, &q, 16);
wdenkb00ec162003-06-19 23:40:20 +000067
68 if ((q - p) != 2 || *q++ != term)
69 break;
70
71 p = q;
72 }
73
74 if (i == 6) {
75 /* it looks ok - set it */
76 printf ("Setting ethernet addr to %s\n",
77 console_buffer);
78
79 setenv ("ethaddr", console_buffer);
80
81 puts ("Remember to do a 'saveenv' to "
82 "make it permanent\n");
83
84 return (0);
85 }
86 }
87
88 printf ("Invalid ethernet addr (%s) - please re-enter\n",
89 console_buffer);
90 }
91}