c40c8b7f89d399b49936756b11b03cf652d29a1a
[openwrt/staging/aparcar.git] /
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 --- a/arch/mips/bcm47xx/nvram.c
23 +++ b/arch/mips/bcm47xx/nvram.c
24 @@ -139,36 +139,28 @@ static int nvram_init(void)
25 struct mtd_info *mtd;
26 struct nvram_header header;
27 size_t bytes_read;
28 - int err, i;
29 + int err;
30
31 mtd = get_mtd_device_nm("nvram");
32 if (IS_ERR(mtd))
33 return -ENODEV;
34
35 - for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
36 - loff_t from = mtd->size - nvram_sizes[i];
37 -
38 - if (from < 0)
39 - continue;
40 + err = mtd_read(mtd, 0, sizeof(header), &bytes_read, (uint8_t *)&header);
41 + if (!err && header.magic == NVRAM_MAGIC) {
42 + u8 *dst = (uint8_t *)nvram_buf;
43 + size_t len = header.len;
44 +
45 + if (header.len > NVRAM_SPACE) {
46 + pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
47 + header.len, NVRAM_SPACE);
48 + len = NVRAM_SPACE;
49 + }
50
51 - err = mtd_read(mtd, from, sizeof(header), &bytes_read,
52 - (uint8_t *)&header);
53 - if (!err && header.magic == NVRAM_MAGIC) {
54 - u8 *dst = (uint8_t *)nvram_buf;
55 - size_t len = header.len;
56 -
57 - if (header.len > NVRAM_SPACE) {
58 - pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
59 - header.len, NVRAM_SPACE);
60 - len = NVRAM_SPACE;
61 - }
62 -
63 - err = mtd_read(mtd, from, len, &bytes_read, dst);
64 - if (err)
65 - return err;
66 + err = mtd_read(mtd, 0, len, &bytes_read, dst);
67 + if (err)
68 + return err;
69
70 - return 0;
71 - }
72 + return 0;
73 }
74 #endif
75