]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/emk/common/vpd.c
rename CFG_ macros to CONFIG_SYS
[karo-tx-uboot.git] / board / emk / common / vpd.c
1 /*
2  * (C) Copyright 2003
3  * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.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
26 /*****************************************************************************
27  * read "factory" part of EEPROM and set some environment variables
28  *****************************************************************************/
29 void read_factory_r (void)
30 {
31         /* read 'factory' part of EEPROM */
32         uchar buf[81];
33         uchar *p;
34         uint length;
35         uint addr;
36         uint len;
37
38         /* get length first */
39         addr = CONFIG_SYS_FACT_OFFSET;
40         if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, 2)) {
41           bailout:
42                 printf ("cannot read factory configuration\n");
43                 printf ("be sure to set ethaddr yourself!\n");
44                 return;
45         }
46         length = buf[0] + (buf[1] << 8);
47         addr += 2;
48
49         /* sanity check */
50         if (length < 20 || length > CONFIG_SYS_FACT_SIZE - 2)
51                 goto bailout;
52
53         /* read lines */
54         while (length > 0) {
55                 /* read one line */
56                 len = length > 80 ? 80 : length;
57                 if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, len))
58                         goto bailout;
59                 /* mark end of buffer */
60                 buf[len] = 0;
61                 /* search end of line */
62                 for (p = buf; *p && *p != 0x0a; p++);
63                 if (!*p)
64                         goto bailout;
65                 *p++ = 0;
66                 /* advance to next line start */
67                 length -= p - buf;
68                 addr += p - buf;
69                 /*printf ("%s\n", buf); */
70                 /* search for our specific entry */
71                 if (!strncmp ((char *) buf, "[RLA/lan/Ethernet] ", 19)) {
72                         setenv ("ethaddr", (char *)(buf + 19));
73                 } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) {
74                         setenv ("serial#", (char *)(buf + 15));
75                 } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) {
76                         setenv ("board_id", (char *)(buf + 13));
77                 }
78         }
79 }