wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
| 10 | /***************************************************************************** |
| 11 | * read "factory" part of EEPROM and set some environment variables |
| 12 | *****************************************************************************/ |
| 13 | void 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | addr = CONFIG_SYS_FACT_OFFSET; |
| 24 | if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, 2)) { |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 25 | 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | if (length < 20 || length > CONFIG_SYS_FACT_SIZE - 2) |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 35 | goto bailout; |
| 36 | |
| 37 | /* read lines */ |
| 38 | while (length > 0) { |
| 39 | /* read one line */ |
| 40 | len = length > 80 ? 80 : length; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 41 | if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, len)) |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 42 | 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 Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 56 | setenv ("ethaddr", (char *)(buf + 19)); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 57 | } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 58 | setenv ("serial#", (char *)(buf + 15)); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 59 | } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 60 | setenv ("board_id", (char *)(buf + 13)); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | } |