wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 399ed9a | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 9 | #include <bootretry.h> |
Simon Glass | dec3c01 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 10 | #include <cli.h> |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 11 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 12 | int |
| 13 | hymod_get_serno (const char *prompt) |
| 14 | { |
| 15 | for (;;) { |
| 16 | int n, serno; |
| 17 | char *p; |
| 18 | |
Simon Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 19 | bootretry_reset_cmd_timeout(); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 20 | |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 21 | n = cli_readline(prompt); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 22 | |
| 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 | |
| 39 | int |
| 40 | hymod_get_ethaddr (void) |
| 41 | { |
| 42 | for (;;) { |
| 43 | int n; |
| 44 | |
Simon Glass | 09007c4 | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 45 | bootretry_reset_cmd_timeout(); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 46 | |
Simon Glass | be6aafc | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 47 | n = cli_readline("Enter board ethernet address: "); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 48 | |
| 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; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 58 | |
| 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 Denk | 6f1cf05 | 2011-11-05 05:13:10 +0000 | [diff] [blame] | 66 | (void)simple_strtol (p, &q, 16); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 67 | |
| 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 | } |