blob: 20fe799cdca38096ade435a777c08650bb379984 [file] [log] [blame]
wdenke07ec1b2004-05-12 22:54:36 +00001/*
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenke07ec1b2004-05-12 22:54:36 +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 KUP Hardware Information Block is defined as
18 * follows:
19 * - located in first flash bank
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020020 * - starts at offset CONFIG_SYS_HWINFO_OFFSET
21 * - size CONFIG_SYS_HWINFO_SIZE
wdenke07ec1b2004-05-12 22:54:36 +000022 *
23 * Internal structure:
24 * - sequence of ASCII character lines
25 * - fields separated by <CR><LF>
26 * - last field terminated by NUL character (0x00)
27 *
28 * Fields in Hardware Information Block:
29 * 1) Module Type
30 * 2) MAC Address
31 * 3) ....
32 */
33
34
35#define ETHADDR_TOKEN "ethaddr="
36#define LCD_TOKEN "lcd="
37
38void load_sernum_ethaddr (void)
39{
40 unsigned char *hwi;
Wolfgang Denk7fb52662005-10-13 16:45:02 +020041 char *var;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 unsigned char hwi_stack[CONFIG_SYS_HWINFO_SIZE];
Wolfgang Denk7fb52662005-10-13 16:45:02 +020043 char *p;
wdenke07ec1b2004-05-12 22:54:36 +000044
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045 hwi = (unsigned char *) (CONFIG_SYS_FLASH_BASE + CONFIG_SYS_HWINFO_OFFSET);
46 if (*((unsigned long *) hwi) != (unsigned long) CONFIG_SYS_HWINFO_MAGIC) {
wdenke07ec1b2004-05-12 22:54:36 +000047 printf ("HardwareInfo not found!\n");
48 return;
49 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050 memcpy (hwi_stack, hwi, CONFIG_SYS_HWINFO_SIZE);
wdenke07ec1b2004-05-12 22:54:36 +000051
52 /*
53 ** ethaddr
54 */
Wolfgang Denk7fb52662005-10-13 16:45:02 +020055 var = strstr ((char *)hwi_stack, ETHADDR_TOKEN);
wdenke07ec1b2004-05-12 22:54:36 +000056 if (var) {
57 var += sizeof (ETHADDR_TOKEN) - 1;
58 p = strchr (var, '\r');
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059 if ((unsigned char *)p < hwi + CONFIG_SYS_HWINFO_SIZE) {
wdenke07ec1b2004-05-12 22:54:36 +000060 *p = '\0';
61 setenv ("ethaddr", var);
62 *p = '\r';
63 }
64 }
65 /*
66 ** lcd
67 */
Wolfgang Denk7fb52662005-10-13 16:45:02 +020068 var = strstr ((char *)hwi_stack, LCD_TOKEN);
wdenke07ec1b2004-05-12 22:54:36 +000069 if (var) {
70 var += sizeof (LCD_TOKEN) - 1;
71 p = strchr (var, '\r');
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072 if ((unsigned char *)p < hwi + CONFIG_SYS_HWINFO_SIZE) {
wdenke07ec1b2004-05-12 22:54:36 +000073 *p = '\0';
74 setenv ("lcd", var);
75 *p = '\r';
76 }
77 }
78}