|
10 | 10 |
|
11 | 11 | #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
|
12 | 12 |
|
| 13 | +#include <linux/bcm963xx_nvram.h> |
13 | 14 | #include <linux/init.h>
|
14 | 15 | #include <linux/crc32.h>
|
15 | 16 | #include <linux/export.h>
|
|
18 | 19 |
|
19 | 20 | #include <bcm63xx_nvram.h>
|
20 | 21 |
|
21 |
| -/* |
22 |
| - * nvram structure |
23 |
| - */ |
24 |
| -struct bcm963xx_nvram { |
25 |
| - u32 version; |
26 |
| - u8 reserved1[256]; |
27 |
| - u8 name[16]; |
28 |
| - u32 main_tp_number; |
29 |
| - u32 psi_size; |
30 |
| - u32 mac_addr_count; |
31 |
| - u8 mac_addr_base[ETH_ALEN]; |
32 |
| - u8 reserved2[2]; |
33 |
| - u32 checksum_old; |
34 |
| - u8 reserved3[720]; |
35 |
| - u32 checksum_high; |
36 |
| -}; |
37 |
| - |
38 | 22 | #define BCM63XX_DEFAULT_PSI_SIZE 64
|
39 | 23 |
|
40 | 24 | static struct bcm963xx_nvram nvram;
|
41 | 25 | static int mac_addr_used;
|
42 | 26 |
|
43 | 27 | void __init bcm63xx_nvram_init(void *addr)
|
44 | 28 | {
|
45 |
| - unsigned int check_len; |
46 | 29 | u32 crc, expected_crc;
|
47 | 30 | u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff };
|
48 | 31 |
|
49 | 32 | /* extract nvram data */
|
50 |
| - memcpy(&nvram, addr, sizeof(nvram)); |
| 33 | + memcpy(&nvram, addr, BCM963XX_NVRAM_V5_SIZE); |
51 | 34 |
|
52 | 35 | /* check checksum before using data */
|
53 |
| - if (nvram.version <= 4) { |
54 |
| - check_len = offsetof(struct bcm963xx_nvram, reserved3); |
55 |
| - expected_crc = nvram.checksum_old; |
56 |
| - nvram.checksum_old = 0; |
57 |
| - } else { |
58 |
| - check_len = sizeof(nvram); |
59 |
| - expected_crc = nvram.checksum_high; |
60 |
| - nvram.checksum_high = 0; |
61 |
| - } |
62 |
| - |
63 |
| - crc = crc32_le(~0, (u8 *)&nvram, check_len); |
64 |
| - |
65 |
| - if (crc != expected_crc) |
| 36 | + if (bcm963xx_nvram_checksum(&nvram, &expected_crc, &crc)) |
66 | 37 | pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n",
|
67 | 38 | expected_crc, crc);
|
68 | 39 |
|
|
0 commit comments