load_sernum_ethaddr.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * (C) Copyright 2000, 2001, 2002
  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 TQM8xxL / TQM82xx Hardware Information Block is defined as
  32. * follows:
  33. * - located in first flash bank
  34. * - starts at offset 0x0003FFC0
  35. * - size 0x00000040
  36. *
  37. * Internal structure:
  38. * - sequence of ASCII character strings
  39. * - fields separated by a single space character (0x20)
  40. * - last field terminated by NUL character (0x00)
  41. * - remaining space filled with NUL characters (0x00)
  42. *
  43. * Fields in Hardware Information Block:
  44. * 1) Module Type
  45. * 2) Serial Number
  46. * 3) First MAC Address
  47. * 4) Number of additional MAC addresses
  48. */
  49. void load_sernum_ethaddr (void)
  50. {
  51. unsigned char *hwi;
  52. unsigned char serial [CFG_HWINFO_SIZE];
  53. unsigned char ethaddr[CFG_HWINFO_SIZE];
  54. unsigned short ih, is, ie, part;
  55. hwi = (unsigned char *)(CFG_FLASH_BASE + CFG_HWINFO_OFFSET);
  56. ih = is = ie = 0;
  57. if (*((unsigned long *)hwi) != (unsigned long)CFG_HWINFO_MAGIC) {
  58. return;
  59. }
  60. part = 1;
  61. /* copy serial # / MAC address */
  62. while ((hwi[ih] != '\0') && (ih < CFG_HWINFO_SIZE)) {
  63. if (hwi[ih] < ' ' || hwi[ih] > '~') { /* ASCII strings! */
  64. return;
  65. }
  66. switch (part) {
  67. default: /* Copy serial # */
  68. if (hwi[ih] == ' ') {
  69. ++part;
  70. }
  71. serial[is++] = hwi[ih];
  72. break;
  73. case 3: /* Copy MAC address */
  74. if (hwi[ih] == ' ') {
  75. ++part;
  76. break;
  77. }
  78. ethaddr[ie++] = hwi[ih];
  79. if ((ie % 3) == 2)
  80. ethaddr[ie++] = ':';
  81. break;
  82. }
  83. ++ih;
  84. }
  85. serial[is] = '\0';
  86. if (ie && ethaddr[ie-1] == ':')
  87. --ie;
  88. ethaddr[ie] = '\0';
  89. /* set serial# and ethaddr if not yet defined */
  90. if (getenv("serial#") == NULL) {
  91. setenv ((char *)"serial#", (char *)serial);
  92. }
  93. if (getenv("ethaddr") == NULL) {
  94. setenv ((char *)"ethaddr", (char *)ethaddr);
  95. }
  96. }