2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/magic.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/byteorder/generic.h>
25 mtdsplit_parse_squashfs(struct mtd_info *master,
26 struct mtd_partition **pparts,
27 struct mtd_part_parser_data *data)
29 struct mtd_partition *part;
30 struct mtd_info *parent_mtd;
35 err = mtd_get_squashfs_len(master, 0, &squashfs_len);
39 parent_mtd = mtdpart_get_master(master);
40 part_offset = mtdpart_get_offset(master);
42 part = kzalloc(sizeof(*part), GFP_KERNEL);
44 pr_alert("unable to allocate memory for \"%s\" partition\n",
49 part->name = ROOTFS_SPLIT_NAME;
50 part->offset = mtd_roundup_to_eb(part_offset + squashfs_len,
51 parent_mtd) - part_offset;
52 part->size = master->size - part->offset;
58 static struct mtd_part_parser mtdsplit_squashfs_parser = {
60 .name = "squashfs-split",
61 .parse_fn = mtdsplit_parse_squashfs,
62 .type = MTD_PARSER_TYPE_ROOTFS,
66 mtdsplit_squashfs_init(void)
68 return register_mtd_parser(&mtdsplit_squashfs_parser);
71 subsys_initcall(mtdsplit_squashfs_init);