brcm47xx: add patches for kernel 4.0
[openwrt.git] / target / linux / brcm47xx / patches-4.0 / 030-09-MIPS-BCM47XX-Don-t-try-guessing-NVRAM-size-on-MTD-pa.patch
1 From 40d12172c8a5c2f3fc39642fc564b053575cd000 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 1 Apr 2015 08:23:05 +0200
4 Subject: [PATCH] MIPS: BCM47XX: Don't try guessing NVRAM size on MTD partition
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 When dealing with whole flash content (bcm47xx_nvram_init_from_mem) we
10 need to find NVRAM start trying various partition sizes (nvram_sizes).
11 This is not needed when using MTD as we have direct partition access.
12
13 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
14 Cc: linux-mips@linux-mips.org
15 Cc: Hauke Mehrtens <hauke@hauke-m.de>
16 Patchwork: https://patchwork.linux-mips.org/patch/9652/
17 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
18 ---
19  arch/mips/bcm47xx/nvram.c | 36 ++++++++++++++----------------------
20  1 file changed, 14 insertions(+), 22 deletions(-)
21
22 diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
23 index 2ac7482..ba632ff 100644
24 --- a/arch/mips/bcm47xx/nvram.c
25 +++ b/arch/mips/bcm47xx/nvram.c
26 @@ -139,36 +139,28 @@ static int nvram_init(void)
27         struct mtd_info *mtd;
28         struct nvram_header header;
29         size_t bytes_read;
30 -       int err, i;
31 +       int err;
32  
33         mtd = get_mtd_device_nm("nvram");
34         if (IS_ERR(mtd))
35                 return -ENODEV;
36  
37 -       for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
38 -               loff_t from = mtd->size - nvram_sizes[i];
39 -
40 -               if (from < 0)
41 -                       continue;
42 -
43 -               err = mtd_read(mtd, from, sizeof(header), &bytes_read,
44 -                              (uint8_t *)&header);
45 -               if (!err && header.magic == NVRAM_MAGIC) {
46 -                       u8 *dst = (uint8_t *)nvram_buf;
47 -                       size_t len = header.len;
48 +       err = mtd_read(mtd, 0, sizeof(header), &bytes_read, (uint8_t *)&header);
49 +       if (!err && header.magic == NVRAM_MAGIC) {
50 +               u8 *dst = (uint8_t *)nvram_buf;
51 +               size_t len = header.len;
52  
53 -                       if (header.len > NVRAM_SPACE) {
54 -                               pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
55 -                                      header.len, NVRAM_SPACE);
56 -                               len = NVRAM_SPACE;
57 -                       }
58 +               if (header.len > NVRAM_SPACE) {
59 +                       pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
60 +                               header.len, NVRAM_SPACE);
61 +                       len = NVRAM_SPACE;
62 +               }
63  
64 -                       err = mtd_read(mtd, from, len, &bytes_read, dst);
65 -                       if (err)
66 -                               return err;
67 +               err = mtd_read(mtd, 0, len, &bytes_read, dst);
68 +               if (err)
69 +                       return err;
70  
71 -                       return 0;
72 -               }
73 +               return 0;
74         }
75  #endif
76  
77 -- 
78 1.8.4.5
79