input.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * (C) Copyright 2003
  3. * Murray Jensen, CSIRO-MIT, <Murray.Jensen@csiro.au>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. /* imports from common/main.c */
  25. extern char console_buffer[CONFIG_SYS_CBSIZE];
  26. int
  27. hymod_get_serno (const char *prompt)
  28. {
  29. for (;;) {
  30. int n, serno;
  31. char *p;
  32. #ifdef CONFIG_BOOT_RETRY_TIME
  33. reset_cmd_timeout ();
  34. #endif
  35. n = readline (prompt);
  36. if (n < 0)
  37. return (n);
  38. if (n == 0)
  39. continue;
  40. serno = (int) simple_strtol (console_buffer, &p, 10);
  41. if (p > console_buffer && *p == '\0' && serno > 0)
  42. return (serno);
  43. printf ("Invalid number (%s) - please re-enter\n",
  44. console_buffer);
  45. }
  46. }
  47. int
  48. hymod_get_ethaddr (void)
  49. {
  50. for (;;) {
  51. int n;
  52. #ifdef CONFIG_BOOT_RETRY_TIME
  53. reset_cmd_timeout ();
  54. #endif
  55. n = readline ("Enter board ethernet address: ");
  56. if (n < 0)
  57. return (n);
  58. if (n == 0)
  59. continue;
  60. if (n == 17) {
  61. int i;
  62. char *p, *q;
  63. uchar ea[6];
  64. /* see if it looks like an ethernet address */
  65. p = console_buffer;
  66. for (i = 0; i < 6; i++) {
  67. char term = (i == 5 ? '\0' : ':');
  68. ea[i] = simple_strtol (p, &q, 16);
  69. if ((q - p) != 2 || *q++ != term)
  70. break;
  71. p = q;
  72. }
  73. if (i == 6) {
  74. /* it looks ok - set it */
  75. printf ("Setting ethernet addr to %s\n",
  76. console_buffer);
  77. setenv ("ethaddr", console_buffer);
  78. puts ("Remember to do a 'saveenv' to "
  79. "make it permanent\n");
  80. return (0);
  81. }
  82. }
  83. printf ("Invalid ethernet addr (%s) - please re-enter\n",
  84. console_buffer);
  85. }
  86. }