kernel: update linux 3.3 to 3.3.6
[openwrt/staging/yousong.git] / target / linux / lantiq / patches-3.3 / 201-owrt-mtd_split.patch
1 --- a/drivers/mtd/Kconfig
2 +++ b/drivers/mtd/Kconfig
3 @@ -31,6 +31,10 @@ config MTD_ROOTFS_SPLIT
4 bool "Automatically split 'rootfs' partition for squashfs"
5 default y
6
7 +config MTD_UIMAGE_SPLIT
8 + bool "Automatically split 'linux' partition into 'kernel' and 'rootfs'"
9 + default y
10 +
11 config MTD_REDBOOT_PARTS
12 tristate "RedBoot partition table parsing"
13 ---help---
14 --- a/drivers/mtd/mtdpart.c
15 +++ b/drivers/mtd/mtdpart.c
16 @@ -867,6 +867,169 @@ static int refresh_rootfs_split(struct m
17 }
18 #endif /* CONFIG_MTD_ROOTFS_SPLIT */
19
20 +
21 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
22 +static unsigned long find_uimage_size(struct mtd_info *mtd,
23 + unsigned long offset)
24 +{
25 +#define UBOOT_MAGIC 0x56190527
26 + unsigned long magic = 0;
27 + unsigned long temp;
28 + size_t len;
29 + int ret;
30 +
31 + ret = mtd->read(mtd, offset, 4, &len, (void *)&magic);
32 + if (ret || len != sizeof(magic))
33 + return 0;
34 +
35 + if (le32_to_cpu(magic) != UBOOT_MAGIC)
36 + return 0;
37 +
38 + ret = mtd->read(mtd, offset + 12, 4, &len, (void *)&temp);
39 + if (ret || len != sizeof(temp))
40 + return 0;
41 +
42 + return temp + 0x40;
43 +}
44 +
45 +static unsigned long find_eva_size(struct mtd_info *mtd,
46 + unsigned long offset)
47 +{
48 +#define EVA_MAGIC 0xfeed1281
49 + unsigned long magic = 0;
50 + unsigned long temp;
51 + size_t len;
52 + int ret;
53 +
54 + ret = mtd->read(mtd, offset, 4, &len, (void *)&magic);
55 + if (ret || len != sizeof(magic))
56 + return 0;
57 +
58 + if (le32_to_cpu(magic) != EVA_MAGIC)
59 + return 0;
60 +
61 + ret = mtd->read(mtd, offset + 4, 4, &len, (void *)&temp);
62 + if (ret || len != sizeof(temp))
63 + return 0;
64 +
65 + /* add eva header size */
66 + temp = le32_to_cpu(temp) + 0x18;
67 +
68 + temp &= ~0xffff;
69 + temp += 0x10000;
70 + return temp;
71 +}
72 +
73 +static int detect_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
74 +{
75 + unsigned long temp;
76 + size_t len;
77 + int ret;
78 +
79 + ret = mtd->read(mtd, offset, 4, &len, (void *)&temp);
80 + if (ret || len != sizeof(temp))
81 + return 0;
82 +
83 +
84 + return le32_to_cpu(temp) == SQUASHFS_MAGIC;
85 +}
86 +
87 +static int detect_eva_squashfs_partition(struct mtd_info *mtd, unsigned long offset)
88 +{
89 + unsigned long temp;
90 + size_t len;
91 + int ret;
92 +
93 + ret = mtd->read(mtd, offset, 4, &len, (void *)&temp);
94 + if (ret || len != sizeof(temp))
95 + return 0;
96 +
97 + return be32_to_cpu(temp) == SQUASHFS_MAGIC;
98 +}
99 +
100 +static unsigned long find_brnimage_size(struct mtd_info *mtd,
101 + unsigned long offset)
102 +{
103 + unsigned long buf[4];
104 + // Assume at most 2MB of kernel image
105 + unsigned long end = offset + (2 << 20);
106 + unsigned long ptr = offset + 0x400 - 12;
107 + size_t len;
108 + int ret;
109 +
110 + while (ptr < end) {
111 + long size_min = ptr - 0x400 - 12 - offset;
112 + long size_max = ptr + 12 - offset;
113 + ret = mtd->read(mtd, ptr, 16, &len, (void *)buf);
114 + if (ret || len != 16)
115 + return 0;
116 +
117 + if (le32_to_cpu(buf[0]) < size_min ||
118 + le32_to_cpu(buf[0]) > size_max) {
119 + ptr += 0x400;
120 + continue;
121 + }
122 +
123 + if (le32_to_cpu(buf[3]) == SQUASHFS_MAGIC)
124 + return ptr + 12 - offset;
125 +
126 + ptr += 0x400;
127 + }
128 +
129 + return 0;
130 +}
131 +
132 +static int split_uimage(struct mtd_info *mtd,
133 + const struct mtd_partition *part)
134 +{
135 + static struct mtd_partition split_partitions[] = {
136 + {
137 + .name = "kernel",
138 + .offset = 0x0,
139 + .size = 0x0,
140 + }, {
141 + .name = "rootfs",
142 + .offset = 0x0,
143 + .size = 0x0,
144 + },
145 + };
146 +
147 + split_partitions[0].size = find_uimage_size(mtd, part->offset);
148 + if (!split_partitions[0].size) {
149 + split_partitions[0].size = find_eva_size(mtd, part->offset);
150 + if (!split_partitions[0].size) {
151 + split_partitions[0].size = find_brnimage_size(mtd, part->offset);
152 + if (!split_partitions[0].size) {
153 + printk(KERN_NOTICE "no uImage or brnImage or eva found in linux partition\n");
154 + return -1;
155 + }
156 + }
157 + }
158 +
159 + if (detect_eva_squashfs_partition(mtd,
160 + part->offset
161 + + split_partitions[0].size)) {
162 + split_partitions[0].size += 0x100;
163 + pr_info("found eva dummy squashfs behind kernel\n");
164 + } else if (!detect_squashfs_partition(mtd,
165 + part->offset
166 + + split_partitions[0].size)) {
167 + split_partitions[0].size &= ~(mtd->erasesize - 1);
168 + split_partitions[0].size += mtd->erasesize;
169 + } else {
170 + pr_info("found squashfs behind kernel\n");
171 + }
172 +
173 + split_partitions[0].offset = part->offset;
174 + split_partitions[1].offset = part->offset + split_partitions[0].size;
175 + split_partitions[1].size = part->size - split_partitions[0].size;
176 +
177 + add_mtd_partitions(mtd, split_partitions, 2);
178 +
179 + return 0;
180 +}
181 +#endif
182 +
183 /*
184 * This function, given a master MTD object and a partition table, creates
185 * and registers slave MTD objects which are bound to the master according to
186 @@ -883,7 +1046,7 @@ int add_mtd_partitions(struct mtd_info *
187 struct mtd_part *slave;
188 uint64_t cur_offset = 0;
189 int i;
190 -#ifdef CONFIG_MTD_ROOTFS_SPLIT
191 +#if defined(CONFIG_MTD_ROOTFS_SPLIT) || defined(CONFIG_MTD_UIMAGE_SPLIT)
192 int ret;
193 #endif
194
195 @@ -900,6 +1063,17 @@ int add_mtd_partitions(struct mtd_info *
196
197 add_mtd_device(&slave->mtd);
198
199 +#ifdef CONFIG_MTD_UIMAGE_SPLIT
200 + if (!strcmp(parts[i].name, "linux")) {
201 + ret = split_uimage(master, &parts[i]);
202 +
203 + if (ret) {
204 + printk(KERN_WARNING
205 + "Can't split linux partition\n");
206 + }
207 + }
208 +#endif
209 +
210 if (!strcmp(parts[i].name, "rootfs")) {
211 #ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
212 if (ROOT_DEV == 0) {
213 --- a/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
214 +++ b/arch/mips/include/asm/mach-lantiq/xway/lantiq_soc.h
215 @@ -166,6 +166,7 @@ extern unsigned char ltq_boot_select(voi
216
217 extern __iomem void *ltq_ebu_membase;
218 extern __iomem void *ltq_cgu_membase;
219 +extern unsigned long ltq_brn_boot;
220
221 static inline int ltq_is_ase(void)
222 {
223 --- a/arch/mips/lantiq/setup.c
224 +++ b/arch/mips/lantiq/setup.c
225 @@ -18,6 +18,9 @@
226 #include "devices.h"
227 #include "prom.h"
228
229 +/* set to 1 if the bootloader is BRN-BOOT instead of u-boot */
230 +unsigned long ltq_brn_boot = 0;
231 +
232 void __init plat_mem_setup(void)
233 {
234 /* assume 16M as default incase uboot fails to pass proper ramsize */
235 @@ -38,6 +41,10 @@ void __init plat_mem_setup(void)
236 if (strict_strtoul(e, 0, &memsize))
237 pr_warn("bad memsize specified\n");
238 }
239 + if (!strncmp(e, "BRN-BOOT", 8)){
240 + pr_info("Found BRN-BOOT instead of u-boot\n");
241 + ltq_brn_boot = 1;
242 + }
243 envp++;
244 }
245 memsize *= 1024 * 1024;