1 Index: linux-3.2.9/drivers/mtd/Kconfig
2 ===================================================================
3 --- linux-3.2.9.orig/drivers/mtd/Kconfig 2012-03-17 17:43:47.395607926 +0100
4 +++ linux-3.2.9/drivers/mtd/Kconfig 2012-03-17 20:49:30.279873461 +0100
6 bool "Automatically split 'rootfs' partition for squashfs"
9 +config MTD_UIMAGE_SPLIT
10 + bool "Automatically split 'linux' partition into 'kernel' and 'rootfs'"
13 config MTD_REDBOOT_PARTS
14 tristate "RedBoot partition table parsing"
16 Index: linux-3.2.9/drivers/mtd/mtdpart.c
17 ===================================================================
18 --- linux-3.2.9.orig/drivers/mtd/mtdpart.c 2012-03-17 17:43:47.407607922 +0100
19 +++ linux-3.2.9/drivers/mtd/mtdpart.c 2012-03-17 20:49:42.987873819 +0100
22 #endif /* CONFIG_MTD_ROOTFS_SPLIT */
25 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
26 +static unsigned long find_uimage_size(struct mtd_info *mtd,
27 + unsigned long offset)
29 +#define UBOOT_MAGIC 0x56190527
30 + unsigned long magic = 0;
35 + ret = mtd->read(mtd, offset, 4, &len, (void *)&magic);
36 + if (ret || len != sizeof(magic))
39 + if (le32_to_cpu(magic) != UBOOT_MAGIC)
42 + ret = mtd->read(mtd, offset + 12, 4, &len, (void *)&temp);
43 + if (ret || len != sizeof(temp))
49 +static unsigned long find_eva_size(struct mtd_info *mtd,
50 + unsigned long offset)
52 +#define EVA_MAGIC 0xfeed1281
53 + unsigned long magic = 0;
58 + ret = mtd->read(mtd, offset, 4, &len, (void *)&magic);
59 + if (ret || len != sizeof(magic))
62 + if (le32_to_cpu(magic) != EVA_MAGIC)
65 + ret = mtd->read(mtd, offset + 4, 4, &len, (void *)&temp);
66 + if (ret || len != sizeof(temp))
69 + /* add eva header size */
70 + temp = le32_to_cpu(temp) + 0x18;
77 +static int detect_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
83 + ret = mtd->read(mtd, offset, 4, &len, (void *)&temp);
84 + if (ret || len != sizeof(temp))
88 + return le32_to_cpu(temp) == SQUASHFS_MAGIC;
91 +static int detect_eva_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
97 + ret = mtd->read(mtd, offset, 4, &len, (void *)&temp);
98 + if (ret || len != sizeof(temp))
101 + return be32_to_cpu(temp) == SQUASHFS_MAGIC;
104 +static unsigned long find_brnimage_size(struct mtd_info *mtd,
105 + unsigned long offset)
107 + unsigned long buf[4];
108 + // Assume at most 2MB of kernel image
109 + unsigned long end = offset + (2 << 20);
110 + unsigned long ptr = offset + 0x400 - 12;
114 + while (ptr < end) {
115 + long size_min = ptr - 0x400 - 12 - offset;
116 + long size_max = ptr + 12 - offset;
117 + ret = mtd->read(mtd, ptr, 16, &len, (void *)buf);
118 + if (ret || len != 16)
121 + if (le32_to_cpu(buf[0]) < size_min ||
122 + le32_to_cpu(buf[0]) > size_max) {
127 + if (le32_to_cpu(buf[3]) == SQUASHFS_MAGIC)
128 + return ptr + 12 - offset;
136 +static int split_uimage(struct mtd_info *mtd,
137 + const struct mtd_partition *part)
139 + static struct mtd_partition split_partitions[] = {
151 + split_partitions[0].size = find_uimage_size(mtd, part->offset);
152 + if (!split_partitions[0].size) {
153 + split_partitions[0].size = find_eva_size(mtd, part->offset);
154 + if (!split_partitions[0].size) {
155 + split_partitions[0].size = find_brnimage_size(mtd, part->offset);
156 + if (!split_partitions[0].size) {
157 + printk(KERN_NOTICE "no uImage or brnImage or eva found in linux partition\n");
163 + if (detect_eva_squashfs_partition(mtd,
165 + + split_partitions[0].size)) {
166 + split_partitions[0].size += 0x100;
167 + pr_info("found eva dummy squashfs behind kernel\n");
168 + } else if (!detect_squashfs_partition(mtd,
170 + + split_partitions[0].size)) {
171 + split_partitions[0].size &= ~(mtd->erasesize - 1);
172 + split_partitions[0].size += mtd->erasesize;
174 + pr_info("found squashfs behind kernel\n");
177 + split_partitions[0].offset = part->offset;
178 + split_partitions[1].offset = part->offset + split_partitions[0].size;
179 + split_partitions[1].size = part->size - split_partitions[0].size;
181 + add_mtd_partitions(mtd, split_partitions, 2);
188 * This function, given a master MTD object and a partition table, creates
189 * and registers slave MTD objects which are bound to the master according to
190 @@ -907,6 +1070,17 @@
192 add_mtd_device(&slave->mtd);
194 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
195 + if (!strcmp(parts[i].name, "linux")) {
196 + ret = split_uimage(master, &parts[i]);
199 + printk(KERN_WARNING
200 + "Can't split linux partition\n");
205 if (!strcmp(parts[i].name, "rootfs")) {
206 #ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
208 Index: linux-3.2.9/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
209 ===================================================================
210 --- linux-3.2.9.orig/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h 2012-03-17 20:49:32.000000000 +0100
211 +++ linux-3.2.9/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h 2012-03-17 20:50:07.815874369 +0100
214 extern __iomem void *ltq_ebu_membase;
215 extern __iomem void *ltq_cgu_membase;
216 +extern unsigned long ltq_brn_boot;
218 static inline int ltq_is_ase(void)
220 Index: linux-3.2.9/arch/mips/lantiq/setup.c
221 ===================================================================
222 --- linux-3.2.9.orig/arch/mips/lantiq/setup.c 2012-03-17 20:49:32.000000000 +0100
223 +++ linux-3.2.9/arch/mips/lantiq/setup.c 2012-03-17 20:50:07.815874369 +0100
228 +/* set to 1 if the bootloader is BRN-BOOT instead of u-boot */
229 +unsigned long ltq_brn_boot = 0;
231 void __init plat_mem_setup(void)
233 /* assume 16M as default incase uboot fails to pass proper ramsize */
235 if (strict_strtoul(e, 0, &memsize))
236 pr_warn("bad memsize specified\n");
238 + if (!strncmp(e, "BRN-BOOT", 8)){
239 + pr_info("Found BRN-BOOT instead of u-boot\n");
244 memsize *= 1024 * 1024;