1 --- a/drivers/mtd/mtdpart.c
2 +++ b/drivers/mtd/mtdpart.c
4 #include <linux/root_dev.h>
5 #include <linux/magic.h>
7 +#define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
9 /* Our partition linked list */
10 static LIST_HEAD(mtd_partitions);
12 @@ -226,13 +228,60 @@ static int part_erase(struct mtd_info *m
14 if (instr->addr >= mtd->size)
17 + instr->partial_start = false;
18 + if (mtd->flags & MTD_ERASE_PARTIAL) {
22 + instr->erase_buf = kmalloc(part->master->erasesize, GFP_ATOMIC);
23 + if (!instr->erase_buf)
26 + mtd_ofs = part->offset + instr->addr;
27 + instr->erase_buf_ofs = do_div(mtd_ofs, part->master->erasesize);
29 + if (instr->erase_buf_ofs > 0) {
30 + instr->addr -= instr->erase_buf_ofs;
31 + ret = part->master->read(part->master,
32 + instr->addr + part->offset,
33 + part->master->erasesize,
34 + &readlen, instr->erase_buf);
36 + instr->partial_start = true;
38 + mtd_ofs = part->offset + part->mtd.size;
39 + instr->erase_buf_ofs = part->master->erasesize -
40 + do_div(mtd_ofs, part->master->erasesize);
42 + if (instr->erase_buf_ofs > 0) {
43 + instr->len += instr->erase_buf_ofs;
44 + ret = part->master->read(part->master,
45 + part->offset + instr->addr +
46 + instr->len - part->master->erasesize,
47 + part->master->erasesize, &readlen,
54 + kfree(instr->erase_buf);
60 instr->addr += part->offset;
61 ret = part->master->erase(part->master, instr);
63 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
64 instr->fail_addr -= part->offset;
65 instr->addr -= part->offset;
66 + if (mtd->flags & MTD_ERASE_PARTIAL)
67 + kfree(instr->erase_buf);
73 @@ -240,7 +289,25 @@ void mtd_erase_callback(struct erase_inf
75 if (instr->mtd->erase == part_erase) {
76 struct mtd_part *part = PART(instr->mtd);
79 + if (instr->mtd->flags & MTD_ERASE_PARTIAL) {
80 + if (instr->partial_start) {
81 + part->master->write(part->master,
82 + instr->addr, instr->erase_buf_ofs,
83 + &wrlen, instr->erase_buf);
84 + instr->addr += instr->erase_buf_ofs;
86 + instr->len -= instr->erase_buf_ofs;
87 + part->master->write(part->master,
88 + instr->addr + instr->len,
89 + instr->erase_buf_ofs, &wrlen,
91 + part->master->erasesize -
92 + instr->erase_buf_ofs);
94 + kfree(instr->erase_buf);
96 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
97 instr->fail_addr -= part->offset;
98 instr->addr -= part->offset;
99 @@ -473,18 +540,24 @@ static struct mtd_part *add_one_partitio
100 if ((slave->mtd.flags & MTD_WRITEABLE) &&
101 mtd_mod_by_eb(slave->offset, &slave->mtd)) {
102 /* Doesn't start on a boundary of major erase size */
103 - /* FIXME: Let it be writable if it is on a boundary of
104 - * _minor_ erase size though */
105 - slave->mtd.flags &= ~MTD_WRITEABLE;
106 - printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
108 + slave->mtd.flags |= MTD_ERASE_PARTIAL;
109 + if (((u32) slave->mtd.size) > master->erasesize)
110 + slave->mtd.flags &= ~MTD_WRITEABLE;
112 + slave->mtd.erasesize = slave->mtd.size;
114 if ((slave->mtd.flags & MTD_WRITEABLE) &&
115 - mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) {
116 - slave->mtd.flags &= ~MTD_WRITEABLE;
117 - printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
120 + mtd_mod_by_eb(slave->offset + slave->mtd.size, &slave->mtd)) {
121 + slave->mtd.flags |= MTD_ERASE_PARTIAL;
123 + if ((u32) slave->mtd.size > master->erasesize)
124 + slave->mtd.flags &= ~MTD_WRITEABLE;
126 + slave->mtd.erasesize = slave->mtd.size;
128 + if ((slave->mtd.flags & (MTD_ERASE_PARTIAL|MTD_WRITEABLE)) == MTD_ERASE_PARTIAL)
129 + printk(KERN_WARNING"mtd: partition \"%s\" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only\n",
132 slave->mtd.ecclayout = master->ecclayout;
133 if (master->block_isbad) {
134 --- a/include/linux/mtd/mtd.h
135 +++ b/include/linux/mtd/mtd.h
136 @@ -45,6 +45,10 @@ struct erase_info {
139 struct erase_info *next;
143 + bool partial_start;
146 struct mtd_erase_region_info {