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
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 -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
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 = kmalloc (sizeof(*slave), GFP_KERNEL);
40 + printk ("memory allocation error while creating partitions for \"%s\"\n",
42 + del_mtd_partitions(master);
45 + memset(slave, 0, sizeof(*slave));
46 + list_add(&slave->list, &mtd_partitions);
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;
57 + slave->mtd.name = part->name;
58 + slave->mtd.bank_size = master->bank_size;
59 + slave->mtd.owner = master->owner;
61 + slave->mtd.read = part_read;
62 + slave->mtd.write = part_write;
64 + if(master->point && master->unpoint){
65 + slave->mtd.point = part_point;
66 + slave->mtd.unpoint = part_unpoint;
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;
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;
92 + slave->mtd.writev = part_writev;
94 + slave->mtd.lock = part_lock;
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;
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);
118 + if (slave->mtd.size == MTDPART_SIZ_FULL)
119 + slave->mtd.size = master->size - slave->offset;
120 + cur_offset = slave->offset + slave->mtd.size;
122 + printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
123 + slave->offset + slave->mtd.size, slave->mtd.name);
125 + /* let's do some sanity checks */
126 + if (slave->offset >= master->size) {
127 + /* let's register it anyway to preserve ordering */
129 + slave->mtd.size = 0;
130 + printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
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);
138 + if (master->numeraseregions>1) {
139 + /* Deal with variable erase size stuff */
141 + struct mtd_erase_region_info *regions = master->eraseregions;
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++)
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;
153 + /* Single erase size */
154 + slave->mtd.erasesize = master->erasesize;
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",
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",
172 + slave->mtd.ecclayout = master->ecclayout;
173 + if (master->block_isbad) {
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;
185 + { /* store the object pointer (caller may or may not register it */
186 + *part->mtdp = &slave->mtd;
187 + slave->registered = 0;
191 + /* register our partition */
192 + add_mtd_device(&slave->mtd);
193 + slave->registered = 1;
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,
206 - struct mtd_part *slave;
207 - u_int32_t cur_offset = 0;
209 + struct mtd_partition *part;
212 printk (KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
214 for (i = 0; i < nbparts; i++) {
215 + part = (struct mtd_partition *) &parts[i];
216 + ret = add_mtd_partition(master, part, i);
219 + if (strcmp(part->name, "rootfs") == 0) {
220 +#ifdef CONFIG_MTD_SPLIT_ROOTFS
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)) {
231 + part = kmalloc(sizeof(struct mtd_partition), GFP_KERNEL);
232 + memcpy(part, &parts[i], sizeof(struct mtd_partition));
234 + part->name = kmalloc(sizeof(ROOTFS_SPLIT_NAME) + 1, GFP_KERNEL);
235 + strcpy(part->name, ROOTFS_SPLIT_NAME);
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;
245 + if (master->erasesize <= part->size)
246 + ret = add_mtd_partition(master, part, i + 1);
252 - /* allocate the partition structure */
253 - slave = kmalloc (sizeof(*slave), GFP_KERNEL);
255 - printk ("memory allocation error while creating partitions for \"%s\"\n",
257 - del_mtd_partitions(master);
260 - memset(slave, 0, sizeof(*slave));
261 - list_add(&slave->list, &mtd_partitions);
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;
272 - slave->mtd.name = parts[i].name;
273 - slave->mtd.bank_size = master->bank_size;
274 - slave->mtd.owner = master->owner;
276 - slave->mtd.read = part_read;
277 - slave->mtd.write = part_write;
279 - if(master->point && master->unpoint){
280 - slave->mtd.point = part_point;
281 - slave->mtd.unpoint = part_unpoint;
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;
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;
306 - if (master->writev)
307 - slave->mtd.writev = part_writev;
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;
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);
334 - if (slave->mtd.size == MTDPART_SIZ_FULL)
335 - slave->mtd.size = master->size - slave->offset;
336 - cur_offset = slave->offset + slave->mtd.size;
338 - printk (KERN_NOTICE "0x%08x-0x%08x : \"%s\"\n", slave->offset,
339 - slave->offset + slave->mtd.size, slave->mtd.name);
341 - /* let's do some sanity checks */
342 - if (slave->offset >= master->size) {
343 - /* let's register it anyway to preserve ordering */
345 - slave->mtd.size = 0;
346 - printk ("mtd: partition \"%s\" is out of reach -- disabled\n",
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);
354 - if (master->numeraseregions>1) {
355 - /* Deal with variable erase size stuff */
357 - struct mtd_erase_region_info *regions = master->eraseregions;
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++)
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;
369 - /* Single erase size */
370 - slave->mtd.erasesize = master->erasesize;
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",
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",
388 - slave->mtd.ecclayout = master->ecclayout;
389 - if (master->block_isbad) {
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;
401 - { /* store the object pointer (caller may or may not register it */
402 - *parts[i].mtdp = &slave->mtd;
403 - slave->registered = 0;
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);