wdenk | e07ec1b | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <mpc8xx.h> |
| 10 | |
| 11 | /*----------------------------------------------------------------------- |
| 12 | * Process Hardware Information Block: |
| 13 | * |
| 14 | * If we boot on a system fresh from factory, check if the Hardware |
| 15 | * Information Block exists and save the information it contains. |
| 16 | * |
| 17 | * The KUP Hardware Information Block is defined as |
| 18 | * follows: |
| 19 | * - located in first flash bank |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | * - starts at offset CONFIG_SYS_HWINFO_OFFSET |
| 21 | * - size CONFIG_SYS_HWINFO_SIZE |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 22 | * |
| 23 | * Internal structure: |
| 24 | * - sequence of ASCII character lines |
| 25 | * - fields separated by <CR><LF> |
| 26 | * - last field terminated by NUL character (0x00) |
| 27 | * |
| 28 | * Fields in Hardware Information Block: |
| 29 | * 1) Module Type |
| 30 | * 2) MAC Address |
| 31 | * 3) .... |
| 32 | */ |
| 33 | |
| 34 | |
| 35 | #define ETHADDR_TOKEN "ethaddr=" |
| 36 | #define LCD_TOKEN "lcd=" |
| 37 | |
| 38 | void load_sernum_ethaddr (void) |
| 39 | { |
| 40 | unsigned char *hwi; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 41 | char *var; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | unsigned char hwi_stack[CONFIG_SYS_HWINFO_SIZE]; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 43 | char *p; |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 44 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | hwi = (unsigned char *) (CONFIG_SYS_FLASH_BASE + CONFIG_SYS_HWINFO_OFFSET); |
| 46 | if (*((unsigned long *) hwi) != (unsigned long) CONFIG_SYS_HWINFO_MAGIC) { |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 47 | printf ("HardwareInfo not found!\n"); |
| 48 | return; |
| 49 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | memcpy (hwi_stack, hwi, CONFIG_SYS_HWINFO_SIZE); |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | ** ethaddr |
| 54 | */ |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 55 | var = strstr ((char *)hwi_stack, ETHADDR_TOKEN); |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 56 | if (var) { |
| 57 | var += sizeof (ETHADDR_TOKEN) - 1; |
| 58 | p = strchr (var, '\r'); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | if ((unsigned char *)p < hwi + CONFIG_SYS_HWINFO_SIZE) { |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 60 | *p = '\0'; |
| 61 | setenv ("ethaddr", var); |
| 62 | *p = '\r'; |
| 63 | } |
| 64 | } |
| 65 | /* |
| 66 | ** lcd |
| 67 | */ |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 68 | var = strstr ((char *)hwi_stack, LCD_TOKEN); |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 69 | if (var) { |
| 70 | var += sizeof (LCD_TOKEN) - 1; |
| 71 | p = strchr (var, '\r'); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | if ((unsigned char *)p < hwi + CONFIG_SYS_HWINFO_SIZE) { |
wdenk | e07ec1b | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 73 | *p = '\0'; |
| 74 | setenv ("lcd", var); |
| 75 | *p = '\r'; |
| 76 | } |
| 77 | } |
| 78 | } |