1 diff -urN linux-2.6.21.1.old/drivers/mtd/Kconfig linux-2.6.21.1.dev/drivers/mtd/Kconfig
2 --- linux-2.6.21.1.old/drivers/mtd/Kconfig 2007-04-27 23:49:26.000000000 +0200
3 +++ linux-2.6.21.1.dev/drivers/mtd/Kconfig 2007-05-26 19:58:42.320520952 +0200
5 devices. Partitioning on NFTL 'devices' is a different - that's the
6 'normal' form of partitioning used on a block device.
8 +config MTD_SPLIT_ROOTFS
9 + bool "Automatically split rootfs partition for squashfs"
10 + depends on MTD_PARTITIONS
13 config MTD_REDBOOT_PARTS
14 tristate "RedBoot partition table parsing"
15 depends on MTD_PARTITIONS
16 diff -urN linux-2.6.21.1.old/drivers/mtd/mtdpart.c linux-2.6.21.1.dev/drivers/mtd/mtdpart.c
17 --- linux-2.6.21.1.old/drivers/mtd/mtdpart.c 2007-04-27 23:49:26.000000000 +0200
18 +++ linux-2.6.21.1.dev/drivers/mtd/mtdpart.c 2007-05-26 19:58:42.331519280 +0200
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>
26 /* Our partition linked list */
27 static LIST_HEAD(mtd_partitions);
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)
35 + struct mtd_part *slave;
37 + /* allocate the partition structure */
38 + slave = kzalloc (sizeof(*slave), GFP_KERNEL);
40 + printk ("memory allocation error while creating partitions for \"%s\"\n",
42 + del_mtd_partitions(master);
45 + list_add(&slave->list, &mtd_partitions);
47 + /* set up the MTD object for this partition */
48 + slave->mtd.type = master->type;
49 + slave->mtd.flags = master->flags & ~part->mask_flags;
50 + slave->mtd.size = part->size;
51 + slave->mtd.writesize = master->writesize;
52 + slave->mtd.oobsize = master->oobsize;
53 + slave->mtd.oobavail = master->oobavail;
54 + slave->mtd.subpage_sft = master->subpage_sft;
56 + slave->mtd.name = part->name;
57 + slave->mtd.bank_size = master->bank_size;
58 + slave->mtd.owner = master->owner;
60 + slave->mtd.read = part_read;
61 + slave->mtd.write = part_write;
63 + if(master->point && master->unpoint){
64 + slave->mtd.point = part_point;
65 + slave->mtd.unpoint = part_unpoint;
68 + if (master->read_oob)
69 + slave->mtd.read_oob = part_read_oob;
70 + if (master->write_oob)
71 + slave->mtd.write_oob = part_write_oob;
72 + if(master->read_user_prot_reg)
73 + slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
74 + if(master->read_fact_prot_reg)
75 + slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
76 + if(master->write_user_prot_reg)
77 + slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
78 + if(master->lock_user_prot_reg)
79 + slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
80 + if(master->get_user_prot_info)
81 + slave->mtd.get_user_prot_info = part_get_user_prot_info;
82 + if(master->get_fact_prot_info)
83 + slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
85 + slave->mtd.sync = part_sync;
86 + if (!i && master->suspend && master->resume) {
87 + slave->mtd.suspend = part_suspend;
88 + slave->mtd.resume = part_resume;
91 + slave->mtd.writev = part_writev;
93 + slave->mtd.lock = part_lock;
95 + slave->mtd.unlock = part_unlock;
96 + if (master->block_isbad)
97 + slave->mtd.block_isbad = part_block_isbad;
98 + if (master->block_markbad)
99 + slave->mtd.block_markbad = part_block_markbad;
100 + slave->mtd.erase = part_erase;
101 + slave->master = master;
102 + slave->offset = part->offset;
105 + if (slave->offset == MTDPART_OFS_APPEND)
106 + slave->offset = cur_offset;
107 + if (slave->offset == MTDPART_OFS_NXTBLK) {
108 + slave->offset = cur_offset;
109 + if ((cur_offset % master->erasesize) != 0) {
110 + /* Round up to next erasesize */
111 + slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
112 + printk(KERN_NOTICE "Moving partition %d: "
113 + "0x%08x -> 0x%08x\n", i,
114 + cur_offset, slave->offset);
117 + if (slave->mtd.size == MTDPART_SIZ_FULL)
118 + slave->mtd.size = master->size - slave->offset;
119 + cur_offset = slave->offset + slave->mtd.size;
121 + printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
122 + slave->offset + slave->mtd.size, slave->mtd.name);
124 + /* let's do some sanity checks */
125 + if (slave->offset >= master->size) {
126 + /* let's register it anyway to preserve ordering */
128 + slave->mtd.size = 0;
129 + printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
132 + if (slave->offset + slave->mtd.size > master->size) {
133 + slave->mtd.size = master->size - slave->offset;
134 + printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
135 + part->name, master->name, slave->mtd.size);
137 + if (master->numeraseregions>1) {
138 + /* Deal with variable erase size stuff */
140 + struct mtd_erase_region_info *regions = master->eraseregions;
142 + /* Find the first erase regions which is part of this partition. */
143 + for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
146 + for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
147 + if (slave->mtd.erasesize < regions[i].erasesize) {
148 + slave->mtd.erasesize = regions[i].erasesize;
152 + /* Single erase size */
153 + slave->mtd.erasesize = master->erasesize;
156 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
157 + (slave->offset % slave->mtd.erasesize)) {
158 + /* Doesn't start on a boundary of major erase size */
159 + /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
160 + slave->mtd.flags &= ~MTD_WRITEABLE;
161 + printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
164 + if ((slave->mtd.flags & MTD_WRITEABLE) &&
165 + (slave->mtd.size % slave->mtd.erasesize)) {
166 + slave->mtd.flags &= ~MTD_WRITEABLE;
167 + printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
171 + slave->mtd.ecclayout = master->ecclayout;
172 + if (master->block_isbad) {
175 + while(offs < slave->mtd.size) {
176 + if (master->block_isbad(master,
177 + offs + slave->offset))
178 + slave->mtd.ecc_stats.badblocks++;
179 + offs += slave->mtd.erasesize;
184 + { /* store the object pointer (caller may or may not register it */
185 + *part->mtdp = &slave->mtd;
186 + slave->registered = 0;
190 + /* register our partition */
191 + add_mtd_device(&slave->mtd);
192 + slave->registered = 1;
199 * This function, given a master MTD object and a partition table, creates
200 * and registers slave MTD objects which are bound to the master according to
201 @@ -319,170 +487,53 @@
202 const struct mtd_partition *parts,
205 - struct mtd_part *slave;
206 - u_int32_t cur_offset = 0;
208 + struct mtd_partition *part;
211 printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
213 for (i = 0; i < nbparts; i++) {
214 + part = (struct mtd_partition *) &parts[i];
215 + ret = add_mtd_partition(master, part, i);
218 + if (strcmp(part->name, "rootfs") == 0) {
219 +#ifdef CONFIG_MTD_SPLIT_ROOTFS
222 + struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
223 +#define ROOTFS_SPLIT_NAME "rootfs_data"
224 + if ((master->read(master, part->offset, sizeof(struct squashfs_super_block), &len, buf) == 0) &&
225 + (len == sizeof(struct squashfs_super_block)) &&
226 + (*((u32 *) buf) == SQUASHFS_MAGIC) &&
227 + (sb->bytes_used > 0)) {
230 + part = kmalloc(sizeof(struct mtd_partition), GFP_KERNEL);
231 + memcpy(part, &parts[i], sizeof(struct mtd_partition));
233 + part->name = kmalloc(sizeof(ROOTFS_SPLIT_NAME) + 1, GFP_KERNEL);
234 + strcpy(part->name, ROOTFS_SPLIT_NAME);
236 + len = (u32) sb->bytes_used;
237 + len += (part->offset & 0x000fffff);
238 + len += (master->erasesize - 1);
239 + len &= ~(master->erasesize - 1);
240 + len -= (part->offset & 0x000fffff);
241 + part->offset += len;
244 + if (master->erasesize <= part->size)
245 + ret = add_mtd_partition(master, part, i + 1);
251 - /* allocate the partition structure */
252 - slave = kzalloc (sizeof(*slave), GFP_KERNEL);
254 - printk ("memory allocation error while creating partitions for \"%s\"\n",
256 - del_mtd_partitions(master);
259 - list_add(&slave->list, &mtd_partitions);
261 - /* set up the MTD object for this partition */
262 - slave->mtd.type = master->type;
263 - slave->mtd.flags = master->flags & ~parts[i].mask_flags;
264 - slave->mtd.size = parts[i].size;
265 - slave->mtd.writesize = master->writesize;
266 - slave->mtd.oobsize = master->oobsize;
267 - slave->mtd.oobavail = master->oobavail;
268 - slave->mtd.subpage_sft = master->subpage_sft;
270 - slave->mtd.name = parts[i].name;
271 - slave->mtd.bank_size = master->bank_size;
272 - slave->mtd.owner = master->owner;
274 - slave->mtd.read = part_read;
275 - slave->mtd.write = part_write;
277 - if(master->point && master->unpoint){
278 - slave->mtd.point = part_point;
279 - slave->mtd.unpoint = part_unpoint;
282 - if (master->read_oob)
283 - slave->mtd.read_oob = part_read_oob;
284 - if (master->write_oob)
285 - slave->mtd.write_oob = part_write_oob;
286 - if(master->read_user_prot_reg)
287 - slave->mtd.read_user_prot_reg = part_read_user_prot_reg;
288 - if(master->read_fact_prot_reg)
289 - slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg;
290 - if(master->write_user_prot_reg)
291 - slave->mtd.write_user_prot_reg = part_write_user_prot_reg;
292 - if(master->lock_user_prot_reg)
293 - slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg;
294 - if(master->get_user_prot_info)
295 - slave->mtd.get_user_prot_info = part_get_user_prot_info;
296 - if(master->get_fact_prot_info)
297 - slave->mtd.get_fact_prot_info = part_get_fact_prot_info;
299 - slave->mtd.sync = part_sync;
300 - if (!i && master->suspend && master->resume) {
301 - slave->mtd.suspend = part_suspend;
302 - slave->mtd.resume = part_resume;
304 - if (master->writev)
305 - slave->mtd.writev = part_writev;
307 - slave->mtd.lock = part_lock;
308 - if (master->unlock)
309 - slave->mtd.unlock = part_unlock;
310 - if (master->block_isbad)
311 - slave->mtd.block_isbad = part_block_isbad;
312 - if (master->block_markbad)
313 - slave->mtd.block_markbad = part_block_markbad;
314 - slave->mtd.erase = part_erase;
315 - slave->master = master;
316 - slave->offset = parts[i].offset;
319 - if (slave->offset == MTDPART_OFS_APPEND)
320 - slave->offset = cur_offset;
321 - if (slave->offset == MTDPART_OFS_NXTBLK) {
322 - slave->offset = cur_offset;
323 - if ((cur_offset % master->erasesize) != 0) {
324 - /* Round up to next erasesize */
325 - slave->offset = ((cur_offset / master->erasesize) + 1) * master->erasesize;
326 - printk(KERN_NOTICE "Moving partition %d: "
327 - "0x%08x -> 0x%08x\n", i,
328 - cur_offset, slave->offset);
332 - if (slave->mtd.size == MTDPART_SIZ_FULL)
333 - slave->mtd.size = master->size - slave->offset;
334 - cur_offset = slave->offset + slave->mtd.size;
336 - printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
337 - slave->offset + slave->mtd.size, slave->mtd.name);
339 - /* let's do some sanity checks */
340 - if (slave->offset >= master->size) {
341 - /* let's register it anyway to preserve ordering */
343 - slave->mtd.size = 0;
344 - printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
347 - if (slave->offset + slave->mtd.size > master->size) {
348 - slave->mtd.size = master->size - slave->offset;
349 - printk ("mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#x\n",
350 - parts[i].name, master->name, slave->mtd.size);
352 - if (master->numeraseregions>1) {
353 - /* Deal with variable erase size stuff */
355 - struct mtd_erase_region_info *regions = master->eraseregions;
357 - /* Find the first erase regions which is part of this partition. */
358 - for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
361 - for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
362 - if (slave->mtd.erasesize < regions[i].erasesize) {
363 - slave->mtd.erasesize = regions[i].erasesize;
367 - /* Single erase size */
368 - slave->mtd.erasesize = master->erasesize;
371 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
372 - (slave->offset % slave->mtd.erasesize)) {
373 - /* Doesn't start on a boundary of major erase size */
374 - /* FIXME: Let it be writable if it is on a boundary of _minor_ erase size though */
375 - slave->mtd.flags &= ~MTD_WRITEABLE;
376 - printk ("mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
379 - if ((slave->mtd.flags & MTD_WRITEABLE) &&
380 - (slave->mtd.size % slave->mtd.erasesize)) {
381 - slave->mtd.flags &= ~MTD_WRITEABLE;
382 - printk ("mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
386 - slave->mtd.ecclayout = master->ecclayout;
387 - if (master->block_isbad) {
390 - while(offs < slave->mtd.size) {
391 - if (master->block_isbad(master,
392 - offs + slave->offset))
393 - slave->mtd.ecc_stats.badblocks++;
394 - offs += slave->mtd.erasesize;
399 - { /* store the object pointer (caller may or may not register it */
400 - *parts[i].mtdp = &slave->mtd;
401 - slave->registered = 0;
405 - /* register our partition */
406 - add_mtd_device(&slave->mtd);
407 - slave->registered = 1;
408 +#endif /* CONFIG_MTD_SPLIT_ROOTFS */
409 + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, i);