[U-Boot] [PATCH v3 6/7] dfu, nand, ubi: fix erasing after write finish
Heiko Schocher
hs at denx.de
Tue Jun 7 08:55:44 CEST 2016
writting to ubi nand partitions need after write ends an erase
of the remaining sectors. This fail, if dfu write size was not
a multiple of erasesize, example log:
Failure erase: -1
Fix this error.
Signed-off-by: Heiko Schocher <hs at denx.de>
---
Changes in v2:
- rebase to current mainline commit id:
e4a94ce4ac77396b181663c0493c50bc2d5b9143
and the "mtd: nand Sync with Linux v4.6" patches:
[U-Boot,1/7] mtd: nand: Remove jz4740 driver
http://patchwork.ozlabs.org/patch/627922/
[U-Boot,2/7] mtd: nand: Remove docg4 driver and palmtreo680 flashing tool
http://patchwork.ozlabs.org/patch/627924/
[U-Boot,3/7] mtd: nand: Remove nand_info_t typedef
http://patchwork.ozlabs.org/patch/627923/
[U-Boot,4/7] nand: Embed mtd_info in struct nand_chip
http://patchwork.ozlabs.org/patch/627925/
[U-Boot,5/7] mtd: nand: Add+use mtd_to/from_nand and nand_get/set_controller_data
http://patchwork.ozlabs.org/patch/627926/
[U-Boot,6/7] mtd: nand: Add page argument to write_page() etc.
http://patchwork.ozlabs.org/patch/627927/
[U-Boot,7/7] mtd: nand: Sync with Linux v4.6
http://patchwork.ozlabs.org/patch/627928/
drivers/dfu/dfu_nand.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c
index 5906057..1ca10d4 100644
--- a/drivers/dfu/dfu_nand.c
+++ b/drivers/dfu/dfu_nand.c
@@ -143,6 +143,7 @@ static int dfu_read_medium_nand(struct dfu_entity *dfu, u64 offset, void *buf,
static int dfu_flush_medium_nand(struct dfu_entity *dfu)
{
int ret = 0;
+ u64 off;
/* in case of ubi partition, erase rest of the partition */
if (dfu->data.nand.ubi) {
@@ -159,7 +160,16 @@ static int dfu_flush_medium_nand(struct dfu_entity *dfu)
mtd = nand_info[nand_curr_device];
memset(&opts, 0, sizeof(opts));
- opts.offset = dfu->data.nand.start + dfu->offset +
+ off = dfu->offset;
+ if ((off & (mtd->erasesize - 1)) != 0) {
+ /*
+ * last write ended with unaligned length
+ * sector is erased, jump to next
+ */
+ off = off & ~((mtd->erasesize - 1));
+ off += mtd->erasesize;
+ }
+ opts.offset = dfu->data.nand.start + off +
dfu->bad_skip;
opts.length = dfu->data.nand.start +
dfu->data.nand.size - opts.offset;
--
2.5.5
More information about the U-Boot
mailing list