blob: d9af92a528bf0ab9304cc1a8942cb384f3630eb3 [file] [log] [blame]
wdenkb983fa22004-01-16 00:30:56 +00001/*
2 * (C) Copyright 2003
3 * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkb983fa22004-01-16 00:30:56 +00006 */
7
8#include <common.h>
9
10/*****************************************************************************
11 * read "factory" part of EEPROM and set some environment variables
12 *****************************************************************************/
13void read_factory_r (void)
14{
15 /* read 'factory' part of EEPROM */
16 uchar buf[81];
17 uchar *p;
18 uint length;
19 uint addr;
20 uint len;
21
22 /* get length first */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023 addr = CONFIG_SYS_FACT_OFFSET;
24 if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, 2)) {
wdenkb983fa22004-01-16 00:30:56 +000025 bailout:
26 printf ("cannot read factory configuration\n");
27 printf ("be sure to set ethaddr yourself!\n");
28 return;
29 }
30 length = buf[0] + (buf[1] << 8);
31 addr += 2;
32
33 /* sanity check */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020034 if (length < 20 || length > CONFIG_SYS_FACT_SIZE - 2)
wdenkb983fa22004-01-16 00:30:56 +000035 goto bailout;
36
37 /* read lines */
38 while (length > 0) {
39 /* read one line */
40 len = length > 80 ? 80 : length;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041 if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, len))
wdenkb983fa22004-01-16 00:30:56 +000042 goto bailout;
43 /* mark end of buffer */
44 buf[len] = 0;
45 /* search end of line */
46 for (p = buf; *p && *p != 0x0a; p++);
47 if (!*p)
48 goto bailout;
49 *p++ = 0;
50 /* advance to next line start */
51 length -= p - buf;
52 addr += p - buf;
53 /*printf ("%s\n", buf); */
54 /* search for our specific entry */
55 if (!strncmp ((char *) buf, "[RLA/lan/Ethernet] ", 19)) {
Wolfgang Denk7fb52662005-10-13 16:45:02 +020056 setenv ("ethaddr", (char *)(buf + 19));
wdenkb983fa22004-01-16 00:30:56 +000057 } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) {
Wolfgang Denk7fb52662005-10-13 16:45:02 +020058 setenv ("serial#", (char *)(buf + 15));
wdenkb983fa22004-01-16 00:30:56 +000059 } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) {
Wolfgang Denk7fb52662005-10-13 16:45:02 +020060 setenv ("board_id", (char *)(buf + 13));
wdenkb983fa22004-01-16 00:30:56 +000061 }
62 }
63}