brcm47xx: add initial support for kernel 3.8
[openwrt/openwrt.git] / target / linux / brcm47xx / patches-3.8 / 023-mtd-bcm47xxpart-improve-probing-of-nvram-partition.patch
1 --- a/drivers/mtd/bcm47xxpart.c
2 +++ b/drivers/mtd/bcm47xxpart.c
3 @@ -19,12 +19,6 @@
4 /* 10 parts were found on sflash on Netgear WNDR4500 */
5 #define BCM47XXPART_MAX_PARTS 12
6
7 -/*
8 - * Amount of bytes we read when analyzing each block of flash memory.
9 - * Set it big enough to allow detecting partition and reading important data.
10 - */
11 -#define BCM47XXPART_BYTES_TO_READ 0x404
12 -
13 /* Magics */
14 #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
15 #define POT_MAGIC1 0x54544f50 /* POTT */
16 @@ -63,14 +57,17 @@ static int bcm47xxpart_parse(struct mtd_
17 struct trx_header *trx;
18 int trx_part = -1;
19 int last_trx_part = -1;
20 + int max_bytes_to_read = 0x8004;
21
22 if (blocksize <= 0x10000)
23 blocksize = 0x10000;
24 + if (blocksize == 0x20000)
25 + max_bytes_to_read = 0x18004;
26
27 /* Alloc */
28 parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
29 GFP_KERNEL);
30 - buf = kzalloc(BCM47XXPART_BYTES_TO_READ, GFP_KERNEL);
31 + buf = kzalloc(max_bytes_to_read, GFP_KERNEL);
32
33 /* Parse block by block looking for magics */
34 for (offset = 0; offset <= master->size - blocksize;
35 @@ -85,7 +82,7 @@ static int bcm47xxpart_parse(struct mtd_
36 }
37
38 /* Read beginning of the block */
39 - if (mtd_read(master, offset, BCM47XXPART_BYTES_TO_READ,
40 + if (mtd_read(master, offset, max_bytes_to_read,
41 &bytes_read, (uint8_t *)buf) < 0) {
42 pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
43 offset);
44 @@ -100,9 +97,16 @@ static int bcm47xxpart_parse(struct mtd_
45 }
46
47 /* Standard NVRAM */
48 - if (buf[0x000 / 4] == NVRAM_HEADER) {
49 + if (buf[0x000 / 4] == NVRAM_HEADER ||
50 + buf[0x1000 / 4] == NVRAM_HEADER ||
51 + buf[0x8000 / 4] == NVRAM_HEADER ||
52 + (blocksize == 0x20000 && (
53 + buf[0x10000 / 4] == NVRAM_HEADER ||
54 + buf[0x11000 / 4] == NVRAM_HEADER ||
55 + buf[0x18000 / 4] == NVRAM_HEADER))) {
56 bcm47xxpart_add_part(&parts[curr_part++], "nvram",
57 offset, 0);
58 + offset = rounddown(offset, blocksize);
59 continue;
60 }
61