mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 00/10] mmc: add SD/eMMC erase support
@ 2024-07-31  8:05 Ahmad Fatoum
  2024-07-31  8:05 ` [PATCH v2 01/10] fs: give erase() a new erase_type parameter Ahmad Fatoum
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Ahmad Fatoum @ 2024-07-31  8:05 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
  cdev: factor out range identical/overlap check
  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
  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                       |  66 ++++
 commands/flash.c                          |   2 +-
 commands/nandtest.c                       |   2 +-
 commands/sync.c                           |  42 +++
 common/Kconfig                            |   3 +
 common/bbu.c                              |   2 +-
 common/block.c                            | 114 ++++--
 common/environment.c                      |   7 +-
 common/fastboot.c                         |   2 +-
 common/partitions.c                       |  16 +-
 common/state/backend_bucket_circular.c    |   2 +-
 drivers/mci/Kconfig                       |   5 +
 drivers/mci/mci-core.c                    | 401 ++++++++++++++++++++--
 drivers/misc/storage-by-uuid.c            |   3 +
 drivers/usb/gadget/function/dfu.c         |   4 +-
 fs/devfs-core.c                           |  26 +-
 fs/devfs.c                                |   5 +-
 fs/fs.c                                   |   4 +-
 include/block.h                           |  11 +
 include/driver.h                          |  13 +
 include/fs.h                              |  26 +-
 include/mci.h                             |  75 +++-
 include/range.h                           |  57 +++
 lib/libfile.c                             |   2 +-
 29 files changed, 824 insertions(+), 101 deletions(-)
 create mode 100644 commands/blkstats.c
 create mode 100644 commands/sync.c
 create mode 100644 include/range.h

-- 
2.39.2




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

end of thread, other threads:[~2024-08-01 11:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-31  8:05 [PATCH v2 00/10] mmc: add SD/eMMC erase support Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 01/10] fs: give erase() a new erase_type parameter Ahmad Fatoum
2024-08-01 10:51   ` Sascha Hauer
2024-08-01 10:54     ` Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 02/10] cdev: factor out range identical/overlap check Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 03/10] block: factor out chunk_flush helper Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 04/10] block: allow block devices to implement the cdev erase operation Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 05/10] mci: turn bool members into bitfield in struct mci Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 06/10] mci: describe more command structure in mci.h Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 07/10] mci: core: use CONFIG_MCI_WRITE, not CONFIG_BLOCK_WRITE Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 08/10] mci: add support for discarding write blocks Ahmad Fatoum
2024-08-01 11:27   ` Sascha Hauer
2024-07-31  8:05 ` [PATCH v2 09/10] commands: sync: add new command to flush cached writes Ahmad Fatoum
2024-07-31  8:05 ` [PATCH v2 10/10] commands: blkstats: add command to print block device statistics Ahmad Fatoum
2024-08-01 10:49 ` [PATCH v2 00/10] mmc: add SD/eMMC erase support Sascha Hauer

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