[PATCH 0/2] cmd: mtd: fix default read behavior and boundary checks

Peter Suti peter.suti at streamunlimited.com
Tue Dec 16 14:40:40 CET 2025


This series addresses two issues in the 'mtd read' command regarding how
default read lengths are calculated and handled when no size argument is
provided.

The first patch fixes a failure when reading a full NAND partition that
contains bad blocks. Currently, skipping bad blocks increments the physical
offset without adjusting the remaining byte count, causing the read to
attempt accessing past the end of the partition. The fix ensures that
default full-partition reads are truncated gracefully at the physical
boundary rather than returning an error.
This behaviour is similar to the raw `nand` command which adjusts the size
of the read with adjust_size_for_badblocks().

The second patch fixes the default length calculation when a starting
offset is specified. Previously, the command defaulted to reading the
entire partition size ('mtd->size') starting from the offset, which
inevitably exceeds the partition bounds. The fix adjusts the default length
to 'mtd->size - offset'.

Peter Suti (2):
  cmd: mtd: fix read failure on default full partition read with bad
    blocks
  cmd: mtd: fix default length calculation when offset is specified

 cmd/mtd.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

-- 
2.43.0



More information about the U-Boot mailing list