input.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. int
  25. hymod_get_serno (const char *prompt)
  26. {
  27. for (;;) {
  28. int n, serno;
  29. char *p;
  30. #ifdef CONFIG_BOOT_RETRY_TIME
  31. reset_cmd_timeout ();
  32. #endif
  33. n = readline (prompt);
  34. if (n < 0)
  35. return (n);
  36. if (n == 0)
  37. continue;
  38. serno = (int) simple_strtol (console_buffer, &p, 10);
  39. if (p > console_buffer && *p == '\0' && serno > 0)
  40. return (serno);
  41. printf ("Invalid number (%s) - please re-enter\n",
  42. console_buffer);
  43. }
  44. }
  45. int
  46. hymod_get_ethaddr (void)
  47. {
  48. for (;;) {
  49. int n;
  50. #ifdef CONFIG_BOOT_RETRY_TIME
  51. reset_cmd_timeout ();
  52. #endif
  53. n = readline ("Enter board ethernet address: ");
  54. if (n < 0)
  55. return (n);
  56. if (n == 0)
  57. continue;
  58. if (n == 17) {
  59. int i;
  60. char *p, *q;
  61. /* see if it looks like an ethernet address */
  62. p = console_buffer;
  63. for (i = 0; i < 6; i++) {
  64. char term = (i == 5 ? '\0' : ':');
  65. (void)simple_strtol (p, &q, 16);
  66. if ((q - p) != 2 || *q++ != term)
  67. break;
  68. p = q;
  69. }
  70. if (i == 6) {
  71. /* it looks ok - set it */
  72. printf ("Setting ethernet addr to %s\n",
  73. console_buffer);
  74. setenv ("ethaddr", console_buffer);
  75. puts ("Remember to do a 'saveenv' to "
  76. "make it permanent\n");
  77. return (0);
  78. }
  79. }
  80. printf ("Invalid ethernet addr (%s) - please re-enter\n",
  81. console_buffer);
  82. }
  83. }