public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] dfu: mtd: skip empty pages when writing page for UBI partition
@ 2022-01-18  9:26 Patrick Delaunay
  2022-01-29 18:49 ` Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Delaunay @ 2022-01-18  9:26 UTC (permalink / raw)
  To: u-boot; +Cc: Patrick Delaunay, Lukasz Majewski, U-Boot STM32

Align the DFU MTD backend for the UBI partitions with the mtd command write
behavior when the option .dontskipff is not used: don't write the empty
pages (full of 0xFF); it is not required for UBI, see [1] for details.

This patch avoids the "free space fixup" procedure in the kernel [2]
and allows to program a UBIFS volume generated by mkfs.ubifs without the
option -F, --space-fixup.

The MTD DFU backend implements this behavior introduced on DFU NAND
backend by the commit 13cb7cc9e8e4 ("dfu: Add option to skip empty pages
when flashing UBI images to NAND") and also supported by the command nand
by CONFIG_CMD_NAND_TRIMFFS and by commit c9494866df83 ("cmd_nand: add nand
write.trimffs command").

[1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo
[2] http://www.linux-mtd.infradead.org/faq/ubifs.html#L_free_space_fixup

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 drivers/dfu/dfu_mtd.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/dfu/dfu_mtd.c b/drivers/dfu/dfu_mtd.c
index 0b7f17761f..cce9ce0845 100644
--- a/drivers/dfu/dfu_mtd.c
+++ b/drivers/dfu/dfu_mtd.c
@@ -18,6 +18,20 @@ static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size)
 	return !do_div(size, mtd->erasesize);
 }
 
+/* Logic taken from cmd/mtd.c:mtd_oob_write_is_empty() */
+static bool mtd_page_is_empty(struct mtd_oob_ops *op)
+{
+	int i;
+
+	for (i = 0; i < op->len; i++)
+		if (op->datbuf[i] != 0xff)
+			return false;
+
+	/* oob is not used, with MTD_OPS_AUTO_OOB & ooblen=0 */
+
+	return true;
+}
+
 static int mtd_block_op(enum dfu_op op, struct dfu_entity *dfu,
 			u64 offset, void *buf, long *len)
 {
@@ -129,8 +143,14 @@ static int mtd_block_op(enum dfu_op op, struct dfu_entity *dfu,
 
 		if (op == DFU_OP_READ)
 			ret = mtd_read_oob(mtd, off, &io_op);
-		else
+		else if (has_pages && dfu->data.mtd.ubi && mtd_page_is_empty(&io_op)) {
+			/* in case of ubi partition, do not write an empty page, only skip it */
+			ret = 0;
+			io_op.retlen = mtd->writesize;
+			io_op.oobretlen = mtd->oobsize;
+		} else {
 			ret = mtd_write_oob(mtd, off, &io_op);
+		}
 
 		if (ret) {
 			printf("Failure while %s at offset 0x%llx\n",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dfu: mtd: skip empty pages when writing page for UBI partition
  2022-01-18  9:26 [PATCH] dfu: mtd: skip empty pages when writing page for UBI partition Patrick Delaunay
@ 2022-01-29 18:49 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2022-01-29 18:49 UTC (permalink / raw)
  To: Patrick Delaunay; +Cc: u-boot, Lukasz Majewski, U-Boot STM32

[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]

On Tue, Jan 18, 2022 at 10:26:21AM +0100, Patrick Delaunay wrote:

> Align the DFU MTD backend for the UBI partitions with the mtd command write
> behavior when the option .dontskipff is not used: don't write the empty
> pages (full of 0xFF); it is not required for UBI, see [1] for details.
> 
> This patch avoids the "free space fixup" procedure in the kernel [2]
> and allows to program a UBIFS volume generated by mkfs.ubifs without the
> option -F, --space-fixup.
> 
> The MTD DFU backend implements this behavior introduced on DFU NAND
> backend by the commit 13cb7cc9e8e4 ("dfu: Add option to skip empty pages
> when flashing UBI images to NAND") and also supported by the command nand
> by CONFIG_CMD_NAND_TRIMFFS and by commit c9494866df83 ("cmd_nand: add nand
> write.trimffs command").
> 
> [1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_flasher_algo
> [2] http://www.linux-mtd.infradead.org/faq/ubifs.html#L_free_space_fixup
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-29 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-18  9:26 [PATCH] dfu: mtd: skip empty pages when writing page for UBI partition Patrick Delaunay
2022-01-29 18:49 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox