wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2004 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.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 | #include <mpc8xx.h> |
| 26 | |
| 27 | /*----------------------------------------------------------------------- |
| 28 | * Process Hardware Information Block: |
| 29 | * |
| 30 | * If we boot on a system fresh from factory, check if the Hardware |
| 31 | * Information Block exists and save the information it contains. |
| 32 | * |
| 33 | * The KUP Hardware Information Block is defined as |
| 34 | * follows: |
| 35 | * - located in first flash bank |
| 36 | * - starts at offset CFG_HWINFO_OFFSET |
| 37 | * - size CFG_HWINFO_SIZE |
| 38 | * |
| 39 | * Internal structure: |
| 40 | * - sequence of ASCII character lines |
| 41 | * - fields separated by <CR><LF> |
| 42 | * - last field terminated by NUL character (0x00) |
| 43 | * |
| 44 | * Fields in Hardware Information Block: |
| 45 | * 1) Module Type |
| 46 | * 2) MAC Address |
| 47 | * 3) .... |
| 48 | */ |
| 49 | |
| 50 | |
| 51 | #define ETHADDR_TOKEN "ethaddr=" |
| 52 | #define LCD_TOKEN "lcd=" |
| 53 | |
| 54 | void load_sernum_ethaddr (void) |
| 55 | { |
| 56 | unsigned char *hwi; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 57 | char *var; |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 58 | unsigned char hwi_stack[CFG_HWINFO_SIZE]; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 59 | char *p; |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 60 | |
| 61 | hwi = (unsigned char *) (CFG_FLASH_BASE + CFG_HWINFO_OFFSET); |
| 62 | if (*((unsigned long *) hwi) != (unsigned long) CFG_HWINFO_MAGIC) { |
| 63 | printf ("HardwareInfo not found!\n"); |
| 64 | return; |
| 65 | } |
| 66 | memcpy (hwi_stack, hwi, CFG_HWINFO_SIZE); |
| 67 | |
| 68 | /* |
| 69 | ** ethaddr |
| 70 | */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 71 | var = strstr ((char *)hwi_stack, ETHADDR_TOKEN); |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 72 | if (var) { |
| 73 | var += sizeof (ETHADDR_TOKEN) - 1; |
| 74 | p = strchr (var, '\r'); |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 75 | if ((unsigned char *)p < hwi + CFG_HWINFO_SIZE) { |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 76 | *p = '\0'; |
| 77 | setenv ("ethaddr", var); |
| 78 | *p = '\r'; |
| 79 | } |
| 80 | } |
| 81 | /* |
| 82 | ** lcd |
| 83 | */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 84 | var = strstr ((char *)hwi_stack, LCD_TOKEN); |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 85 | if (var) { |
| 86 | var += sizeof (LCD_TOKEN) - 1; |
| 87 | p = strchr (var, '\r'); |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 88 | if ((unsigned char *)p < hwi + CFG_HWINFO_SIZE) { |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 89 | *p = '\0'; |
| 90 | setenv ("lcd", var); |
| 91 | *p = '\r'; |
| 92 | } |
| 93 | } |
| 94 | } |