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)
{
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",