[RFC PATCH 0/6] Add GPT parser to MTD layer

Romain Gantois
2023-12-11T15:12:41Z

Hello everyone,

MTD devices were historically partitioned using fixed partitions schemes
defined in the kernel device tree or on the cmdline. More recently, a bunch
of dynamic parsers have been introduced, allowing partitioning information
to be stored in-band. However, unlike disks, parsers for MTD devices do not
support runtime discovery of the partition format. This format is instead
named in the device-tree using a compatible string.

The GUID Partition Table is one of the most common ways of partitioning a
block device. As of now, there is no support in the MTD layer for parsing
GPT tables. Indeed, use cases for layouts like GPT on raw Flash devices are
rare, and for good reason since these partitioning schemes are sensitive to
bad blocks in strategic locations such as LBA 2. Moreover, they do not
allow proper wear-leveling to be performed on the full span of the device.

However, allowing GPT to be used on MTD devices can be practical in some
cases. In the context of an A/B OTA upgrade that can act on either NOR of
eMMC devices, having the same partition table format for both kinds of
devices can simplify the task of the update software.

This series adds a fully working MTD GPT parser to the kernel. Use of the
parser is restricted to NOR flash devices, since NAND flashes are too
susceptible to bad blocks. To ensure coherence and code-reuse between
subsystems, I've factored device-agnostic code from the block layer GPT
parser and moved it to a new generic library in lib/gpt.c. No functional
change is intended in the block layer parser.

I understand that this can seem like a strange feature for MTD devices, but
with the restriction to NOR devices, the partition table can be fairly
reliable. Moreover, this addition fits nicely into the MTD parser model.
Please tell me what you think.

Best Regards,

Romain

Romain Gantois (6):
block: partitions: efi: Move efi.h header to include/linux/gpt.h
block: partitions: efi: Fix some style issues
block: partitions: efi: Separate out GPT-specific code
block: partitions: efi: Move GPT-specific code to a new library
drivers: mtd: introduce GPT parser for NOR flash devices
dt-bindings: mtd: add GPT partition bindings

.../bindings/mtd/partitions/gpt.yaml | 41 ++
.../bindings/mtd/partitions/partitions.yaml | 1 +
MAINTAINERS | 4 +-
block/partitions/Kconfig | 2 +-
block/partitions/efi.c | 478 +++---------------
block/partitions/msdos.c | 2 +-
drivers/mtd/parsers/Kconfig | 10 +
drivers/mtd/parsers/Makefile | 1 +
drivers/mtd/parsers/gpt.c | 222 ++++++++
include/linux/efi.h | 18 +
block/partitions/efi.h => include/linux/gpt.h | 72 ++-
lib/Kconfig | 3 +
lib/Makefile | 3 +
lib/gpt.c | 342 +++++++++++++
14 files changed, 777 insertions(+), 422 deletions(-)
create mode 100644 Documentation/devicetree/bindings/mtd/partitions/gpt.yaml
create mode 100644 drivers/mtd/parsers/gpt.c
rename block/partitions/efi.h => include/linux/gpt.h (61%)
create mode 100644 lib/gpt.c

--
2.43.0