summaryrefslogtreecommitdiff
path: root/target/linux/generic/files
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 /target/linux/generic/files
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
Diffstat (limited to 'target/linux/generic/files')
-rw-r--r--target/linux/generic/files/drivers/mtd/mtdsplit_squashfs.c71
1 files changed, 71 insertions, 0 deletions
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);