mtd: Add MTD virtual concat support via device tree
Subsystems (2)
v2 cover mtd: Add MTD virtual concat support via device tree
Some boards have two or more flash devices on separate chip selects (for example QSPI/OSPI flashes) and need a single filesystem or image to span them. This series adds MTD virtual concatenation, where partitions on different flash devices are linked in the device tree with the "part-concat-next" property and exposed as one concatenated MTD device:
flash@0 {
partitions {
compatible = "fixed-partitions";
part0: partition@0 {
label = "flash0-part";
part-concat-next = <&part1>;
reg = <0x0 0x800000>;
};
};
};
flash@1 {
partitions {
compatible = "fixed-partitions";
part1: partition@0 {
label = "flash1-part";
reg = <0x0 0x800000>;
};
};
};With CONFIG_MTD_VIRT_CONCAT enabled, only the concatenated device ("flash0-part-flash1-part-concat") is registered. The member partitions are not registered individually. Multiple concat groups, each with two or more partitions, are supported.
This is based on the Linux driver added by
commit 43db6366fc2d ("mtd: Add driver for concatenating devices"):
https://git.kernel.org/torvalds/c/43db6366fc2d
If a group is incomplete, or cannot be joined, a warning is printed and its partitions are registered individually.
A concatenated device is kept when the partitions are scanned again. It is destroyed when a flash it uses is removed, e.g. by 'sf probe', or when mtdparts defines the partitions of that flash instead of the device tree. It is not destroyed while it is in use: mtdparts is not applied to its flash then, and removing the flash only prints a warning, so it should not be in use when its flash is removed.
On ZynqMP, accessing the flash on CS1 needs the GQSPI chip select fix, which is now sent separately:
"spi: zynqmp_gqspi: Use the device's chip select"
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Patch 7 enables the option for ZynqMP, Versal, Versal NET and Versal Gen 2.
On ZynqMP, the board has two mt25qu512a QSPI flashes on CS0 and CS1. Partition "rootfs_a" (flash@0, 0x1000000-0x4000000) is concatenated with "rootfs_c" (flash@1, 0x1000000-0x4000000) into a single 96 MiB device, while the remaining partitions on each flash are registered as usual:
ZynqMP> mtd list
SF: Detected mt25qu512a with page size 256 Bytes, erase size 64 KiB, total 64 MiB
SF: Detected mt25qu512a with page size 256 Bytes, erase size 64 KiB, total 64 MiB (0): "rootfs_a"
(1): "rootfs_c"
List of MTD devices:
* nor0
- device: flash@0
- parent: spi@ff0f0000
- driver: jedec_spi_nor
- path: /axi/spi@ff0f0000/flash@0
- type: NOR flash
- block size: 0x10000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000004000000 : "nor0"
- 0x000000000000-0x000001000000 : "qspi-fsbl-uboot"
* nor1
- device: flash@1
- parent: spi@ff0f0000
- driver: jedec_spi_nor
- path: /axi/spi@ff0f0000/flash@1
- type: NOR flash
- block size: 0x10000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000004000000 : "nor1"
- 0x000000000000-0x000001000000 : "rootfs_b"
* rootfs_a-rootfs_c-concat
- type: NOR flash
- block size: 0x10000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000006000000 : "rootfs_a-rootfs_c-concat"
Erase/write/read-back across the CS0/CS1 boundary at 0x3000000:
ZynqMP> mtd erase rootfs_a-rootfs_c-concat 0x02F00000 0x00200000 Erasing 0x02f00000 ... 0x030fffff (32 eraseblock(s)) ZynqMP> mtd write rootfs_a-rootfs_c-concat 0x200000 0x02F00000 0x1E3200 Writing 1978880 byte(s) at offset 0x02f00000
ZynqMP> mw.b 0x5000000 0x00 0x1E3200
ZynqMP> mtd read rootfs_a-rootfs_c-concat 0x5000000 0x02F00000 0x1E3200 Reading 1978880 byte(s) at offset 0x02f00000
ZynqMP> cmp.b 0x200000 0x5000000 0x1E3200
Total of 1978880 byte(s) were the same
On Versal NET, the board has two mx66uw2g345gx0 OSPI flashes on CS0 and CS1 of the Cadence OSPI controller. Partition "ospi-flash1" (flash@0, 0x200000-0x8000000) is concatenated with "ospi-flash2" (flash@1, 0x0-0x200000) into a single 128 MiB device. This test also used "mtd: spi-nor: Remove SPI_NOR_OCTAL_DTR_READ flag for mx66uw2g345gx0 flash part", which the flashes on this board need and which is not part of this series:
Versal NET> mtd list
SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB
SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB
SF: Detected mx25u3235f with page size 256 Bytes, erase size 4 KiB, total 4 MiB (0): "ospi-flash1"
(1): "ospi-flash2"
List of MTD devices:
* nor0
- device: flash@1
- parent: spi@f1010000
- driver: jedec_spi_nor
- path: /axi/spi@f1010000/flash@1
- type: NOR flash
- block size: 0x10000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000010000000 : "nor0"
- 0x000000200000-0x000008000000 : "ospi-flash3"
* nor1
- device: flash@0
- parent: spi@f1010000
- driver: jedec_spi_nor
- path: /axi/spi@f1010000/flash@0
- type: NOR flash
- block size: 0x10000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000010000000 : "nor1"
- 0x000000000000-0x000000200000 : "ospi-flash0"
* nor2
- device: flash@2
- parent: spi@f1970000
- driver: jedec_spi_nor
- path: /axi/spi@f1970000/flash@2
- type: NOR flash
- block size: 0x1000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000000400000 : "nor2"
- 0x000000000000-0x000000080000 : "spi0-flash0"
* ospi-flash1-ospi-flash2-concat
- type: NOR flash
- block size: 0x10000 bytes
- min I/O: 0x1 bytes
- 0x000000000000-0x000008000000 : "ospi-flash1-ospi-flash2-concat"
Erase/write/read-back across the CS0/CS1 boundary at 0x7e00000, then reading each flash directly to check that each half landed on the right one:
Versal NET> mw.b 2000000 cd 200000
Versal NET> mtd erase ospi-flash1-ospi-flash2-concat 7d00000 200000 Erasing 0x07d00000 ... 0x07efffff (32 eraseblock(s))
Versal NET> mtd write ospi-flash1-ospi-flash2-concat 2000000 7d00000 200000 Writing 2097152 byte(s) at offset 0x07d00000
Versal NET> mtd read ospi-flash1-ospi-flash2-concat 3000000 7d00000 200000 Reading 2097152 byte(s) at offset 0x07d00000
Versal NET> cmp.b 2000000 3000000 200000
Total of 2097152 byte(s) were the same
Versal NET> sf probe 0:0
SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB Versal NET> sf read 4000000 7f00000 100000
device 0 offset 0x7f00000, size 0x100000
SF: 1048576 bytes @ 0x7f00000 Read: OK
Versal NET> cmp.b 2000000 4000000 100000
Total of 1048576 byte(s) were the same
Versal NET> sf probe 0:1
SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB Versal NET> sf read 5000000 0 100000
device 0 offset 0x0, size 0x100000
SF: 1048576 bytes @ 0x0 Read: OK
Versal NET> cmp.b 2100000 5000000 100000
Total of 1048576 byte(s) were the same
After 'sf probe' re-probed both flashes, the next 'mtd list' printed the concatenated device again, as the scan created it again.
Patch 4 fixes concat_write_oob() and concat_read_oob(), which made any write to a concatenated NAND device fail. It is needed to use the new support with NAND partitions.
The sandbox tests in patch 5 cover joining, access across the boundary between the flashes, rescanning, flashes and concatenated devices which are in use, removing a flash, incomplete groups and a partition which is out of reach. They also cover patch 4, with a concatenated NAND device. Patch 3 fixes the existing NAND tests, which otherwise fail when they run after a test that probes the MTD devices. Patch 6 adds the documentation, in doc/usage/mtd_concat.rst.
Changes in v2:
- New patch to fix the lengths returned by concat_write_oob() and concat_read_oob()
- Drop "mtd: Move struct mtd_concat definition to header file", which the driver no longer needs
- New patch to move the DFS helpers to ofnode, with tests
- Register the partitions of incomplete or failed groups individually with a warning
- Warn about an invalid part-concat-next property
- Do not concatenate a partition which is out of reach, or which is found more than once
- Free the member partitions when a group is freed, and keep a concat device that is still in use
- Keep a concat device when the partitions are scanned again, and only destroy it when a flash it uses is removed, or when mtdparts replaces the partitions of that flash
- Do not apply mtdparts to a flash while a concat device which uses it is in use
- Fix mtd_virt_concat_destroy(), which never matched, and call it from del_mtd_device() so that every kind of flash is covered
- Drop the IS_ENABLED() checks, and depend on MTD_PARTITIONS but no longer on MTD_CONCAT, which also joins NAND and CFI flash chips
- Refer to the merged Linux commit
- Send the ZynqMP GQSPI fix as a separate patch
- New patch to fix the NAND tests when they run after an MTD test
- New patch with sandbox tests
- New patch with documentation
- Do not enable CONFIG_MTD_CONCAT in the defconfigs
Link to v1: https://patchwork.ozlabs.org/project/uboot/list/?series=529258
Padmarao Begari (7):
dm: core: Add ofnode_find_node_with_property()
mtd: Add virtual concat support via device tree
test: dm: nand: Probe the NAND controller in the test
mtd: concat: Fix the lengths in the concat OOB functions
test: dm: Add tests for MTD virtual concat
doc: Add documentation for MTD virtual concat
arm64: xilinx: Enable MTD virtual concat
MAINTAINERS | 9 + arch/sandbox/dts/test.dts | 23 + configs/amd_versal2_virt_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/xilinx_versal_net_virt_defconfig | 1 + configs/xilinx_versal_virt_defconfig | 1 + configs/xilinx_zynqmp_virt_defconfig | 1 + doc/usage/index.rst | 1 + doc/usage/mtd_concat.rst | 146 ++++++ drivers/core/ofnode.c | 31 ++ drivers/mtd/Kconfig | 17 + drivers/mtd/Makefile | 5 +- drivers/mtd/mtd_uboot.c | 48 +- drivers/mtd/mtd_virt_concat.c | 457 +++++++++++++++++++ drivers/mtd/mtdconcat.c | 5 +- drivers/mtd/mtdcore.c | 12 + drivers/mtd/mtdpart.c | 17 + include/dm/ofnode.h | 23 + include/linux/mtd/concat.h | 86 +++- test/dm/Makefile | 1 + test/dm/mtd_concat.c | 543 +++++++++++++++++++++++ test/dm/nand.c | 10 + test/dm/ofnode.c | 55 +++ 23 files changed, 1488 insertions(+), 6 deletions(-) create mode 100644 doc/usage/mtd_concat.rst create mode 100644 drivers/mtd/mtd_virt_concat.c create mode 100644 test/dm/mtd_concat.c
Signature · 1 line
2.34.1
PATCH v2 1/7 dm: core: Add ofnode_find_node_with_property()
Add a function to find the next node that has a given property, whatever its value, walking the tree in depth-first order. This is needed by the MTD virtual concat support to find all partitions with a "part-concat-next" property.
Also export ofnode_dfs_next(), which it uses to step through the tree, and add tests for both.
---
Changes in v2:
- New patch: move the DFS helpers from the MTD driver to ofnode and add tests
checkpatch reports 'Please use a blank line after function/struct/union/enum declarations' for each DM_TEST() line. DM_TEST() is placed directly after its test function, as in the other tests.
drivers/core/ofnode.c | 31 ++++++++++++++++++++++++ include/dm/ofnode.h | 23 ++++++++++++++++++ test/dm/ofnode.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+)
drivers/core/ofnode.c +31 -0
@@ -1791,6 +1791,37 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname, } } +ofnode ofnode_dfs_next (ofnode node) +{ +ofnode child, sibling; + + child =ofnode_first_subnode (node); +if (ofnode_valid (child)) +return child; + +while (ofnode_valid (node)) { + sibling =ofnode_next_subnode (node); +if (ofnode_valid (sibling)) +return sibling; + node =ofnode_get_parent (node); + } + +return ofnode_null (); +} + +ofnode ofnode_find_node_with_property (ofnode from,const char *propname) +{ +ofnode node; + + node =ofnode_valid (from) ?ofnode_dfs_next (from) :ofnode_root (); +for (;ofnode_valid (node); node =ofnode_dfs_next (node)) { +if (ofnode_has_property (node, propname)) +return node; + } + +return ofnode_null (); +} +int ofnode_write_prop (ofnode node,const char *propname,const void *value,int len,bool copy) {
include/dm/ofnode.h +23 -0
@@ -1488,6 +1488,29 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat);ofnode ofnode_by_prop_value (ofnode from,const char *propname,const void *propval,int proplen); +/** +* ofnode_dfs_next() - Get the next node in depth-first order +* +* Return the first subnode of @node if it has one, otherwise its next sibling, +* otherwise the next sibling of the nearest parent that has one. +* +* @node: valid node to start from +* Return: next node, or ofnode_null() at the end of the tree +*/ +ofnode ofnode_dfs_next (ofnode node); + +/** +* ofnode_find_node_with_property() - Find the next node with a property +* +* Walk the tree in depth-first order, starting after @from, and return the +* first node that has a property called @propname, whatever its value. +* +* @from: ofnode to start after (use ofnode_null() to start at the root) +* @propname: name of the property to look for +* Return: ofnode found, or ofnode_null() if none +*/ +ofnode ofnode_find_node_with_property (ofnode from,const char *propname); +/** * ofnode_for_each_subnode() - iterate over all subnodes of a parent *
test/dm/ofnode.c +55 -0
61 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/7 mtd: Add virtual concat support via device tree
In reply to Padmarao BegariAdd CONFIG_MTD_VIRT_CONCAT to join MTD partitions into a single concatenated MTD device, based on the "part-concat-next" device tree property. This is useful when a filesystem spans partitions on separate flash devices, such as QSPI/OSPI flashes on different chip selects.
The property is set on the first partition of a group and lists the phandles of the other partitions of the group, as described in dts/upstream/Bindings/mtd/partitions/partition.yaml. Only partitions under a fixed-partitions node are supported, since those are the ones which have a device tree node when they are created; partitions from mtdparts do not. There can be several groups, each with two or more partitions.
Each time the MTD devices are probed, the device tree is scanned for groups which do not exist yet. While the partitions are added, those which belong to a group are held back instead of being registered, and so that partitions are found by their device tree node, the node is now recorded in each partition's flash_node. Once all the devices are probed, the partitions of each complete group are joined into one MTD device, named by joining their labels with '-' and appending '-concat' (e.g. "rootfs_a-rootfs_b-rootfs_c-concat"). Only the concatenated device is registered, as the individual partitions are not normally needed.
An invalid "part-concat-next" property only causes a warning, and the group is ignored. If a group is incomplete, or cannot be joined, a warning is printed and its partitions are registered individually. A partition which is out of reach, and so has no size, makes its group incomplete.
A concatenated device is kept when the MTD devices are probed again, and the partitions which belong to it are not created again, so it can be used while the other partitions of its flash devices are scanned. It is destroyed, and the partitions it holds are freed, when a device it uses is removed, which del_mtd_device() takes care of for every kind of flash, or when mtdparts defines the partitions of such a device, since they replace the device tree ones. A concatenated device which is still in use is never destroyed: the device it uses cannot be removed, as when one of that device's own partitions is in use, and mtdparts is not applied to it, which is tried again each time the MTD devices are probed.
Do not make the option depend on MTD_CONCAT, which also joins NAND and CFI flash chips, which this feature does not need. Build the code of mtdconcat.c for either option instead.
Also drop the reference which parse_mtdparts() holds on a device when it does not replace that device's partitions.
This is based on the Linux MTD virtual concat driver.
---
Changes in v2:
- Depend on MTD_PARTITIONS, and no longer on MTD_CONCAT, which also joins NAND and CFI flash chips, as this is not needed here
- Drop the IS_ENABLED() checks and rely on the stubs in concat.h
- Drop the forward declaration
- Use ofnode_find_node_with_property() from ofnode
- Warn about an invalid part-concat-next property and drop the unreachable -EINVAL path
- Register the partitions of an incomplete group, or of a group which cannot be joined, individually with a warning, instead of dropping them or rolling back all groups
- Do not concatenate a partition which is out of reach, or which is found more than once
- Use a single helper to free a group, which checks del_mtd_device() and keeps a concat device that is still in use
- Free the member partitions and their names, fixing a leak on rescan
- Keep a concat device when the MTD devices are probed again, instead of destroying it and creating it each time, and do not create its partitions again; destroy it only when a device it uses is removed, or when mtdparts replaces the partitions of that device
- Do not apply mtdparts to a device while a concat device which uses it is in use, and try again next time
- Destroy the concat devices which use a device from del_mtd_device(), so that it covers every kind of flash, instead of from mtd_device_unregister(), which is not built for U-Boot. Match on the members' parent, do not re-register the members, and carry on past a concat device which is in use
- Drop the reference which parse_mtdparts() holds on a device it leaves alone
- Record the DT node in flash_node for all partitions, and drop mtd_get_node() and mtd_is_part_concat()
- Refer to the merged Linux commit instead of the v17 series
- Rewrite the commit message
MAINTAINERS | 7 + drivers/mtd/Kconfig | 17 ++ drivers/mtd/Makefile | 5 +- drivers/mtd/mtd_uboot.c | 48 +++- drivers/mtd/mtd_virt_concat.c | 457 ++++++++++++++++++++++++++++++++++ drivers/mtd/mtdcore.c | 12 + drivers/mtd/mtdpart.c | 17 ++ include/linux/mtd/concat.h | 86 ++++++- 8 files changed, 645 insertions(+), 4 deletions(-) create mode 100644 drivers/mtd/mtd_virt_concat.c
MAINTAINERS +7 -0
@@ -1318,6 +1318,13 @@ T: git https://git.u-boot-project.org/u-boot/custodians/u-boot-mmc.git F: drivers/mmc/ N: mmc +MTD VIRTUAL CONCAT +M: Padmarao Begari <[email protected]> +M: Amit Kumar Mahapatra <[email protected]> +S: Maintained +F: drivers/mtd/mtd_virt_concat.c +F: include/linux/mtd/concat.h + NETWORK M: Jerome Forissier <[email protected]> S: Maintained
drivers/mtd/Kconfig +17 -0
@@ -32,6 +32,23 @@ config MTD_CONCAT into a single logical device. The larger logical device can then be partitioned. +config MTD_VIRT_CONCAT + bool "Virtual MTD concatenation via Device Tree" + depends on MTD_PARTITIONS && DM && OF_CONTROL + help + Enable virtual concatenation of MTD partitions based on the + "part-concat-next" device tree property. + + Partitions declared in the device tree are transparently joined + into a single logical MTD device. This is useful when a + filesystem spans partitions on separate flash devices, such as + QSPI/OSPI flashes on different chip selects. + + This includes the concatenation support it needs, so it does not + need MTD_CONCAT, which also joins NAND and CFI flash chips. + + If unsure, say N. + config MTD_BLOCK bool "Enable block device access to MTD devices" select BLK
drivers/mtd/Makefile +4 -1
@@ -6,7 +6,10 @@ mtd-$(CONFIG_MTD) += mtdcore.o mtd_uboot.o mtd-$(CONFIG_DM_MTD) += mtd-uclass.o mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o -mtd-$(CONFIG_MTD_CONCAT) += mtdconcat.o +ifneq ($(CONFIG_MTD_CONCAT)$(CONFIG_MTD_VIRT_CONCAT),) +mtd-y += mtdconcat.o +endif +mtd-$(CONFIG_MTD_VIRT_CONCAT) += mtd_virt_concat.o mtd-$(CONFIG_ALTERA_QSPI) += altera_qspi.o mtd-$(CONFIG_FLASH_CFI_DRIVER) += cfi_flash.o mtd-$(CONFIG_FLASH_CFI_MTD) += cfi_mtd.o
drivers/mtd/mtd_uboot.c +46 -2
91 lines not on this page · raw message
drivers/mtd/mtd_virt_concat.c new file +457 -0
457 lines not on this page · raw message
drivers/mtd/mtdcore.c +12 -0
@@ -33,6 +33,7 @@#endif #include <linux/log2.h> +#include <linux/mtd/concat.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h>
@@ -566,6 +567,17 @@ int del_mtd_device(struct mtd_info *mtd)struct mtd_notifier *not;#endif +/* +* Concatenated devices made of partitions of this device must go +* first. If one is still in use, so is this device +*/ + ret =mtd_virt_concat_destroy (mtd); +if (ret) { +debug ("Failed to destroy concat MTD devices using %s (err %d)\n" , + mtd->name, ret); +return ret; + } + ret =del_mtd_partitions (mtd);if (ret) { debug("Failed to delete MTD partitions attached to %s (err %d)\n",
drivers/mtd/mtdpart.c +17 -0
@@ -27,6 +27,7 @@#include <linux/compat.h> #include <ubi_uboot.h> +#include <linux/mtd/concat.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #include <linux/err.h>
@@ -908,6 +909,13 @@ int add_mtd_partitions_of(struct mtd_info *master)if (!ofnode_is_enabled (child))continue ; +/* +* A concatenated device from an earlier scan holds this +* partition already +*/ +if (mtd_virt_concat_is_joined (child)) +continue ; + offset =ofnode_get_addr_size_index_notrans (child,0 , &size);if (offset ==FDT_ADDR_T_NONE ) { debug("Missing partition offset on \"%s\" partition\n",
@@ -940,6 +948,15 @@ int add_mtd_partitions_of(struct mtd_info *master)if (IS_ERR (slave))return PTR_ERR (slave); +/* +* Store the DT node so that mtd_virt_concat_add() can match +* this partition against the concat groups, and let it take +* the partition if it is part of one +*/ + slave->flash_node = child; +if (mtd_virt_concat_add (slave)) +continue ; +mutex_lock (&mtd_partitions_mutex);list_add_tail (&slave->node, &master->partitions);mutex_unlock (&mtd_partitions_mutex);
include/linux/mtd/concat.h +85 -1
95 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 3/7 test: dm: nand: Probe the NAND controller in the test
In reply to Padmarao BegariThe NAND tests use the devices which were registered when U-Boot started. If an earlier test probes the sandbox NAND controller, e.g. by calling mtd_probe_devices(), the controller registers its devices again, in the driver model of that test. When that test finishes, the controller is removed and the devices are unregistered, so the NAND tests which run after it fail, since there are no NAND devices left.
This happens if imagemap_test_mtd_blk runs before the NAND tests, and also with the MTD virtual concat tests, which are added next to the dm suite, ahead of the NAND tests.
Probe the controller in each test, so that the devices are registered in the driver model of the test.
---
Changes in v2:
- New patch: needed so that the new MTD virtual concat tests do not break the NAND tests which run after them
test/dm/nand.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
test/dm/nand.c +10 -0
@@ -3,6 +3,7 @@* Copyright (C) 2023 Sean Anderson <[email protected]> */ +#include <dm.h> #include <nand.h> #include <part.h> #include <rand.h>
@@ -15,6 +16,7 @@static int run_test_nand (struct unit_test_state *uts,int dev,bool end) {nand_erase_options_t opts = { }; +struct udevice *ctrl;struct mtd_info *mtd;size_t length;loff_t size;
@@ -28,6 +30,14 @@ static int run_test_nand(struct unit_test_state *uts, int dev, bool end)/* Seed RNG for bit errors */ srand ((off >>32 ) ^ off ^ ~dev); +/* +* Probe the controller, which registers the NAND devices. Another test +* may have probed it before, in a driver model which is now gone, in +* which case its devices are no longer registered. +*/ +ut_assertok (uclass_get_device_by_driver (UCLASS_MTD , +DM_DRIVER_GET (sand_nand), + &ctrl)); mtd =get_nand_dev_by_index (dev);ut_assertnonnull (mtd); size = mtd->erasesize *4 ;
Signature · 1 line
2.34.1
PATCH v2 4/7 mtd: concat: Fix the lengths in the concat OOB functions
In reply to Padmarao Begariconcat_write_oob() adds the OOB length written to a sub-device to the data length that it returns, instead of the data length, and never counts the OOB length. A write of data which fits in the first sub-device is then reported as not written at all, so the whole length is written again to the next sub-device, from a position past the end of the caller's buffer, and -EINVAL is returned.
Count both lengths, as concat_read_oob() does.
concat_read_oob() also moves the OOB buffer on by the total OOB length read so far, rather than by what the last sub-device read, so it reads into the wrong place when it needs a third sub-device. Fix that too.
---
Changes in v2:
- New patch: fix concat_write_oob() and concat_read_oob(), which made a write to a concatenated NAND device fail
drivers/mtd/mtdconcat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/mtd/mtdconcat.c +3 -2
@@ -285,7 +285,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) devops.ooblen = ops->ooblen - ops->oobretlen;if (!devops.ooblen)return ret; - devops.oobbuf += ops->oobretlen; + devops.oobbuf += devops.oobretlen; } from =0 ;
@@ -318,7 +318,8 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) devops.len = subdev->size - to; err =mtd_write_oob (subdev, to, &devops); - ops->retlen += devops.oobretlen; + ops->retlen += devops.retlen; + ops->oobretlen += devops.oobretlen;if (err)return err;
Signature · 1 line
2.34.1
PATCH v2 5/7 test: dm: Add tests for MTD virtual concat
In reply to Padmarao BegariEnable CONFIG_MTD_VIRT_CONCAT for sandbox and concatenate the unused "nor-spare" partition of spi.bin@0 with a new "nor1-spare" partition on spi.bin@1. Also concatenate two new partitions of spi.bin@1, "nor1-b1" and "nor1-b2", with each other. All the flashes use spi.bin, but the partitions of the first group do not overlap, and the second group is only used to check which devices exist.
Add tests which check that:
- the partitions are joined into one device, and are not registered on their own, while other partitions are
- data written across the boundary between the flashes lands in the right place on each flash
- scanning the partitions again keeps the concatenated devices, and does not leak memory
- a concatenated device which is in use, or a partition of its flash which is in use, does not change when the partitions are scanned, and mtdparts is not applied to a flash while its concatenated device is in use
- destroying the concatenated devices of a flash carries on past one which is in use
- removing a flash destroys its concatenated devices, and the next scan creates them again
- the partitions of an incomplete group are registered individually, and so is one which is out of reach
- a page can be written to a concatenated device made of NAND devices
Most of the tests need the live tree, since the sandbox NAND devices, which are also scanned for partitions, refer to it.
---
Changes in v2:
- New patch: add sandbox tests
checkpatch reports 'Please use a blank line after function/struct/union/enum declarations' for each DM_TEST() line. DM_TEST() is placed directly after its test function, as in the other tests.
MAINTAINERS | 1 + arch/sandbox/dts/test.dts | 23 ++ configs/sandbox_defconfig | 1 + test/dm/Makefile | 1 + test/dm/mtd_concat.c | 543 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 569 insertions(+) create mode 100644 test/dm/mtd_concat.c
MAINTAINERS +1 -0
@@ -1324,6 +1324,7 @@ M: Amit Kumar Mahapatra <[email protected]> S: Maintained F: drivers/mtd/mtd_virt_concat.c F: include/linux/mtd/concat.h +F: test/dm/mtd_concat.c NETWORK M: Jerome Forissier <[email protected]>
arch/sandbox/dts/test.dts +23 -0
@@ -1685,6 +1685,7 @@ partition@100000 { label = "nor-spare"; reg = <0x100000 0x100000>; + part-concat-next = <&nor1_spare>; }; }; };
@@ -1695,6 +1696,28 @@ sandbox,filename = "spi.bin"; spi-cpol; spi-cpha; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + nor1_spare: partition@0 { + label = "nor1-spare"; + reg = <0x0 0x100000>; + }; + + partition@100000 { + label = "nor1-b1"; + reg = <0x100000 0x80000>; + part-concat-next = <&nor1_b2>; + }; + + nor1_b2: partition@180000 { + label = "nor1-b2"; + reg = <0x180000 0x80000>; + }; + }; }; eeprom@3 { reg = <3>;
configs/sandbox_defconfig +1 -0
@@ -264,6 +264,7 @@ CONFIG_MMC_PCI=y CONFIG_MMC_SANDBOX=y CONFIG_MMC_SDHCI=y CONFIG_DM_MTD=y +CONFIG_MTD_VIRT_CONCAT=y CONFIG_MTD_BLOCK=y CONFIG_MTD_RAW_NAND=y CONFIG_SYS_MAX_NAND_DEVICE=8
test/dm/Makefile +1 -0
@@ -90,6 +90,7 @@ obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_MEMORY) += memory.o obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_MMC) += mmc.o +obj-$(CONFIG_MTD_VIRT_CONCAT) += mtd_concat.o obj-$(CONFIG_CMD_MUX) += mux-cmd.o obj-$(CONFIG_MULTIPLEXER) += mux-emul.o obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
test/dm/mtd_concat.c new file +543 -0
543 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 6/7 doc: Add documentation for MTD virtual concat
In reply to Padmarao BegariDescribe how to enable MTD virtual concatenation, the device tree property and its binding, how the concatenated device is named and used, how it interacts with mtdparts, and how it behaves when the MTD devices are probed again, when a group is incomplete and when a flash is removed.
---
Changes in v2:
- New patch: add documentation
MAINTAINERS | 1 + doc/usage/index.rst | 1 + doc/usage/mtd_concat.rst | 146 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 doc/usage/mtd_concat.rst
MAINTAINERS +1 -0
@@ -1322,6 +1322,7 @@ MTD VIRTUAL CONCAT M: Padmarao Begari <[email protected]> M: Amit Kumar Mahapatra <[email protected]> S: Maintained +F: doc/usage/mtd_concat.rst F: drivers/mtd/mtd_virt_concat.c F: include/linux/mtd/concat.h F: test/dm/mtd_concat.c
doc/usage/index.rst +1 -0
@@ -10,6 +10,7 @@ Use U-Boot environment fdt_overlays fit/index + mtd_concat netconsole partitions pxe
doc/usage/mtd_concat.rst new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 7/7 arm64: xilinx: Enable MTD virtual concat
In reply to Padmarao BegariEnable CONFIG_MTD_VIRT_CONCAT in the ZynqMP, Versal, Versal NET and Versal Gen 2 virt defconfigs, so that partitions on separate QSPI/OSPI flash devices can be joined into a single MTD device, for example to let one filesystem span two flashes.
This has no effect on boards whose device tree does not use the "part-concat-next" property.
---
Changes in v2:
- Do not enable CONFIG_MTD_CONCAT, which CONFIG_MTD_VIRT_CONCAT no longer needs
- Reword the commit message
- Keep the Reviewed-by from v1, as this only drops the CONFIG_MTD_CONCAT line
configs/amd_versal2_virt_defconfig | 1 + configs/xilinx_versal_net_virt_defconfig | 1 + configs/xilinx_versal_virt_defconfig | 1 + configs/xilinx_zynqmp_virt_defconfig | 1 + 4 files changed, 4 insertions(+)
configs/amd_versal2_virt_defconfig +1 -0
@@ -120,6 +120,7 @@ CONFIG_MMC_SDHCI_ZYNQ=y CONFIG_ZYNQ_SDHCI_MIN_FREQ=100000 CONFIG_MTD=y CONFIG_DM_MTD=y +CONFIG_MTD_VIRT_CONCAT=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_SPI_FLASH_ISSI=y
configs/xilinx_versal_net_virt_defconfig +1 -0
@@ -98,6 +98,7 @@ CONFIG_MMC_SDHCI_ADMA=y CONFIG_MMC_SDHCI_ZYNQ=y CONFIG_ZYNQ_SDHCI_MIN_FREQ=100000 CONFIG_MTD=y +CONFIG_MTD_VIRT_CONCAT=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_GIGADEVICE=y CONFIG_SPI_FLASH_ISSI=y
configs/xilinx_versal_virt_defconfig +1 -0
@@ -111,6 +111,7 @@ CONFIG_MMC_SDHCI_ZYNQ=y CONFIG_ZYNQ_SDHCI_MIN_FREQ=100000 CONFIG_MTD=y CONFIG_DM_MTD=y +CONFIG_MTD_VIRT_CONCAT=y CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_SOFT_RESET=y CONFIG_SPI_FLASH_SOFT_RESET_ON_BOOT=y
configs/xilinx_zynqmp_virt_defconfig +1 -0
@@ -158,6 +158,7 @@ CONFIG_MMC_HS200_SUPPORT=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_ZYNQ=y CONFIG_DM_MTD=y +CONFIG_MTD_VIRT_CONCAT=y CONFIG_MTD_RAW_NAND=y CONFIG_NAND_ARASAN=y CONFIG_SYS_NAND_ONFI_DETECTION=y
Signature · 1 line
2.34.1
Quoted 265 lines · Padmarao Begari
Some boards have two or more flash devices on separate chip selects (for example QSPI/OSPI flashes) and need a single filesystem or image to span them. This series adds MTD virtual concatenation, where partitions on different flash devices are linked in the device tree with the "part-concat-next" property and exposed as one concatenated MTD device:
flash@0 { partitions { compatible = "fixed-partitions"; part0: partition@0 { label = "flash0-part"; part-concat-next = <&part1>; reg = <0x0 0x800000>; }; }; }; flash@1 { partitions { compatible = "fixed-partitions"; part1: partition@0 { label = "flash1-part"; reg = <0x0 0x800000>; }; }; };With
CONFIG_MTD_VIRT_CONCATenabled, only the concatenated device ("flash0-part-flash1-part-concat") is registered. The member partitions are not registered individually. Multiple concat groups, each with two or more partitions, are supported.This is based on the Linux driver added by
commit43db6366fc2d("mtd: Add driver for concatenating devices"):
https://git.kernel.org/torvalds/c/43db6366fc2dIf a group is incomplete, or cannot be joined, a warning is printed and its partitions are registered individually.
A concatenated device is kept when the partitions are scanned again. It is destroyed when a flash it uses is removed, e.g. by 'sf probe', or when mtdparts defines the partitions of that flash instead of the device tree. It is not destroyed while it is in use: mtdparts is not applied to its flash then, and removing the flash only prints a warning, so it should not be in use when its flash is removed.
On ZynqMP, accessing the flash on CS1 needs the GQSPI chip select fix, which is now sent separately:
"spi:zynqmp_gqspi: Use the device's chip select"
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Patch 7 enables the option for ZynqMP, Versal, Versal NET and Versal Gen 2.
On ZynqMP, the board has two mt25qu512a QSPI flashes on CS0 and CS1. Partition "
rootfs_a" (flash@0, 0x1000000-0x4000000) is concatenated with "rootfs_c" (flash@1, 0x1000000-0x4000000) into a single 96 MiB device, while the remaining partitions on each flash are registered as usual:ZynqMP> mtd list
SF: Detected mt25qu512a with page size 256 Bytes, erase size 64 KiB, total 64 MiB
SF: Detected mt25qu512a with page size 256 Bytes, erase size 64 KiB, total 64 MiB (0): "rootfs_a"
(1): "rootfs_c"
List of MTD devices:
* nor0
- device: flash@0
- parent: spi@ff0f0000
- driver:jedec_spi_nor
- path: /axi/spi@ff0f0000/flash@0
- type: NOR flash
- block size:0x10000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000004000000 : "nor0"
- 0x000000000000-0x000001000000 : "qspi-fsbl-uboot"
* nor1
- device: flash@1
- parent: spi@ff0f0000
- driver:jedec_spi_nor
- path: /axi/spi@ff0f0000/flash@1
- type: NOR flash
- block size:0x10000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000004000000 : "nor1"
- 0x000000000000-0x000001000000 : "rootfs_b"
* rootfs_a-rootfs_c-concat
- type: NOR flash
- block size:0x10000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000006000000 : "rootfs_a-rootfs_c-concat"Erase/write/read-back across the CS0/CS1 boundary at
0x3000000:ZynqMP> mtd erase rootfs_a-rootfs_c-concat 0x02F00000 0x00200000 Erasing 0x02f00000 ... 0x030fffff (32 eraseblock(s)) ZynqMP> mtd write rootfs_a-rootfs_c-concat 0x200000 0x02F00000 0x1E3200 Writing 1978880 byte(s) at offset 0x02f00000 ZynqMP> mw.b 0x5000000 0x00 0x1E3200 ZynqMP> mtd read rootfs_a-rootfs_c-concat 0x5000000 0x02F00000 0x1E3200 Reading 1978880 byte(s) at offset 0x02f00000 ZynqMP> cmp.b 0x200000 0x5000000 0x1E3200 Total of 1978880 byte(s) were the sameOn Versal NET, the board has two mx66uw2g345gx0 OSPI flashes on CS0 and CS1 of the Cadence OSPI controller. Partition "ospi-flash1" (flash@0, 0x200000-0x8000000) is concatenated with "ospi-flash2" (flash@1, 0x0-0x200000) into a single 128 MiB device. This test also used "mtd: spi-nor: Remove
SPI_NOR_OCTAL_DTR_READflag for mx66uw2g345gx0 flash part", which the flashes on this board need and which is not part of this series:Versal NET> mtd list
SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB
SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB
SF: Detected mx25u3235f with page size 256 Bytes, erase size 4 KiB, total 4 MiB (0): "ospi-flash1"
(1): "ospi-flash2"
List of MTD devices:
* nor0
- device: flash@1
- parent: spi@f1010000
- driver:jedec_spi_nor
- path: /axi/spi@f1010000/flash@1
- type: NOR flash
- block size:0x10000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000010000000 : "nor0"
- 0x000000200000-0x000008000000 : "ospi-flash3"
* nor1
- device: flash@0
- parent: spi@f1010000
- driver:jedec_spi_nor
- path: /axi/spi@f1010000/flash@0
- type: NOR flash
- block size:0x10000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000010000000 : "nor1"
- 0x000000000000-0x000000200000 : "ospi-flash0"
* nor2
- device: flash@2
- parent: spi@f1970000
- driver:jedec_spi_nor
- path: /axi/spi@f1970000/flash@2
- type: NOR flash
- block size:0x1000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000000400000 : "nor2"
- 0x000000000000-0x000000080000 : "spi0-flash0"
* ospi-flash1-ospi-flash2-concat
- type: NOR flash
- block size:0x10000bytes
- min I/O:0x1bytes
- 0x000000000000-0x000008000000 : "ospi-flash1-ospi-flash2-concat"Erase/write/read-back across the CS0/CS1 boundary at
0x7e00000, then reading each flash directly to check that each half landed on the right one:Versal NET> mw.b 2000000 cd 200000 Versal NET> mtd erase ospi-flash1-ospi-flash2-concat 7d00000 200000 Erasing 0x07d00000 ... 0x07efffff (32 eraseblock(s)) Versal NET> mtd write ospi-flash1-ospi-flash2-concat 2000000 7d00000 200000 Writing 2097152 byte(s) at offset 0x07d00000 Versal NET> mtd read ospi-flash1-ospi-flash2-concat 3000000 7d00000 200000 Reading 2097152 byte(s) at offset 0x07d00000 Versal NET> cmp.b 2000000 3000000 200000 Total of 2097152 byte(s) were the same Versal NET> sf probe 0:0 SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB Versal NET> sf read 4000000 7f00000 100000 device 0 offset 0x7f00000, size 0x100000 SF: 1048576 bytes @ 0x7f00000 Read: OK Versal NET> cmp.b 2000000 4000000 100000 Total of 1048576 byte(s) were the same Versal NET> sf probe 0:1 SF: Detected mx66uw2g345gx0 with page size 256 Bytes, erase size 64 KiB, total 256 MiB Versal NET> sf read 5000000 0 100000 device 0 offset 0x0, size 0x100000 SF: 1048576 bytes @ 0x0 Read: OK Versal NET> cmp.b 2100000 5000000 100000 Total of 1048576 byte(s) were the sameAfter 'sf probe' re-probed both flashes, the next 'mtd list' printed the concatenated device again, as the scan created it again.
Patch 4 fixes
concat_write_oob()andconcat_read_oob(), which made any write to a concatenated NAND device fail. It is needed to use the new support with NAND partitions.The sandbox tests in patch 5 cover joining, access across the boundary between the flashes, rescanning, flashes and concatenated devices which are in use, removing a flash, incomplete groups and a partition which is out of reach. They also cover patch 4, with a concatenated NAND device. Patch 3 fixes the existing NAND tests, which otherwise fail when they run after a test that probes the MTD devices. Patch 6 adds the documentation, in
doc/usage/mtd_concat.rst.Changes in v2:
- New patch to fix the lengths returned byconcat_write_oob()andconcat_read_oob()
- Drop "mtd: Move structmtd_concatdefinition to header file", which the driver no longer needs
- New patch to move the DFS helpers to ofnode, with tests
- Register the partitions of incomplete or failed groups individually with a warning
- Warn about an invalid part-concat-next property
- Do not concatenate a partition which is out of reach, or which is found more than once
- Free the member partitions when a group is freed, and keep a concat device that is still in use
- Keep a concat device when the partitions are scanned again, and only destroy it when a flash it uses is removed, or when mtdparts replaces the partitions of that flash
- Do not apply mtdparts to a flash while a concat device which uses it is in use
- Fixmtd_virt_concat_destroy(), which never matched, and call it fromdel_mtd_device()so that every kind of flash is covered
- Drop theIS_ENABLED()checks, and depend onMTD_PARTITIONSbut no longer onMTD_CONCAT, which also joins NAND and CFI flash chips
- Refer to the merged Linux commit
- Send the ZynqMP GQSPI fix as a separate patch
- New patch to fix the NAND tests when they run after an MTD test
- New patch with sandbox tests
- New patch with documentation
- Do not enableCONFIG_MTD_CONCATin the defconfigsLink to v1: https://patchwork.ozlabs.org/project/uboot/list/?series=529258
Padmarao Begari (7):
dm: core: Addofnode_find_node_with_property()
mtd: Add virtual concat support via device tree
test: dm: nand: Probe the NAND controller in the test
mtd: concat: Fix the lengths in the concat OOB functions
test: dm: Add tests for MTD virtual concat
doc: Add documentation for MTD virtual concat
arm64: xilinx: Enable MTD virtual concatMAINTAINERS | 9 + arch/sandbox/dts/test.dts | 23 + configs/amd_versal2_virt_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/xilinx_versal_net_virt_defconfig | 1 + configs/xilinx_versal_virt_defconfig | 1 + configs/xilinx_zynqmp_virt_defconfig | 1 + doc/usage/index.rst | 1 + doc/usage/mtd_concat.rst | 146 ++++++ drivers/core/ofnode.c | 31 ++ drivers/mtd/Kconfig | 17 + drivers/mtd/Makefile | 5 +- drivers/mtd/mtd_uboot.c | 48 +- drivers/mtd/mtd_virt_concat.c | 457 +++++++++++++++++++ drivers/mtd/mtdconcat.c | 5 +- drivers/mtd/mtdcore.c | 12 + drivers/mtd/mtdpart.c | 17 + include/dm/ofnode.h | 23 + include/linux/mtd/concat.h | 86 +++- test/dm/Makefile | 1 + test/dm/mtd_concat.c | 543 +++++++++++++++++++++++ test/dm/nand.c | 10 + test/dm/ofnode.c | 55 +++ 23 files changed, 1488 insertions(+), 6 deletions(-)
Quoted 4 lines
create mode 100644
doc/usage/mtd_concat.rstcreate mode 100644drivers/mtd/mtd_virt_concat.ccreate mode 100644test/dm/mtd_concat.c
This work is based on the same work which went to Linux.
CI is passing on this that's why let me apply it and get it to next to see if any issue pops up. Definitely I would like to see someone with SPI experience to review this but it is fine for me.
Applied.
M