Skip to contentSkip to conversation

Introduce mtdblock device

PATCH Superseded Alexey Romanov 2 participants 7 messages Apr 4, 2024 – May 6, 2024

Subsystems (3)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce mtdblock device

Hello!

This series adds support for the mtdblock device, which allows to read/write data block by block. For example, it can now be used for BCB or Android AB command:

  $ bcb load mtd 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers.

---

Changes V1 -> V2 [1]:

- Drop patch [2].
- Add warning if bind NAND mtdblock device.
- Move documentation of mtdblock implementation from commit message to the source code.
- Remove __maybe_unused from mtd partition functions description.
- Use blk_enabled() instead of #ifdefs.

Changes V2 -> V3 [2]:

- Rebased over [3].
- Rename mtd_bread/bwrite -> mtd_blk_read/write.
- Fix GPL-2.0 license short name definiton in headers.
- Add empty line after MTD_ENTRY_NUMBERS define.

Links:

- [1] https://lore.kernel.org/all/[email protected]/
- [2] https://lore.kernel.org/all/[email protected]/
- [3] https://lore.kernel.org/u-boot/[email protected]/T/#u

Alexey Romanov (3):
disk: support MTD partitions
drivers: introduce mtdblock abstraction
spinand: bind mtdblock

 disk/part.c                 |   3 +-
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/Kconfig         |   1 +
 drivers/mtd/Makefile        |   1 +
 drivers/mtd/mtdblock.c      | 227 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/mtdpart.c       |  69 +++++++++++
 drivers/mtd/nand/spi/core.c |  20 ++++
 include/linux/mtd/mtd.h     |  12 ++
 include/part.h              |   3 +
 9 files changed, 336 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/mtdblock.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/3 disk: support MTD partitions

Add new MTD partition driver, which can be useful with mtdblock driver combination.

---
 disk/part.c           |  3 +-
 drivers/mtd/Kconfig   |  1 +
 drivers/mtd/mtdpart.c | 69 +++++++++++++++++++++++++++++++++++++++++++
 include/part.h        |  3 ++
 4 files changed, 75 insertions(+), 1 deletion(-)
disk/part.c +2 -1
index b6b485a637..5ed7dee6fa 100644
@@ -304,7 +304,8 @@ static void print_part_header(const char *type, struct blk_desc *desc)
 	CONFIG_IS_ENABLED(DOS_PARTITION) || \
 	CONFIG_IS_ENABLED(ISO_PARTITION) || \
 	CONFIG_IS_ENABLED(AMIGA_PARTITION) || \
-	CONFIG_IS_ENABLED(EFI_PARTITION)
+	CONFIG_IS_ENABLED(EFI_PARTITION) || \
+	CONFIG_IS_ENABLED(MTD_PARTITIONS)
 	printf("\nPartition Map for %s device %d  --   Partition Type: %s\n\n",
 	       uclass_get_name(desc->uclass_id), desc->devnum, type);
 #endif /* any CONFIG_..._PARTITION */
drivers/mtd/Kconfig +1 -0
index 1902351719..40272f7e50 100644
@@ -2,6 +2,7 @@ menu "MTD Support"
 
 config MTD_PARTITIONS
 	bool
+	select PARTITIONS
 
 config MTD
 	bool "Enable MTD layer"
drivers/mtd/mtdpart.c +69 -0

78 lines not on this page · raw message

include/part.h +3 -0
index db34bc6bb7..85c1b881b9 100644
@@ -30,12 +30,15 @@ struct block_drvr {
 #define PART_TYPE_ISO		0x03
 #define PART_TYPE_AMIGA		0x04
 #define PART_TYPE_EFI		0x05
+#define PART_TYPE_MTD		0x06
 
 /* maximum number of partition entries supported by search */
 #define DOS_ENTRY_NUMBERS	8
 #define ISO_ENTRY_NUMBERS	64
 #define MAC_ENTRY_NUMBERS	64
 #define AMIGA_ENTRY_NUMBERS	8
+#define MTD_ENTRY_NUMBERS	64
+
 /*
  * Type string for U-Boot bootable partitions
  */
Signature · 1 line
2.34.1
#2 lore raw

PATCH v3 2/3 drivers: introduce mtdblock abstraction

In reply to Alexey Romanov

MTD block - abstraction over MTD subsystem, allowing to read and write in blocks using BLK UCLASS.

---
 drivers/block/blk-uclass.c |   1 +
 drivers/mtd/Makefile       |   1 +
 drivers/mtd/mtdblock.c     | 227 +++++++++++++++++++++++++++++++++++++
 include/linux/mtd/mtd.h    |  12 ++
 4 files changed, 241 insertions(+)
 create mode 100644 drivers/mtd/mtdblock.c
drivers/block/blk-uclass.c +1 -0
index 77066da352..ab0a9105c9 100644
@@ -37,6 +37,7 @@ static struct {
 	{ UCLASS_PVBLOCK, "pvblock" },
 	{ UCLASS_BLKMAP, "blkmap" },
 	{ UCLASS_RKMTD, "rkmtd" },
+	{ UCLASS_MTD, "mtd" },
 };
 
 static enum uclass_id uclass_name_to_iftype(const char *uclass_idname)
drivers/mtd/Makefile +1 -0
index c638980ea2..993b122ac4 100644
@@ -26,6 +26,7 @@ obj-y += onenand/
 obj-y += spi/
 obj-$(CONFIG_MTD_UBI) += ubi/
 obj-$(CONFIG_NVMXIP) += nvmxip/
+obj-$(CONFIG_BLK) += mtdblock.o
 
 #SPL/TPL build
 else
drivers/mtd/mtdblock.c new file +227 -0

227 lines not on this page · raw message

include/linux/mtd/mtd.h +12 -0
index 09f5269887..9b997fadd1 100644
@@ -26,6 +26,9 @@
 #include <dm/device.h>
 #endif
 #include <dm/ofnode.h>
+#if IS_ENABLED(CONFIG_BLK)
+#include <blk.h>
+#endif
 
 #define MAX_MTD_DEVICES 32
 #endif
@@ -412,6 +415,15 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
 int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
 		    const u_char *buf);
 
+#if IS_ENABLED(CONFIG_BLK)
+static inline struct mtd_info *blk_desc_to_mtd(struct blk_desc *bdesc)
+{
+	return *((struct mtd_info **)dev_get_priv(bdesc->bdev));
+}
+
+int mtd_bind(struct udevice *dev, struct mtd_info **mtd);
+#endif
+
 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
 int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 3/3 spinand: bind mtdblock

In reply to Alexey Romanov

Bind SPI-NAND driver to MTD block driver.

---
 drivers/mtd/nand/spi/core.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/mtd/nand/spi/core.c +20 -0
index 2a3dbcfcb4..dd880adf31 100644
@@ -36,6 +36,10 @@
 #include <linux/printk.h>
 #endif
 
+struct spinand_plat {
+	struct mtd_info *mtd;
+};
+
 /* SPI NAND index visible in MTD names */
 static int spi_nand_idx;
 
@@ -1174,12 +1178,24 @@ static void spinand_cleanup(struct spinand_device *spinand)
 	kfree(spinand->scratchbuf);
 }
 
+static int spinand_bind(struct udevice *dev)
+{
+	if (blk_enabled()) {
+		struct spinand_plat *plat = dev_get_plat(dev);
+
+		return mtd_bind(dev, &plat->mtd);
+	}
+
+	return 0;
+}
+
 static int spinand_probe(struct udevice *dev)
 {
 	struct spinand_device *spinand = dev_get_priv(dev);
 	struct spi_slave *slave = dev_get_parent_priv(dev);
 	struct mtd_info *mtd = dev_get_uclass_priv(dev);
 	struct nand_device *nand = spinand_to_nand(spinand);
+	struct spinand_plat *plat = dev_get_plat(dev);
 	int ret;
 
 #ifndef __UBOOT__
@@ -1219,6 +1235,8 @@ static int spinand_probe(struct udevice *dev)
 	if (ret)
 		goto err_spinand_cleanup;
 
+	plat->mtd = mtd;
+
 	return 0;
 
 err_spinand_cleanup:
@@ -1288,6 +1306,8 @@ U_BOOT_DRIVER(spinand) = {
 	.of_match = spinand_ids,
 	.priv_auto	= sizeof(struct spinand_device),
 	.probe = spinand_probe,
+	.bind = spinand_bind,
+	.plat_auto = sizeof(struct spinand_plat),
 };
 
 void board_nand_init(void)
Signature · 1 line
2.34.1
#4 lore raw
In reply to Alexey Romanov

Hello! Ping.

Quoted 56 lines · Alexey Romanov

Hello!

This series adds support for the mtdblock device, which allows to read/write data block by block. For example, it can now be used for BCB or Android AB command:

  $ bcb load mtd 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers.

---

Changes V1 -> V2 [1]:

- Drop patch [2].
- Add warning if bind NAND mtdblock device.
- Move documentation of mtdblock implementation from commit message to the source code.
- Remove __maybe_unused from mtd partition functions description.
- Use blk_enabled() instead of #ifdefs.

Changes V2 -> V3 [2]:

- Rebased over [3].
- Rename mtd_bread/bwrite -> mtd_blk_read/write.
- Fix GPL-2.0 license short name definiton in headers.
- Add empty line after MTD_ENTRY_NUMBERS define.

Links:

- [1] https://lore.kernel.org/all/[email protected]/
- [2] https://lore.kernel.org/all/[email protected]/
- [3] https://lore.kernel.org/u-boot/[email protected]/T/#u

Alexey Romanov (3):
disk: support MTD partitions
drivers: introduce mtdblock abstraction
spinand: bind mtdblock

 disk/part.c                 |   3 +-
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/Kconfig         |   1 +
 drivers/mtd/Makefile        |   1 +
 drivers/mtd/mtdblock.c      | 227 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/mtdpart.c       |  69 +++++++++++
 drivers/mtd/nand/spi/core.c |  20 ++++
 include/linux/mtd/mtd.h     |  12 ++
 include/part.h              |   3 +
 9 files changed, 336 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/mtdblock.c
Signature · 1 line
2.34.1
Signature · 2 lines
Thank you,
Alexey
#5 lore raw

Hi

I will review tomorrow, I need have a time window to test even on my board

Mihcael

Quoted 64 lines · Alexey Romanov

Hello! Ping.

Quoted 53 lines · Alexey Romanov

Hello!

This series adds support for the mtdblock device, which allows to read/write data block by block. For example, it can now be used for BCB or Android AB command:

  $ bcb load mtd 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers.

---

Changes V1 -> V2 [1]:

- Drop patch [2].
- Add warning if bind NAND mtdblock device.
- Move documentation of mtdblock implementation from commit message to the source code.
- Remove __maybe_unused from mtd partition functions description.
- Use blk_enabled() instead of #ifdefs.

Changes V2 -> V3 [2]:

- Rebased over [3].
- Rename mtd_bread/bwrite -> mtd_blk_read/write.
- Fix GPL-2.0 license short name definiton in headers.
- Add empty line after MTD_ENTRY_NUMBERS define.

Links:

- [1] https://lore.kernel.org/all/[email protected]/
- [2] https://lore.kernel.org/all/[email protected]/
- [3] https://lore.kernel.org/u-boot/[email protected]/T/#u

Alexey Romanov (3):
disk: support MTD partitions
drivers: introduce mtdblock abstraction
spinand: bind mtdblock

 disk/part.c                 |   3 +-
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/Kconfig         |   1 +
 drivers/mtd/Makefile        |   1 +
 drivers/mtd/mtdblock.c      | 227 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/mtdpart.c       |  69 +++++++++++
 drivers/mtd/nand/spi/core.c |  20 ++++
 include/linux/mtd/mtd.h     |  12 ++
 include/part.h              |   3 +
 9 files changed, 336 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/mtdblock.c
Quoted 3 lines

--
2.34.1

--
Thank you,
Alexey

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#6 lore raw

Hello Michael,

Quoted 3 lines · Michael Nazzareno Trimarchi

Hi

I will review tomorrow, I need have a time window to test even on my board

Any news?

Quoted 84 lines

Mihcael

Quoted 64 lines · Alexey Romanov

Hello! Ping.

Quoted 53 lines · Alexey Romanov

Hello!

This series adds support for the mtdblock device, which allows to read/write data block by block. For example, it can now be used for BCB or Android AB command:

  $ bcb load mtd 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers.

---

Changes V1 -> V2 [1]:

- Drop patch [2].
- Add warning if bind NAND mtdblock device.
- Move documentation of mtdblock implementation from commit message to the source code.
- Remove __maybe_unused from mtd partition functions description.
- Use blk_enabled() instead of #ifdefs.

Changes V2 -> V3 [2]:

- Rebased over [3].
- Rename mtd_bread/bwrite -> mtd_blk_read/write.
- Fix GPL-2.0 license short name definiton in headers.
- Add empty line after MTD_ENTRY_NUMBERS define.

Links:

- [1] https://lore.kernel.org/all/[email protected]/
- [2] https://lore.kernel.org/all/[email protected]/
- [3] https://lore.kernel.org/u-boot/[email protected]/T/#u

Alexey Romanov (3):
disk: support MTD partitions
drivers: introduce mtdblock abstraction
spinand: bind mtdblock

 disk/part.c                 |   3 +-
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/Kconfig         |   1 +
 drivers/mtd/Makefile        |   1 +
 drivers/mtd/mtdblock.c      | 227 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/mtdpart.c       |  69 +++++++++++
 drivers/mtd/nand/spi/core.c |  20 ++++
 include/linux/mtd/mtd.h     |  12 ++
 include/part.h              |   3 +
 9 files changed, 336 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/mtdblock.c
Quoted 3 lines

--
2.34.1

--
Thank you,
Alexey

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Signature · 2 lines
Thank you,
Alexey