This backports some patches from linux upstream.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
SVN-Revision: 39249
--- /dev/null
+From 99b1d1887fee36ef9ff5d2ee24f0cf3e8c172104 Mon Sep 17 00:00:00 2001
+From: Hauke Mehrtens <hauke@hauke-m.de>
+Date: Sun, 13 Oct 2013 22:53:49 +0200
+Subject: [PATCH] mtd: bcm47xxpart: handle malloc failures
+
+Handle return NULL in malloc.
+
+Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
+Signed-off-by: Brian Norris <computersforpeace@gmail.com>
+---
+ drivers/mtd/bcm47xxpart.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+--- a/drivers/mtd/bcm47xxpart.c
++++ b/drivers/mtd/bcm47xxpart.c
+@@ -71,7 +71,14 @@ static int bcm47xxpart_parse(struct mtd_
+ /* Alloc */
+ parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
+ GFP_KERNEL);
++ if (!parts)
++ return -ENOMEM;
++
+ buf = kzalloc(BCM47XXPART_BYTES_TO_READ, GFP_KERNEL);
++ if (!buf) {
++ kfree(parts);
++ return -ENOMEM;
++ }
+
+ /* Parse block by block looking for magics */
+ for (offset = 0; offset <= master->size - blocksize;
--- /dev/null
+From 020c6bcfbeabee72c18d862769d72cf9241b9004 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
+Date: Mon, 21 Oct 2013 22:34:37 +0200
+Subject: [PATCH] mtd: bcm47xxpart: detect block aligned Squashfs partition
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Most of the bcm47xx devices use TRX format for storing kernel and some
+partition like Squashfs or JFFS2. This is pretty flexible solution, CFE
+(the bootloader) just writes (and later boots) TRX at some hardcoded
+place and paritions can vary in the size.
+
+However some devices don't use TRX format. Very recently we have
+discovered ZTE H218N that has kernel and rootfs partitions at some
+"random" places.
+
+This patch allows Linux find a rootfs partition after installing custom
+image with a CFE bootloader.
+
+Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
+Signed-off-by: Brian Norris <computersforpeace@gmail.com>
+---
+ drivers/mtd/bcm47xxpart.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+--- a/drivers/mtd/bcm47xxpart.c
++++ b/drivers/mtd/bcm47xxpart.c
+@@ -32,6 +32,7 @@
+ #define ML_MAGIC1 0x39685a42
+ #define ML_MAGIC2 0x26594131
+ #define TRX_MAGIC 0x30524448
++#define SQSH_MAGIC 0x71736873 /* shsq */
+
+ struct trx_header {
+ uint32_t magic;
+@@ -174,6 +175,13 @@ static int bcm47xxpart_parse(struct mtd_
+ offset = rounddown(offset + trx->length, blocksize);
+ continue;
+ }
++
++ /* Squashfs on devices not using TRX */
++ if (buf[0x000 / 4] == SQSH_MAGIC) {
++ bcm47xxpart_add_part(&parts[curr_part++], "rootfs",
++ offset, 0);
++ continue;
++ }
+ }
+
+ /* Look for NVRAM at the end of the last block. */
--- /dev/null
+From 33094c736cd36a6cecadae6bce4daba89dabc326 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
+Date: Mon, 21 Oct 2013 22:35:34 +0200
+Subject: [PATCH] mtd: bcm47xxpart: detect "factory" partition
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+A new type of partition with magic FCTY was found on Huawei E970:
+46 43 54 59 4b 51 37 4e 41 42 31 38 41 32 39 30 |FCTYKQ7NAB18A290|
+
+Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
+Signed-off-by: Brian Norris <computersforpeace@gmail.com>
+---
+ drivers/mtd/bcm47xxpart.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+--- a/drivers/mtd/bcm47xxpart.c
++++ b/drivers/mtd/bcm47xxpart.c
+@@ -27,6 +27,7 @@
+
+ /* Magics */
+ #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
++#define FACTORY_MAGIC 0x59544346 /* FCTY */
+ #define POT_MAGIC1 0x54544f50 /* POTT */
+ #define POT_MAGIC2 0x504f /* OP */
+ #define ML_MAGIC1 0x39685a42
+@@ -117,6 +118,13 @@ static int bcm47xxpart_parse(struct mtd_
+ offset, MTD_WRITEABLE);
+ continue;
+ }
++
++ /* Found on Huawei E970 */
++ if (buf[0x000 / 4] == FACTORY_MAGIC) {
++ bcm47xxpart_add_part(&parts[curr_part++], "factory",
++ offset, MTD_WRITEABLE);
++ continue;
++ }
+
+ /* POT(TOP) */
+ if (buf[0x000 / 4] == POT_MAGIC1 &&
--- /dev/null
+From 4f8aaf72287578c846ed7ac8c6114aacbf416e45 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
+Date: Sat, 21 Dec 2013 19:39:11 +0100
+Subject: [PATCH] mtd: bcm47xxpart: find boot partition by CFE magic
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Some devices have even nicer-to-recognize CFE thanks to the magic.
+
+Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
+Signed-off-by: Brian Norris <computersforpeace@gmail.com>
+---
+ drivers/mtd/bcm47xxpart.c | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+--- a/drivers/mtd/bcm47xxpart.c
++++ b/drivers/mtd/bcm47xxpart.c
+@@ -23,10 +23,11 @@
+ * Amount of bytes we read when analyzing each block of flash memory.
+ * Set it big enough to allow detecting partition and reading important data.
+ */
+-#define BCM47XXPART_BYTES_TO_READ 0x404
++#define BCM47XXPART_BYTES_TO_READ 0x4e8
+
+ /* Magics */
+ #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
++#define CFE_MAGIC 0x43464531 /* 1EFC */
+ #define FACTORY_MAGIC 0x59544346 /* FCTY */
+ #define POT_MAGIC1 0x54544f50 /* POTT */
+ #define POT_MAGIC2 0x504f /* OP */
+@@ -102,8 +103,9 @@ static int bcm47xxpart_parse(struct mtd_
+ continue;
+ }
+
+- /* CFE has small NVRAM at 0x400 */
+- if (buf[0x400 / 4] == NVRAM_HEADER) {
++ /* Magic or small NVRAM at 0x400 */
++ if ((buf[0x4e0 / 4] == CFE_MAGIC && buf[0x4e4 / 4] == CFE_MAGIC) ||
++ (buf[0x400 / 4] == NVRAM_HEADER)) {
+ bcm47xxpart_add_part(&parts[curr_part++], "boot",
+ offset, MTD_WRITEABLE);
+ continue;
--- /dev/null
+From f0501e81fbaa51cfc8c28c60bc3fc7965fde94f4 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
+Date: Sat, 21 Dec 2013 19:39:12 +0100
+Subject: [PATCH] mtd: bcm47xxpart: alternative MAGIC for board_data partition
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Some devices (like WNDR3700v3) have board_data without MPFR magic, some
+extra header or extra NVRAM around 0x100. In such case we have to look
+for another magic which is BD 0B 0D BD (BD probably stands for Board
+Data). It's located "far far away", so instead of extending buffer add
+another mtd_read.
+
+Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
+Signed-off-by: Brian Norris <computersforpeace@gmail.com>
+---
+ drivers/mtd/bcm47xxpart.c | 16 ++++++++++++++++
+ 1 file changed, 16 insertions(+)
+
+--- a/drivers/mtd/bcm47xxpart.c
++++ b/drivers/mtd/bcm47xxpart.c
+@@ -27,6 +27,7 @@
+
+ /* Magics */
+ #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
++#define BOARD_DATA_MAGIC2 0xBD0D0BBD
+ #define CFE_MAGIC 0x43464531 /* 1EFC */
+ #define FACTORY_MAGIC 0x59544346 /* FCTY */
+ #define POT_MAGIC1 0x54544f50 /* POTT */
+@@ -192,6 +193,21 @@ static int bcm47xxpart_parse(struct mtd_
+ offset, 0);
+ continue;
+ }
++
++ /* Read middle of the block */
++ if (mtd_read(master, offset + 0x8000, 0x4,
++ &bytes_read, (uint8_t *)buf) < 0) {
++ pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
++ offset);
++ continue;
++ }
++
++ /* Some devices (ex. WNDR3700v3) don't have a standard 'MPFR' */
++ if (buf[0x000 / 4] == BOARD_DATA_MAGIC2) {
++ bcm47xxpart_add_part(&parts[curr_part++], "board_data",
++ offset, MTD_WRITEABLE);
++ continue;
++ }
+ }
+
+ /* Look for NVRAM at the end of the last block. */
+++ /dev/null
---- a/drivers/mtd/bcm47xxpart.c
-+++ b/drivers/mtd/bcm47xxpart.c
-@@ -23,9 +23,10 @@
- * Amount of bytes we read when analyzing each block of flash memory.
- * Set it big enough to allow detecting partition and reading important data.
- */
--#define BCM47XXPART_BYTES_TO_READ 0x404
-+#define BCM47XXPART_BYTES_TO_READ 0x4e8
-
- /* Magics */
-+#define CFE_MAGIC 0x43464531 /* 1EFC */
- #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
- #define POT_MAGIC1 0x54544f50 /* POTT */
- #define POT_MAGIC2 0x504f /* OP */
-@@ -93,8 +94,9 @@ static int bcm47xxpart_parse(struct mtd_
- continue;
- }
-
-- /* CFE has small NVRAM at 0x400 */
-- if (buf[0x400 / 4] == NVRAM_HEADER) {
-+ /* Magic or small NVRAM at 0x400 */
-+ if (buf[0x4e0 / 4] == CFE_MAGIC ||
-+ buf[0x400 / 4] == NVRAM_HEADER) {
- bcm47xxpart_add_part(&parts[curr_part++], "boot",
- offset, MTD_WRITEABLE);
- continue;
--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
-@@ -65,6 +65,7 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -68,6 +68,7 @@ static int bcm47xxpart_parse(struct mtd_
int trx_part = -1;
int last_trx_part = -1;
int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
if (blocksize <= 0x10000)
blocksize = 0x10000;
-@@ -190,12 +191,23 @@ static int bcm47xxpart_parse(struct mtd_
+@@ -229,12 +230,23 @@ static int bcm47xxpart_parse(struct mtd_
if (buf[0] == NVRAM_HEADER) {
bcm47xxpart_add_part(&parts[curr_part++], "nvram",
master->size - blocksize, 0);
+++ /dev/null
-mtd: bcm47xxpart: detect block aligned Squashfs partition
-
-Most of the bcm47xx devices use TRX format for storing kernel and some
-partition like Squashfs or JFFS2. This is pretty flexible solution, CFE
-(the bootloader) just writes (and later boots) TRX at some hardcoded
-place and paritions can vary in the size.
-
-However some devices don't use TRX format. Very recently we have
-discovered ZTE H218N that has kernel and rootfs partitions at some
-"random" places.
-
-This patch allows Linux find a rootfs partition after installing custom
-image with a CFE bootloader.
-
-Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
-
---- a/drivers/mtd/bcm47xxpart.c
-+++ b/drivers/mtd/bcm47xxpart.c
-@@ -33,6 +33,7 @@
- #define ML_MAGIC1 0x39685a42
- #define ML_MAGIC2 0x26594131
- #define TRX_MAGIC 0x30524448
-+#define SQSH_MAGIC 0x71736873 /* shsq */
-
- struct trx_header {
- uint32_t magic;
-@@ -170,6 +171,13 @@ static int bcm47xxpart_parse(struct mtd_
- offset = rounddown(offset + trx->length, blocksize);
- continue;
- }
-+
-+ /* Squashfs on devices not using TRX */
-+ if (buf[0x000 / 4] == SQSH_MAGIC) {
-+ bcm47xxpart_add_part(&parts[curr_part++], "rootfs",
-+ offset, 0);
-+ continue;
-+ }
- }
-
- /* Look for NVRAM at the end of the last block. */
+++ /dev/null
-mtd: bcm47xxpart: detect "factory" partition
-
-A new type of partition with magic FCTY was found on Huawei E970:
-46 43 54 59 4b 51 37 4e 41 42 31 38 41 32 39 30 |FCTYKQ7NAB18A290|
-
-Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
-
---- a/drivers/mtd/bcm47xxpart.c
-+++ b/drivers/mtd/bcm47xxpart.c
-@@ -28,6 +28,7 @@
- /* Magics */
- #define CFE_MAGIC 0x43464531 /* 1EFC */
- #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
-+#define FACTORY_MAGIC 0x59544346 /* FCTY */
- #define POT_MAGIC1 0x54544f50 /* POTT */
- #define POT_MAGIC2 0x504f /* OP */
- #define ML_MAGIC1 0x39685a42
-@@ -113,6 +114,13 @@ static int bcm47xxpart_parse(struct mtd_
- offset, MTD_WRITEABLE);
- continue;
- }
-+
-+ /* Found on Huawei E970 */
-+ if (buf[0x000 / 4] == FACTORY_MAGIC) {
-+ bcm47xxpart_add_part(&parts[curr_part++], "factory",
-+ offset, MTD_WRITEABLE);
-+ continue;
-+ }
-
- /* POT(TOP) */
- if (buf[0x000 / 4] == POT_MAGIC1 &&