ramips: fix cd-poll sd card remove randomly
[openwrt/openwrt.git] / target / linux / generic / patches-3.18 / 041-mtd-bcm47xxpart-backports-from-3.20.patch
1 --- a/drivers/mtd/bcm47xxpart.c
2 +++ b/drivers/mtd/bcm47xxpart.c
3 @@ -15,6 +15,8 @@
4 #include <linux/mtd/mtd.h>
5 #include <linux/mtd/partitions.h>
6
7 +#include <uapi/linux/magic.h>
8 +
9 /*
10 * NAND flash on Netgear R6250 was verified to contain 15 partitions.
11 * This will result in allocating too big array for some old devices, but the
12 @@ -39,7 +41,8 @@
13 #define ML_MAGIC1 0x39685a42
14 #define ML_MAGIC2 0x26594131
15 #define TRX_MAGIC 0x30524448
16 -#define SQSH_MAGIC 0x71736873 /* shsq */
17 +#define SHSQ_MAGIC 0x71736873 /* shsq (weird ZTE H218N endianness) */
18 +#define UBI_EC_MAGIC 0x23494255 /* UBI# */
19
20 struct trx_header {
21 uint32_t magic;
22 @@ -50,7 +53,7 @@ struct trx_header {
23 uint32_t offset[3];
24 } __packed;
25
26 -static void bcm47xxpart_add_part(struct mtd_partition *part, char *name,
27 +static void bcm47xxpart_add_part(struct mtd_partition *part, const char *name,
28 u64 offset, uint32_t mask_flags)
29 {
30 part->name = name;
31 @@ -58,6 +61,26 @@ static void bcm47xxpart_add_part(struct
32 part->mask_flags = mask_flags;
33 }
34
35 +static const char *bcm47xxpart_trx_data_part_name(struct mtd_info *master,
36 + size_t offset)
37 +{
38 + uint32_t buf;
39 + size_t bytes_read;
40 +
41 + if (mtd_read(master, offset, sizeof(buf), &bytes_read,
42 + (uint8_t *)&buf) < 0) {
43 + pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
44 + offset);
45 + goto out_default;
46 + }
47 +
48 + if (buf == UBI_EC_MAGIC)
49 + return "ubi";
50 +
51 +out_default:
52 + return "rootfs";
53 +}
54 +
55 static int bcm47xxpart_parse(struct mtd_info *master,
56 struct mtd_partition **pparts,
57 struct mtd_part_parser_data *data)
58 @@ -73,8 +96,12 @@ static int bcm47xxpart_parse(struct mtd_
59 int last_trx_part = -1;
60 int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
61
62 - if (blocksize <= 0x10000)
63 - blocksize = 0x10000;
64 + /*
65 + * Some really old flashes (like AT45DB*) had smaller erasesize-s, but
66 + * partitions were aligned to at least 0x1000 anyway.
67 + */
68 + if (blocksize < 0x1000)
69 + blocksize = 0x1000;
70
71 /* Alloc */
72 parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
73 @@ -186,8 +213,11 @@ static int bcm47xxpart_parse(struct mtd_
74 * we want to have jffs2 (overlay) in the same mtd.
75 */
76 if (trx->offset[i]) {
77 + const char *name;
78 +
79 + name = bcm47xxpart_trx_data_part_name(master, offset + trx->offset[i]);
80 bcm47xxpart_add_part(&parts[curr_part++],
81 - "rootfs",
82 + name,
83 offset + trx->offset[i],
84 0);
85 i++;
86 @@ -205,7 +235,8 @@ static int bcm47xxpart_parse(struct mtd_
87 }
88
89 /* Squashfs on devices not using TRX */
90 - if (buf[0x000 / 4] == SQSH_MAGIC) {
91 + if (le32_to_cpu(buf[0x000 / 4]) == SQUASHFS_MAGIC ||
92 + buf[0x000 / 4] == SHSQ_MAGIC) {
93 bcm47xxpart_add_part(&parts[curr_part++], "rootfs",
94 offset, 0);
95 continue;