1 Index: linux-2.6.21.7/drivers/mtd/Kconfig
2 ===================================================================
3 --- linux-2.6.21.7.orig/drivers/mtd/Kconfig
4 +++ linux-2.6.21.7/drivers/mtd/Kconfig
5 @@ -49,6 +49,16 @@ config MTD_PARTITIONS
6 devices. Partitioning on NFTL 'devices' is a different - that's the
7 'normal' form of partitioning used on a block device.
9 +config MTD_ROOTFS_ROOT_DEV
10 + bool "Automatically set 'rootfs' partition to be root filesystem"
11 + depends on MTD_PARTITIONS
14 +config MTD_ROOTFS_SPLIT
15 + bool "Automatically split 'rootfs' partition for squashfs"
16 + depends on MTD_PARTITIONS
19 config MTD_REDBOOT_PARTS
20 tristate "RedBoot partition table parsing"
21 depends on MTD_PARTITIONS
22 Index: linux-2.6.21.7/drivers/mtd/mtdpart.c
23 ===================================================================
24 --- linux-2.6.21.7.orig/drivers/mtd/mtdpart.c
25 +++ linux-2.6.21.7/drivers/mtd/mtdpart.c
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/partitions.h>
29 #include <linux/mtd/compatmac.h>
30 +#include <linux/squashfs_fs.h>
31 +#include <linux/root_dev.h>
33 /* Our partition linked list */
34 static LIST_HEAD(mtd_partitions);
35 @@ -308,6 +310,266 @@ int del_mtd_partitions(struct mtd_info *
39 +static u_int32_t cur_offset = 0;
40 +static int add_one_partition(struct mtd_info *master, const struct mtd_partition *part,
41 + int i, struct mtd_part **slp)
43 + struct mtd_part *slave;
45 + /* allocate the partition structure */
46 + slave = kzalloc (sizeof(*slave), GFP_KERNEL);
48 + printk ("memory allocation error while creating partitions for \"%s\"\n",
50 + del_mtd_partitions(master);
53 + list_add(&slave->list, &mtd_partitions);
55 + /* set up the MTD object for this partition */
56 + slave->mtd.type = master->type;
57 + slave->mtd.flags = master->flags & ~part->mask_flags;
58 + slave->mtd.size = part->size;
59 + slave->mtd.writesize = master->writesize;
60 + slave->mtd.oobsize = master->oobsize;
61 + slave->mtd.oobavail = master->oobavail;
62 + slave->mtd.subpage_sft = master->subpage_sft;
64 + slave->mtd.name = part->name;
65 + slave->mtd.bank_size = master->bank_size;
66 + slave->mtd.owner = master->owner;
68 + slave->mtd.read = part_read;
69 + slave->mtd.write = part_write;
71 + if(master->point && master->unpoint){
72 + slave->mtd.point = part_point;
73 + slave->mtd.unpoint = part_unpoint;
76 + if (master->read_oob)
77 + slave->mtd.read_oob = part_read_oob;
78 + if (master->write_oob)
79 + slave->mtd.write_oob = part_write_oob;
80 + if(master->read_user_prot_reg)
81 + slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
82 + if(master->read_fact_prot_reg)
83 + slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
84 + if(master->write_user_prot_reg)
85 + slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
86 + if(master->lock_user_prot_reg)
87 + slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
88 + if(master->get_user_prot_info)
89 + slave->mtd.get_user_prot_info = part_get_user_prot_info;
90 + if(master->get_fact_prot_info)
91 + slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
93 + slave->mtd.sync = part_sync;
94 + if (!i && master->suspend && master->resume) {
95 + slave->mtd.suspend = part_suspend;
96 + slave->mtd.resume = part_resume;
99 + slave->mtd.writev = part_writev;
101 + slave->mtd.lock = part_lock;
102 + if (master->unlock)
103 + slave->mtd.unlock = part_unlock;
104 + if (master->block_isbad)
105 + slave->mtd.block_isbad = part_block_isbad;
106 + if (master->block_markbad)
107 + slave->mtd.block_markbad = part_block_markbad;
108 + slave->mtd.erase = part_erase;
109 + slave->master = master;
110 + slave->offset = part->offset;
113 + if (slave->offset == MTDPART_OFS_APPEND)
114 + slave->offset = cur_offset;
115 + if (slave->offset == MTDPART_OFS_NXTBLK) {
116 + slave->offset = cur_offset;
117 + if ((cur_offset % master->erasesize) != 0) {
118 + /* Round up to next erasesize */
119 + slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
120 + printk(KERN_NOTICE "Moving partition %d: "
121 + "0x%08x -> 0x%08x\n", i,
122 + cur_offset, slave->offset);
125 + if (slave->mtd.size == MTDPART_SIZ_FULL)
126 + slave->mtd.size = master->size - slave->offset;
127 + cur_offset = slave->offset + slave->mtd.size;
129 + printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
130 + slave->offset + slave->mtd.size, slave->mtd.name);
132 + /* let's do some sanity checks */
133 + if (slave->offset >= master->size) {
134 + /* let's register it anyway to preserve ordering */
136 + slave->mtd.size = 0;
137 + printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
140 + if (slave->offset + slave->mtd.size > master->size) {
141 + slave->mtd.size = master->size - slave->offset;
142 + printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
143 + part->name, master->name, slave->mtd.size);
145 + if (master->numeraseregions>1) {
146 + /* Deal with variable erase size stuff */
148 + struct mtd_erase_region_info *regions = master->eraseregions;
150 + /* Find the first erase regions which is part of this partition. */
151 + for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
154 + for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
155 + if (slave->mtd.erasesize < regions[i].erasesize) {
156 + slave->mtd.erasesize = regions[i].erasesize;
160 + /* Single erase size */
161 + slave->mtd.erasesize = master->erasesize;
164 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
165 + (slave->offset % slave->mtd.erasesize)) {
166 + /* Doesn't start on a boundary of major erase size */
167 + /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
168 + slave->mtd.flags &= ~MTD_WRITEABLE;
169 + printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
172 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
173 + (slave->mtd.size % slave->mtd.erasesize)) {
174 + slave->mtd.flags &= ~MTD_WRITEABLE;
175 + printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
179 + slave->mtd.ecclayout = master->ecclayout;
180 + if (master->block_isbad) {
183 + while(offs < slave->mtd.size) {
184 + if (master->block_isbad(master,
185 + offs + slave->offset))
186 + slave->mtd.ecc_stats.badblocks++;
187 + offs += slave->mtd.erasesize;
192 + { /* store the object pointer (caller may or may not register it */
193 + *part->mtdp = &slave->mtd;
194 + slave->registered = 0;
198 + /* register our partition */
199 + add_mtd_device(&slave->mtd);
200 + slave->registered = 1;
209 +#ifdef CONFIG_MTD_ROOTFS_SPLIT
210 +#define ROOTFS_SPLIT_NAME "rootfs_data"
211 +static int split_squashfs(struct mtd_info *master, struct mtd_partition *old,
212 + struct mtd_partition **new)
214 + struct mtd_partition *part = NULL;
217 + struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
220 + ret = master->read(master, old->offset, sizeof(*sb), &len, buf);
222 + printk(KERN_ALERT "split_squashfs: error occured while reading "
223 + "from \"%s\"\n", master->name);
227 + if (len != sizeof(*sb)) {
228 + printk(KERN_ALERT "split_squashfs: unable to read superblock "
229 + "from \"%s\"\n", master->name);
234 + if (*((u32 *) buf) != SQUASHFS_MAGIC) {
235 + printk(KERN_ALERT "split_squasfs: no squashfs found in \"%s\"\n",
241 + if (sb->bytes_used <= 0) {
242 + printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n",
248 + part = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
249 + if (part == NULL) {
250 + printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
251 + ROOTFS_SPLIT_NAME);
256 + memcpy(part, old, sizeof(*part));
257 + part->name = (unsigned char *)&part[1];
258 + strcpy(part->name, ROOTFS_SPLIT_NAME);
260 + len = (u32) sb->bytes_used;
261 + len += (part->offset & 0x000fffff);
262 + len += (master->erasesize - 1);
263 + len &= ~(master->erasesize - 1);
264 + len -= (part->offset & 0x000fffff);
265 + part->offset += len;
275 +static int split_rootfs_data(struct mtd_info *master, struct mtd_partition *part,
278 + struct mtd_partition *dpart;
281 + ret = split_squashfs(master, part, &dpart);
288 + printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%X, len=%X \n",
289 + ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
291 + ret = add_one_partition(master, dpart, index, NULL);
297 +#endif /* CONFIG_MTD_ROOTFS_SPLIT */
300 * This function, given a master MTD object and a partition table, creates
301 * and registers slave MTD objects which are bound to the master according to
302 @@ -320,169 +582,31 @@ int add_mtd_partitions(struct mtd_info *
305 struct mtd_part *slave;
306 - u_int32_t cur_offset = 0;
308 + struct mtd_partition *part;
311 printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
313 - for (i = 0; i < nbparts; i++) {
315 - /* allocate the partition structure */
316 - slave = kzalloc (sizeof(*slave), GFP_KERNEL);
318 - printk ("memory allocation error while creating partitions for \"%s\"\n",
320 - del_mtd_partitions(master);
323 - list_add(&slave->list, &mtd_partitions);
325 - /* set up the MTD object for this partition */
326 - slave->mtd.type = master->type;
327 - slave->mtd.flags = master->flags & ~parts[i].mask_flags;
328 - slave->mtd.size = parts[i].size;
329 - slave->mtd.writesize = master->writesize;
330 - slave->mtd.oobsize = master->oobsize;
331 - slave->mtd.oobavail = master->oobavail;
332 - slave->mtd.subpage_sft = master->subpage_sft;
334 - slave->mtd.name = parts[i].name;
335 - slave->mtd.bank_size = master->bank_size;
336 - slave->mtd.owner = master->owner;
338 - slave->mtd.read = part_read;
339 - slave->mtd.write = part_write;
341 - if(master->point && master->unpoint){
342 - slave->mtd.point = part_point;
343 - slave->mtd.unpoint = part_unpoint;
346 - if (master->read_oob)
347 - slave->mtd.read_oob = part_read_oob;
348 - if (master->write_oob)
349 - slave->mtd.write_oob = part_write_oob;
350 - if(master->read_user_prot_reg)
351 - slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
352 - if(master->read_fact_prot_reg)
353 - slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
354 - if(master->write_user_prot_reg)
355 - slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
356 - if(master->lock_user_prot_reg)
357 - slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
358 - if(master->get_user_prot_info)
359 - slave->mtd.get_user_prot_info = part_get_user_prot_info;
360 - if(master->get_fact_prot_info)
361 - slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
363 - slave->mtd.sync = part_sync;
364 - if (!i && master->suspend && master->resume) {
365 - slave->mtd.suspend = part_suspend;
366 - slave->mtd.resume = part_resume;
368 - if (master->writev)
369 - slave->mtd.writev = part_writev;
371 - slave->mtd.lock = part_lock;
372 - if (master->unlock)
373 - slave->mtd.unlock = part_unlock;
374 - if (master->block_isbad)
375 - slave->mtd.block_isbad = part_block_isbad;
376 - if (master->block_markbad)
377 - slave->mtd.block_markbad = part_block_markbad;
378 - slave->mtd.erase = part_erase;
379 - slave->master = master;
380 - slave->offset = parts[i].offset;
383 - if (slave->offset == MTDPART_OFS_APPEND)
384 - slave->offset = cur_offset;
385 - if (slave->offset == MTDPART_OFS_NXTBLK) {
386 - slave->offset = cur_offset;
387 - if ((cur_offset % master->erasesize) != 0) {
388 - /* Round up to next erasesize */
389 - slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
390 - printk(KERN_NOTICE "Moving partition %d: "
391 - "0x%08x -> 0x%08x\n", i,
392 - cur_offset, slave->offset);
395 - if (slave->mtd.size == MTDPART_SIZ_FULL)
396 - slave->mtd.size = master->size - slave->offset;
397 - cur_offset = slave->offset + slave->mtd.size;
399 - printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
400 - slave->offset + slave->mtd.size, slave->mtd.name);
402 - /* let's do some sanity checks */
403 - if (slave->offset >= master->size) {
404 - /* let's register it anyway to preserve ordering */
406 - slave->mtd.size = 0;
407 - printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
410 - if (slave->offset + slave->mtd.size > master->size) {
411 - slave->mtd.size = master->size - slave->offset;
412 - printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
413 - parts[i].name, master->name, slave->mtd.size);
415 - if (master->numeraseregions>1) {
416 - /* Deal with variable erase size stuff */
418 - struct mtd_erase_region_info *regions = master->eraseregions;
420 - /* Find the first erase regions which is part of this partition. */
421 - for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
424 - for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
425 - if (slave->mtd.erasesize < regions[i].erasesize) {
426 - slave->mtd.erasesize = regions[i].erasesize;
430 - /* Single erase size */
431 - slave->mtd.erasesize = master->erasesize;
434 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
435 - (slave->offset % slave->mtd.erasesize)) {
436 - /* Doesn't start on a boundary of major erase size */
437 - /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
438 - slave->mtd.flags &= ~MTD_WRITEABLE;
439 - printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
442 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
443 - (slave->mtd.size % slave->mtd.erasesize)) {
444 - slave->mtd.flags &= ~MTD_WRITEABLE;
445 - printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
449 - slave->mtd.ecclayout = master->ecclayout;
450 - if (master->block_isbad) {
453 - while(offs < slave->mtd.size) {
454 - if (master->block_isbad(master,
455 - offs + slave->offset))
456 - slave->mtd.ecc_stats.badblocks++;
457 - offs += slave->mtd.erasesize;
458 + for (i = 0, j = 0; i < nbparts; i++) {
459 + part = (struct mtd_partition *) &parts[i];
460 + ret = add_one_partition(master, part, j, &slave);
465 + if (strcmp(part->name, "rootfs") == 0 && slave->registered) {
466 +#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV
467 + if (ROOT_DEV == 0) {
468 + printk(KERN_NOTICE "mtd: partition \"rootfs\" "
469 + "set to be root filesystem\n");
470 + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, slave->mtd.index);
475 - { /* store the object pointer (caller may or may not register it */
476 - *parts[i].mtdp = &slave->mtd;
477 - slave->registered = 0;
481 - /* register our partition */
482 - add_mtd_device(&slave->mtd);
483 - slave->registered = 1;
485 +#ifdef CONFIG_MTD_ROOTFS_SPLIT
486 + ret = split_rootfs_data(master, part, j);