1
2
3
4
5
6
7
8#include <common.h>
9#include <mpc8xx.h>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36void load_sernum_ethaddr (void)
37{
38 unsigned char *hwi;
39 unsigned char serial [CONFIG_SYS_HWINFO_SIZE];
40 unsigned char ethaddr[CONFIG_SYS_HWINFO_SIZE];
41 unsigned short ih, is, ie, part;
42
43 hwi = (unsigned char *)(CONFIG_SYS_FLASH_BASE + CONFIG_SYS_HWINFO_OFFSET);
44 ih = is = ie = 0;
45
46 if (*((unsigned long *)hwi) != (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
47 return;
48 }
49
50 part = 1;
51
52
53 while ((hwi[ih] != '\0') && (ih < CONFIG_SYS_HWINFO_SIZE)) {
54 if (hwi[ih] < ' ' || hwi[ih] > '~') {
55 return;
56 }
57 switch (part) {
58 default:
59 if (hwi[ih] == ' ') {
60 ++part;
61 }
62 serial[is++] = hwi[ih];
63 break;
64 case 3:
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
82 if (getenv("serial#") == NULL) {
83 setenv ((char *)"serial#", (char *)serial);
84 }
85
86 if (getenv("ethaddr") == NULL) {
87 setenv ((char *)"ethaddr", (char *)ethaddr);
88 }
89}
90