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 | * |
| 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | addr = CONFIG_SYS_FACT_OFFSET; |
| 40 | if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, 2)) { |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 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 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | if (length < 20 || length > CONFIG_SYS_FACT_SIZE - 2) |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 51 | goto bailout; |
| 52 | |
| 53 | /* read lines */ |
| 54 | while (length > 0) { |
| 55 | /* read one line */ |
| 56 | len = length > 80 ? 80 : length; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | if (eeprom_read (CONFIG_SYS_I2C_FACT_ADDR, addr, buf, len)) |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 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)) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 72 | setenv ("ethaddr", (char *)(buf + 19)); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 73 | } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 74 | setenv ("serial#", (char *)(buf + 15)); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 75 | } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 76 | setenv ("board_id", (char *)(buf + 13)); |
wdenk | 1c43771 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | } |