bump kernel to 3.2.12
[openwrt/staging/dedeckeh.git] / target / linux / lantiq / patches-3.2 / 201-owrt-mtd_split.patch
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
5 @@ -31,6 +31,10 @@
6 bool "Automatically split 'rootfs' partition for squashfs"
7 default y
8
9 +config MTD_UIMAGE_SPLIT
10 + bool "Automatically split 'linux' partition into 'kernel' and 'rootfs'"
11 + default y
12 +
13 config MTD_REDBOOT_PARTS
14 tristate "RedBoot partition table parsing"
15 ---help---
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
20 @@ -874,6 +874,169 @@
21 }
22 #endif /* CONFIG_MTD_ROOTFS_SPLIT */
23
24 +
25 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
26 +static unsigned long find_uimage_size(struct mtd_info *mtd,
27 + unsigned long offset)
28 +{
29 +#define UBOOT_MAGIC 0x56190527
30 + unsigned long magic = 0;
31 + unsigned long temp;
32 + size_t len;
33 + int ret;
34 +
35 + ret = mtd->read(mtd, offset, 4, &len, (void *)&magic);
36 + if (ret || len != sizeof(magic))
37 + return 0;
38 +
39 + if (le32_to_cpu(magic) != UBOOT_MAGIC)
40 + return 0;
41 +
42 + ret = mtd->read(mtd, offset + 12, 4, &len, (void *)&temp);
43 + if (ret || len != sizeof(temp))
44 + return 0;
45 +
46 + return temp + 0x40;
47 +}
48 +
49 +static unsigned long find_eva_size(struct mtd_info *mtd,
50 + unsigned long offset)
51 +{
52 +#define EVA_MAGIC 0xfeed1281
53 + unsigned long magic = 0;
54 + unsigned long temp;
55 + size_t len;
56 + int ret;
57 +
58 + ret = mtd->read(mtd, offset, 4, &len, (void *)&magic);
59 + if (ret || len != sizeof(magic))
60 + return 0;
61 +
62 + if (le32_to_cpu(magic) != EVA_MAGIC)
63 + return 0;
64 +
65 + ret = mtd->read(mtd, offset + 4, 4, &len, (void *)&temp);
66 + if (ret || len != sizeof(temp))
67 + return 0;
68 +
69 + /* add eva header size */
70 + temp = le32_to_cpu(temp) + 0x18;
71 +
72 + temp &= ~0xffff;
73 + temp += 0x10000;
74 + return temp;
75 +}
76 +
77 +static int detect_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
78 +{
79 + unsigned long temp;
80 + size_t len;
81 + int ret;
82 +
83 + ret = mtd->read(mtd, offset, 4, &len, (void *)&temp);
84 + if (ret || len != sizeof(temp))
85 + return 0;
86 +
87 +
88 + return le32_to_cpu(temp) == SQUASHFS_MAGIC;
89 +}
90 +
91 +static int detect_eva_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
92 +{
93 + unsigned long temp;
94 + size_t len;
95 + int ret;
96 +
97 + ret = mtd->read(mtd, offset, 4, &len, (void *)&temp);
98 + if (ret || len != sizeof(temp))
99 + return 0;
100 +
101 + return be32_to_cpu(temp) == SQUASHFS_MAGIC;
102 +}
103 +
104 +static unsigned long find_brnimage_size(struct mtd_info *mtd,
105 + unsigned long offset)
106 +{
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;
111 + size_t len;
112 + int ret;
113 +
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)
119 + return 0;
120 +
121 + if (le32_to_cpu(buf[0]) < size_min ||
122 + le32_to_cpu(buf[0]) > size_max) {
123 + ptr += 0x400;
124 + continue;
125 + }
126 +
127 + if (le32_to_cpu(buf[3]) == SQUASHFS_MAGIC)
128 + return ptr + 12 - offset;
129 +
130 + ptr += 0x400;
131 + }
132 +
133 + return 0;
134 +}
135 +
136 +static int split_uimage(struct mtd_info *mtd,
137 + const struct mtd_partition *part)
138 +{
139 + static struct mtd_partition split_partitions[] = {
140 + {
141 + .name = "kernel",
142 + .offset = 0x0,
143 + .size = 0x0,
144 + }, {
145 + .name = "rootfs",
146 + .offset = 0x0,
147 + .size = 0x0,
148 + },
149 + };
150 +
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");
158 + return -1;
159 + }
160 + }
161 + }
162 +
163 + if (detect_eva_squashfs_partition(mtd,
164 + part->offset
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,
169 + part->offset
170 + + split_partitions[0].size)) {
171 + split_partitions[0].size &= ~(mtd->erasesize - 1);
172 + split_partitions[0].size += mtd->erasesize;
173 + } else {
174 + pr_info("found squashfs behind kernel\n");
175 + }
176 +
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;
180 +
181 + add_mtd_partitions(mtd, split_partitions, 2);
182 +
183 + return 0;
184 +}
185 +#endif
186 +
187 /*
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 @@
191
192 add_mtd_device(&slave->mtd);
193
194 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
195 + if (!strcmp(parts[i].name, "linux")) {
196 + ret = split_uimage(master, &parts[i]);
197 +
198 + if (ret) {
199 + printk(KERN_WARNING
200 + "Can't split linux partition\n");
201 + }
202 + }
203 +#endif
204 +
205 if (!strcmp(parts[i].name, "rootfs")) {
206 #ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
207 if (ROOT_DEV == 0) {
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
212 @@ -156,6 +156,7 @@
213
214 extern __iomem void *ltq_ebu_membase;
215 extern __iomem void *ltq_cgu_membase;
216 +extern unsigned long ltq_brn_boot;
217
218 static inline int ltq_is_ase(void)
219 {
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
224 @@ -18,6 +18,9 @@
225 #include "devices.h"
226 #include "prom.h"
227
228 +/* set to 1 if the bootloader is BRN-BOOT instead of u-boot */
229 +unsigned long ltq_brn_boot = 0;
230 +
231 void __init plat_mem_setup(void)
232 {
233 /* assume 16M as default incase uboot fails to pass proper ramsize */
234 @@ -38,6 +41,10 @@
235 if (strict_strtoul(e, 0, &memsize))
236 pr_warn("bad memsize specified\n");
237 }
238 + if (!strncmp(e, "BRN-BOOT", 8)){
239 + pr_info("Found BRN-BOOT instead of u-boot\n");
240 + ltq_brn_boot = 1;
241 + }
242 envp++;
243 }
244 memsize *= 1024 * 1024;