Skip to content

Commit 5a8b0b1

Browse files
nomisralfbaechle
authored andcommitted
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>
1 parent 3271e61 commit 5a8b0b1

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

arch/mips/bcm63xx/nvram.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
1212

13+
#include <linux/bcm963xx_nvram.h>
1314
#include <linux/init.h>
1415
#include <linux/crc32.h>
1516
#include <linux/export.h>
@@ -18,51 +19,21 @@
1819

1920
#include <bcm63xx_nvram.h>
2021

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-
3822
#define BCM63XX_DEFAULT_PSI_SIZE 64
3923

4024
static struct bcm963xx_nvram nvram;
4125
static int mac_addr_used;
4226

4327
void __init bcm63xx_nvram_init(void *addr)
4428
{
45-
unsigned int check_len;
4629
u32 crc, expected_crc;
4730
u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff };
4831

4932
/* extract nvram data */
50-
memcpy(&nvram, addr, sizeof(nvram));
33+
memcpy(&nvram, addr, BCM963XX_NVRAM_V5_SIZE);
5134

5235
/* 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))
6637
pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n",
6738
expected_crc, crc);
6839

0 commit comments

Comments
 (0)