#include "rt3050.dtsi" #include #include / { compatible = "upvel,ur-336un", "ralink,rt3052-soc"; model = "UPVEL UR-336UN"; aliases { led-boot = &led_wps; led-failsafe = &led_wps; led-running = &led_wps; led-upgrade = &led_wps; }; flash@1f000000 { compatible = "cfi-flash"; reg = <0x1f000000 0x800000>; bank-width = <2>; device-width = <2>; partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; partition@0 { label = "u-boot"; reg = <0x0 0x30000>; read-only; }; partition@30000 { label = "u-boot-env"; reg = <0x30000 0x10000>; read-only; }; factory: partition@40000 { label = "factory"; reg = <0x40000 0x10000>; read-only; }; partition@50000 { compatible = "denx,uimage"; label = "firmware"; reg = <0x50000 0x7b0000>; }; }; }; leds { compatible = "gpio-leds"; 3g { label = "green:3g"; gpios = <&gpio0 9 GPIO_ACTIVE_LOW>; }; gateway { label = "green:gateway"; gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; }; ap { label = "green:ap"; gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; }; led_wps: wps { label = "green:wps"; gpios = <&gpio0 14 GPIO_ACTIVE_LOW>; }; station { label = "green:station"; gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; }; }; keys { compatible = "gpio-keys-polled"; poll-interval = <20>; reset_wps { label = "reset_wps"; gpios = <&gpio0 10 GPIO_ACTIVE_LOW>; linux,code = ; }; mode { label = "mode"; gpios = <&gpio0 7 GPIO_ACTIVE_LOW>; linux,code = ; }; }; }; &state_default { gpio { groups = "spi", "i2c", "jtag", "rgmii", "mdio", "uartf"; function = "gpio"; }; }; ðernet { nvmem-cells = <&macaddr_factory_4004>; nvmem-cell-names = "mac-address"; }; &esw { mediatek,portmap = <0x2f>; }; &wmac { ralink,mtd-eeprom = <&factory 0x0>; }; &otg { status = "okay"; }; &factory { compatible = "nvmem-cells"; #address-cells = <1>; #size-cells = <1>; macaddr_factory_4004: macaddr@4004 { reg = <0x4004 0x6>; }; }; m47xxpart-check-for-bad-blocks-when-calculatin.patch'>logtreecommitdiffstats
blob: 6adac7766959d6e4025792a0e0d9f65cfc3a2194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
Date: Sat, 2 Jan 2016 01:04:52 +0100
Subject: [PATCH] mtd: bcm47xxpart: check for bad blocks when calculating
 offsets
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
 drivers/mtd/bcm47xxpart.c | 50 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 10 deletions(-)

--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
@@ -61,6 +61,34 @@ static void bcm47xxpart_add_part(struct mtd_partition *part, const char *name,
 	part->mask_flags = mask_flags;
 }
 
+/*
+ * Calculate real end offset (address) for a given amount of data. It checks
+ * all blocks skipping bad ones.
+ */
+static size_t bcm47xxpart_real_offset(struct mtd_info *master, size_t offset,
+				      size_t bytes)
+{
+	size_t real_offset = offset;
+
+	if (mtd_block_isbad(master, real_offset))
+		pr_warn("Base offset shouldn't be at bad block");
+
+	while (bytes >= master->erasesize) {
+		bytes -= master->erasesize;
+		real_offset += master->erasesize;
+		while (mtd_block_isbad(master, real_offset)) {
+			real_offset += master->erasesize;
+
+			if (real_offset >= master->size)
+				return real_offset - master->erasesize;
+		}
+	}
+
+	real_offset += bytes;
+
+	return real_offset;
+}
+
 static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
 						  size_t offset)
 {
@@ -182,6 +210,8 @@ static int bcm47xxpart_parse(struct mtd_info *master,
 
 		/* TRX */
 		if (buf[0x000 / 4] == TRX_MAGIC) {
+			uint32_t tmp;
+
 			if (BCM47XXPART_MAX_PARTS - curr_part < 4) {
 				pr_warn("Not enough partitions left to register trx, scanning stopped!\n");
 				break;
@@ -196,18 +226,18 @@ static int bcm47xxpart_parse(struct mtd_info *master,
 			i = 0;
 			/* We have LZMA loader if offset[2] points to sth */
 			if (trx->offset[2]) {
+				tmp = bcm47xxpart_real_offset(master, offset,
+							      trx->offset[i]);
 				bcm47xxpart_add_part(&parts[curr_part++],
-						     "loader",
-						     offset + trx->offset[i],
-						     0);
+						     "loader", tmp, 0);
 				i++;
 			}
 
 			if (trx->offset[i]) {
+				tmp = bcm47xxpart_real_offset(master, offset,
+							      trx->offset[i]);
 				bcm47xxpart_add_part(&parts[curr_part++],
-						     "linux",
-						     offset + trx->offset[i],
-						     0);
+						     "linux", tmp, 0);
 				i++;
 			}
 
@@ -219,11 +249,11 @@ static int bcm47xxpart_parse(struct mtd_info *master,
 			if (trx->offset[i]) {
 				const char *name;
 
-				name = bcm47xxpart_trx_data_part_name(master, offset + trx->offset[i]);
+				tmp = bcm47xxpart_real_offset(master, offset,
+							      trx->offset[i]);
+				name = bcm47xxpart_trx_data_part_name(master, tmp);
 				bcm47xxpart_add_part(&parts[curr_part++],
-						     name,
-						     offset + trx->offset[i],
-						     0);
+						     name, tmp, 0);
 				i++;
 			}