blob: 98baf7f67db37a76b0fdbe79783a58a6d4c69037 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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
24#include <common.h>
25#include <mpc8xx.h>
26
27/*-----------------------------------------------------------------------
28 * Process Hardware Information Block:
29 *
30 * If we boot on a system fresh from factory, check if the Hardware
31 * Information Block exists and save the information it contains.
32 *
33 * The TQM8xxL / TQM82xx Hardware Information Block is defined as
34 * follows:
35 * - located in first flash bank
36 * - starts at offset 0x0003FFC0
37 * - size 0x00000040
38 *
39 * Internal structure:
40 * - sequence of ASCII character strings
41 * - fields separated by a single space character (0x20)
42 * - last field terminated by NUL character (0x00)
43 * - remaining space filled with NUL characters (0x00)
44 *
45 * Fields in Hardware Information Block:
46 * 1) Module Type
47 * 2) Serial Number
48 * 3) First MAC Address
49 * 4) Number of additional MAC addresses
50 */
51
52void load_sernum_ethaddr (void)
53{
54 unsigned char *hwi;
55 unsigned char serial [CFG_HWINFO_SIZE];
56 unsigned char ethaddr[CFG_HWINFO_SIZE];
57 unsigned short ih, is, ie, part;
58
59 hwi = (unsigned char *)(CFG_FLASH_BASE + CFG_HWINFO_OFFSET);
60 ih = is = ie = 0;
61
62 if (*((unsigned long *)hwi) != (unsigned long)CFG_HWINFO_MAGIC) {
63 return;
64 }
65
66 part = 1;
67
68 /* copy serial # / MAC address */
69 while ((hwi[ih] != '\0') && (ih < CFG_HWINFO_SIZE)) {
70 if (hwi[ih] < ' ' || hwi[ih] > '~') { /* ASCII strings! */
71 return;
72 }
73 switch (part) {
74 default: /* Copy serial # */
75 if (hwi[ih] == ' ') {
76 ++part;
77 }
78 serial[is++] = hwi[ih];
79 break;
80 case 3: /* Copy MAC address */
81 if (hwi[ih] == ' ') {
82 ++part;
83 break;
84 }
85 ethaddr[ie++] = hwi[ih];
86 if ((ie % 3) == 2)
87 ethaddr[ie++] = ':';
88 break;
89 }
90 ++ih;
91 }
92 serial[is] = '\0';
93 if (ie && ethaddr[ie-1] == ':')
94 --ie;
95 ethaddr[ie] = '\0';
96
97 /* set serial# and ethaddr if not yet defined */
98 if (getenv("serial#") == NULL) {
99 setenv ("serial#", serial);
100 }
101
102 if (getenv("ethaddr") == NULL) {
103 setenv ("ethaddr", ethaddr);
104 }
105}