+++ /dev/null
-/*
- * Copyright (C) 2009-2013 Felix Fietkau <nbd@openwrt.org>
- * Copyright (C) 2009-2013 Gabor Juhos <juhosg@openwrt.org>
- * Copyright (C) 2012 Jonas Gorski <jogo@openwrt.org>
- * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de>
- *
- * 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) "mtdsplit: " fmt
-
-#include <linux/export.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/magic.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/partitions.h>
-#include <linux/byteorder/generic.h>
-
-#include "mtdsplit.h"
-
-struct squashfs_super_block {
- __le32 s_magic;
- __le32 pad0[9];
- __le64 bytes_used;
-};
-
-int mtd_get_squashfs_len(struct mtd_info *master,
- size_t offset,
- size_t *squashfs_len)
-{
- struct squashfs_super_block sb;
- size_t retlen;
- int err;
-
- err = mtd_read(master, offset, sizeof(sb), &retlen, (void *)&sb);
- if (err || (retlen != sizeof(sb))) {
- pr_alert("error occured while reading from \"%s\"\n",
- master->name);
- return -EIO;
- }
-
- if (le32_to_cpu(sb.s_magic) != SQUASHFS_MAGIC) {
- pr_alert("no squashfs found in \"%s\"\n", master->name);
- return -EINVAL;
- }
-
- retlen = le64_to_cpu(sb.bytes_used);
- if (retlen <= 0) {
- pr_alert("squashfs is empty in \"%s\"\n", master->name);
- return -ENODEV;
- }
-
- if (offset + retlen > master->size) {
- pr_alert("squashfs has invalid size in \"%s\"\n",
- master->name);
- return -EINVAL;
- }
-
- *squashfs_len = retlen;
- return 0;
-}
-EXPORT_SYMBOL_GPL(mtd_get_squashfs_len);
-
-static ssize_t mtd_next_eb(struct mtd_info *mtd, size_t offset)
-{
- return mtd_rounddown_to_eb(offset, mtd) + mtd->erasesize;
-}
-
-int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
-{
- u32 magic;
- size_t retlen;
- int ret;
-
- ret = mtd_read(mtd, offset, sizeof(magic), &retlen,
- (unsigned char *) &magic);
- if (ret)
- return ret;
-
- if (retlen != sizeof(magic))
- return -EIO;
-
- if (le32_to_cpu(magic) != SQUASHFS_MAGIC &&
- magic != 0x19852003)
- return -EINVAL;
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(mtd_check_rootfs_magic);
-
-int mtd_find_rootfs_from(struct mtd_info *mtd,
- size_t from,
- size_t limit,
- size_t *ret_offset)
-{
- size_t offset;
- int err;
-
- for (offset = from; offset < limit;
- offset = mtd_next_eb(mtd, offset)) {
- err = mtd_check_rootfs_magic(mtd, offset);
- if (err)
- continue;
-
- *ret_offset = offset;
- return 0;
- }
-
- return -ENODEV;
-}
-EXPORT_SYMBOL_GPL(mtd_find_rootfs_from);
-
+++ /dev/null
-/*
- * Copyright (C) 2009-2013 Felix Fietkau <nbd@openwrt.org>
- * Copyright (C) 2009-2013 Gabor Juhos <juhosg@openwrt.org>
- * Copyright (C) 2012 Jonas Gorski <jogo@openwrt.org>
- * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de>
- *
- * 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.
- *
- */
-
-#ifndef _MTDSPLIT_H
-#define _MTDSPLIT_H
-
-#define KERNEL_PART_NAME "kernel"
-#define ROOTFS_PART_NAME "rootfs"
-
-#define ROOTFS_SPLIT_NAME "rootfs_data"
-
-#ifdef CONFIG_MTD_SPLIT
-int mtd_get_squashfs_len(struct mtd_info *master,
- size_t offset,
- size_t *squashfs_len);
-
-int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset);
-
-int mtd_find_rootfs_from(struct mtd_info *mtd,
- size_t from,
- size_t limit,
- size_t *ret_offset);
-
-#else
-static inline int mtd_get_squashfs_len(struct mtd_info *master,
- size_t offset,
- size_t *squashfs_len)
-{
- return -ENODEV;
-}
-
-static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
-{
- return -EINVAL;
-}
-
-static inline int mtd_find_rootfs_from(struct mtd_info *mtd,
- size_t from,
- size_t limit,
- size_t *ret_offset)
-{
- return -ENODEV;
-}
-#endif /* CONFIG_MTD_SPLIT */
-
-#endif /* _MTDSPLIT_H */
+config MTD_SPLIT
+ def_bool n
+ help
+ Generic MTD split support.
+
+config MTD_SPLIT_SUPPORT
+ def_bool MTD = y
+
comment "Rootfs partition parsers"
config MTD_SPLIT_SQUASHFS_ROOT
bool "Squashfs based root partition parser"
+ depends on MTD_SPLIT_SUPPORT
select MTD_SPLIT
default n
help
config MTD_SPLIT_SEAMA_FW
bool "Seama 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
select MTD_SPLIT
config MTD_SPLIT_LZMA_FW
bool "LZMA compressed kernel based firmware partition parser"
+ depends on MTD_SPLIT_SUPPORT
select MTD_SPLIT
--- /dev/null
+obj-$(CONFIG_MTD_SPLIT) += mtdsplit.o
+obj-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o
+obj-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
+obj-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
+obj-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
--- /dev/null
+/*
+ * Copyright (C) 2009-2013 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2009-2013 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2012 Jonas Gorski <jogo@openwrt.org>
+ * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de>
+ *
+ * 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) "mtdsplit: " fmt
+
+#include <linux/export.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/magic.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/byteorder/generic.h>
+
+#include "mtdsplit.h"
+
+struct squashfs_super_block {
+ __le32 s_magic;
+ __le32 pad0[9];
+ __le64 bytes_used;
+};
+
+int mtd_get_squashfs_len(struct mtd_info *master,
+ size_t offset,
+ size_t *squashfs_len)
+{
+ struct squashfs_super_block sb;
+ size_t retlen;
+ int err;
+
+ err = mtd_read(master, offset, sizeof(sb), &retlen, (void *)&sb);
+ if (err || (retlen != sizeof(sb))) {
+ pr_alert("error occured while reading from \"%s\"\n",
+ master->name);
+ return -EIO;
+ }
+
+ if (le32_to_cpu(sb.s_magic) != SQUASHFS_MAGIC) {
+ pr_alert("no squashfs found in \"%s\"\n", master->name);
+ return -EINVAL;
+ }
+
+ retlen = le64_to_cpu(sb.bytes_used);
+ if (retlen <= 0) {
+ pr_alert("squashfs is empty in \"%s\"\n", master->name);
+ return -ENODEV;
+ }
+
+ if (offset + retlen > master->size) {
+ pr_alert("squashfs has invalid size in \"%s\"\n",
+ master->name);
+ return -EINVAL;
+ }
+
+ *squashfs_len = retlen;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mtd_get_squashfs_len);
+
+static ssize_t mtd_next_eb(struct mtd_info *mtd, size_t offset)
+{
+ return mtd_rounddown_to_eb(offset, mtd) + mtd->erasesize;
+}
+
+int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
+{
+ u32 magic;
+ size_t retlen;
+ int ret;
+
+ ret = mtd_read(mtd, offset, sizeof(magic), &retlen,
+ (unsigned char *) &magic);
+ if (ret)
+ return ret;
+
+ if (retlen != sizeof(magic))
+ return -EIO;
+
+ if (le32_to_cpu(magic) != SQUASHFS_MAGIC &&
+ magic != 0x19852003)
+ return -EINVAL;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mtd_check_rootfs_magic);
+
+int mtd_find_rootfs_from(struct mtd_info *mtd,
+ size_t from,
+ size_t limit,
+ size_t *ret_offset)
+{
+ size_t offset;
+ int err;
+
+ for (offset = from; offset < limit;
+ offset = mtd_next_eb(mtd, offset)) {
+ err = mtd_check_rootfs_magic(mtd, offset);
+ if (err)
+ continue;
+
+ *ret_offset = offset;
+ return 0;
+ }
+
+ return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(mtd_find_rootfs_from);
+
--- /dev/null
+/*
+ * Copyright (C) 2009-2013 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2009-2013 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2012 Jonas Gorski <jogo@openwrt.org>
+ * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de>
+ *
+ * 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.
+ *
+ */
+
+#ifndef _MTDSPLIT_H
+#define _MTDSPLIT_H
+
+#define KERNEL_PART_NAME "kernel"
+#define ROOTFS_PART_NAME "rootfs"
+
+#define ROOTFS_SPLIT_NAME "rootfs_data"
+
+#ifdef CONFIG_MTD_SPLIT
+int mtd_get_squashfs_len(struct mtd_info *master,
+ size_t offset,
+ size_t *squashfs_len);
+
+int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset);
+
+int mtd_find_rootfs_from(struct mtd_info *mtd,
+ size_t from,
+ size_t limit,
+ size_t *ret_offset);
+
+#else
+static inline int mtd_get_squashfs_len(struct mtd_info *master,
+ size_t offset,
+ size_t *squashfs_len)
+{
+ return -ENODEV;
+}
+
+static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
+{
+ return -EINVAL;
+}
+
+static inline int mtd_find_rootfs_from(struct mtd_info *mtd,
+ size_t from,
+ size_t limit,
+ size_t *ret_offset)
+{
+ return -ENODEV;
+}
+#endif /* CONFIG_MTD_SPLIT */
+
+#endif /* _MTDSPLIT_H */
--- /dev/null
+/*
+ * Copyright (C) 2014 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.
+ *
+ */
+
+#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 <asm/unaligned.h>
+
+#include "mtdsplit.h"
+
+#define LZMA_NR_PARTS 2
+#define LZMA_PROPERTIES_SIZE 5
+
+struct lzma_header {
+ u8 props[LZMA_PROPERTIES_SIZE];
+ u8 size_low[4];
+ u8 size_high[4];
+};
+
+static int mtdsplit_parse_lzma(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ struct lzma_header hdr;
+ size_t hdr_len, retlen;
+ size_t rootfs_offset;
+ u32 t;
+ struct mtd_partition *parts;
+ 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;
+
+ /* verify LZMA properties */
+ if (hdr.props[0] >= (9 * 5 * 5))
+ return -EINVAL;
+
+ t = get_unaligned_le32(&hdr.props[1]);
+ if (!is_power_of_2(t))
+ return -EINVAL;
+
+ t = get_unaligned_le32(&hdr.size_high);
+ if (t)
+ return -EINVAL;
+
+ err = mtd_find_rootfs_from(master, master->erasesize,
+ master->size, &rootfs_offset);
+ if (err)
+ return err;
+
+ parts = kzalloc(LZMA_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 LZMA_NR_PARTS;
+}
+
+static struct mtd_part_parser mtdsplit_lzma_parser = {
+ .owner = THIS_MODULE,
+ .name = "lzma-fw",
+ .parse_fn = mtdsplit_parse_lzma,
+ .type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
+static int __init mtdsplit_lzma_init(void)
+{
+ register_mtd_parser(&mtdsplit_lzma_parser);
+
+ return 0;
+}
+
+subsys_initcall(mtdsplit_lzma_init);
--- /dev/null
+/*
+ * 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.
+ *
+ */
+
+#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 SEAMA_MAGIC 0x5EA3A417
+#define SEAMA_NR_PARTS 2
+#define SEAMA_MIN_ROOTFS_OFFS 0x80000 /* 512KiB */
+
+struct seama_header {
+ __be32 magic; /* should always be SEAMA_MAGIC. */
+ __be16 reserved; /* reserved for */
+ __be16 metasize; /* size of the META data */
+ __be32 size; /* size of the image */
+};
+
+static int mtdsplit_parse_seama(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ struct seama_header hdr;
+ size_t hdr_len, retlen, kernel_size;
+ size_t rootfs_offset;
+ struct mtd_partition *parts;
+ 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 (be32_to_cpu(hdr.magic) != SEAMA_MAGIC)
+ return -EINVAL;
+
+ kernel_size = hdr_len + be32_to_cpu(hdr.size) +
+ be16_to_cpu(hdr.metasize);
+ if (kernel_size > master->size)
+ return -EINVAL;
+
+ /* Find the rootfs after the kernel. */
+ err = mtd_check_rootfs_magic(master, kernel_size);
+ if (!err) {
+ rootfs_offset = kernel_size;
+ } else {
+ /*
+ * The size in the header might cover the rootfs as well.
+ * Start the search from an arbitrary offset.
+ */
+ err = mtd_find_rootfs_from(master, SEAMA_MIN_ROOTFS_OFFS,
+ master->size, &rootfs_offset);
+ if (err)
+ return err;
+ }
+
+ parts = kzalloc(SEAMA_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 SEAMA_NR_PARTS;
+}
+
+static struct mtd_part_parser mtdsplit_seama_parser = {
+ .owner = THIS_MODULE,
+ .name = "seama-fw",
+ .parse_fn = mtdsplit_parse_seama,
+ .type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
+static int __init mtdsplit_seama_init(void)
+{
+ register_mtd_parser(&mtdsplit_seama_parser);
+
+ return 0;
+}
+
+subsys_initcall(mtdsplit_seama_init);
--- /dev/null
+/*
+ * 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 __init mtdsplit_squashfs_init(void)
+{
+ register_mtd_parser(&mtdsplit_squashfs_parser);
+
+ return 0;
+}
+
+subsys_initcall(mtdsplit_squashfs_init);
--- /dev/null
+/*
+ * 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/vmalloc.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/byteorder/generic.h>
+
+#include "mtdsplit.h"
+
+#define IH_MAGIC 0x27051956 /* Image Magic Number */
+#define IH_NMLEN 32 /* Image Name Length */
+
+#define IH_OS_LINUX 5 /* Linux */
+
+#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
+#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image */
+
+/*
+ * Legacy format image header,
+ * all data in network byte order (aka natural aka bigendian).
+ */
+struct uimage_header {
+ uint32_t ih_magic; /* Image Header Magic Number */
+ uint32_t ih_hcrc; /* Image Header CRC Checksum */
+ uint32_t ih_time; /* Image Creation Timestamp */
+ uint32_t ih_size; /* Image Data Size */
+ uint32_t ih_load; /* Data Load Address */
+ uint32_t ih_ep; /* Entry Point Address */
+ uint32_t ih_dcrc; /* Image Data CRC Checksum */
+ uint8_t ih_os; /* Operating System */
+ uint8_t ih_arch; /* CPU architecture */
+ uint8_t ih_type; /* Image Type */
+ uint8_t ih_comp; /* Compression Type */
+ uint8_t ih_name[IH_NMLEN]; /* Image Name */
+};
+
+static int
+read_uimage_header(struct mtd_info *mtd, size_t offset,
+ struct uimage_header *header)
+{
+ size_t header_len;
+ size_t retlen;
+ int ret;
+
+ header_len = sizeof(*header);
+ ret = mtd_read(mtd, offset, header_len, &retlen,
+ (unsigned char *) header);
+ if (ret) {
+ pr_debug("read error in \"%s\"\n", mtd->name);
+ return ret;
+ }
+
+ if (retlen != header_len) {
+ pr_debug("short read in \"%s\"\n", mtd->name);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+static int __mtdsplit_parse_uimage(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data,
+ bool (*verify)(struct uimage_header *hdr))
+{
+ struct mtd_partition *parts;
+ struct uimage_header *header;
+ int nr_parts;
+ size_t offset;
+ size_t uimage_offset;
+ size_t uimage_size = 0;
+ size_t rootfs_offset;
+ size_t rootfs_size = 0;
+ int uimage_part, rf_part;
+ int ret;
+
+ nr_parts = 2;
+ parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
+ if (!parts)
+ return -ENOMEM;
+
+ header = vmalloc(sizeof(*header));
+ if (!header) {
+ ret = -ENOMEM;
+ goto err_free_parts;
+ }
+
+ /* find uImage on erase block boundaries */
+ for (offset = 0; offset < master->size; offset += master->erasesize) {
+ uimage_size = 0;
+
+ ret = read_uimage_header(master, offset, header);
+ if (ret)
+ continue;
+
+ if (!verify(header)) {
+ pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
+ master->name, (unsigned long long) offset);
+ continue;
+ }
+
+ uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size);
+ if ((offset + uimage_size) > master->size) {
+ pr_debug("uImage exceeds MTD device \"%s\"\n",
+ master->name);
+ continue;
+ }
+ break;
+ }
+
+ if (uimage_size == 0) {
+ pr_debug("no uImage found in \"%s\"\n", master->name);
+ ret = -ENODEV;
+ goto err_free_header;
+ }
+
+ uimage_offset = offset;
+
+ if (uimage_offset == 0) {
+ uimage_part = 0;
+ rf_part = 1;
+
+ /* find the roots after the uImage */
+ ret = mtd_find_rootfs_from(master,
+ uimage_offset + uimage_size,
+ master->size,
+ &rootfs_offset);
+ if (ret) {
+ pr_debug("no rootfs after uImage in \"%s\"\n",
+ master->name);
+ goto err_free_header;
+ }
+
+ rootfs_size = master->size - rootfs_offset;
+ uimage_size = rootfs_offset - uimage_offset;
+ } else {
+ rf_part = 0;
+ uimage_part = 1;
+
+ /* check rootfs presence at offset 0 */
+ ret = mtd_check_rootfs_magic(master, 0);
+ if (ret) {
+ pr_debug("no rootfs before uImage in \"%s\"\n",
+ master->name);
+ goto err_free_header;
+ }
+
+ rootfs_offset = 0;
+ rootfs_size = uimage_offset;
+ }
+
+ if (rootfs_size == 0) {
+ pr_debug("no rootfs found in \"%s\"\n", master->name);
+ ret = -ENODEV;
+ goto err_free_header;
+ }
+
+ parts[uimage_part].name = KERNEL_PART_NAME;
+ parts[uimage_part].offset = uimage_offset;
+ parts[uimage_part].size = uimage_size;
+
+ parts[rf_part].name = ROOTFS_PART_NAME;
+ parts[rf_part].offset = rootfs_offset;
+ parts[rf_part].size = rootfs_size;
+
+ vfree(header);
+
+ *pparts = parts;
+ return nr_parts;
+
+err_free_header:
+ vfree(header);
+
+err_free_parts:
+ kfree(parts);
+ return ret;
+}
+
+static bool uimage_verify_default(struct uimage_header *header)
+{
+ /* default sanity checks */
+ if (be32_to_cpu(header->ih_magic) != IH_MAGIC) {
+ pr_debug("invalid uImage magic: %08x\n",
+ be32_to_cpu(header->ih_magic));
+ return false;
+ }
+
+ if (header->ih_os != IH_OS_LINUX) {
+ pr_debug("invalid uImage OS: %08x\n",
+ be32_to_cpu(header->ih_os));
+ return false;
+ }
+
+ if (header->ih_type != IH_TYPE_KERNEL) {
+ pr_debug("invalid uImage type: %08x\n",
+ be32_to_cpu(header->ih_type));
+ return false;
+ }
+
+ return true;
+}
+
+static int
+mtdsplit_uimage_parse_generic(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ return __mtdsplit_parse_uimage(master, pparts, data,
+ uimage_verify_default);
+}
+
+static struct mtd_part_parser uimage_generic_parser = {
+ .owner = THIS_MODULE,
+ .name = "uimage-fw",
+ .parse_fn = mtdsplit_uimage_parse_generic,
+ .type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
+#define FW_MAGIC_WNR2000V3 0x32303033
+#define FW_MAGIC_WNR2000V4 0x32303034
+#define FW_MAGIC_WNR2200 0x32323030
+#define FW_MAGIC_WNR612V2 0x32303631
+#define FW_MAGIC_WNDR3700 0x33373030
+#define FW_MAGIC_WNDR3700V2 0x33373031
+
+static bool uimage_verify_wndr3700(struct uimage_header *header)
+{
+ uint8_t expected_type = IH_TYPE_FILESYSTEM;
+ switch be32_to_cpu(header->ih_magic) {
+ case FW_MAGIC_WNR612V2:
+ case FW_MAGIC_WNR2000V3:
+ case FW_MAGIC_WNR2200:
+ case FW_MAGIC_WNDR3700:
+ case FW_MAGIC_WNDR3700V2:
+ break;
+ case FW_MAGIC_WNR2000V4:
+ expected_type = IH_TYPE_KERNEL;
+ break;
+ default:
+ return false;
+ }
+
+ if (header->ih_os != IH_OS_LINUX ||
+ header->ih_type != expected_type)
+ return false;
+
+ return true;
+}
+
+static int
+mtdsplit_uimage_parse_netgear(struct mtd_info *master,
+ struct mtd_partition **pparts,
+ struct mtd_part_parser_data *data)
+{
+ return __mtdsplit_parse_uimage(master, pparts, data,
+ uimage_verify_wndr3700);
+}
+
+static struct mtd_part_parser uimage_netgear_parser = {
+ .owner = THIS_MODULE,
+ .name = "netgear-fw",
+ .parse_fn = mtdsplit_uimage_parse_netgear,
+ .type = MTD_PARSER_TYPE_FIRMWARE,
+};
+
+static int __init mtdsplit_uimage_init(void)
+{
+ register_mtd_parser(&uimage_generic_parser);
+ register_mtd_parser(&uimage_netgear_parser);
+
+ return 0;
+}
+
+module_init(mtdsplit_uimage_init);
+++ /dev/null
-/*
- * Copyright (C) 2014 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.
- *
- */
-
-#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 <asm/unaligned.h>
-
-#include "mtdsplit.h"
-
-#define LZMA_NR_PARTS 2
-#define LZMA_PROPERTIES_SIZE 5
-
-struct lzma_header {
- u8 props[LZMA_PROPERTIES_SIZE];
- u8 size_low[4];
- u8 size_high[4];
-};
-
-static int mtdsplit_parse_lzma(struct mtd_info *master,
- struct mtd_partition **pparts,
- struct mtd_part_parser_data *data)
-{
- struct lzma_header hdr;
- size_t hdr_len, retlen;
- size_t rootfs_offset;
- u32 t;
- struct mtd_partition *parts;
- 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;
-
- /* verify LZMA properties */
- if (hdr.props[0] >= (9 * 5 * 5))
- return -EINVAL;
-
- t = get_unaligned_le32(&hdr.props[1]);
- if (!is_power_of_2(t))
- return -EINVAL;
-
- t = get_unaligned_le32(&hdr.size_high);
- if (t)
- return -EINVAL;
-
- err = mtd_find_rootfs_from(master, master->erasesize,
- master->size, &rootfs_offset);
- if (err)
- return err;
-
- parts = kzalloc(LZMA_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 LZMA_NR_PARTS;
-}
-
-static struct mtd_part_parser mtdsplit_lzma_parser = {
- .owner = THIS_MODULE,
- .name = "lzma-fw",
- .parse_fn = mtdsplit_parse_lzma,
- .type = MTD_PARSER_TYPE_FIRMWARE,
-};
-
-static int __init mtdsplit_lzma_init(void)
-{
- register_mtd_parser(&mtdsplit_lzma_parser);
-
- return 0;
-}
-
-subsys_initcall(mtdsplit_lzma_init);
+++ /dev/null
-/*
- * 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.
- *
- */
-
-#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 SEAMA_MAGIC 0x5EA3A417
-#define SEAMA_NR_PARTS 2
-#define SEAMA_MIN_ROOTFS_OFFS 0x80000 /* 512KiB */
-
-struct seama_header {
- __be32 magic; /* should always be SEAMA_MAGIC. */
- __be16 reserved; /* reserved for */
- __be16 metasize; /* size of the META data */
- __be32 size; /* size of the image */
-};
-
-static int mtdsplit_parse_seama(struct mtd_info *master,
- struct mtd_partition **pparts,
- struct mtd_part_parser_data *data)
-{
- struct seama_header hdr;
- size_t hdr_len, retlen, kernel_size;
- size_t rootfs_offset;
- struct mtd_partition *parts;
- 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 (be32_to_cpu(hdr.magic) != SEAMA_MAGIC)
- return -EINVAL;
-
- kernel_size = hdr_len + be32_to_cpu(hdr.size) +
- be16_to_cpu(hdr.metasize);
- if (kernel_size > master->size)
- return -EINVAL;
-
- /* Find the rootfs after the kernel. */
- err = mtd_check_rootfs_magic(master, kernel_size);
- if (!err) {
- rootfs_offset = kernel_size;
- } else {
- /*
- * The size in the header might cover the rootfs as well.
- * Start the search from an arbitrary offset.
- */
- err = mtd_find_rootfs_from(master, SEAMA_MIN_ROOTFS_OFFS,
- master->size, &rootfs_offset);
- if (err)
- return err;
- }
-
- parts = kzalloc(SEAMA_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 SEAMA_NR_PARTS;
-}
-
-static struct mtd_part_parser mtdsplit_seama_parser = {
- .owner = THIS_MODULE,
- .name = "seama-fw",
- .parse_fn = mtdsplit_parse_seama,
- .type = MTD_PARSER_TYPE_FIRMWARE,
-};
-
-static int __init mtdsplit_seama_init(void)
-{
- register_mtd_parser(&mtdsplit_seama_parser);
-
- return 0;
-}
-
-subsys_initcall(mtdsplit_seama_init);
+++ /dev/null
-/*
- * 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 __init mtdsplit_squashfs_init(void)
-{
- register_mtd_parser(&mtdsplit_squashfs_parser);
-
- return 0;
-}
-
-subsys_initcall(mtdsplit_squashfs_init);
+++ /dev/null
-/*
- * 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/vmalloc.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mtd/partitions.h>
-#include <linux/byteorder/generic.h>
-
-#include "mtdsplit.h"
-
-#define IH_MAGIC 0x27051956 /* Image Magic Number */
-#define IH_NMLEN 32 /* Image Name Length */
-
-#define IH_OS_LINUX 5 /* Linux */
-
-#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
-#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image */
-
-/*
- * Legacy format image header,
- * all data in network byte order (aka natural aka bigendian).
- */
-struct uimage_header {
- uint32_t ih_magic; /* Image Header Magic Number */
- uint32_t ih_hcrc; /* Image Header CRC Checksum */
- uint32_t ih_time; /* Image Creation Timestamp */
- uint32_t ih_size; /* Image Data Size */
- uint32_t ih_load; /* Data Load Address */
- uint32_t ih_ep; /* Entry Point Address */
- uint32_t ih_dcrc; /* Image Data CRC Checksum */
- uint8_t ih_os; /* Operating System */
- uint8_t ih_arch; /* CPU architecture */
- uint8_t ih_type; /* Image Type */
- uint8_t ih_comp; /* Compression Type */
- uint8_t ih_name[IH_NMLEN]; /* Image Name */
-};
-
-static int
-read_uimage_header(struct mtd_info *mtd, size_t offset,
- struct uimage_header *header)
-{
- size_t header_len;
- size_t retlen;
- int ret;
-
- header_len = sizeof(*header);
- ret = mtd_read(mtd, offset, header_len, &retlen,
- (unsigned char *) header);
- if (ret) {
- pr_debug("read error in \"%s\"\n", mtd->name);
- return ret;
- }
-
- if (retlen != header_len) {
- pr_debug("short read in \"%s\"\n", mtd->name);
- return -EIO;
- }
-
- return 0;
-}
-
-static int __mtdsplit_parse_uimage(struct mtd_info *master,
- struct mtd_partition **pparts,
- struct mtd_part_parser_data *data,
- bool (*verify)(struct uimage_header *hdr))
-{
- struct mtd_partition *parts;
- struct uimage_header *header;
- int nr_parts;
- size_t offset;
- size_t uimage_offset;
- size_t uimage_size = 0;
- size_t rootfs_offset;
- size_t rootfs_size = 0;
- int uimage_part, rf_part;
- int ret;
-
- nr_parts = 2;
- parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
- if (!parts)
- return -ENOMEM;
-
- header = vmalloc(sizeof(*header));
- if (!header) {
- ret = -ENOMEM;
- goto err_free_parts;
- }
-
- /* find uImage on erase block boundaries */
- for (offset = 0; offset < master->size; offset += master->erasesize) {
- uimage_size = 0;
-
- ret = read_uimage_header(master, offset, header);
- if (ret)
- continue;
-
- if (!verify(header)) {
- pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
- master->name, (unsigned long long) offset);
- continue;
- }
-
- uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size);
- if ((offset + uimage_size) > master->size) {
- pr_debug("uImage exceeds MTD device \"%s\"\n",
- master->name);
- continue;
- }
- break;
- }
-
- if (uimage_size == 0) {
- pr_debug("no uImage found in \"%s\"\n", master->name);
- ret = -ENODEV;
- goto err_free_header;
- }
-
- uimage_offset = offset;
-
- if (uimage_offset == 0) {
- uimage_part = 0;
- rf_part = 1;
-
- /* find the roots after the uImage */
- ret = mtd_find_rootfs_from(master,
- uimage_offset + uimage_size,
- master->size,
- &rootfs_offset);
- if (ret) {
- pr_debug("no rootfs after uImage in \"%s\"\n",
- master->name);
- goto err_free_header;
- }
-
- rootfs_size = master->size - rootfs_offset;
- uimage_size = rootfs_offset - uimage_offset;
- } else {
- rf_part = 0;
- uimage_part = 1;
-
- /* check rootfs presence at offset 0 */
- ret = mtd_check_rootfs_magic(master, 0);
- if (ret) {
- pr_debug("no rootfs before uImage in \"%s\"\n",
- master->name);
- goto err_free_header;
- }
-
- rootfs_offset = 0;
- rootfs_size = uimage_offset;
- }
-
- if (rootfs_size == 0) {
- pr_debug("no rootfs found in \"%s\"\n", master->name);
- ret = -ENODEV;
- goto err_free_header;
- }
-
- parts[uimage_part].name = KERNEL_PART_NAME;
- parts[uimage_part].offset = uimage_offset;
- parts[uimage_part].size = uimage_size;
-
- parts[rf_part].name = ROOTFS_PART_NAME;
- parts[rf_part].offset = rootfs_offset;
- parts[rf_part].size = rootfs_size;
-
- vfree(header);
-
- *pparts = parts;
- return nr_parts;
-
-err_free_header:
- vfree(header);
-
-err_free_parts:
- kfree(parts);
- return ret;
-}
-
-static bool uimage_verify_default(struct uimage_header *header)
-{
- /* default sanity checks */
- if (be32_to_cpu(header->ih_magic) != IH_MAGIC) {
- pr_debug("invalid uImage magic: %08x\n",
- be32_to_cpu(header->ih_magic));
- return false;
- }
-
- if (header->ih_os != IH_OS_LINUX) {
- pr_debug("invalid uImage OS: %08x\n",
- be32_to_cpu(header->ih_os));
- return false;
- }
-
- if (header->ih_type != IH_TYPE_KERNEL) {
- pr_debug("invalid uImage type: %08x\n",
- be32_to_cpu(header->ih_type));
- return false;
- }
-
- return true;
-}
-
-static int
-mtdsplit_uimage_parse_generic(struct mtd_info *master,
- struct mtd_partition **pparts,
- struct mtd_part_parser_data *data)
-{
- return __mtdsplit_parse_uimage(master, pparts, data,
- uimage_verify_default);
-}
-
-static struct mtd_part_parser uimage_generic_parser = {
- .owner = THIS_MODULE,
- .name = "uimage-fw",
- .parse_fn = mtdsplit_uimage_parse_generic,
- .type = MTD_PARSER_TYPE_FIRMWARE,
-};
-
-#define FW_MAGIC_WNR2000V3 0x32303033
-#define FW_MAGIC_WNR2000V4 0x32303034
-#define FW_MAGIC_WNR2200 0x32323030
-#define FW_MAGIC_WNR612V2 0x32303631
-#define FW_MAGIC_WNDR3700 0x33373030
-#define FW_MAGIC_WNDR3700V2 0x33373031
-
-static bool uimage_verify_wndr3700(struct uimage_header *header)
-{
- uint8_t expected_type = IH_TYPE_FILESYSTEM;
- switch be32_to_cpu(header->ih_magic) {
- case FW_MAGIC_WNR612V2:
- case FW_MAGIC_WNR2000V3:
- case FW_MAGIC_WNR2200:
- case FW_MAGIC_WNDR3700:
- case FW_MAGIC_WNDR3700V2:
- break;
- case FW_MAGIC_WNR2000V4:
- expected_type = IH_TYPE_KERNEL;
- break;
- default:
- return false;
- }
-
- if (header->ih_os != IH_OS_LINUX ||
- header->ih_type != expected_type)
- return false;
-
- return true;
-}
-
-static int
-mtdsplit_uimage_parse_netgear(struct mtd_info *master,
- struct mtd_partition **pparts,
- struct mtd_part_parser_data *data)
-{
- return __mtdsplit_parse_uimage(master, pparts, data,
- uimage_verify_wndr3700);
-}
-
-static struct mtd_part_parser uimage_netgear_parser = {
- .owner = THIS_MODULE,
- .name = "netgear-fw",
- .parse_fn = mtdsplit_uimage_parse_netgear,
- .type = MTD_PARSER_TYPE_FIRMWARE,
-};
-
-static int __init mtdsplit_uimage_init(void)
-{
- register_mtd_parser(&uimage_generic_parser);
- register_mtd_parser(&uimage_netgear_parser);
-
- return 0;
-}
-
-module_init(mtdsplit_uimage_init);
depends on m
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -29,6 +29,7 @@
+@@ -29,9 +29,11 @@
#include <linux/kmod.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/err.h>
#include "mtdcore.h"
-@@ -45,13 +46,14 @@ struct mtd_part {
++#include "mtdsplit/mtdsplit.h"
+
+ /* Our partition linked list */
+ static LIST_HEAD(mtd_partitions);
+@@ -45,13 +47,14 @@ struct mtd_part {
struct list_head list;
};
/*
* MTD methods which simply translate the effective address and pass through
* to the _real_ device.
-@@ -533,8 +535,10 @@ out_register:
+@@ -533,8 +536,10 @@ out_register:
return slave;
}
{
struct mtd_partition part;
struct mtd_part *p, *new;
-@@ -566,21 +570,24 @@ int mtd_add_partition(struct mtd_info *m
+@@ -566,21 +571,24 @@ int mtd_add_partition(struct mtd_info *m
end = offset + length;
mutex_lock(&mtd_partitions_mutex);
return ret;
err_inv:
-@@ -590,6 +597,12 @@ err_inv:
+@@ -590,6 +598,12 @@ err_inv:
}
EXPORT_SYMBOL_GPL(mtd_add_partition);
int mtd_del_partition(struct mtd_info *master, int partno)
{
struct mtd_part *slave, *next;
-@@ -613,6 +626,144 @@ int mtd_del_partition(struct mtd_info *m
+@@ -613,6 +627,144 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
/*
* This function, given a master MTD object and a partition table, creates
* and registers slave MTD objects which are bound to the master according to
-@@ -642,6 +793,7 @@ int add_mtd_partitions(struct mtd_info *
+@@ -642,6 +794,7 @@ int add_mtd_partitions(struct mtd_info *
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&slave->mtd);
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -823,6 +823,30 @@ static struct mtd_part_parser *get_parti
+@@ -824,6 +824,30 @@ static struct mtd_part_parser *get_parti
#define put_partition_parser(p) do { module_put((p)->owner); } while (0)
int register_mtd_parser(struct mtd_part_parser *p)
{
spin_lock(&part_parser_lock);
-@@ -899,6 +923,38 @@ int parse_mtd_partitions(struct mtd_info
+@@ -900,6 +924,38 @@ int parse_mtd_partitions(struct mtd_info
return ret;
}
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -626,6 +626,37 @@ int mtd_del_partition(struct mtd_info *m
+@@ -627,6 +627,37 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
static inline unsigned long
mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
{
-@@ -685,6 +716,10 @@ static void split_rootfs_data(struct mtd
+@@ -686,6 +717,10 @@ static void split_rootfs_data(struct mtd
unsigned int split_size;
int ret;
ret = split_squashfs(master, part->offset, &split_offset);
if (ret)
return;
-@@ -734,6 +769,12 @@ static void split_uimage(struct mtd_info
+@@ -735,6 +770,12 @@ static void split_uimage(struct mtd_info
static void split_firmware(struct mtd_info *master, struct mtd_part *part)
{
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -36,6 +36,11 @@ config MTD_UIMAGE_SPLIT
+@@ -36,6 +36,8 @@ config MTD_UIMAGE_SPLIT
depends on MTD_SPLIT_FIRMWARE
default y
-+config MTD_SPLIT
-+ def_bool n
-+ help
-+ Generic MTD split support.
++source "drivers/mtd/mtdsplit/Kconfig"
+
endmenu
obj-$(CONFIG_MTD) += mtd.o
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
-+mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
++obj-$(CONFIG_MTD_SPLIT) += mtdsplit/
+
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -33,6 +33,7 @@
- #include <linux/err.h>
-
- #include "mtdcore.h"
-+#include "mtdsplit.h"
-
- /* Our partition linked list */
- static LIST_HEAD(mtd_partitions);
-@@ -668,43 +669,16 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+@@ -669,43 +669,16 @@ mtd_pad_erasesize(struct mtd_info *mtd,
return len;
}
+++ /dev/null
---- 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
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -48,6 +48,12 @@ config MTD_SPLIT_SQUASHFS_ROOT
- offset and size of the unused portion of a rootfs partition
- containing a squashfs.
-
-+comment "Firmware partition parsers"
-+
-+config MTD_SPLIT_UIMAGE_FW
-+ bool "uImage based firmware partition parser"
-+ select MTD_SPLIT
-+
- config MTD_SPLIT
- def_bool n
- help
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -8,6 +8,7 @@ mtd-y := mtdcore.o mtdsuper.o mtdconc
-
- mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
- mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
-+mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -50,6 +50,10 @@ config MTD_SPLIT_SQUASHFS_ROOT
-
- comment "Firmware partition parsers"
-
-+config MTD_SPLIT_SEAMA_FW
-+ bool "Seama firmware parser"
-+ select MTD_SPLIT
-+
- config MTD_SPLIT_UIMAGE_FW
- bool "uImage based firmware partition parser"
- select MTD_SPLIT
---- 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_SEAMA_FW) += mtdsplit_seama.o
- mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
- mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -58,6 +58,10 @@ config MTD_SPLIT_UIMAGE_FW
- bool "uImage based firmware partition parser"
- select MTD_SPLIT
-
-+config MTD_SPLIT_LZMA_FW
-+ bool "LZMA compressed kernel based firmware partition parser"
-+ select MTD_SPLIT
-+
- config MTD_SPLIT
- def_bool n
- help
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -10,6 +10,7 @@ mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
- mtd-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o
- mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
- mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-+mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
-
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
+++ b/drivers/mtd/mtdpart.c
@@ -35,6 +35,8 @@
#include "mtdcore.h"
- #include "mtdsplit.h"
+ #include "mtdsplit/mtdsplit.h"
+#define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
+
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -212,6 +212,22 @@ config MTD_BCM47XX_PARTS
+@@ -184,6 +184,22 @@ config MTD_BCM47XX_PARTS
This provides partitions parser for devices based on BCM47xx
boards.
config MTD_BLKDEVS
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
-@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
+@@ -15,6 +15,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o
obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1209,6 +1209,48 @@
+@@ -1207,6 +1207,48 @@ static struct mtd_info * __init open_mtd
return mtd;
}
static int __init ubi_init(void)
{
int err, i, k;
-@@ -1298,6 +1340,12 @@
+@@ -1290,6 +1332,12 @@ static int __init ubi_init(void)
}
}
depends on m
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -29,6 +29,7 @@
+@@ -29,9 +29,11 @@
#include <linux/kmod.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/err.h>
#include "mtdcore.h"
-@@ -45,13 +46,14 @@ struct mtd_part {
++#include "mtdsplit/mtdsplit.h"
+
+ /* Our partition linked list */
+ static LIST_HEAD(mtd_partitions);
+@@ -45,13 +47,14 @@ struct mtd_part {
struct list_head list;
};
/*
* MTD methods which simply translate the effective address and pass through
* to the _real_ device.
-@@ -534,8 +536,10 @@ out_register:
+@@ -534,8 +537,10 @@ out_register:
return slave;
}
{
struct mtd_partition part;
struct mtd_part *p, *new;
-@@ -567,21 +571,24 @@ int mtd_add_partition(struct mtd_info *m
+@@ -567,21 +572,24 @@ int mtd_add_partition(struct mtd_info *m
end = offset + length;
mutex_lock(&mtd_partitions_mutex);
return ret;
err_inv:
-@@ -591,6 +598,12 @@ err_inv:
+@@ -591,6 +599,12 @@ err_inv:
}
EXPORT_SYMBOL_GPL(mtd_add_partition);
int mtd_del_partition(struct mtd_info *master, int partno)
{
struct mtd_part *slave, *next;
-@@ -614,6 +627,144 @@ int mtd_del_partition(struct mtd_info *m
+@@ -614,6 +628,144 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
/*
* This function, given a master MTD object and a partition table, creates
* and registers slave MTD objects which are bound to the master according to
-@@ -643,6 +794,7 @@ int add_mtd_partitions(struct mtd_info *
+@@ -643,6 +795,7 @@ int add_mtd_partitions(struct mtd_info *
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&slave->mtd);
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -824,6 +824,30 @@ static struct mtd_part_parser *get_parti
+@@ -825,6 +825,30 @@ static struct mtd_part_parser *get_parti
#define put_partition_parser(p) do { module_put((p)->owner); } while (0)
int register_mtd_parser(struct mtd_part_parser *p)
{
spin_lock(&part_parser_lock);
-@@ -900,6 +924,38 @@ int parse_mtd_partitions(struct mtd_info
+@@ -901,6 +925,38 @@ int parse_mtd_partitions(struct mtd_info
return ret;
}
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -627,6 +627,37 @@ int mtd_del_partition(struct mtd_info *m
+@@ -628,6 +628,37 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
static inline unsigned long
mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
{
-@@ -686,6 +717,10 @@ static void split_rootfs_data(struct mtd
+@@ -687,6 +718,10 @@ static void split_rootfs_data(struct mtd
unsigned int split_size;
int ret;
ret = split_squashfs(master, part->offset, &split_offset);
if (ret)
return;
-@@ -735,6 +770,12 @@ static void split_uimage(struct mtd_info
+@@ -736,6 +771,12 @@ static void split_uimage(struct mtd_info
static void split_firmware(struct mtd_info *master, struct mtd_part *part)
{
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -36,6 +36,11 @@ config MTD_UIMAGE_SPLIT
+@@ -36,6 +36,8 @@ config MTD_UIMAGE_SPLIT
depends on MTD_SPLIT_FIRMWARE
default y
-+config MTD_SPLIT
-+ def_bool n
-+ help
-+ Generic MTD split support.
++source "drivers/mtd/mtdsplit/Kconfig"
+
endmenu
obj-$(CONFIG_MTD) += mtd.o
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
-+mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
++obj-$(CONFIG_MTD_SPLIT) += mtdsplit/
+
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
-@@ -33,6 +33,7 @@
- #include <linux/err.h>
-
- #include "mtdcore.h"
-+#include "mtdsplit.h"
-
- /* Our partition linked list */
- static LIST_HEAD(mtd_partitions);
-@@ -669,43 +670,16 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+@@ -670,43 +670,16 @@ mtd_pad_erasesize(struct mtd_info *mtd,
return len;
}
+++ /dev/null
---- 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
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -48,6 +48,12 @@ config MTD_SPLIT_SQUASHFS_ROOT
- offset and size of the unused portion of a rootfs partition
- containing a squashfs.
-
-+comment "Firmware partition parsers"
-+
-+config MTD_SPLIT_UIMAGE_FW
-+ bool "uImage based firmware partition parser"
-+ select MTD_SPLIT
-+
- config MTD_SPLIT
- def_bool n
- help
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -8,6 +8,7 @@ mtd-y := mtdcore.o mtdsuper.o mtdconc
-
- mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
- mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
-+mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -50,6 +50,10 @@ config MTD_SPLIT_SQUASHFS_ROOT
-
- comment "Firmware partition parsers"
-
-+config MTD_SPLIT_SEAMA_FW
-+ bool "Seama firmware parser"
-+ select MTD_SPLIT
-+
- config MTD_SPLIT_UIMAGE_FW
- bool "uImage based firmware partition parser"
- select MTD_SPLIT
---- 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_SEAMA_FW) += mtdsplit_seama.o
- mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
- mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -58,6 +58,10 @@ config MTD_SPLIT_UIMAGE_FW
- bool "uImage based firmware partition parser"
- select MTD_SPLIT
-
-+config MTD_SPLIT_LZMA_FW
-+ bool "LZMA compressed kernel based firmware partition parser"
-+ select MTD_SPLIT
-+
- config MTD_SPLIT
- def_bool n
- help
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -10,6 +10,7 @@ mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
- mtd-$(CONFIG_MTD_SPLIT_SEAMA_FW) += mtdsplit_seama.o
- mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
- mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-+mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
-
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
+++ b/drivers/mtd/mtdpart.c
@@ -35,6 +35,8 @@
#include "mtdcore.h"
- #include "mtdsplit.h"
+ #include "mtdsplit/mtdsplit.h"
+#define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
+
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -212,6 +212,22 @@ config MTD_BCM47XX_PARTS
+@@ -184,6 +184,22 @@ config MTD_BCM47XX_PARTS
This provides partitions parser for devices based on BCM47xx
boards.
config MTD_BLKDEVS
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
-@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
+@@ -15,6 +15,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o
obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o
/****************************************************************************/
struct m25p {
-@@ -1032,7 +1038,7 @@ static int m25p_probe(struct spi_device
+@@ -1032,7 +1038,7 @@ static int m25p_probe(struct spi_device
flash->mtd._write = m25p80_write;
/* prefer "small sector" erase if possible */
static struct proc_dir_entry *my_proc_entry;
static char *yaffs_dump_dev_part0(char *buf, struct yaffs_dev *dev)
-@@ -3398,6 +3399,7 @@ static int yaffs_proc_write(struct file
+@@ -3398,6 +3399,7 @@ static int yaffs_proc_write(struct file
return yaffs_proc_debug_write(file, buf, count, data);
return yaffs_proc_write_trace_options(file, buf, count, data);
}
#include <linux/err.h>
#include "mtdcore.h"
-+#include "mtdsplit.h"
++#include "mtdsplit/mtdsplit.h"
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
+@@ -27,6 +27,8 @@ config MTD_SPLIT_FIRMWARE_NAME
depends on MTD_SPLIT_FIRMWARE
default "firmware"
-+config MTD_SPLIT
-+ def_bool n
-+ help
-+ Generic MTD split support.
++source "drivers/mtd/mtdsplit/Kconfig"
+
endmenu
obj-$(CONFIG_MTD) += mtd.o
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
-+mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
++obj-$(CONFIG_MTD_SPLIT) += mtdsplit/
+
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
--- /dev/null
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -434,14 +434,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;
+@@ -659,6 +657,17 @@ run_parsers_by_type(struct mtd_part *sla
+ return nr_parts;
+ }
+
++static inline unsigned long
++mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
++{
++ unsigned long mask = mtd->erasesize - 1;
++
++ len += offset & mask;
++ len = (len + mask) & ~mask;
++ len -= offset & mask;
++ return len;
++}
++
+ #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #else
+@@ -900,6 +909,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, const 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)
+++ /dev/null
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -434,14 +434,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;
-@@ -659,6 +657,17 @@ run_parsers_by_type(struct mtd_part *sla
- return nr_parts;
- }
-
-+static inline unsigned long
-+mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
-+{
-+ unsigned long mask = mtd->erasesize - 1;
-+
-+ len += offset & mask;
-+ len = (len + mask) & ~mask;
-+ len -= offset & mask;
-+ return len;
-+}
-+
- #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #else
-@@ -900,6 +909,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, const 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)
--- /dev/null
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
+ depends on MTD_SPLIT_FIRMWARE
+ default "firmware"
+
++config MTD_UIMAGE_SPLIT
++ bool "Enable split support for firmware partitions containing a uImage"
++ depends on MTD_SPLIT_FIRMWARE
++ default y
++
+ source "drivers/mtd/mtdsplit/Kconfig"
+
+ endmenu
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -668,6 +668,37 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+ return len;
+ }
+
++#define UBOOT_MAGIC 0x27051956
++
++static void split_uimage(struct mtd_info *master, struct mtd_part *part)
++{
++ struct {
++ __be32 magic;
++ __be32 pad[2];
++ __be32 size;
++ } hdr;
++ size_t len;
++
++ if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
++ return;
++
++ if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
++ return;
++
++ len = be32_to_cpu(hdr.size) + 0x40;
++ len = mtd_pad_erasesize(master, part->offset, len);
++ if (len + master->erasesize > part->mtd.size)
++ return;
++
++ if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
++ pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
++ else
++ pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
++
++ __mtd_add_partition(master, "rootfs", part->offset + len,
++ part->mtd.size - len, false);
++}
++
+ #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #else
+@@ -676,7 +707,14 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+
+ static void split_firmware(struct mtd_info *master, struct mtd_part *part)
+ {
+- run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
++ int ret;
++
++ ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
++ if (ret > 0)
++ return;
++
++ if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
++ split_uimage(master, part);
+ }
+
+ void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -27,6 +27,8 @@ config MTD_SPLIT_FIRMWARE_NAME
- depends on MTD_SPLIT_FIRMWARE
- default "firmware"
-
-+source "drivers/mtd/mtdsplit/Kconfig"
-+
- config MTD_SPLIT
- def_bool n
- help
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -7,6 +7,10 @@ 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_SEAMA_FW) += mtdsplit_seama.o
-+mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
-+mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-+mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
-
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
--- /dev/null
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -18,6 +18,11 @@ config MTD_ROOTFS_ROOT_DEV
+ bool "Automatically set 'rootfs' partition to be root filesystem"
+ default y
+
++config MTD_ROOTFS_SPLIT
++ bool "Automatically split 'rootfs' partition for squashfs"
++ select MTD_SPLIT
++ default y
++
+ config MTD_SPLIT_FIRMWARE
+ bool "Automatically split firmware partition for kernel+rootfs"
+ default y
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -668,6 +668,47 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+ return len;
+ }
+
++static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
++{
++ size_t squashfs_len;
++ int len, ret;
++
++ ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
++ if (ret)
++ return ret;
++
++ len = mtd_pad_erasesize(master, offset, squashfs_len);
++ *split_offset = offset + len;
++
++ return 0;
++}
++
++static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
++{
++ unsigned int split_offset = 0;
++ unsigned int split_size;
++ int ret;
++
++ ret = split_squashfs(master, part->offset, &split_offset);
++ if (ret)
++ return;
++
++ if (split_offset <= 0)
++ return;
++
++ if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
++ pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
++ else
++ pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
++
++ split_size = part->mtd.size - (split_offset - part->offset);
++ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
++ ROOTFS_SPLIT_NAME, split_offset, split_size);
++
++ __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
++ split_size, false);
++}
++
+ #define UBOOT_MAGIC 0x27051956
+
+ static void split_uimage(struct mtd_info *master, struct mtd_part *part)
+@@ -730,7 +771,10 @@ static void mtd_partition_split(struct m
+ return;
+
+ if (!strcmp(part->mtd.name, "rootfs")) {
+- run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
++ int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
++
++ if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
++ split_rootfs_data(master, part);
+
+ rootfs_found = 1;
+ }
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
- depends on MTD_SPLIT_FIRMWARE
- default "firmware"
-
-+config MTD_UIMAGE_SPLIT
-+ bool "Enable split support for firmware partitions containing a uImage"
-+ depends on MTD_SPLIT_FIRMWARE
-+ default y
-+
- source "drivers/mtd/mtdsplit/Kconfig"
-
- config MTD_SPLIT
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -668,6 +668,37 @@ mtd_pad_erasesize(struct mtd_info *mtd,
- return len;
- }
-
-+#define UBOOT_MAGIC 0x27051956
-+
-+static void split_uimage(struct mtd_info *master, struct mtd_part *part)
-+{
-+ struct {
-+ __be32 magic;
-+ __be32 pad[2];
-+ __be32 size;
-+ } hdr;
-+ size_t len;
-+
-+ if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
-+ return;
-+
-+ if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
-+ return;
-+
-+ len = be32_to_cpu(hdr.size) + 0x40;
-+ len = mtd_pad_erasesize(master, part->offset, len);
-+ if (len + master->erasesize > part->mtd.size)
-+ return;
-+
-+ if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
-+ pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
-+ else
-+ pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
-+
-+ __mtd_add_partition(master, "rootfs", part->offset + len,
-+ part->mtd.size - len, false);
-+}
-+
- #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #else
-@@ -676,7 +707,14 @@ mtd_pad_erasesize(struct mtd_info *mtd,
-
- static void split_firmware(struct mtd_info *master, struct mtd_part *part)
- {
-- run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
-+ int ret;
-+
-+ ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
-+ if (ret > 0)
-+ return;
-+
-+ if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
-+ split_uimage(master, part);
- }
-
- void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -18,6 +18,11 @@ config MTD_ROOTFS_ROOT_DEV
- bool "Automatically set 'rootfs' partition to be root filesystem"
- default y
-
-+config MTD_ROOTFS_SPLIT
-+ bool "Automatically split 'rootfs' partition for squashfs"
-+ select MTD_SPLIT
-+ default y
-+
- config MTD_SPLIT_FIRMWARE
- bool "Automatically split firmware partition for kernel+rootfs"
- default y
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -668,6 +668,47 @@ mtd_pad_erasesize(struct mtd_info *mtd,
- return len;
- }
-
-+static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
-+{
-+ size_t squashfs_len;
-+ int len, ret;
-+
-+ ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
-+ if (ret)
-+ return ret;
-+
-+ len = mtd_pad_erasesize(master, offset, squashfs_len);
-+ *split_offset = offset + len;
-+
-+ return 0;
-+}
-+
-+static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
-+{
-+ unsigned int split_offset = 0;
-+ unsigned int split_size;
-+ int ret;
-+
-+ ret = split_squashfs(master, part->offset, &split_offset);
-+ if (ret)
-+ return;
-+
-+ if (split_offset <= 0)
-+ return;
-+
-+ if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
-+ pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
-+ else
-+ pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
-+
-+ split_size = part->mtd.size - (split_offset - part->offset);
-+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
-+ ROOTFS_SPLIT_NAME, split_offset, split_size);
-+
-+ __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
-+ split_size, false);
-+}
-+
- #define UBOOT_MAGIC 0x27051956
-
- static void split_uimage(struct mtd_info *master, struct mtd_part *part)
-@@ -730,7 +771,10 @@ static void mtd_partition_split(struct m
- return;
-
- if (!strcmp(part->mtd.name, "rootfs")) {
-- run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
-+ int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
-+
-+ if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
-+ split_rootfs_data(master, part);
-
- rootfs_found = 1;
- }
+++ b/drivers/mtd/mtdpart.c
@@ -35,6 +35,8 @@
#include "mtdcore.h"
- #include "mtdsplit.h"
+ #include "mtdsplit/mtdsplit.h"
+#define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
+
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -189,6 +189,22 @@ config MTD_BCM47XX_PARTS
+@@ -184,6 +184,22 @@ config MTD_BCM47XX_PARTS
This provides partitions parser for devices based on BCM47xx
boards.
#
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
-@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
+@@ -15,6 +15,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o
obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o
u64 offset, uint32_t mask_flags)
{
part->name = name;
-@@ -58,6 +59,26 @@ static void bcm47xxpart_add_part(struct
+@@ -58,6 +59,26 @@ static void bcm47xxpart_add_part(struct
part->mask_flags = mask_flags;
}
/****************************************************************************/
enum read_type {
-@@ -1192,7 +1198,7 @@ static int m25p_probe(struct spi_device
+@@ -1192,7 +1198,7 @@ static int m25p_probe(struct spi_device
flash->mtd._write = m25p80_write;
/* prefer "small sector" erase if possible */
#include <linux/err.h>
#include "mtdcore.h"
-+#include "mtdsplit.h"
++#include "mtdsplit/mtdsplit.h"
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
+@@ -27,6 +27,8 @@ config MTD_SPLIT_FIRMWARE_NAME
depends on MTD_SPLIT_FIRMWARE
default "firmware"
-+config MTD_SPLIT
-+ def_bool n
-+ help
-+ Generic MTD split support.
++source "drivers/mtd/mtdsplit/Kconfig"
+
endmenu
obj-$(CONFIG_MTD) += mtd.o
mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o
-+mtd-$(CONFIG_MTD_SPLIT) += mtdsplit.o
++obj-$(CONFIG_MTD_SPLIT) += mtdsplit/
+
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
--- /dev/null
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -445,14 +445,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;
+@@ -672,6 +670,17 @@ run_parsers_by_type(struct mtd_part *sla
+ return nr_parts;
+ }
+
++static inline unsigned long
++mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
++{
++ unsigned long mask = mtd->erasesize - 1;
++
++ len += offset & mask;
++ len = (len + mask) & ~mask;
++ len -= offset & mask;
++ return len;
++}
++
+ #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #else
+@@ -913,6 +922,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, const 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
+@@ -333,6 +333,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)
+++ /dev/null
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -445,14 +445,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;
-@@ -672,6 +670,17 @@ run_parsers_by_type(struct mtd_part *sla
- return nr_parts;
- }
-
-+static inline unsigned long
-+mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
-+{
-+ unsigned long mask = mtd->erasesize - 1;
-+
-+ len += offset & mask;
-+ len = (len + mask) & ~mask;
-+ len -= offset & mask;
-+ return len;
-+}
-+
- #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #else
-@@ -913,6 +922,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, const 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
-@@ -333,6 +333,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)
--- /dev/null
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
+ depends on MTD_SPLIT_FIRMWARE
+ default "firmware"
+
++config MTD_UIMAGE_SPLIT
++ bool "Enable split support for firmware partitions containing a uImage"
++ depends on MTD_SPLIT_FIRMWARE
++ default y
++
+ source "drivers/mtd/mtdsplit/Kconfig"
+
+ endmenu
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -681,6 +681,37 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+ return len;
+ }
+
++#define UBOOT_MAGIC 0x27051956
++
++static void split_uimage(struct mtd_info *master, struct mtd_part *part)
++{
++ struct {
++ __be32 magic;
++ __be32 pad[2];
++ __be32 size;
++ } hdr;
++ size_t len;
++
++ if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
++ return;
++
++ if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
++ return;
++
++ len = be32_to_cpu(hdr.size) + 0x40;
++ len = mtd_pad_erasesize(master, part->offset, len);
++ if (len + master->erasesize > part->mtd.size)
++ return;
++
++ if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
++ pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
++ else
++ pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
++
++ __mtd_add_partition(master, "rootfs", part->offset + len,
++ part->mtd.size - len, false);
++}
++
+ #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
+ #else
+@@ -689,7 +720,14 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+
+ static void split_firmware(struct mtd_info *master, struct mtd_part *part)
+ {
+- run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
++ int ret;
++
++ ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
++ if (ret > 0)
++ return;
++
++ if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
++ split_uimage(master, part);
+ }
+
+ void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -27,6 +27,8 @@ config MTD_SPLIT_FIRMWARE_NAME
- depends on MTD_SPLIT_FIRMWARE
- default "firmware"
-
-+source "drivers/mtd/mtdsplit/Kconfig"
-+
- config MTD_SPLIT
- def_bool n
- help
---- a/drivers/mtd/Makefile
-+++ b/drivers/mtd/Makefile
-@@ -7,6 +7,10 @@ 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_SEAMA_FW) += mtdsplit_seama.o
-+mtd-$(CONFIG_MTD_SPLIT_SQUASHFS_ROOT) += mtdsplit_squashfs.o
-+mtd-$(CONFIG_MTD_SPLIT_UIMAGE_FW) += mtdsplit_uimage.o
-+mtd-$(CONFIG_MTD_SPLIT_LZMA_FW) += mtdsplit_lzma.o
-
- obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
- obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
--- /dev/null
+--- a/drivers/mtd/Kconfig
++++ b/drivers/mtd/Kconfig
+@@ -18,6 +18,11 @@ config MTD_ROOTFS_ROOT_DEV
+ bool "Automatically set 'rootfs' partition to be root filesystem"
+ default y
+
++config MTD_ROOTFS_SPLIT
++ bool "Automatically split 'rootfs' partition for squashfs"
++ select MTD_SPLIT
++ default y
++
+ config MTD_SPLIT_FIRMWARE
+ bool "Automatically split firmware partition for kernel+rootfs"
+ default y
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -681,6 +681,47 @@ mtd_pad_erasesize(struct mtd_info *mtd,
+ return len;
+ }
+
++static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
++{
++ size_t squashfs_len;
++ int len, ret;
++
++ ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
++ if (ret)
++ return ret;
++
++ len = mtd_pad_erasesize(master, offset, squashfs_len);
++ *split_offset = offset + len;
++
++ return 0;
++}
++
++static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
++{
++ unsigned int split_offset = 0;
++ unsigned int split_size;
++ int ret;
++
++ ret = split_squashfs(master, part->offset, &split_offset);
++ if (ret)
++ return;
++
++ if (split_offset <= 0)
++ return;
++
++ if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
++ pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
++ else
++ pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
++
++ split_size = part->mtd.size - (split_offset - part->offset);
++ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
++ ROOTFS_SPLIT_NAME, split_offset, split_size);
++
++ __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
++ split_size, false);
++}
++
+ #define UBOOT_MAGIC 0x27051956
+
+ static void split_uimage(struct mtd_info *master, struct mtd_part *part)
+@@ -743,7 +784,10 @@ static void mtd_partition_split(struct m
+ return;
+
+ if (!strcmp(part->mtd.name, "rootfs")) {
+- run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
++ int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
++
++ if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
++ split_rootfs_data(master, part);
+
+ rootfs_found = 1;
+ }
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -27,6 +27,11 @@ config MTD_SPLIT_FIRMWARE_NAME
- depends on MTD_SPLIT_FIRMWARE
- default "firmware"
-
-+config MTD_UIMAGE_SPLIT
-+ bool "Enable split support for firmware partitions containing a uImage"
-+ depends on MTD_SPLIT_FIRMWARE
-+ default y
-+
- source "drivers/mtd/mtdsplit/Kconfig"
-
- config MTD_SPLIT
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -681,6 +681,37 @@ mtd_pad_erasesize(struct mtd_info *mtd,
- return len;
- }
-
-+#define UBOOT_MAGIC 0x27051956
-+
-+static void split_uimage(struct mtd_info *master, struct mtd_part *part)
-+{
-+ struct {
-+ __be32 magic;
-+ __be32 pad[2];
-+ __be32 size;
-+ } hdr;
-+ size_t len;
-+
-+ if (mtd_read(master, part->offset, sizeof(hdr), &len, (void *) &hdr))
-+ return;
-+
-+ if (len != sizeof(hdr) || hdr.magic != cpu_to_be32(UBOOT_MAGIC))
-+ return;
-+
-+ len = be32_to_cpu(hdr.size) + 0x40;
-+ len = mtd_pad_erasesize(master, part->offset, len);
-+ if (len + master->erasesize > part->mtd.size)
-+ return;
-+
-+ if (config_enabled(CONFIG_MTD_SPLIT_UIMAGE_FW))
-+ pr_err("Dedicated partitioner didn't split firmware partition, please fill a bug report!\n");
-+ else
-+ pr_warn("Support for built-in firmware splitter will be removed, please use CONFIG_MTD_SPLIT_UIMAGE_FW\n");
-+
-+ __mtd_add_partition(master, "rootfs", part->offset + len,
-+ part->mtd.size - len, false);
-+}
-+
- #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
- #else
-@@ -689,7 +720,14 @@ mtd_pad_erasesize(struct mtd_info *mtd,
-
- static void split_firmware(struct mtd_info *master, struct mtd_part *part)
- {
-- run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
-+ int ret;
-+
-+ ret = run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
-+ if (ret > 0)
-+ return;
-+
-+ if (config_enabled(CONFIG_MTD_UIMAGE_SPLIT))
-+ split_uimage(master, part);
- }
-
- void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
+++ /dev/null
---- a/drivers/mtd/Kconfig
-+++ b/drivers/mtd/Kconfig
-@@ -18,6 +18,11 @@ config MTD_ROOTFS_ROOT_DEV
- bool "Automatically set 'rootfs' partition to be root filesystem"
- default y
-
-+config MTD_ROOTFS_SPLIT
-+ bool "Automatically split 'rootfs' partition for squashfs"
-+ select MTD_SPLIT
-+ default y
-+
- config MTD_SPLIT_FIRMWARE
- bool "Automatically split firmware partition for kernel+rootfs"
- default y
---- a/drivers/mtd/mtdpart.c
-+++ b/drivers/mtd/mtdpart.c
-@@ -681,6 +681,47 @@ mtd_pad_erasesize(struct mtd_info *mtd,
- return len;
- }
-
-+static int split_squashfs(struct mtd_info *master, int offset, int *split_offset)
-+{
-+ size_t squashfs_len;
-+ int len, ret;
-+
-+ ret = mtd_get_squashfs_len(master, offset, &squashfs_len);
-+ if (ret)
-+ return ret;
-+
-+ len = mtd_pad_erasesize(master, offset, squashfs_len);
-+ *split_offset = offset + len;
-+
-+ return 0;
-+}
-+
-+static void split_rootfs_data(struct mtd_info *master, struct mtd_part *part)
-+{
-+ unsigned int split_offset = 0;
-+ unsigned int split_size;
-+ int ret;
-+
-+ ret = split_squashfs(master, part->offset, &split_offset);
-+ if (ret)
-+ return;
-+
-+ if (split_offset <= 0)
-+ return;
-+
-+ if (config_enabled(CONFIG_MTD_SPLIT_SQUASHFS_ROOT))
-+ pr_err("Dedicated partitioner didn't create \"rootfs_data\" partition, please fill a bug report!\n");
-+ else
-+ pr_warn("Support for built-in \"rootfs_data\" splitter will be removed, please use CONFIG_MTD_SPLIT_SQUASHFS_ROOT\n");
-+
-+ split_size = part->mtd.size - (split_offset - part->offset);
-+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=0x%x, len=0x%x\n",
-+ ROOTFS_SPLIT_NAME, split_offset, split_size);
-+
-+ __mtd_add_partition(master, ROOTFS_SPLIT_NAME, split_offset,
-+ split_size, false);
-+}
-+
- #define UBOOT_MAGIC 0x27051956
-
- static void split_uimage(struct mtd_info *master, struct mtd_part *part)
-@@ -743,7 +784,10 @@ static void mtd_partition_split(struct m
- return;
-
- if (!strcmp(part->mtd.name, "rootfs")) {
-- run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
-+ int num = run_parsers_by_type(part, MTD_PARSER_TYPE_ROOTFS);
-+
-+ if (num <= 0 && config_enabled(CONFIG_MTD_ROOTFS_SPLIT))
-+ split_rootfs_data(master, part);
-
- rootfs_found = 1;
- }
+++ b/drivers/mtd/mtdpart.c
@@ -35,6 +35,8 @@
#include "mtdcore.h"
- #include "mtdsplit.h"
+ #include "mtdsplit/mtdsplit.h"
+#define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
+
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
-@@ -189,6 +189,22 @@ config MTD_BCM47XX_PARTS
+@@ -184,6 +184,22 @@ config MTD_BCM47XX_PARTS
This provides partitions parser for devices based on BCM47xx
boards.
#
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
-@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
+@@ -15,6 +15,7 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o
obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o
u64 offset, uint32_t mask_flags)
{
part->name = name;
-@@ -58,6 +59,26 @@ static void bcm47xxpart_add_part(struct
+@@ -58,6 +59,26 @@ static void bcm47xxpart_add_part(struct
part->mask_flags = mask_flags;
}
static struct proc_dir_entry *my_proc_entry;
static char *yaffs_dump_dev_part0(char *buf, struct yaffs_dev *dev)
-@@ -3398,6 +3399,7 @@ static int yaffs_proc_write(struct file
+@@ -3398,6 +3399,7 @@ static int yaffs_proc_write(struct file
return yaffs_proc_debug_write(file, buf, count, data);
return yaffs_proc_write_trace_options(file, buf, count, data);
}