mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/10] mmc: add SD/eMMC erase support
@ 2024-07-30  7:19 Ahmad Fatoum
  2024-07-30  7:19 ` [PATCH 01/10] fs: give erase() a new erase_type parameter Ahmad Fatoum
                   ` (9 more replies)
  0 siblings, 10 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2024-07-30  7:19 UTC (permalink / raw)
  To: barebox

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




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

end of thread, other threads:[~2024-07-31  7:20 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-30  7:19 [PATCH 00/10] mmc: add SD/eMMC erase support Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 01/10] fs: give erase() a new erase_type parameter Ahmad Fatoum
2024-07-30  8:31   ` Sascha Hauer
2024-07-30  8:32     ` Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 02/10] block: factor out chunk_flush helper Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 03/10] block: allow block devices to implement the cdev erase operation Ahmad Fatoum
2024-07-30  8:55   ` Sascha Hauer
2024-07-30 11:10     ` Ahmad Fatoum
2024-07-30 11:21       ` Sascha Hauer
2024-07-30  7:19 ` [PATCH 04/10] mci: turn bool members into bitfield in struct mci Ahmad Fatoum
2024-07-30  9:06   ` Sascha Hauer
2024-07-30 11:10     ` Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 05/10] mci: describe more command structure in mci.h Ahmad Fatoum
2024-07-30  9:25   ` Yann Sionneau
2024-07-30 11:07     ` Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 06/10] mci: core: use CONFIG_MCI_WRITE, not CONFIG_BLOCK_WRITE Ahmad Fatoum
2024-07-30  9:18   ` Sascha Hauer
2024-07-30 11:08     ` Ahmad Fatoum
2024-07-31  7:19       ` Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 07/10] mci: add support for discarding write blocks Ahmad Fatoum
2024-07-30  9:23   ` Yann Sionneau
2024-07-30 11:14     ` Ahmad Fatoum
2024-07-30 10:05   ` Sascha Hauer
2024-07-30 11:17     ` Ahmad Fatoum
2024-07-30  7:19 ` [PATCH 08/10] commands: sync: add new command to flush cached writes Ahmad Fatoum
2024-07-30 10:08   ` Sascha Hauer
2024-07-30  7:19 ` [PATCH 09/10] mci: core: remove reference to SD Card from common mci_card_probe Ahmad Fatoum
2024-07-30 10:09   ` Sascha Hauer
2024-07-30  7:19 ` [PATCH 10/10] commands: blkstats: add command to print block device statistics Ahmad Fatoum

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