wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000, 2001, 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +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 TQM8xxL / TQM82xx Hardware Information Block is defined as |
| 18 | * follows: |
| 19 | * - located in first flash bank |
| 20 | * - starts at offset 0x0003FFC0 |
| 21 | * - size 0x00000040 |
| 22 | * |
| 23 | * Internal structure: |
| 24 | * - sequence of ASCII character strings |
| 25 | * - fields separated by a single space character (0x20) |
| 26 | * - last field terminated by NUL character (0x00) |
| 27 | * - remaining space filled with NUL characters (0x00) |
| 28 | * |
| 29 | * Fields in Hardware Information Block: |
| 30 | * 1) Module Type |
| 31 | * 2) Serial Number |
| 32 | * 3) First MAC Address |
| 33 | * 4) Number of additional MAC addresses |
| 34 | */ |
| 35 | |
| 36 | void load_sernum_ethaddr (void) |
| 37 | { |
| 38 | unsigned char *hwi; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | unsigned char serial [CONFIG_SYS_HWINFO_SIZE]; |
| 40 | unsigned char ethaddr[CONFIG_SYS_HWINFO_SIZE]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | unsigned short ih, is, ie, part; |
| 42 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 43 | hwi = (unsigned char *)(CONFIG_SYS_FLASH_BASE + CONFIG_SYS_HWINFO_OFFSET); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | ih = is = ie = 0; |
| 45 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 46 | if (*((unsigned long *)hwi) != (unsigned long)CONFIG_SYS_HWINFO_MAGIC) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | |
| 50 | part = 1; |
| 51 | |
| 52 | /* copy serial # / MAC address */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | while ((hwi[ih] != '\0') && (ih < CONFIG_SYS_HWINFO_SIZE)) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | if (hwi[ih] < ' ' || hwi[ih] > '~') { /* ASCII strings! */ |
| 55 | return; |
| 56 | } |
| 57 | switch (part) { |
| 58 | default: /* Copy serial # */ |
| 59 | if (hwi[ih] == ' ') { |
| 60 | ++part; |
| 61 | } |
| 62 | serial[is++] = hwi[ih]; |
| 63 | break; |
| 64 | case 3: /* Copy MAC address */ |
| 65 | if (hwi[ih] == ' ') { |
| 66 | ++part; |
| 67 | break; |
| 68 | } |
| 69 | ethaddr[ie++] = hwi[ih]; |
| 70 | if ((ie % 3) == 2) |
| 71 | ethaddr[ie++] = ':'; |
| 72 | break; |
| 73 | } |
| 74 | ++ih; |
| 75 | } |
| 76 | serial[is] = '\0'; |
| 77 | if (ie && ethaddr[ie-1] == ':') |
| 78 | --ie; |
| 79 | ethaddr[ie] = '\0'; |
| 80 | |
| 81 | /* set serial# and ethaddr if not yet defined */ |
| 82 | if (getenv("serial#") == NULL) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 83 | setenv ((char *)"serial#", (char *)serial); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | if (getenv("ethaddr") == NULL) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 87 | setenv ((char *)"ethaddr", (char *)ethaddr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 88 | } |
| 89 | } |