blob: 0070da1fb85db5219b1a69a7bf13c5be2722e18d [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8#include <common.h>
9#include <mpc8xx.h>
10
11/*-----------------------------------------------------------------------
12 * Process Hardware Information Block:
13 *
14 * If we boot on a system fresh from factory, check if the Hardware
15 * Information Block exists and save the information it contains.
16 *
17 * The TQM8xxL / TQM82xx Hardware Information Block is defined as
18 * follows:
19 * - located in first flash bank
20 * - starts at offset 0x0003FFC0
21 * - size 0x00000040
22 *
23 * Internal structure:
24 * - sequence of ASCII character strings
25 * - fields separated by a single space character (0x20)
26 * - last field terminated by NUL character (0x00)
27 * - remaining space filled with NUL characters (0x00)
28 *
29 * Fields in Hardware Information Block:
30 * 1) Module Type
31 * 2) Serial Number
32 * 3) First MAC Address
33 * 4) Number of additional MAC addresses
34 */
35
36void load_sernum_ethaddr (void)
37{
38 unsigned char *hwi;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 unsigned char serial [CONFIG_SYS_HWINFO_SIZE];
40 unsigned char ethaddr[CONFIG_SYS_HWINFO_SIZE];
wdenkc6097192002-11-03 00:24:07 +000041 unsigned short ih, is, ie, part;
42
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020043 hwi = (unsigned char *)(CONFIG_SYS_FLASH_BASE + CONFIG_SYS_HWINFO_OFFSET);
wdenkc6097192002-11-03 00:24:07 +000044 ih = is = ie = 0;
45
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046 if (*((unsigned long *)hwi) != (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
wdenkc6097192002-11-03 00:24:07 +000047 return;
48 }
49
50 part = 1;
51
52 /* copy serial # / MAC address */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 while ((hwi[ih] != '\0') && (ih < CONFIG_SYS_HWINFO_SIZE)) {
wdenkc6097192002-11-03 00:24:07 +000054 if (hwi[ih] < ' ' || hwi[ih] > '~') { /* ASCII strings! */
55 return;
56 }
57 switch (part) {
58 default: /* Copy serial # */
59 if (hwi[ih] == ' ') {
60 ++part;
61 }
62 serial[is++] = hwi[ih];
63 break;
64 case 3: /* Copy MAC address */
65 if (hwi[ih] == ' ') {
66 ++part;
67 break;
68 }
69 ethaddr[ie++] = hwi[ih];
70 if ((ie % 3) == 2)
71 ethaddr[ie++] = ':';
72 break;
73 }
74 ++ih;
75 }
76 serial[is] = '\0';
77 if (ie && ethaddr[ie-1] == ':')
78 --ie;
79 ethaddr[ie] = '\0';
80
81 /* set serial# and ethaddr if not yet defined */
82 if (getenv("serial#") == NULL) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +020083 setenv ((char *)"serial#", (char *)serial);
wdenkc6097192002-11-03 00:24:07 +000084 }
85
86 if (getenv("ethaddr") == NULL) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +020087 setenv ((char *)"ethaddr", (char *)ethaddr);
wdenkc6097192002-11-03 00:24:07 +000088 }
89}