1 --- a/drivers/mtd/mtdpart.c
2 +++ b/drivers/mtd/mtdpart.c
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);
11 static DEFINE_MUTEX(mtd_partitions_mutex);
12 @@ -258,13 +260,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 @@ -272,7 +321,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 @@ -543,18 +610,24 @@ static struct mtd_part *allocate_partiti
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",
119 + mtd_mod_by_eb(slave->offset + slave->mtd.size, &slave->mtd)) {
120 + slave->mtd.flags |= MTD_ERASE_PARTIAL;
122 + if ((u32) slave->mtd.size > master->erasesize)
123 + slave->mtd.flags &= ~MTD_WRITEABLE;
125 + slave->mtd.erasesize = slave->mtd.size;
127 + if ((slave->mtd.flags & (MTD_ERASE_PARTIAL|MTD_WRITEABLE)) == MTD_ERASE_PARTIAL)
128 + 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",
131 slave->mtd.ecclayout = master->ecclayout;
132 if (master->block_isbad) {
133 --- a/include/linux/mtd/mtd.h
134 +++ b/include/linux/mtd/mtd.h
135 @@ -58,6 +58,10 @@ struct erase_info {
138 struct erase_info *next;
142 + bool partial_start;
145 struct mtd_erase_region_info {