1 From 2a295753a10823a47542c779a25bbb1f52c71281 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Fri, 3 Aug 2012 10:27:13 +0200
4 Subject: [PATCH 19/25] owrt mtd split
7 .../mips/include/asm/mach-lantiq/xway/lantiq_soc.h | 1 +
8 arch/mips/lantiq/setup.c | 7 +
9 drivers/mtd/Kconfig | 4 +
10 drivers/mtd/mtdpart.c | 173 +++++++++++++++++++-
11 4 files changed, 184 insertions(+), 1 deletions(-)
13 Index: linux-3.9-rc4/drivers/mtd/Kconfig
14 ===================================================================
15 --- linux-3.9-rc4.orig/drivers/mtd/Kconfig 2013-03-27 09:26:32.005789709 +0100
16 +++ linux-3.9-rc4/drivers/mtd/Kconfig 2013-03-27 09:26:35.669789796 +0100
18 bool "Automatically split 'rootfs' partition for squashfs"
21 +config MTD_UIMAGE_SPLIT
22 + bool "Automatically split 'linux' partition into 'kernel' and 'rootfs'"
25 config MTD_REDBOOT_PARTS
26 tristate "RedBoot partition table parsing"
28 Index: linux-3.9-rc4/drivers/mtd/mtdpart.c
29 ===================================================================
30 --- linux-3.9-rc4.orig/drivers/mtd/mtdpart.c 2013-03-27 09:26:32.281789715 +0100
31 +++ linux-3.9-rc4/drivers/mtd/mtdpart.c 2013-03-27 17:20:12.874466937 +0100
34 #endif /* CONFIG_MTD_ROOTFS_SPLIT */
36 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
37 +static unsigned long find_uimage_size(struct mtd_info *mtd,
38 + unsigned long offset)
40 +#define UBOOT_MAGIC 0x56190527
41 + unsigned long magic = 0;
46 + ret = mtd_read(mtd, offset, 4, &len, (void *)&magic);
47 + if (ret || len != sizeof(magic))
50 + if (le32_to_cpu(magic) != UBOOT_MAGIC)
53 + ret = mtd_read(mtd, offset + 12, 4, &len, (void *)&temp);
54 + if (ret || len != sizeof(temp))
57 + return be32_to_cpu(temp) + 0x40;
60 +static int detect_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
66 + ret = mtd_read(mtd, offset, 4, &len, (void *)&temp);
67 + if (ret || len != sizeof(temp))
70 + return le32_to_cpu(temp) == SQUASHFS_MAGIC;
73 +static unsigned long find_squashfs_offset(struct mtd_info *mtd, unsigned long _offset)
75 + /* scan the first 2MB at 64K offsets */
78 + for (i = 0; i < 32; i++) {
79 + unsigned long offset = i * 64 * 1024;
80 + if (detect_squashfs_partition(mtd, _offset + offset))
86 +static int split_uimage(struct mtd_info *mtd,
87 + const struct mtd_partition *part)
89 + static struct mtd_partition split_partitions[] = {
101 + split_partitions[0].size = find_uimage_size(mtd, part->offset);
102 + if (!split_partitions[0].size) {
103 + split_partitions[0].size = find_squashfs_offset(mtd, part->offset);
104 + if (!split_partitions[0].size) {
105 + pr_err("failed to split firmware partition\n");
110 + if (!detect_squashfs_partition(mtd,
112 + + split_partitions[0].size)) {
113 + split_partitions[0].size &= ~(mtd->erasesize - 1);
114 + split_partitions[0].size += mtd->erasesize;
116 + pr_info("found squashfs behind kernel\n");
119 + split_partitions[0].offset = part->offset;
120 + split_partitions[1].offset = part->offset + split_partitions[0].size;
121 + split_partitions[1].size = part->size - split_partitions[0].size;
123 + add_mtd_partitions(mtd, split_partitions, 2);
130 * This function, given a master MTD object and a partition table, creates
131 * and registers slave MTD objects which are bound to the master according to
133 struct mtd_part *slave;
134 uint64_t cur_offset = 0;
136 -#ifdef CONFIG_MTD_ROOTFS_SPLIT
137 +#if defined(CONFIG_MTD_ROOTFS_SPLIT) || defined(CONFIG_MTD_UIMAGE_SPLIT)
143 add_mtd_device(&slave->mtd);
145 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
146 + if (!strcmp(parts[i].name, "firmware")) {
147 + ret = split_uimage(master, &parts[i]);
149 + printk(KERN_WARNING "Can't split firmware partition\n");
153 if (!strcmp(parts[i].name, "rootfs")) {
154 #ifdef CONFIG_MTD_ROOTFS_ROOT_DEV