Style fixes
[openwrt.git] / target / linux / etrax / patches / generic_2.6 / 060-rootfs_split.patch
1 diff -ur linux.old/drivers/mtd/Kconfig linux.dev/drivers/mtd/Kconfig
2 --- linux.old/drivers/mtd/Kconfig 2007-01-10 20:10:37.000000000 +0100
3 +++ linux.dev/drivers/mtd/Kconfig 2007-02-19 23:00:53.739457000 +0100
4 @@ -49,6 +49,11 @@
5 devices. Partitioning on NFTL 'devices' is a different - that's the
6 'normal' form of partitioning used on a block device.
7
8 +config MTD_SPLIT_ROOTFS
9 + bool "Automatically split rootfs partition for squashfs"
10 + depends on MTD_PARTITIONS
11 + default y
12 +
13 config MTD_REDBOOT_PARTS
14 tristate "RedBoot partition table parsing"
15 depends on MTD_PARTITIONS
16 diff -ur linux.old/drivers/mtd/mtdpart.c linux.dev/drivers/mtd/mtdpart.c
17 --- linux.old/drivers/mtd/mtdpart.c 2007-01-10 20:10:37.000000000 +0100
18 +++ linux.dev/drivers/mtd/mtdpart.c 2007-02-20 00:01:38.587355896 +0100
19 @@ -20,6 +20,8 @@
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/partitions.h>
22 #include <linux/mtd/compatmac.h>
23 +#include <linux/squashfs_fs.h>
24 +#include <linux/root_dev.h>
25
26 /* Our partition linked list */
27 static LIST_HEAD(mtd_partitions);
28 @@ -303,6 +305,173 @@
29 return 0;
30 }
31
32 +static u_int32_t cur_offset = 0;
33 +static int add_mtd_partition(struct mtd_info *master, const struct mtd_partition *part, int i)
34 +{
35 + struct mtd_part *slave;
36 +
37 + /* allocate the partition structure */
38 + slave = kmalloc (sizeof(*slave), GFP_KERNEL);
39 + if (!slave) {
40 + printk ("memory allocation error while creating partitions for \"%s\"\n",
41 + master->name);
42 + del_mtd_partitions(master);
43 + return -ENOMEM;
44 + }
45 + memset(slave, 0, sizeof(*slave));
46 + list_add(&slave->list, &mtd_partitions);
47 +
48 + /* set up the MTD object for this partition */
49 + slave->mtd.type = master->type;
50 + slave->mtd.flags = master->flags & ~part->mask_flags;
51 + slave->mtd.size = part->size;
52 + slave->mtd.writesize = master->writesize;
53 + slave->mtd.oobsize = master->oobsize;
54 + slave->mtd.ecctype = master->ecctype;
55 + slave->mtd.eccsize = master->eccsize;
56 +
57 + slave->mtd.name = part->name;
58 + slave->mtd.bank_size = master->bank_size;
59 + slave->mtd.owner = master->owner;
60 +
61 + slave->mtd.read = part_read;
62 + slave->mtd.write = part_write;
63 +
64 + if(master->point && master->unpoint){
65 + slave->mtd.point = part_point;
66 + slave->mtd.unpoint = part_unpoint;
67 + }
68 +
69 + if (master->read_oob)
70 + slave->mtd.read_oob = part_read_oob;
71 + if (master->write_oob)
72 + slave->mtd.write_oob = part_write_oob;
73 + if(master->read_user_prot_reg)
74 + slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
75 + if(master->read_fact_prot_reg)
76 + slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
77 + if(master->write_user_prot_reg)
78 + slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
79 + if(master->lock_user_prot_reg)
80 + slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
81 + if(master->get_user_prot_info)
82 + slave->mtd.get_user_prot_info = part_get_user_prot_info;
83 + if(master->get_fact_prot_info)
84 + slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
85 + if (master->sync)
86 + slave->mtd.sync = part_sync;
87 + if (!i && master->suspend && master->resume) {
88 + slave->mtd.suspend = part_suspend;
89 + slave->mtd.resume = part_resume;
90 + }
91 + if (master->writev)
92 + slave->mtd.writev = part_writev;
93 + if (master->lock)
94 + slave->mtd.lock = part_lock;
95 + if (master->unlock)
96 + slave->mtd.unlock = part_unlock;
97 + if (master->block_isbad)
98 + slave->mtd.block_isbad = part_block_isbad;
99 + if (master->block_markbad)
100 + slave->mtd.block_markbad = part_block_markbad;
101 + slave->mtd.erase = part_erase;
102 + slave->master = master;
103 + slave->offset = part->offset;
104 + slave->index = i;
105 +
106 + if (slave->offset == MTDPART_OFS_APPEND)
107 + slave->offset = cur_offset;
108 + if (slave->offset == MTDPART_OFS_NXTBLK) {
109 + slave->offset = cur_offset;
110 + if ((cur_offset % master->erasesize) != 0) {
111 + /* Round up to next erasesize */
112 + slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
113 + printk(KERN_NOTICE "Moving partition %d: "
114 + "0x%08x -> 0x%08x\n", i,
115 + cur_offset, slave->offset);
116 + }
117 + }
118 + if (slave->mtd.size == MTDPART_SIZ_FULL)
119 + slave->mtd.size = master->size - slave->offset;
120 + cur_offset = slave->offset + slave->mtd.size;
121 +
122 + printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
123 + slave->offset + slave->mtd.size, slave->mtd.name);
124 +
125 + /* let's do some sanity checks */
126 + if (slave->offset >= master->size) {
127 + /* let's register it anyway to preserve ordering */
128 + slave->offset = 0;
129 + slave->mtd.size = 0;
130 + printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
131 + part->name);
132 + }
133 + if (slave->offset + slave->mtd.size > master->size) {
134 + slave->mtd.size = master->size - slave->offset;
135 + printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
136 + part->name, master->name, slave->mtd.size);
137 + }
138 + if (master->numeraseregions>1) {
139 + /* Deal with variable erase size stuff */
140 + int i;
141 + struct mtd_erase_region_info *regions = master->eraseregions;
142 +
143 + /* Find the first erase regions which is part of this partition. */
144 + for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
145 + ;
146 +
147 + for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
148 + if (slave->mtd.erasesize < regions[i].erasesize) {
149 + slave->mtd.erasesize = regions[i].erasesize;
150 + }
151 + }
152 + } else {
153 + /* Single erase size */
154 + slave->mtd.erasesize = master->erasesize;
155 + }
156 +
157 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
158 + (slave->offset % slave->mtd.erasesize)) {
159 + /* Doesn't start on a boundary of major erase size */
160 + /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
161 + slave->mtd.flags &= ~MTD_WRITEABLE;
162 + printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
163 + part->name);
164 + }
165 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
166 + (slave->mtd.size % slave->mtd.erasesize)) {
167 + slave->mtd.flags &= ~MTD_WRITEABLE;
168 + printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
169 + part->name);
170 + }
171 +
172 + slave->mtd.ecclayout = master->ecclayout;
173 + if (master->block_isbad) {
174 + uint32_t offs = 0;
175 +
176 + while(offs < slave->mtd.size) {
177 + if (master->block_isbad(master,
178 + offs + slave->offset))
179 + slave->mtd.ecc_stats.badblocks++;
180 + offs += slave->mtd.erasesize;
181 + }
182 + }
183 +
184 + if(part->mtdp)
185 + { /* store the object pointer (caller may or may not register it */
186 + *part->mtdp = &slave->mtd;
187 + slave->registered = 0;
188 + }
189 + else
190 + {
191 + /* register our partition */
192 + add_mtd_device(&slave->mtd);
193 + slave->registered = 1;
194 + }
195 +
196 + return 0;
197 +}
198 +
199 /*
200 * This function, given a master MTD object and a partition table, creates
201 * and registers slave MTD objects which are bound to the master according to
202 @@ -314,171 +483,53 @@
203 const struct mtd_partition *parts,
204 int nbparts)
205 {
206 - struct mtd_part *slave;
207 - u_int32_t cur_offset = 0;
208 - int i;
209 + struct mtd_partition *part;
210 + int i, ret = 0;
211
212 printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
213
214 for (i = 0; i < nbparts; i++) {
215 + part = (struct mtd_partition *) &parts[i];
216 + ret = add_mtd_partition(master, part, i);
217 + if (ret)
218 + return ret;
219 + if (strcmp(part->name, "rootfs") == 0) {
220 +#ifdef CONFIG_MTD_SPLIT_ROOTFS
221 + int len;
222 + char buf[512];
223 + struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
224 +#define ROOTFS_SPLIT_NAME "rootfs_data"
225 + if ((master->read(master, part->offset, sizeof(struct squashfs_super_block), &len, buf) == 0) &&
226 + (len == sizeof(struct squashfs_super_block)) &&
227 + (*((u32 *) buf) == SQUASHFS_MAGIC) &&
228 + (sb->bytes_used > 0)) {
229 +
230 +
231 + part = kmalloc(sizeof(struct mtd_partition), GFP_KERNEL);
232 + memcpy(part, &parts[i], sizeof(struct mtd_partition));
233 +
234 + part->name = kmalloc(sizeof(ROOTFS_SPLIT_NAME) + 1, GFP_KERNEL);
235 + strcpy(part->name, ROOTFS_SPLIT_NAME);
236 +
237 + len = (u32) sb->bytes_used;
238 + len += (part->offset & 0x000fffff);
239 + len += (master->erasesize - 1);
240 + len &= ~(master->erasesize - 1);
241 + len -= (part->offset & 0x000fffff);
242 + part->offset += len;
243 + part->size -= len;
244 +
245 + if (master->erasesize <= part->size)
246 + ret = add_mtd_partition(master, part, i + 1);
247 + else
248 + kfree(part->name);
249 + if (ret)
250 + return ret;
251
252 - /* allocate the partition structure */
253 - slave = kmalloc (sizeof(*slave), GFP_KERNEL);
254 - if (!slave) {
255 - printk ("memory allocation error while creating partitions for \"%s\"\n",
256 - master->name);
257 - del_mtd_partitions(master);
258 - return -ENOMEM;
259 - }
260 - memset(slave, 0, sizeof(*slave));
261 - list_add(&slave->list, &mtd_partitions);
262 -
263 - /* set up the MTD object for this partition */
264 - slave->mtd.type = master->type;
265 - slave->mtd.flags = master->flags & ~parts[i].mask_flags;
266 - slave->mtd.size = parts[i].size;
267 - slave->mtd.writesize = master->writesize;
268 - slave->mtd.oobsize = master->oobsize;
269 - slave->mtd.ecctype = master->ecctype;
270 - slave->mtd.eccsize = master->eccsize;
271 -
272 - slave->mtd.name = parts[i].name;
273 - slave->mtd.bank_size = master->bank_size;
274 - slave->mtd.owner = master->owner;
275 -
276 - slave->mtd.read = part_read;
277 - slave->mtd.write = part_write;
278 -
279 - if(master->point && master->unpoint){
280 - slave->mtd.point = part_point;
281 - slave->mtd.unpoint = part_unpoint;
282 - }
283 -
284 - if (master->read_oob)
285 - slave->mtd.read_oob = part_read_oob;
286 - if (master->write_oob)
287 - slave->mtd.write_oob = part_write_oob;
288 - if(master->read_user_prot_reg)
289 - slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
290 - if(master->read_fact_prot_reg)
291 - slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
292 - if(master->write_user_prot_reg)
293 - slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
294 - if(master->lock_user_prot_reg)
295 - slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
296 - if(master->get_user_prot_info)
297 - slave->mtd.get_user_prot_info = part_get_user_prot_info;
298 - if(master->get_fact_prot_info)
299 - slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
300 - if (master->sync)
301 - slave->mtd.sync = part_sync;
302 - if (!i && master->suspend && master->resume) {
303 - slave->mtd.suspend = part_suspend;
304 - slave->mtd.resume = part_resume;
305 - }
306 - if (master->writev)
307 - slave->mtd.writev = part_writev;
308 - if (master->lock)
309 - slave->mtd.lock = part_lock;
310 - if (master->unlock)
311 - slave->mtd.unlock = part_unlock;
312 - if (master->block_isbad)
313 - slave->mtd.block_isbad = part_block_isbad;
314 - if (master->block_markbad)
315 - slave->mtd.block_markbad = part_block_markbad;
316 - slave->mtd.erase = part_erase;
317 - slave->master = master;
318 - slave->offset = parts[i].offset;
319 - slave->index = i;
320 -
321 - if (slave->offset == MTDPART_OFS_APPEND)
322 - slave->offset = cur_offset;
323 - if (slave->offset == MTDPART_OFS_NXTBLK) {
324 - slave->offset = cur_offset;
325 - if ((cur_offset % master->erasesize) != 0) {
326 - /* Round up to next erasesize */
327 - slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
328 - printk(KERN_NOTICE "Moving partition %d: "
329 - "0x%08x -> 0x%08x\n", i,
330 - cur_offset, slave->offset);
331 + kfree(part);
332 }
333 - }
334 - if (slave->mtd.size == MTDPART_SIZ_FULL)
335 - slave->mtd.size = master->size - slave->offset;
336 - cur_offset = slave->offset + slave->mtd.size;
337 -
338 - printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
339 - slave->offset + slave->mtd.size, slave->mtd.name);
340 -
341 - /* let's do some sanity checks */
342 - if (slave->offset >= master->size) {
343 - /* let's register it anyway to preserve ordering */
344 - slave->offset = 0;
345 - slave->mtd.size = 0;
346 - printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
347 - parts[i].name);
348 - }
349 - if (slave->offset + slave->mtd.size > master->size) {
350 - slave->mtd.size = master->size - slave->offset;
351 - printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
352 - parts[i].name, master->name, slave->mtd.size);
353 - }
354 - if (master->numeraseregions>1) {
355 - /* Deal with variable erase size stuff */
356 - int i;
357 - struct mtd_erase_region_info *regions = master->eraseregions;
358 -
359 - /* Find the first erase regions which is part of this partition. */
360 - for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
361 - ;
362 -
363 - for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
364 - if (slave->mtd.erasesize < regions[i].erasesize) {
365 - slave->mtd.erasesize = regions[i].erasesize;
366 - }
367 - }
368 - } else {
369 - /* Single erase size */
370 - slave->mtd.erasesize = master->erasesize;
371 - }
372 -
373 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
374 - (slave->offset % slave->mtd.erasesize)) {
375 - /* Doesn't start on a boundary of major erase size */
376 - /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
377 - slave->mtd.flags &= ~MTD_WRITEABLE;
378 - printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
379 - parts[i].name);
380 - }
381 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
382 - (slave->mtd.size % slave->mtd.erasesize)) {
383 - slave->mtd.flags &= ~MTD_WRITEABLE;
384 - printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
385 - parts[i].name);
386 - }
387 -
388 - slave->mtd.ecclayout = master->ecclayout;
389 - if (master->block_isbad) {
390 - uint32_t offs = 0;
391 -
392 - while(offs < slave->mtd.size) {
393 - if (master->block_isbad(master,
394 - offs + slave->offset))
395 - slave->mtd.ecc_stats.badblocks++;
396 - offs += slave->mtd.erasesize;
397 - }
398 - }
399 -
400 - if(parts[i].mtdp)
401 - { /* store the object pointer (caller may or may not register it */
402 - *parts[i].mtdp = &slave->mtd;
403 - slave->registered = 0;
404 - }
405 - else
406 - {
407 - /* register our partition */
408 - add_mtd_device(&slave->mtd);
409 - slave->registered = 1;
410 +#endif /* CONFIG_MTD_SPLIT_ROOTFS */
411 + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, i);
412 }
413 }
414
This page took 0.087534 seconds and 5 git commands to generate.