[PATCH 00/10] mmc: add SD/eMMC erase support
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Jul 30 00:19:19 PDT 2024
A common optimization for flashing is to skip gaps between partitions
and only flash actual data. The problem with that is that data from
the previous installation may persist and confuse later software, e.g.
an existing barebox state partition not contained in the image may
survive, when the expectation is that a new state is created.
eMMCs can support three different commands for erasing data:
- Erase: This has the widest support, but works on only on the level
of erase groups that may span multiple write blocks.
The region reads as either '0' or '1' afterwards.
- Trim: New in eMMC v4.4. This erases write blocks.
The region reads as either '0' or '1' afterwards.
- Discard: New in eMMC v4.5. This discards write blocks. It's up to the
card what action if any is taken.
All or part of the data may remain accessible.
All of these don't enforce a actual physical NAND erase operation.
In case erasure does happen, it may happen later at a convenient time.
All of them, except for discard guarantee that a fixed pattern (either
all zeroes or all ones) will be read back after the erase operation
concludes. Therefore let's use them in barebox to implement the erase
command.
The behavior of the erase command will be similar to the Linux
blkdiscard -z command when the erase byte value is all-zeroes. In Linux
blkdiscard -z is emulated with zero writes if the erased byte is 0xFF,
but for barebox, the erase operation won't care whether it writes 0x00
or 0xFF.
Note that this is considerably slower than need be, because we don't
erase multiple erase groups at once. Doing so could run into the
send_cmd timeout of the host hardware or its drivers. The correct
workaround is to calculate the duration of the erase operation and split
up the erases, so we always stay below a specific erase operation
duration. There's a comment that explains this and implementing it is
left as future exercise.
Ahmad Fatoum (10):
fs: give erase() a new erase_type parameter
block: factor out chunk_flush helper
block: allow block devices to implement the cdev erase operation
mci: turn bool members into bitfield in struct mci
mci: describe more command structure in mci.h
mci: core: use CONFIG_MCI_WRITE, not CONFIG_BLOCK_WRITE
mci: add support for discarding write blocks
commands: sync: add new command to flush cached writes
mci: core: remove reference to SD Card from common mci_card_probe
commands: blkstats: add command to print block device statistics
arch/arm/mach-imx/imx-bbu-external-nand.c | 2 +-
arch/arm/mach-imx/imx-bbu-internal.c | 4 +-
arch/arm/mach-omap/am33xx_bbu_spi_mlo.c | 2 +-
commands/Kconfig | 25 ++
commands/Makefile | 2 +
commands/blkstats.c | 60 ++++
commands/flash.c | 2 +-
commands/nandtest.c | 2 +-
commands/sync.c | 42 +++
common/Kconfig | 3 +
common/bbu.c | 2 +-
common/block.c | 123 +++++--
common/environment.c | 7 +-
common/fastboot.c | 2 +-
common/state/backend_bucket_circular.c | 2 +-
drivers/mci/Kconfig | 5 +
drivers/mci/mci-core.c | 405 ++++++++++++++++++++--
drivers/misc/storage-by-uuid.c | 3 +
drivers/usb/gadget/function/dfu.c | 4 +-
fs/devfs-core.c | 7 +-
fs/devfs.c | 5 +-
fs/fs.c | 4 +-
include/block.h | 11 +
include/driver.h | 13 +
include/fs.h | 26 +-
include/mci.h | 75 +++-
lib/libfile.c | 2 +-
27 files changed, 767 insertions(+), 73 deletions(-)
create mode 100644 commands/blkstats.c
create mode 100644 commands/sync.c
--
2.39.2
More information about the barebox
mailing list