load_sernum_ethaddr.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.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. #include <mpc8xx.h>
  25. /*-----------------------------------------------------------------------
  26. * Process Hardware Information Block:
  27. *
  28. * If we boot on a system fresh from factory, check if the Hardware
  29. * Information Block exists and save the information it contains.
  30. *
  31. * The KUP Hardware Information Block is defined as
  32. * follows:
  33. * - located in first flash bank
  34. * - starts at offset CFG_HWINFO_OFFSET
  35. * - size CFG_HWINFO_SIZE
  36. *
  37. * Internal structure:
  38. * - sequence of ASCII character lines
  39. * - fields separated by <CR><LF>
  40. * - last field terminated by NUL character (0x00)
  41. *
  42. * Fields in Hardware Information Block:
  43. * 1) Module Type
  44. * 2) MAC Address
  45. * 3) ....
  46. */
  47. #define ETHADDR_TOKEN "ethaddr="
  48. #define LCD_TOKEN "lcd="
  49. void load_sernum_ethaddr (void)
  50. {
  51. unsigned char *hwi;
  52. char *var;
  53. unsigned char hwi_stack[CFG_HWINFO_SIZE];
  54. char *p;
  55. hwi = (unsigned char *) (CFG_FLASH_BASE + CFG_HWINFO_OFFSET);
  56. if (*((unsigned long *) hwi) != (unsigned long) CFG_HWINFO_MAGIC) {
  57. printf ("HardwareInfo not found!\n");
  58. return;
  59. }
  60. memcpy (hwi_stack, hwi, CFG_HWINFO_SIZE);
  61. /*
  62. ** ethaddr
  63. */
  64. var = strstr ((char *)hwi_stack, ETHADDR_TOKEN);
  65. if (var) {
  66. var += sizeof (ETHADDR_TOKEN) - 1;
  67. p = strchr (var, '\r');
  68. if ((unsigned char *)p < hwi + CFG_HWINFO_SIZE) {
  69. *p = '\0';
  70. setenv ("ethaddr", var);
  71. *p = '\r';
  72. }
  73. }
  74. /*
  75. ** lcd
  76. */
  77. var = strstr ((char *)hwi_stack, LCD_TOKEN);
  78. if (var) {
  79. var += sizeof (LCD_TOKEN) - 1;
  80. p = strchr (var, '\r');
  81. if ((unsigned char *)p < hwi + CFG_HWINFO_SIZE) {
  82. *p = '\0';
  83. setenv ("lcd", var);
  84. *p = '\r';
  85. }
  86. }
  87. }