blob: 59ad6aa3ed92a97f9369111de6d4ef4719d43048 [file] [log] [blame]
wdenk6dd652f2003-06-19 23:40:20 +00001/*
2 * (C) Copyright 2003
3 * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk6dd652f2003-06-19 23:40:20 +00006 */
7
8#include <common.h>
Simon Glass18d66532014-04-10 20:01:25 -06009#include <cli.h>
wdenk6dd652f2003-06-19 23:40:20 +000010
wdenk6dd652f2003-06-19 23:40:20 +000011int
12hymod_get_serno (const char *prompt)
13{
14 for (;;) {
15 int n, serno;
16 char *p;
17
18#ifdef CONFIG_BOOT_RETRY_TIME
19 reset_cmd_timeout ();
20#endif
21
Simon Glasse1bf8242014-04-10 20:01:27 -060022 n = cli_readline(prompt);
wdenk6dd652f2003-06-19 23:40:20 +000023
24 if (n < 0)
25 return (n);
26
27 if (n == 0)
28 continue;
29
30 serno = (int) simple_strtol (console_buffer, &p, 10);
31
32 if (p > console_buffer && *p == '\0' && serno > 0)
33 return (serno);
34
35 printf ("Invalid number (%s) - please re-enter\n",
36 console_buffer);
37 }
38}
39
40int
41hymod_get_ethaddr (void)
42{
43 for (;;) {
44 int n;
45
46#ifdef CONFIG_BOOT_RETRY_TIME
47 reset_cmd_timeout ();
48#endif
49
Simon Glasse1bf8242014-04-10 20:01:27 -060050 n = cli_readline("Enter board ethernet address: ");
wdenk6dd652f2003-06-19 23:40:20 +000051
52 if (n < 0)
53 return (n);
54
55 if (n == 0)
56 continue;
57
58 if (n == 17) {
59 int i;
60 char *p, *q;
wdenk6dd652f2003-06-19 23:40:20 +000061
62 /* see if it looks like an ethernet address */
63
64 p = console_buffer;
65
66 for (i = 0; i < 6; i++) {
67 char term = (i == 5 ? '\0' : ':');
68
Wolfgang Denk48fddf62011-11-05 05:13:10 +000069 (void)simple_strtol (p, &q, 16);
wdenk6dd652f2003-06-19 23:40:20 +000070
71 if ((q - p) != 2 || *q++ != term)
72 break;
73
74 p = q;
75 }
76
77 if (i == 6) {
78 /* it looks ok - set it */
79 printf ("Setting ethernet addr to %s\n",
80 console_buffer);
81
82 setenv ("ethaddr", console_buffer);
83
84 puts ("Remember to do a 'saveenv' to "
85 "make it permanent\n");
86
87 return (0);
88 }
89 }
90
91 printf ("Invalid ethernet addr (%s) - please re-enter\n",
92 console_buffer);
93 }
94}