diff options
author | Simon Arlott <simon@fire.lp0.eu> | 2015-12-13 17:46:15 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2016-01-23 21:48:05 -0500 |
commit | 5a8b0b13b66608650e41994f4b9d3c8b9d258e8f (patch) | |
tree | 7dfc9fce0e7e437be0931315807108b62490f5a2 | |
parent | 3271e6103189c5294acb06ffa504cc5495457fbf (diff) |
MIPS: bcm63xx: nvram: Use nvram structure definition from header file
Use the common definition of the nvram structure from the header file
include/linux/bcm963xx_nvram.h instead of maintaining a separate copy.
Read the version 5 size of nvram data from memory and then call the
new checksum verification function from the header file.
Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Brian Norris <computersforpeace@gmail.com>
Cc: Kevin Cernekee <cernekee@gmail.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Jonas Gorski <jogo@openwrt.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: MIPS Mailing List <linux-mips@linux-mips.org>
Cc: MTD Maling List <linux-mtd@lists.infradead.org>
Patchwork: https://patchwork.linux-mips.org/patch/11831/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/bcm63xx/nvram.c | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/arch/mips/bcm63xx/nvram.c b/arch/mips/bcm63xx/nvram.c index 4b50d40f7451..05757aed016c 100644 --- a/arch/mips/bcm63xx/nvram.c +++ b/arch/mips/bcm63xx/nvram.c | |||
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #define pr_fmt(fmt) "bcm63xx_nvram: " fmt | 11 | #define pr_fmt(fmt) "bcm63xx_nvram: " fmt |
12 | 12 | ||
13 | #include <linux/bcm963xx_nvram.h> | ||
13 | #include <linux/init.h> | 14 | #include <linux/init.h> |
14 | #include <linux/crc32.h> | 15 | #include <linux/crc32.h> |
15 | #include <linux/export.h> | 16 | #include <linux/export.h> |
@@ -18,23 +19,6 @@ | |||
18 | 19 | ||
19 | #include <bcm63xx_nvram.h> | 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 | #define BCM63XX_DEFAULT_PSI_SIZE 64 | 22 | #define BCM63XX_DEFAULT_PSI_SIZE 64 |
39 | 23 | ||
40 | static struct bcm963xx_nvram nvram; | 24 | static struct bcm963xx_nvram nvram; |
@@ -42,27 +26,14 @@ static int mac_addr_used; | |||
42 | 26 | ||
43 | void __init bcm63xx_nvram_init(void *addr) | 27 | void __init bcm63xx_nvram_init(void *addr) |
44 | { | 28 | { |
45 | unsigned int check_len; | ||
46 | u32 crc, expected_crc; | 29 | u32 crc, expected_crc; |
47 | u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff }; | 30 | u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff }; |
48 | 31 | ||
49 | /* extract nvram data */ | 32 | /* extract nvram data */ |
50 | memcpy(&nvram, addr, sizeof(nvram)); | 33 | memcpy(&nvram, addr, BCM963XX_NVRAM_V5_SIZE); |
51 | 34 | ||
52 | /* check checksum before using data */ | 35 | /* check checksum before using data */ |
53 | if (nvram.version <= 4) { | 36 | if (bcm963xx_nvram_checksum(&nvram, &expected_crc, &crc)) |
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) | ||
66 | pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n", | 37 | pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n", |
67 | expected_crc, crc); | 38 | expected_crc, crc); |
68 | 39 | ||