wdenk | 6dd652f | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 10 | int |
| 11 | hymod_get_serno (const char *prompt) |
| 12 | { |
| 13 | for (;;) { |
| 14 | int n, serno; |
| 15 | char *p; |
| 16 | |
| 17 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 18 | reset_cmd_timeout (); |
| 19 | #endif |
| 20 | |
| 21 | n = readline (prompt); |
| 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 | |
| 45 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 46 | reset_cmd_timeout (); |
| 47 | #endif |
| 48 | |
| 49 | n = readline ("Enter board ethernet address: "); |
| 50 | |
| 51 | if (n < 0) |
| 52 | return (n); |
| 53 | |
| 54 | if (n == 0) |
| 55 | continue; |
| 56 | |
| 57 | if (n == 17) { |
| 58 | int i; |
| 59 | char *p, *q; |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 60 | |
| 61 | /* see if it looks like an ethernet address */ |
| 62 | |
| 63 | p = console_buffer; |
| 64 | |
| 65 | for (i = 0; i < 6; i++) { |
| 66 | char term = (i == 5 ? '\0' : ':'); |
| 67 | |
Wolfgang Denk | 48fddf6 | 2011-11-05 05:13:10 +0000 | [diff] [blame] | 68 | (void)simple_strtol (p, &q, 16); |
wdenk | 6dd652f | 2003-06-19 23:40:20 +0000 | [diff] [blame] | 69 | |
| 70 | if ((q - p) != 2 || *q++ != term) |
| 71 | break; |
| 72 | |
| 73 | p = q; |
| 74 | } |
| 75 | |
| 76 | if (i == 6) { |
| 77 | /* it looks ok - set it */ |
| 78 | printf ("Setting ethernet addr to %s\n", |
| 79 | console_buffer); |
| 80 | |
| 81 | setenv ("ethaddr", console_buffer); |
| 82 | |
| 83 | puts ("Remember to do a 'saveenv' to " |
| 84 | "make it permanent\n"); |
| 85 | |
| 86 | return (0); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | printf ("Invalid ethernet addr (%s) - please re-enter\n", |
| 91 | console_buffer); |
| 92 | } |
| 93 | } |