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 | dec3c01 | 2014-04-10 20:01:25 -0600 | [diff] [blame^] | 9 | #include <cli.h> |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 10 | |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 11 | int |
| 12 | hymod_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 | |
| 22 | n = readline (prompt); |
| 23 | |
| 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 | |
| 40 | int |
| 41 | hymod_get_ethaddr (void) |
| 42 | { |
| 43 | for (;;) { |
| 44 | int n; |
| 45 | |
| 46 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 47 | reset_cmd_timeout (); |
| 48 | #endif |
| 49 | |
| 50 | n = readline ("Enter board ethernet address: "); |
| 51 | |
| 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; |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 61 | |
| 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 Denk | 6f1cf05 | 2011-11-05 05:13:10 +0000 | [diff] [blame] | 69 | (void)simple_strtol (p, &q, 16); |
wdenk | b00ec16 | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 70 | |
| 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 | } |