[source] kernel: mtdsplit: add support for WRGG images
LEDE Commits
lede-commits at lists.infradead.org
Thu Oct 27 00:18:38 PDT 2016
stintel pushed a commit to source.git, branch master:
https://git.lede-project.org/136319e72d14ed4f77e03db54c0c46dc85d685c3
commit 136319e72d14ed4f77e03db54c0c46dc85d685c3
Author: Stijn Tintel <stijn at linux-ipv6.be>
AuthorDate: Sun Aug 7 13:39:00 2016 +0200
kernel: mtdsplit: add support for WRGG images
Support splitting WRGG images, found in some D-Link devices (e.g.
DAP-2695).
Signed-off-by: Stijn Tintel <stijn at linux-ipv6.be>
Acked-by: John Crispin <john at phrozen.org>
---
target/linux/ar71xx/config-4.4 | 1 +
target/linux/generic/config-3.18 | 1 +
target/linux/generic/config-4.1 | 1 +
target/linux/generic/config-4.4 | 1 +
.../generic/files/drivers/mtd/mtdsplit/Kconfig | 5 +
.../generic/files/drivers/mtd/mtdsplit/Makefile | 1 +
.../files/drivers/mtd/mtdsplit/mtdsplit_wrgg.c | 109 +++++++++++++++++++++
7 files changed, 119 insertions(+)
diff --git a/target/linux/ar71xx/config-4.4 b/target/linux/ar71xx/config-4.4
index 4c24b9f..0e731e8 100644
--- a/target/linux/ar71xx/config-4.4
+++ b/target/linux/ar71xx/config-4.4
@@ -353,6 +353,7 @@ CONFIG_MTD_SPLIT_FIRMWARE=y
CONFIG_MTD_SPLIT_LZMA_FW=y
CONFIG_MTD_SPLIT_SEAMA_FW=y
CONFIG_MTD_SPLIT_UIMAGE_FW=y
+CONFIG_MTD_SPLIT_WRGG_FW=y
CONFIG_MTD_TPLINK_PARTS=y
CONFIG_MYLOADER=y
CONFIG_NEED_DMA_MAP_STATE=y
diff --git a/target/linux/generic/config-3.18 b/target/linux/generic/config-3.18
index 0ccd9ac..8b70c7d 100644
--- a/target/linux/generic/config-3.18
+++ b/target/linux/generic/config-3.18
@@ -2282,6 +2282,7 @@ CONFIG_MTD_SPLIT_SUPPORT=y
# CONFIG_MTD_SPLIT_TRX_FW is not set
# CONFIG_MTD_SPLIT_TPLINK_FW is not set
# CONFIG_MTD_SPLIT_UIMAGE_FW is not set
+# CONFIG_MTD_SPLIT_WRGG_FW is not set
# CONFIG_MTD_SST25L is not set
# CONFIG_MTD_SWAP is not set
# CONFIG_MTD_TESTS is not set
diff --git a/target/linux/generic/config-4.1 b/target/linux/generic/config-4.1
index fc7359e..68bd849 100644
--- a/target/linux/generic/config-4.1
+++ b/target/linux/generic/config-4.1
@@ -2375,6 +2375,7 @@ CONFIG_MTD_SPLIT_SUPPORT=y
# CONFIG_MTD_SPLIT_TRX_FW is not set
# CONFIG_MTD_SPLIT_TPLINK_FW is not set
# CONFIG_MTD_SPLIT_UIMAGE_FW is not set
+# CONFIG_MTD_SPLIT_WRGG_FW is not set
# CONFIG_MTD_SST25L is not set
# CONFIG_MTD_SWAP is not set
# CONFIG_MTD_TESTS is not set
diff --git a/target/linux/generic/config-4.4 b/target/linux/generic/config-4.4
index 687c183..32b291f 100644
--- a/target/linux/generic/config-4.4
+++ b/target/linux/generic/config-4.4
@@ -2365,6 +2365,7 @@ CONFIG_MTD_SPLIT_SUPPORT=y
# CONFIG_MTD_SPLIT_TPLINK_FW is not set
# CONFIG_MTD_SPLIT_TRX_FW is not set
# CONFIG_MTD_SPLIT_UIMAGE_FW is not set
+# CONFIG_MTD_SPLIT_WRGG_FW is not set
# CONFIG_MTD_SST25L is not set
# CONFIG_MTD_SWAP is not set
# CONFIG_MTD_TESTS is not set
diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig b/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig
index 131a74f..7e653e7 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/Kconfig
@@ -25,6 +25,11 @@ config MTD_SPLIT_SEAMA_FW
depends on MTD_SPLIT_SUPPORT
select MTD_SPLIT
+config MTD_SPLIT_WRGG_FW
+ bool "WRGG firmware parser"
+ depends on MTD_SPLIT_SUPPORT
+ select MTD_SPLIT
+
config MTD_SPLIT_UIMAGE_FW
bool "uImage based firmware partition parser"
depends on MTD_SPLIT_SUPPORT
diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile b/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile
index acf799e..c843025 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_MTD_SPLIT_TPLINK_FW) += mtdsplit_tplink.o
obj-$(CONFIG_MTD_SPLIT_TRX_FW) += mtdsplit_trx.o
obj-$(CONFIG_MTD_SPLIT_BRNIMAGE_FW) += mtdsplit_brnimage.o
obj-$(CONFIG_MTD_SPLIT_EVA_FW) += mtdsplit_eva.o
+obj-$(CONFIG_MTD_SPLIT_WRGG_FW) += mtdsplit_wrgg.o
diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_wrgg.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_wrgg.c
new file mode 100644
index 0000000..c1fbccb
--- /dev/null
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_wrgg.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2013 Gabor Juhos <juhosg at openwrt.org>
+ * Copyright (C) 2014 Felix Fietkau <nbd at nbd.name>
+ * Copyright (C) 2016 Stijn Tintel <stijn at linux-ipv6.be>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/byteorder/generic.h>
+
+#include "mtdsplit.h"
+
+#define WRGG_NR_PARTS 2
+#define WRGG_MIN_ROOTFS_OFFS 0x80000 /* 512KiB */
+#define WRGG03_MAGIC 0x20080321
+
+struct wrgg03_header {
+ char signature[32];
+ uint32_t magic1;
+ uint32_t magic2;
+ char version[16];
+ char model[16];
+ uint32_t flag[2];
+ uint32_t reserve[2];
+ char buildno[16];
+ uint32_t size;
+ uint32_t offset;
+ char devname[32];
+ char digest[16];
+} __attribute__ ((packed));
+
+
+static int mtdsplit_parse_wrgg(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ struct wrgg03_header hdr;
+ size_t hdr_len, retlen, kernel_ent_size;
+ size_t rootfs_offset;
+ struct mtd_partition *parts;
+ enum mtdsplit_part_type type;
+ int err;
+
+ hdr_len = sizeof(hdr);
+ err = mtd_read(master, 0, hdr_len, &retlen, (void *) &hdr);
+ if (err)
+ return err;
+
+ if (retlen != hdr_len)
+ return -EIO;
+
+ /* sanity checks */
+ if (le32_to_cpu(hdr.magic1) != WRGG03_MAGIC)
+ return -EINVAL;
+
+ kernel_ent_size = hdr_len + be32_to_cpu(hdr.size);
+
+ if (kernel_ent_size > master->size)
+ return -EINVAL;
+
+ /*
+ * The size in the header covers the rootfs as well.
+ * Start the search from an arbitrary offset.
+ */
+ err = mtd_find_rootfs_from(master, WRGG_MIN_ROOTFS_OFFS,
+ master->size, &rootfs_offset, &type);
+ if (err)
+ return err;
+
+ parts = kzalloc(WRGG_NR_PARTS * sizeof(*parts), GFP_KERNEL);
+ if (!parts)
+ return -ENOMEM;
+
+ parts[0].name = KERNEL_PART_NAME;
+ parts[0].offset = 0;
+ parts[0].size = rootfs_offset;
+
+ parts[1].name = ROOTFS_PART_NAME;
+ parts[1].offset = rootfs_offset;
+ parts[1].size = master->size - rootfs_offset;
+
+ *pparts = parts;
+ return WRGG_NR_PARTS;
+}
+
+static struct mtd_part_parser mtdsplit_wrgg_parser = {
+ .owner = THIS_MODULE,
+ .name = "wrgg-fw",
+ .parse_fn = mtdsplit_parse_wrgg,
+ .type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
+static int __init mtdsplit_wrgg_init(void)
+{
+ register_mtd_parser(&mtdsplit_wrgg_parser);
+
+ return 0;
+}
+
+subsys_initcall(mtdsplit_wrgg_init);
More information about the lede-commits
mailing list