vpd.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * (C) Copyright 2003
  3. * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de
  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. /*****************************************************************************
  25. * read "factory" part of EEPROM and set some environment variables
  26. *****************************************************************************/
  27. void read_factory_r (void)
  28. {
  29. /* read 'factory' part of EEPROM */
  30. uchar buf[81];
  31. uchar *p;
  32. uint length;
  33. uint addr;
  34. uint len;
  35. /* get length first */
  36. addr = CFG_FACT_OFFSET;
  37. if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, 2)) {
  38. bailout:
  39. printf ("cannot read factory configuration\n");
  40. printf ("be sure to set ethaddr yourself!\n");
  41. return;
  42. }
  43. length = buf[0] + (buf[1] << 8);
  44. addr += 2;
  45. /* sanity check */
  46. if (length < 20 || length > CFG_FACT_SIZE - 2)
  47. goto bailout;
  48. /* read lines */
  49. while (length > 0) {
  50. /* read one line */
  51. len = length > 80 ? 80 : length;
  52. if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, len))
  53. goto bailout;
  54. /* mark end of buffer */
  55. buf[len] = 0;
  56. /* search end of line */
  57. for (p = buf; *p && *p != 0x0a; p++);
  58. if (!*p)
  59. goto bailout;
  60. *p++ = 0;
  61. /* advance to next line start */
  62. length -= p - buf;
  63. addr += p - buf;
  64. /*printf ("%s\n", buf); */
  65. /* search for our specific entry */
  66. if (!strncmp ((char *) buf, "[RLA/lan/Ethernet] ", 19)) {
  67. setenv ("ethaddr", buf + 19);
  68. } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) {
  69. setenv ("serial#", buf + 15);
  70. } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) {
  71. setenv ("board_id", buf + 13);
  72. }
  73. }
  74. }