blob: c2af21952edb53a70ffd8aa46671e325cd8d802a [file] [log] [blame]
wdenk1c437712004-01-16 00:30:56 +00001/*
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 *****************************************************************************/
29void 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 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 addr = CONFIG_SYS_FACT_OFFSET;
40 if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, 2)) {
wdenk1c437712004-01-16 00:30:56 +000041 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 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050 if (length < 20 || length > CONFIG_SYS_FACT_SIZE - 2)
wdenk1c437712004-01-16 00:30:56 +000051 goto bailout;
52
53 /* read lines */
54 while (length > 0) {
55 /* read one line */
56 len = length > 80 ? 80 : length;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057 if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, len))
wdenk1c437712004-01-16 00:30:56 +000058 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)) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +020072 setenv ("ethaddr", (char *)(buf + 19));
wdenk1c437712004-01-16 00:30:56 +000073 } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +020074 setenv ("serial#", (char *)(buf + 15));
wdenk1c437712004-01-16 00:30:56 +000075 } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +020076 setenv ("board_id", (char *)(buf + 13));
wdenk1c437712004-01-16 00:30:56 +000077 }
78 }
79}