aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2014-10-27 18:14:39 +0000
committerRafał Miłecki <zajec5@gmail.com>2014-10-27 18:14:39 +0000
commit1513b39a8c8e21e3f8fbebab9fb4c41040ccf695 (patch)
tree7c786effff410b4a96d29c920d60cd279236fbf7 /target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch
parent38e72c779e229933625d96d4355a0250123b6ce5 (diff)
downloadupstream-1513b39a8c8e21e3f8fbebab9fb4c41040ccf695.tar.gz
upstream-1513b39a8c8e21e3f8fbebab9fb4c41040ccf695.tar.bz2
upstream-1513b39a8c8e21e3f8fbebab9fb4c41040ccf695.zip
kernel: start working on 3.18 support
This commit: 1) Copies 3.14 patches 2) Drops mainlined stuff 3) Modifies some patches to apply Signed-off-by: Rafał Miłecki <zajec5@gmail.com> SVN-Revision: 43093
Diffstat (limited to 'target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch')
-rw-r--r--target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch146
1 files changed, 146 insertions, 0 deletions
diff --git a/target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch b/target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch
new file mode 100644
index 0000000000..4a17ccd8d6
--- /dev/null
+++ b/target/linux/generic/patches-3.18/411-mtd-partial_eraseblock_write.patch
@@ -0,0 +1,146 @@
+--- a/drivers/mtd/mtdpart.c
++++ b/drivers/mtd/mtdpart.c
+@@ -35,6 +35,8 @@
+ #include "mtdcore.h"
+ #include "mtdsplit.h"
+
++#define MTD_ERASE_PARTIAL 0x8000 /* partition only covers parts of an erase block */
++
+ /* Our partition linked list */
+ static LIST_HEAD(mtd_partitions);
+ static DEFINE_MUTEX(mtd_partitions_mutex);
+@@ -233,13 +235,61 @@ static int part_erase(struct mtd_info *m
+ struct mtd_part *part = PART(mtd);
+ int ret;
+
++
++ instr->partial_start = false;
++ if (mtd->flags & MTD_ERASE_PARTIAL) {
++ size_t readlen = 0;
++ u64 mtd_ofs;
++
++ instr->erase_buf = kmalloc(part->master->erasesize, GFP_ATOMIC);
++ if (!instr->erase_buf)
++ return -ENOMEM;
++
++ mtd_ofs = part->offset + instr->addr;
++ instr->erase_buf_ofs = do_div(mtd_ofs, part->master->erasesize);
++
++ if (instr->erase_buf_ofs > 0) {
++ instr->addr -= instr->erase_buf_ofs;
++ ret = mtd_read(part->master,
++ instr->addr + part->offset,
++ part->master->erasesize,
++ &readlen, instr->erase_buf);
++
++ instr->len += instr->erase_buf_ofs;
++ instr->partial_start = true;
++ } else {
++ mtd_ofs = part->offset + part->mtd.size;
++ instr->erase_buf_ofs = part->master->erasesize -
++ do_div(mtd_ofs, part->master->erasesize);
++
++ if (instr->erase_buf_ofs > 0) {
++ instr->len += instr->erase_buf_ofs;
++ ret = mtd_read(part->master,
++ part->offset + instr->addr +
++ instr->len - part->master->erasesize,
++ part->master->erasesize, &readlen,
++ instr->erase_buf);
++ } else {
++ ret = 0;
++ }
++ }
++ if (ret < 0) {
++ kfree(instr->erase_buf);
++ return ret;
++ }
++
++ }
++
+ instr->addr += part->offset;
+ ret = part->master->_erase(part->master, instr);
+ if (ret) {
+ if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
+ instr->fail_addr -= part->offset;
+ instr->addr -= part->offset;
++ if (mtd->flags & MTD_ERASE_PARTIAL)
++ kfree(instr->erase_buf);
+ }
++
+ return ret;
+ }
+
+@@ -247,7 +297,25 @@ void mtd_erase_callback(struct erase_inf
+ {
+ if (instr->mtd->_erase == part_erase) {
+ struct mtd_part *part = PART(instr->mtd);
++ size_t wrlen = 0;
+
++ if (instr->mtd->flags & MTD_ERASE_PARTIAL) {
++ if (instr->partial_start) {
++ part->master->_write(part->master,
++ instr->addr, instr->erase_buf_ofs,
++ &wrlen, instr->erase_buf);
++ instr->addr += instr->erase_buf_ofs;
++ } else {
++ instr->len -= instr->erase_buf_ofs;
++ part->master->_write(part->master,
++ instr->addr + instr->len,
++ instr->erase_buf_ofs, &wrlen,
++ instr->erase_buf +
++ part->master->erasesize -
++ instr->erase_buf_ofs);
++ }
++ kfree(instr->erase_buf);
++ }
+ if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
+ instr->fail_addr -= part->offset;
+ instr->addr -= part->offset;
+@@ -514,18 +582,24 @@ static struct mtd_part *allocate_partiti
+ if ((slave->mtd.flags & MTD_WRITEABLE) &&
+ mtd_mod_by_eb(slave->offset, &slave->mtd)) {
+ /* Doesn't start on a boundary of major erase size */
+- /* FIXME: Let it be writable if it is on a boundary of
+- * _minor_ erase size though */
+- slave->mtd.flags &= ~MTD_WRITEABLE;
+- printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
+- part->name);
++ slave->mtd.flags |= MTD_ERASE_PARTIAL;
++ if (((u32) slave->mtd.size) > master->erasesize)
++ slave->mtd.flags &= ~MTD_WRITEABLE;
++ else
++ slave->mtd.erasesize = slave->mtd.size;
+ }
+ if ((slave->mtd.flags & MTD_WRITEABLE) &&
+- mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) {
+- slave->mtd.flags &= ~MTD_WRITEABLE;
+- printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
+- part->name);
++ mtd_mod_by_eb(slave->offset + slave->mtd.size, &slave->mtd)) {
++ slave->mtd.flags |= MTD_ERASE_PARTIAL;
++
++ if ((u32) slave->mtd.size > master->erasesize)
++ slave->mtd.flags &= ~MTD_WRITEABLE;
++ else
++ slave->mtd.erasesize = slave->mtd.size;
+ }
++ if ((slave->mtd.flags & (MTD_ERASE_PARTIAL|MTD_WRITEABLE)) == MTD_ERASE_PARTIAL)
++ 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",
++ part->name);
+
+ slave->mtd.ecclayout = master->ecclayout;
+ slave->mtd.ecc_step_size = master->ecc_step_size;
+--- a/include/linux/mtd/mtd.h
++++ b/include/linux/mtd/mtd.h
+@@ -55,6 +55,10 @@ struct erase_info {
+ u_long priv;
+ u_char state;
+ struct erase_info *next;
++
++ u8 *erase_buf;
++ u32 erase_buf_ofs;
++ bool partial_start;
+ };
+
+ struct mtd_erase_region_info {