bcm63xx: handle huawei nvram layout
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-3.8 / 119-MIPS-BCM63XX-handle-huawei-nvram-layout.patch
1 From fb1e2c8a1073297f4674ca90c7d533de5187d158 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Sat, 9 Feb 2013 12:09:53 +0100
4 Subject: [PATCH] MIPS: BCM63XX: handle huawei nvram layout
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Huawei uses a custom nvram layout, extending it with additional 32
10 byte field. This pushes also the checksum further, causing it to
11 always fail the check.
12
13 Add an additional crc check for handling this modified nvram layout
14 based on the different size.
15
16 Reported-by: Álvaro Fernández Rojas <noltari@gmail.com>
17 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
18 ---
19 arch/mips/bcm63xx/nvram.c | 18 +++++++++++++++++-
20 1 file changed, 17 insertions(+), 1 deletion(-)
21
22 --- a/arch/mips/bcm63xx/nvram.c
23 +++ b/arch/mips/bcm63xx/nvram.c
24 @@ -59,8 +59,24 @@ int __init bcm63xx_nvram_init(void *addr
25
26 crc = crc32_le(~0, (u8 *)&nvram, check_len);
27
28 - if (crc != expected_crc)
29 + if (crc != expected_crc) {
30 + /* huawei uses a modified nvram that is 32 bytes longer */
31 + if (nvram.version == 2 && !strncmp(nvram.name, "HW5", 3)) {
32 + check_len += 32;
33 +
34 + /* restore old value */
35 + nvram.checksum_old = expected_crc;
36 + expected_crc = *(u32 *)&nvram.reserved3[28];
37 + /* zero the checksum field */
38 + memset(&nvram.reserved3[28], 0, 4);
39 +
40 + crc = crc32_le(~0, (u8 *)&nvram, check_len);
41 +
42 + if (crc == expected_crc)
43 + return 0;
44 + }
45 return -EINVAL;
46 + }
47
48 return 0;
49 }