summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2013-09-21 17:55:49 +0000
committerGabor Juhos <juhosg@openwrt.org>2013-09-21 17:55:49 +0000
commitdaec7ad7688415156e2730e401503d09bd3acf91 (patch)
tree19024b77d7baba8cfad2b3321d8edd4a4fbae1c1
parentd89bea92b31b4e157a0fa438e75370f089f73427 (diff)
downloadmtk-20170518-daec7ad7688415156e2730e401503d09bd3acf91.zip
mtk-20170518-daec7ad7688415156e2730e401503d09bd3acf91.tar.gz
mtk-20170518-daec7ad7688415156e2730e401503d09bd3acf91.tar.bz2
kernel/3.10: add separate rootfs partition parser
Signed-off-by: Gabor Juhos <juhosg@openwrt.org> SVN-Revision: 38110
-rw-r--r--target/linux/generic/config-3.101
-rw-r--r--target/linux/generic/files/drivers/mtd/mtdsplit_squashfs.c71
-rw-r--r--target/linux/generic/patches-3.10/405-mtd-add-more-helper-functions.patch83
-rw-r--r--target/linux/generic/patches-3.10/406-mtd-add-squashfs-parser.patch30
4 files changed, 185 insertions, 0 deletions
diff --git a/target/linux/generic/config-3.10 b/target/linux/generic/config-3.10
index 9e1b100..61c7cf7 100644
--- a/target/linux/generic/config-3.10
+++ b/target/linux/generic/config-3.10
@@ -1935,6 +1935,7 @@ CONFIG_MTD_ROOTFS_SPLIT=y
CONFIG_MTD_SPLIT=y
# CONFIG_MTD_SPLIT_FIRMWARE is not set
CONFIG_MTD_SPLIT_FIRMWARE_NAME="firmware"
+# CONFIG_MTD_SPLIT_SQUASHFS_ROOT 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_squashfs.c b/target/linux/generic/files/drivers/mtd/mtdsplit_squashfs.c
new file mode 100644
index 0000000..7953e8c
--- /dev/null
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit_squashfs.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * 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.
+ *
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/magic.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/byteorder/generic.h>
+
+#include "mtdsplit.h"
+
+static int
+mtdsplit_parse_squashfs(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ struct mtd_partition *part;
+ struct mtd_info *parent_mtd;
+ size_t part_offset;
+ size_t squashfs_len;
+ int err;
+
+ err = mtd_get_squashfs_len(master, 0, &squashfs_len);
+ if (err)
+ return err;
+
+ parent_mtd = mtdpart_get_master(master);
+ part_offset = mtdpart_get_offset(master);
+
+ part = kzalloc(sizeof(*part), GFP_KERNEL);
+ if (!part) {
+ pr_alert("unable to allocate memory for \"%s\" partition\n",
+ ROOTFS_SPLIT_NAME);
+ return -ENOMEM;
+ }
+
+ part->name = ROOTFS_SPLIT_NAME;
+ part->offset = mtd_roundup_to_eb(part_offset + squashfs_len,
+ parent_mtd) - part_offset;
+ part->size = master->size - part->offset;
+
+ *pparts = part;
+ return 1;
+}
+
+static struct mtd_part_parser mtdsplit_squashfs_parser = {
+ .owner = THIS_MODULE,
+ .name = "squashfs-split",
+ .parse_fn = mtdsplit_parse_squashfs,
+ .type = MTD_PARSER_TYPE_ROOTFS,
+};
+
+static int
+mtdsplit_squashfs_init(void)
+{
+ return register_mtd_parser(&mtdsplit_squashfs_parser);
+}
+
+subsys_initcall(mtdsplit_squashfs_init);
diff --git a/target/linux/generic/patches-3.10/405-mtd-add-more-helper-functions.patch b/target/linux/generic/patches-3.10/405-mtd-add-more-helper-functions.patch
new file mode 100644
index 0000000..4e54b1b
--- /dev/null
+++ b/target/linux/generic/patches-3.10/405-mtd-add-more-helper-functions.patch
@@ -0,0 +1,83 @@
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -435,14 +435,12 @@ static struct mtd_part *allocate_partiti
+ if (slave->offset == MTDPART_OFS_APPEND)
+ slave->offset = cur_offset;
+ if (slave->offset == MTDPART_OFS_NXTBLK) {
+- slave->offset = cur_offset;
+- if (mtd_mod_by_eb(cur_offset, master) != 0) {
+- /* Round up to next erasesize */
+- slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
++ /* Round up to next erasesize */
++ slave->offset = mtd_roundup_to_eb(cur_offset, master);
++ if (slave->offset != cur_offset)
+ printk(KERN_NOTICE "Moving partition %d: "
+ "0x%012llx -> 0x%012llx\n", partno,
+ (unsigned long long)cur_offset, (unsigned long long)slave->offset);
+- }
+ }
+ if (slave->offset == MTDPART_OFS_RETAIN) {
+ slave->offset = cur_offset;
+@@ -996,6 +994,24 @@ int mtd_is_partition(const struct mtd_in
+ }
+ EXPORT_SYMBOL_GPL(mtd_is_partition);
+
++struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
++{
++ if (!mtd_is_partition(mtd))
++ return (struct mtd_info *)mtd;
++
++ return PART(mtd)->master;
++}
++EXPORT_SYMBOL_GPL(mtdpart_get_master);
++
++uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
++{
++ if (!mtd_is_partition(mtd))
++ return 0;
++
++ return PART(mtd)->offset;
++}
++EXPORT_SYMBOL_GPL(mtdpart_get_offset);
++
+ /* Returns the size of the entire flash chip */
+ uint64_t mtd_get_device_size(const struct mtd_info *mtd)
+ {
+--- a/include/linux/mtd/partitions.h
++++ b/include/linux/mtd/partitions.h
+@@ -90,6 +90,8 @@ int mtd_is_partition(const struct mtd_in
+ int mtd_add_partition(struct mtd_info *master, char *name,
+ long long offset, long long length);
+ int mtd_del_partition(struct mtd_info *master, int partno);
++struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
++uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
+ uint64_t mtd_get_device_size(const struct mtd_info *mtd);
+ extern void __weak arch_split_mtd_part(struct mtd_info *master,
+ const char *name, int offset, int size);
+--- a/include/linux/mtd/mtd.h
++++ b/include/linux/mtd/mtd.h
+@@ -331,6 +331,24 @@ static inline uint32_t mtd_mod_by_eb(uin
+ return do_div(sz, mtd->erasesize);
+ }
+
++static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
++{
++ if (mtd_mod_by_eb(sz, mtd) == 0)
++ return sz;
++
++ /* Round up to next erase block */
++ return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
++}
++
++static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
++{
++ if (mtd_mod_by_eb(sz, mtd) == 0)
++ return sz;
++
++ /* Round down to the start of the current erase block */
++ return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
++}
++
+ static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
+ {
+ if (mtd->writesize_shift)
diff --git a/target/linux/generic/patches-3.10/406-mtd-add-squashfs-parser.patch b/target/linux/generic/patches-3.10/406-mtd-add-squashfs-parser.patch
new file mode 100644
index 0000000..b3ff9d9
--- /dev/null
+++ b/target/linux/generic/patches-3.10/406-mtd-add-squashfs-parser.patch
@@ -0,0 +1,30 @@
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -37,6 +37,17 @@ config MTD_UIMAGE_SPLIT
+ depends on MTD_SPLIT_FIRMWARE
+ default y
+
++comment "Rootfs partition parsers"
++
++config MTD_SPLIT_SQUASHFS_ROOT
++ bool "Squashfs based root partition parser"
++ select MTD_SPLIT
++ default n
++ help
++ This provides a parsing function which allows to detect the
++ offset and size of the unused portion of a rootfs partition
++ containing a squashfs.
++
+ config MTD_SPLIT
+ def_bool n
+ help
+--- a/drivers/mtd/Makefile
++++ b/drivers/mtd/Makefile
+@@ -7,6 +7,7 @@ obj-$(CONFIG_MTD) += mtd.o
+ mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
+
+ mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
++mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
+
+ obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
+ obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o