All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Introduce UBI block device
@ 2024-03-25 14:41 Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 1/6] ubi: allow to read from volume with offset Alexey Romanov
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

Hello!

This series adds support for the UBI block 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 ubi 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers. Can be used with mtdblock device [1].

--- 

Changes V1 -> V2 [2]:

 - Rebased over mtdblock v2 patchset [3].
 - Compile UBI partitions support only if CONFIG_BLK option
   is enabled.

- Links:

  [1] https://lore.kernel.org/all/20240227100441.1811047-1-avromanov@salutedevices.com/
  [2] https://lore.kernel.org/all/20240306134906.1179285-1-avromanov@salutedevices.com/
  [3] https://lore.kernel.org/all/20240307130726.1582487-1-avromanov@salutedevices.com/

Alexey Romanov (6):
  ubi: allow to read from volume with offset
  ubi: allow to write to volume with offset
  drivers: introduce UBI block abstraction
  disk: don't try search for partition type if already set
  disk: support UBI partitions
  spinand: bind UBI block

 cmd/ubi.c                   |  77 +++++++++++++++++++--
 disk/part.c                 |   7 ++
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/nand/spi/core.c |   8 ++-
 drivers/mtd/ubi/Makefile    |   1 +
 drivers/mtd/ubi/block.c     | 130 ++++++++++++++++++++++++++++++++++++
 drivers/mtd/ubi/part.c      |  99 +++++++++++++++++++++++++++
 env/ubi.c                   |  16 ++---
 include/part.h              |   2 +
 include/ubi_uboot.h         |   8 ++-
 10 files changed, 332 insertions(+), 17 deletions(-)
 create mode 100644 drivers/mtd/ubi/block.c
 create mode 100644 drivers/mtd/ubi/part.c

-- 
2.34.1


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

* [PATCH v2 1/6] ubi: allow to read from volume with offset
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
@ 2024-03-25 14:41 ` Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 2/6] ubi: allow to write to " Alexey Romanov
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

Now user can pass an additional parameter 'offset'
to ubi_volume_read() function.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
Acked-by: Heiko Schocher <hs@denx.de>
---
 cmd/ubi.c           | 6 +++---
 env/ubi.c           | 6 +++---
 include/ubi_uboot.h | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 0a6a80bdd1..2257f68498 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -420,13 +420,13 @@ int ubi_volume_write(char *volume, void *buf, size_t size)
 	return ubi_volume_begin_write(volume, buf, size, size);
 }
 
-int ubi_volume_read(char *volume, char *buf, size_t size)
+int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
 {
 	int err, lnum, off, len, tbuf_size;
 	void *tbuf;
 	unsigned long long tmp;
 	struct ubi_volume *vol;
-	loff_t offp = 0;
+	loff_t offp = offset;
 	size_t len_read;
 
 	vol = ubi_find_volume(volume);
@@ -787,7 +787,7 @@ static int do_ubi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		}
 
 		if (argc == 3) {
-			return ubi_volume_read(argv[3], (char *)addr, size);
+			return ubi_volume_read(argv[3], (char *)addr, 0, size);
 		}
 	}
 
diff --git a/env/ubi.c b/env/ubi.c
index 445d34fedb..661801d5a9 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -135,13 +135,13 @@ static int env_ubi_load(void)
 		return -EIO;
 	}
 
-	read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
+	read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1, 0,
 				     CONFIG_ENV_SIZE);
 	if (read1_fail)
 		printf("\n** Unable to read env from %s:%s **\n",
 		       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
 
-	read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND,
+	read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND, 0,
 				     (void *)tmp_env2, CONFIG_ENV_SIZE);
 	if (read2_fail)
 		printf("\n** Unable to read redundant env from %s:%s **\n",
@@ -172,7 +172,7 @@ static int env_ubi_load(void)
 		return -EIO;
 	}
 
-	if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
+	if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, 0, CONFIG_ENV_SIZE)) {
 		printf("\n** Unable to read env from %s:%s **\n",
 		       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
 		env_set_default(NULL, 0);
diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h
index 6da348eb62..bcccb76e6c 100644
--- a/include/ubi_uboot.h
+++ b/include/ubi_uboot.h
@@ -50,7 +50,7 @@ extern int ubi_init(void);
 extern void ubi_exit(void);
 extern int ubi_part(char *part_name, const char *vid_header_offset);
 extern int ubi_volume_write(char *volume, void *buf, size_t size);
-extern int ubi_volume_read(char *volume, char *buf, size_t size);
+extern int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size);
 
 extern struct ubi_device *ubi_devices[];
 int cmd_ubifs_mount(char *vol_name);
-- 
2.34.1


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

* [PATCH v2 2/6] ubi: allow to write to volume with offset
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 1/6] ubi: allow to read from volume with offset Alexey Romanov
@ 2024-03-25 14:41 ` Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 3/6] drivers: introduce UBI block abstraction Alexey Romanov
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

Introduce ubi_volume_offset_write() helper, which
allow to write to ubi volume with specified offset.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
Acked-by: Heiko Schocher <hs@denx.de>
---
 cmd/ubi.c           | 71 +++++++++++++++++++++++++++++++++++++++++++--
 env/ubi.c           | 10 +++----
 include/ubi_uboot.h |  2 +-
 3 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 2257f68498..af874b6a46 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -415,9 +415,74 @@ int ubi_volume_begin_write(char *volume, void *buf, size_t size,
 	return ubi_volume_continue_write(volume, buf, size);
 }
 
-int ubi_volume_write(char *volume, void *buf, size_t size)
+static int ubi_volume_offset_write(char *volume, void *buf, loff_t offset,
+				   size_t size)
 {
-	return ubi_volume_begin_write(volume, buf, size, size);
+	int lnum, len, tbuf_size, ret;
+	struct ubi_volume *vol;
+	loff_t off = offset;
+	void *tbuf;
+
+	vol = ubi_find_volume(volume);
+	if (!vol)
+		return -ENODEV;
+
+	if (size > vol->reserved_pebs * (ubi->leb_size - vol->data_pad))
+		return -EINVAL;
+
+	tbuf_size = vol->usable_leb_size;
+	tbuf = malloc_cache_aligned(tbuf_size);
+	if (!tbuf)
+		return -ENOMEM;
+
+	lnum = off;
+	off = do_div(lnum, vol->usable_leb_size);
+
+	do {
+		struct ubi_volume_desc desc = {
+			.vol = vol,
+			.mode = UBI_READWRITE,
+		};
+
+		len = size > tbuf_size ? tbuf_size : size;
+		if (off + len >= vol->usable_leb_size)
+			len = vol->usable_leb_size - off;
+
+		ret = ubi_read(&desc, lnum, tbuf, 0, tbuf_size);
+		if (ret) {
+			pr_err("Failed to read leb %d (%d)\n", lnum, ret);
+			goto exit;
+		}
+
+		memcpy(tbuf + off, buf, len);
+
+		ret = ubi_leb_change(&desc, lnum, tbuf, tbuf_size);
+		if (ret) {
+			pr_err("Failed to write leb %d(%d)\n", lnum, ret);
+			goto exit;
+		}
+
+		off += len;
+		if (off >= vol->usable_leb_size) {
+			lnum++;
+			off -= vol->usable_leb_size;
+		}
+
+		buf += len;
+		size -= len;
+	} while (size);
+
+exit:
+	free(tbuf);
+	return ret;
+}
+
+int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size)
+{
+	if (!offset)
+		return ubi_volume_begin_write(volume, buf, size, size);
+
+	return ubi_volume_offset_write(volume, buf, offset, size);
 }
 
 int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
@@ -761,7 +826,7 @@ static int do_ubi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 						(void *)addr, size, full_size);
 			}
 		} else {
-			ret = ubi_volume_write(argv[3], (void *)addr, size);
+			ret = ubi_volume_write(argv[3], (void *)addr, 0, size);
 		}
 		if (!ret) {
 			printf("%lld bytes written to volume %s\n", size,
diff --git a/env/ubi.c b/env/ubi.c
index 661801d5a9..6ae74a500b 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -54,7 +54,7 @@ static int env_ubi_save(void)
 	if (gd->env_valid == ENV_VALID) {
 		puts("Writing to redundant UBI... ");
 		if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND,
-				     (void *)env_new, CONFIG_ENV_SIZE)) {
+				     (void *)env_new, 0, CONFIG_ENV_SIZE)) {
 			printf("\n** Unable to write env to %s:%s **\n",
 			       CONFIG_ENV_UBI_PART,
 			       CONFIG_ENV_UBI_VOLUME_REDUND);
@@ -63,7 +63,7 @@ static int env_ubi_save(void)
 	} else {
 		puts("Writing to UBI... ");
 		if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
-				     (void *)env_new, CONFIG_ENV_SIZE)) {
+				     (void *)env_new, 0, CONFIG_ENV_SIZE)) {
 			printf("\n** Unable to write env to %s:%s **\n",
 			       CONFIG_ENV_UBI_PART,
 			       CONFIG_ENV_UBI_VOLUME);
@@ -93,7 +93,7 @@ static int env_ubi_save(void)
 		return 1;
 	}
 
-	if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new,
+	if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new, 0,
 			     CONFIG_ENV_SIZE)) {
 		printf("\n** Unable to write env to %s:%s **\n",
 		       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
@@ -197,7 +197,7 @@ static int env_ubi_erase(void)
 	memset(env_buf, 0x0, CONFIG_ENV_SIZE);
 
 	if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
-			     (void *)env_buf, CONFIG_ENV_SIZE)) {
+			     (void *)env_buf, 0, CONFIG_ENV_SIZE)) {
 		printf("\n** Unable to erase env to %s:%s **\n",
 		       CONFIG_ENV_UBI_PART,
 		       CONFIG_ENV_UBI_VOLUME);
@@ -205,7 +205,7 @@ static int env_ubi_erase(void)
 	}
 	if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
 		if (ubi_volume_write(ENV_UBI_VOLUME_REDUND,
-				     (void *)env_buf, CONFIG_ENV_SIZE)) {
+				     (void *)env_buf, 0, CONFIG_ENV_SIZE)) {
 			printf("\n** Unable to erase env to %s:%s **\n",
 			       CONFIG_ENV_UBI_PART,
 			       ENV_UBI_VOLUME_REDUND);
diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h
index bcccb76e6c..5f046b91a2 100644
--- a/include/ubi_uboot.h
+++ b/include/ubi_uboot.h
@@ -49,7 +49,7 @@ extern int ubi_mtd_param_parse(const char *val, struct kernel_param *kp);
 extern int ubi_init(void);
 extern void ubi_exit(void);
 extern int ubi_part(char *part_name, const char *vid_header_offset);
-extern int ubi_volume_write(char *volume, void *buf, size_t size);
+extern int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size);
 extern int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size);
 
 extern struct ubi_device *ubi_devices[];
-- 
2.34.1


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

* [PATCH v2 3/6] drivers: introduce UBI block abstraction
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 1/6] ubi: allow to read from volume with offset Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 2/6] ubi: allow to write to " Alexey Romanov
@ 2024-03-25 14:41 ` Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 4/6] disk: don't try search for partition type if already set Alexey Romanov
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

UBI block is an virtual device, that runs on top
of the MTD layer. The blocks are UBI volumes.
Intended to be used in combination with other MTD
drivers.

Despite the fact that it, like mtdblock abstraction,
it used with UCLASS_MTD, they can be used together
on the system without conflicting. For example,
using bcb command:

  # Trying to load bcb via mtdblock:
  $ bcb load mtd 0 mtd_partition_name

  # Trying to load bcb via UBI block:
  $ bcb load ubi 1 ubi_volume_name

User always must attach UBI layer (for example, using
ubi_part()) before using UBI block device.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
Acked-by: Heiko Schocher <hs@denx.de>
---
 drivers/block/blk-uclass.c |   1 +
 drivers/mtd/ubi/Makefile   |   1 +
 drivers/mtd/ubi/block.c    | 130 +++++++++++++++++++++++++++++++++++++
 include/ubi_uboot.h        |   4 ++
 4 files changed, 136 insertions(+)
 create mode 100644 drivers/mtd/ubi/block.c

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index ab0a9105c9..8a457e9f70 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -38,6 +38,7 @@ static struct {
 	{ UCLASS_BLKMAP, "blkmap" },
 	{ UCLASS_RKMTD, "rkmtd" },
 	{ UCLASS_MTD, "mtd" },
+	{ UCLASS_MTD, "ubi" },
 };
 
 static enum uclass_id uclass_name_to_iftype(const char *uclass_idname)
diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile
index 30d00fbdfe..67b1a05348 100644
--- a/drivers/mtd/ubi/Makefile
+++ b/drivers/mtd/ubi/Makefile
@@ -7,3 +7,4 @@ obj-y += attach.o build.o vtbl.o vmt.o upd.o kapi.o eba.o io.o wl.o crc32.o
 obj-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o
 obj-y += misc.o
 obj-y += debug.o
+obj-$(CONFIG_BLK) += block.o
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
new file mode 100644
index 0000000000..95d5ef5752
--- /dev/null
+++ b/drivers/mtd/ubi/block.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2024 SaluteDevices, Inc.
+ *
+ * Author: Alexey Romanov <avromanov@salutedevices.com>
+ */
+
+#include <blk.h>
+#include <part.h>
+#include <ubi_uboot.h>
+#include <dm/device.h>
+#include <dm/device-internal.h>
+
+int ubi_bind(struct udevice *dev)
+{
+	struct blk_desc *bdesc;
+	struct udevice *bdev;
+	int ret;
+
+	ret = blk_create_devicef(dev, "ubi_blk", "blk", UCLASS_MTD,
+				 dev_seq(dev), 512, 0, &bdev);
+	if (ret) {
+		pr_err("Cannot create block device");
+		return ret;
+	}
+
+	bdesc = dev_get_uclass_plat(bdev);
+
+	bdesc->bdev = bdev;
+	bdesc->part_type = PART_TYPE_UBI;
+
+	return 0;
+}
+
+static struct ubi_device *get_ubi_device(void)
+{
+	return ubi_devices[0];
+}
+
+static char *get_volume_name(int vol_id)
+{
+	struct ubi_device *ubi = get_ubi_device();
+	int i;
+
+	for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+		struct ubi_volume *volume = ubi->volumes[i];
+
+		if (!volume)
+			continue;
+
+		if (volume->vol_id >= UBI_INTERNAL_VOL_START)
+			continue;
+
+		if (volume->vol_id == vol_id)
+			return volume->name;
+	}
+
+	return NULL;
+}
+
+static ulong ubi_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+		       void *dst)
+{
+	struct blk_desc *block_dev = dev_get_uclass_plat(dev);
+	char *volume_name = get_volume_name(block_dev->hwpart);
+	unsigned int size = blkcnt * block_dev->blksz;
+	loff_t offset = start * block_dev->blksz;
+	int ret;
+
+	if (!volume_name) {
+		pr_err("%s: failed to find volume name for blk=%ld", __func__, start);
+		return -EINVAL;
+	}
+
+	ret = ubi_volume_read(volume_name, dst, offset, size);
+	if (ret) {
+		pr_err("%s: failed to read from %s UBI volume\n", __func__, volume_name);
+		return ret;
+	}
+
+	return blkcnt;
+}
+
+static ulong ubi_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+			const void *src)
+{
+	struct blk_desc *block_dev = dev_get_uclass_plat(dev);
+	char *volume_name = get_volume_name(block_dev->hwpart);
+	unsigned int size = blkcnt * block_dev->blksz;
+	loff_t offset = start * block_dev->blksz;
+	int ret;
+
+	if (!volume_name) {
+		pr_err("%s: failed to find volume for blk=%ld", __func__, start);
+		return -EINVAL;
+	}
+
+	ret = ubi_volume_write(volume_name, (void *)src, offset, size);
+	if (ret) {
+		pr_err("%s: failed to write from %s UBI volume\n", __func__, volume_name);
+		return ret;
+	}
+
+	return blkcnt;
+}
+
+static int ubi_blk_probe(struct udevice *dev)
+{
+	int ret;
+
+	ret = device_probe(dev);
+	if (ret) {
+		pr_err("Probing %s failed (err=%d)\n", dev->name, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static const struct blk_ops ubi_blk_ops = {
+	.read = ubi_bread,
+	.write = ubi_bwrite,
+};
+
+U_BOOT_DRIVER(ubi_blk) = {
+	.name = "ubi_blk",
+	.id = UCLASS_BLK,
+	.ops = &ubi_blk_ops,
+	.probe = ubi_blk_probe,
+};
diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h
index 5f046b91a2..ff06d8005d 100644
--- a/include/ubi_uboot.h
+++ b/include/ubi_uboot.h
@@ -56,4 +56,8 @@ extern struct ubi_device *ubi_devices[];
 int cmd_ubifs_mount(char *vol_name);
 int cmd_ubifs_umount(void);
 
+#if IS_ENABLED(CONFIG_BLK)
+int ubi_bind(struct udevice *dev);
+#endif
+
 #endif
-- 
2.34.1


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

* [PATCH v2 4/6] disk: don't try search for partition type if already set
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
                   ` (2 preceding siblings ...)
  2024-03-25 14:41 ` [PATCH v2 3/6] drivers: introduce UBI block abstraction Alexey Romanov
@ 2024-03-25 14:41 ` Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 5/6] disk: support UBI partitions Alexey Romanov
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

Block devices can already set partition type at initialization
stage, so, in this case is no point in searching for partition type.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
---
 disk/part.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index 0fc5cc0419..362c9de609 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -285,6 +285,13 @@ void part_init(struct blk_desc *desc)
 
 	blkcache_invalidate(desc->uclass_id, desc->devnum);
 
+	if (desc->part_type != PART_TYPE_UNKNOWN) {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			if (entry->part_type == desc->part_type && !entry->test(desc))
+				return;
+		}
+	}
+
 	desc->part_type = PART_TYPE_UNKNOWN;
 	for (entry = drv; entry != drv + n_ents; entry++) {
 		int ret;
-- 
2.34.1


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

* [PATCH v2 5/6] disk: support UBI partitions
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
                   ` (3 preceding siblings ...)
  2024-03-25 14:41 ` [PATCH v2 4/6] disk: don't try search for partition type if already set Alexey Romanov
@ 2024-03-25 14:41 ` Alexey Romanov
  2024-03-25 14:41 ` [PATCH v2 6/6] spinand: bind UBI block Alexey Romanov
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

UBI partition is abstraction over UBI volumes.
Can be used by UBI block device.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
---
 drivers/mtd/ubi/Makefile |  2 +-
 drivers/mtd/ubi/part.c   | 99 ++++++++++++++++++++++++++++++++++++++++
 include/part.h           |  2 +
 3 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/ubi/part.c

diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile
index 67b1a05348..63dc428813 100644
--- a/drivers/mtd/ubi/Makefile
+++ b/drivers/mtd/ubi/Makefile
@@ -7,4 +7,4 @@ obj-y += attach.o build.o vtbl.o vmt.o upd.o kapi.o eba.o io.o wl.o crc32.o
 obj-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o
 obj-y += misc.o
 obj-y += debug.o
-obj-$(CONFIG_BLK) += block.o
+obj-$(CONFIG_BLK) += block.o part.o
diff --git a/drivers/mtd/ubi/part.c b/drivers/mtd/ubi/part.c
new file mode 100644
index 0000000000..8dd7b874af
--- /dev/null
+++ b/drivers/mtd/ubi/part.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2024 SaluteDevices, Inc.
+ *
+ * Author: Alexey Romanov <avromanov@salutedevices.com>
+ */
+
+#include <memalign.h>
+#include <part.h>
+#include <ubi_uboot.h>
+
+static inline struct ubi_device *get_ubi_device(void)
+{
+	return ubi_devices[0];
+}
+
+static struct ubi_volume *ubi_get_volume_by_index(int vol_id)
+{
+	struct ubi_device *ubi = get_ubi_device();
+	int i;
+
+	for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+		struct ubi_volume *volume = ubi->volumes[i];
+
+		if (!volume)
+			continue;
+
+		if (volume->vol_id >= UBI_INTERNAL_VOL_START)
+			continue;
+
+		if (volume->vol_id == vol_id)
+			return volume;
+	}
+
+	return NULL;
+}
+
+static int __maybe_unused part_get_info_ubi(struct blk_desc *dev_desc, int part_idx,
+					    struct disk_partition *info)
+{
+	struct ubi_volume *vol;
+
+	/*
+	 * We must use part_idx - 1 instead of part_idx, because
+	 * part_get_info_by_name() start indexing at 1, not 0.
+	 * ubi volumes idexed starting at 0
+	 */
+	vol = ubi_get_volume_by_index(part_idx - 1);
+	if (!vol)
+		return 0;
+
+	snprintf(info->name, PART_NAME_LEN, vol->name);
+
+	info->start = 0;
+	info->size = vol->used_bytes / dev_desc->blksz;
+	info->blksz = dev_desc->blksz;
+
+	/* Save UBI volume ID in blk device descriptor */
+	dev_desc->hwpart = vol->vol_id;
+
+	return 0;
+}
+
+static void __maybe_unused part_print_ubi(struct blk_desc *dev_desc)
+{
+	struct ubi_device *ubi = get_ubi_device();
+	int i;
+
+	for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+		struct ubi_volume *volume = ubi->volumes[i];
+
+		if (!volume)
+			continue;
+
+		if (volume->vol_id >= UBI_INTERNAL_VOL_START)
+			continue;
+
+		printf("%d: %s\n", volume->vol_id, volume->name);
+	}
+}
+
+static int part_test_ubi(struct blk_desc *dev_desc)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+
+	if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
+		return -1;
+
+	return 0;
+}
+
+U_BOOT_PART_TYPE(ubi) = {
+	.name	= "ubi",
+	.part_type	= PART_TYPE_UBI,
+	.max_entries	= UBI_ENTRY_NUMBERS,
+	.get_info	= part_get_info_ptr(part_get_info_ubi),
+	.print	= part_print_ptr(part_print_ubi),
+	.test	= part_test_ubi,
+};
diff --git a/include/part.h b/include/part.h
index f7f3773a95..10db874e3b 100644
--- a/include/part.h
+++ b/include/part.h
@@ -31,6 +31,7 @@ struct block_drvr {
 #define PART_TYPE_AMIGA		0x04
 #define PART_TYPE_EFI		0x05
 #define PART_TYPE_MTD		0x06
+#define PART_TYPE_UBI		0x07
 
 /* maximum number of partition entries supported by search */
 #define DOS_ENTRY_NUMBERS	8
@@ -38,6 +39,7 @@ struct block_drvr {
 #define MAC_ENTRY_NUMBERS	64
 #define AMIGA_ENTRY_NUMBERS	8
 #define MTD_ENTRY_NUMBERS	64
+#define UBI_ENTRY_NUMBERS	UBI_MAX_VOLUMES
 /*
  * Type string for U-Boot bootable partitions
  */
-- 
2.34.1


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

* [PATCH v2 6/6] spinand: bind UBI block
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
                   ` (4 preceding siblings ...)
  2024-03-25 14:41 ` [PATCH v2 5/6] disk: support UBI partitions Alexey Romanov
@ 2024-03-25 14:41 ` Alexey Romanov
  2024-04-03 15:49   ` Frieder Schrempf
  2024-04-04  3:23   ` Chuanhong Guo
  2024-03-26  4:21 ` [PATCH v2 0/6] Introduce UBI block device Heiko Schocher
  2024-05-06 13:58 ` Alexey Romanov
  7 siblings, 2 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-03-25 14:41 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot, Alexey Romanov

UBI block is virtual block device, which is an abstraction
over MTD layer. Therefore it is logical to use it in combination
with MTD drivers.

Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
---
 drivers/mtd/nand/spi/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index dd880adf31..c47f6c1b46 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -27,6 +27,7 @@
 #include <watchdog.h>
 #include <spi.h>
 #include <spi-mem.h>
+#include <ubi_uboot.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
 #include <dm/uclass.h>
@@ -1182,8 +1183,13 @@ static int spinand_bind(struct udevice *dev)
 {
 	if (blk_enabled()) {
 		struct spinand_plat *plat = dev_get_plat(dev);
+		int ret;
+
+		ret = mtd_bind(dev, &plat->mtd);
+		if (ret)
+			return ret;
 
-		return mtd_bind(dev, &plat->mtd);
+		return ubi_bind(dev);
 	}
 
 	return 0;
-- 
2.34.1


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

* Re: [PATCH v2 0/6] Introduce UBI block device
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
                   ` (5 preceding siblings ...)
  2024-03-25 14:41 ` [PATCH v2 6/6] spinand: bind UBI block Alexey Romanov
@ 2024-03-26  4:21 ` Heiko Schocher
  2024-04-03  8:44   ` Alexey Romanov
  2024-05-06 13:58 ` Alexey Romanov
  7 siblings, 1 reply; 16+ messages in thread
From: Heiko Schocher @ 2024-03-26  4:21 UTC (permalink / raw)
  To: Alexey Romanov, dario.binacchi
  Cc: kernel, u-boot, michael, frieder.schrempf, kmpark,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan

Hello Alexey,

On 25.03.24 15:41, Alexey Romanov wrote:
> Hello!
> 
> This series adds support for the UBI block 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 ubi 0 part_name
> 
> Tested only on SPI NAND, so bind is made only for
> SPI NAND drivers. Can be used with mtdblock device [1].
> 
> ---
> 
> Changes V1 -> V2 [2]:
> 
>   - Rebased over mtdblock v2 patchset [3].
>   - Compile UBI partitions support only if CONFIG_BLK option
>     is enabled.

Thanks!

> - Links:
> 
>    [1] https://lore.kernel.org/all/20240227100441.1811047-1-avromanov@salutedevices.com/
>    [2] https://lore.kernel.org/all/20240306134906.1179285-1-avromanov@salutedevices.com/
>    [3] https://lore.kernel.org/all/20240307130726.1582487-1-avromanov@salutedevices.com/
> 
> Alexey Romanov (6):
>    ubi: allow to read from volume with offset
>    ubi: allow to write to volume with offset
>    drivers: introduce UBI block abstraction
>    disk: don't try search for partition type if already set
>    disk: support UBI partitions
>    spinand: bind UBI block
> 
>   cmd/ubi.c                   |  77 +++++++++++++++++++--
>   disk/part.c                 |   7 ++
>   drivers/block/blk-uclass.c  |   1 +
>   drivers/mtd/nand/spi/core.c |   8 ++-
>   drivers/mtd/ubi/Makefile    |   1 +
>   drivers/mtd/ubi/block.c     | 130 ++++++++++++++++++++++++++++++++++++
>   drivers/mtd/ubi/part.c      |  99 +++++++++++++++++++++++++++
>   env/ubi.c                   |  16 ++---
>   include/part.h              |   2 +
>   include/ubi_uboot.h         |   8 ++-
>   10 files changed, 332 insertions(+), 17 deletions(-)
>   create mode 100644 drivers/mtd/ubi/block.c
>   create mode 100644 drivers/mtd/ubi/part.c

Looks good to me now.

@Dario: I saw that series is delegetad to you in patchwork.
  From my side it is fine. If you think I should  pick it up, please
  send a Reviewed/Acked-by for the SPI NAND parts, and notify me,
  thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

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

* Re: [PATCH v2 0/6] Introduce UBI block device
  2024-03-26  4:21 ` [PATCH v2 0/6] Introduce UBI block device Heiko Schocher
@ 2024-04-03  8:44   ` Alexey Romanov
  0 siblings, 0 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-04-03  8:44 UTC (permalink / raw)
  To: Heiko Schocher, dario.binacchi
  Cc: kernel, u-boot, michael, frieder.schrempf, kmpark,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan

Hi guys! Ping.

On Tue, Mar 26, 2024 at 05:21:29AM +0100, Heiko Schocher wrote:
> Hello Alexey,
> 
> On 25.03.24 15:41, Alexey Romanov wrote:
> > Hello!
> > 
> > This series adds support for the UBI block 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 ubi 0 part_name
> > 
> > Tested only on SPI NAND, so bind is made only for
> > SPI NAND drivers. Can be used with mtdblock device [1].
> > 
> > ---
> > 
> > Changes V1 -> V2 [2]:
> > 
> >   - Rebased over mtdblock v2 patchset [3].
> >   - Compile UBI partitions support only if CONFIG_BLK option
> >     is enabled.
> 
> Thanks!
> 
> > - Links:
> > 
> >    [1] https://lore.kernel.org/all/20240227100441.1811047-1-avromanov@salutedevices.com/
> >    [2] https://lore.kernel.org/all/20240306134906.1179285-1-avromanov@salutedevices.com/
> >    [3] https://lore.kernel.org/all/20240307130726.1582487-1-avromanov@salutedevices.com/
> > 
> > Alexey Romanov (6):
> >    ubi: allow to read from volume with offset
> >    ubi: allow to write to volume with offset
> >    drivers: introduce UBI block abstraction
> >    disk: don't try search for partition type if already set
> >    disk: support UBI partitions
> >    spinand: bind UBI block
> > 
> >   cmd/ubi.c                   |  77 +++++++++++++++++++--
> >   disk/part.c                 |   7 ++
> >   drivers/block/blk-uclass.c  |   1 +
> >   drivers/mtd/nand/spi/core.c |   8 ++-
> >   drivers/mtd/ubi/Makefile    |   1 +
> >   drivers/mtd/ubi/block.c     | 130 ++++++++++++++++++++++++++++++++++++
> >   drivers/mtd/ubi/part.c      |  99 +++++++++++++++++++++++++++
> >   env/ubi.c                   |  16 ++---
> >   include/part.h              |   2 +
> >   include/ubi_uboot.h         |   8 ++-
> >   10 files changed, 332 insertions(+), 17 deletions(-)
> >   create mode 100644 drivers/mtd/ubi/block.c
> >   create mode 100644 drivers/mtd/ubi/part.c
> 
> Looks good to me now.
> 
> @Dario: I saw that series is delegetad to you in patchwork.
>  From my side it is fine. If you think I should  pick it up, please
>  send a Reviewed/Acked-by for the SPI NAND parts, and notify me,
>  thanks!
> 
> bye,
> Heiko
> -- 
> DENX Software Engineering GmbH,      Managing Director: Erika Unter
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

-- 
Thank you,
Alexey

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

* Re: [PATCH v2 6/6] spinand: bind UBI block
  2024-03-25 14:41 ` [PATCH v2 6/6] spinand: bind UBI block Alexey Romanov
@ 2024-04-03 15:49   ` Frieder Schrempf
  2024-04-04  3:23   ` Chuanhong Guo
  1 sibling, 0 replies; 16+ messages in thread
From: Frieder Schrempf @ 2024-04-03 15:49 UTC (permalink / raw)
  To: Alexey Romanov, dario.binacchi, michael, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot

On 25.03.24 15:41, Alexey Romanov wrote:
> UBI block is virtual block device, which is an abstraction
> over MTD layer. Therefore it is logical to use it in combination
> with MTD drivers.
> 
> Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

> ---
>  drivers/mtd/nand/spi/core.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index dd880adf31..c47f6c1b46 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -27,6 +27,7 @@
>  #include <watchdog.h>
>  #include <spi.h>
>  #include <spi-mem.h>
> +#include <ubi_uboot.h>
>  #include <dm/device_compat.h>
>  #include <dm/devres.h>
>  #include <dm/uclass.h>
> @@ -1182,8 +1183,13 @@ static int spinand_bind(struct udevice *dev)
>  {
>  	if (blk_enabled()) {
>  		struct spinand_plat *plat = dev_get_plat(dev);
> +		int ret;
> +
> +		ret = mtd_bind(dev, &plat->mtd);
> +		if (ret)
> +			return ret;
>  
> -		return mtd_bind(dev, &plat->mtd);
> +		return ubi_bind(dev);
>  	}
>  
>  	return 0;

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

* Re: [PATCH v2 6/6] spinand: bind UBI block
  2024-03-25 14:41 ` [PATCH v2 6/6] spinand: bind UBI block Alexey Romanov
  2024-04-03 15:49   ` Frieder Schrempf
@ 2024-04-04  3:23   ` Chuanhong Guo
  2024-04-04  8:02     ` Alexey Romanov
  1 sibling, 1 reply; 16+ messages in thread
From: Chuanhong Guo @ 2024-04-04  3:23 UTC (permalink / raw)
  To: Alexey Romanov
  Cc: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan, kernel, u-boot

Hello!

On Mon, Mar 25, 2024 at 10:46 PM Alexey Romanov
<avromanov@salutedevices.com> wrote:
>
> UBI block is virtual block device, which is an abstraction
> over MTD layer. Therefore it is logical to use it in combination
> with MTD drivers.
>
> Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
> ---
>  drivers/mtd/nand/spi/core.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index dd880adf31..c47f6c1b46 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -27,6 +27,7 @@
>  #include <watchdog.h>
>  #include <spi.h>
>  #include <spi-mem.h>
> +#include <ubi_uboot.h>
>  #include <dm/device_compat.h>
>  #include <dm/devres.h>
>  #include <dm/uclass.h>
> @@ -1182,8 +1183,13 @@ static int spinand_bind(struct udevice *dev)
>  {
>         if (blk_enabled()) {
>                 struct spinand_plat *plat = dev_get_plat(dev);
> +               int ret;
> +
> +               ret = mtd_bind(dev, &plat->mtd);
> +               if (ret)
> +                       return ret;
>
> -               return mtd_bind(dev, &plat->mtd);
> +               return ubi_bind(dev);

Is this expecting the entire SPI-NAND covered by a single UBI partition?
It's almost never this case on real hardware. For SPI-NAND booted
SoCs, the first few blocks always store the first stage bootloader
raw, because bootrom knows nothing about UBI.

>         }
>
>         return 0;
> --
> 2.34.1
>


-- 
Regards,
Chuanhong Guo

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

* Re: [PATCH v2 6/6] spinand: bind UBI block
  2024-04-04  3:23   ` Chuanhong Guo
@ 2024-04-04  8:02     ` Alexey Romanov
  2024-04-05  4:40       ` Chuanhong Guo
  0 siblings, 1 reply; 16+ messages in thread
From: Alexey Romanov @ 2024-04-04  8:02 UTC (permalink / raw)
  To: Chuanhong Guo
  Cc: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan, kernel, u-boot

Hi,

On Thu, Apr 04, 2024 at 11:23:47AM +0800, Chuanhong Guo wrote:
> Hello!
> 
> On Mon, Mar 25, 2024 at 10:46 PM Alexey Romanov
> <avromanov@salutedevices.com> wrote:
> >
> > UBI block is virtual block device, which is an abstraction
> > over MTD layer. Therefore it is logical to use it in combination
> > with MTD drivers.
> >
> > Signed-off-by: Alexey Romanov <avromanov@salutedevices.com>
> > ---
> >  drivers/mtd/nand/spi/core.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> > index dd880adf31..c47f6c1b46 100644
> > --- a/drivers/mtd/nand/spi/core.c
> > +++ b/drivers/mtd/nand/spi/core.c
> > @@ -27,6 +27,7 @@
> >  #include <watchdog.h>
> >  #include <spi.h>
> >  #include <spi-mem.h>
> > +#include <ubi_uboot.h>
> >  #include <dm/device_compat.h>
> >  #include <dm/devres.h>
> >  #include <dm/uclass.h>
> > @@ -1182,8 +1183,13 @@ static int spinand_bind(struct udevice *dev)
> >  {
> >         if (blk_enabled()) {
> >                 struct spinand_plat *plat = dev_get_plat(dev);
> > +               int ret;
> > +
> > +               ret = mtd_bind(dev, &plat->mtd);
> > +               if (ret)
> > +                       return ret;
> >
> > -               return mtd_bind(dev, &plat->mtd);
> > +               return ubi_bind(dev);
> 
> Is this expecting the entire SPI-NAND covered by a single UBI partition?

Why? Nah.

ubi_bind() just create block device and bind it to SPI-NAND device.
When working with this block device user must specify, which SPI-NAND
partition UBI is located on.

> It's almost never this case on real hardware. For SPI-NAND booted
> SoCs, the first few blocks always store the first stage bootloader
> raw, because bootrom knows nothing about UBI.
> 
> >         }
> >
> >         return 0;
> > --
> > 2.34.1
> >
> 
> 
> -- 
> Regards,
> Chuanhong Guo

-- 
Thank you,
Alexey

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

* Re: [PATCH v2 6/6] spinand: bind UBI block
  2024-04-04  8:02     ` Alexey Romanov
@ 2024-04-05  4:40       ` Chuanhong Guo
  0 siblings, 0 replies; 16+ messages in thread
From: Chuanhong Guo @ 2024-04-05  4:40 UTC (permalink / raw)
  To: Alexey Romanov
  Cc: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan, kernel, u-boot

Hi!

On Thu, Apr 4, 2024 at 4:02 PM Alexey Romanov
<avromanov@salutedevices.com> wrote:
> > > +#include <ubi_uboot.h>
> > >  #include <dm/device_compat.h>
> > >  #include <dm/devres.h>
> > >  #include <dm/uclass.h>
> > > @@ -1182,8 +1183,13 @@ static int spinand_bind(struct udevice *dev)
> > >  {
> > >         if (blk_enabled()) {
> > >                 struct spinand_plat *plat = dev_get_plat(dev);
> > > +               int ret;
> > > +
> > > +               ret = mtd_bind(dev, &plat->mtd);
> > > +               if (ret)
> > > +                       return ret;
> > >
> > > -               return mtd_bind(dev, &plat->mtd);
> > > +               return ubi_bind(dev);
> >
> > Is this expecting the entire SPI-NAND covered by a single UBI partition?
>
> Why? Nah.

I can't find the code it's patching in my outdated local tree and
made a wrong guess. Sorry for my ignorance.

> ubi_bind() just create block device and bind it to SPI-NAND device.
> When working with this block device user must specify, which SPI-NAND
> partition UBI is located on.
>

And thanks for the explanation!

-- 
Regards,
Chuanhong Guo

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

* Re: [PATCH v2 0/6] Introduce UBI block device
  2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
                   ` (6 preceding siblings ...)
  2024-03-26  4:21 ` [PATCH v2 0/6] Introduce UBI block device Heiko Schocher
@ 2024-05-06 13:58 ` Alexey Romanov
  2024-05-06 13:59   ` Michael Nazzareno Trimarchi
  2024-05-06 14:04   ` Heiko Schocher
  7 siblings, 2 replies; 16+ messages in thread
From: Alexey Romanov @ 2024-05-06 13:58 UTC (permalink / raw)
  To: dario.binacchi, michael, frieder.schrempf, kmpark, hs,
	joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot

Hello! Ping.

On Mon, Mar 25, 2024 at 05:41:42PM +0300, Alexey Romanov wrote:
> Hello!
> 
> This series adds support for the UBI block 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 ubi 0 part_name
> 
> Tested only on SPI NAND, so bind is made only for
> SPI NAND drivers. Can be used with mtdblock device [1].
> 
> --- 
> 
> Changes V1 -> V2 [2]:
> 
>  - Rebased over mtdblock v2 patchset [3].
>  - Compile UBI partitions support only if CONFIG_BLK option
>    is enabled.
> 
> - Links:
> 
>   [1] https://lore.kernel.org/all/20240227100441.1811047-1-avromanov@salutedevices.com/
>   [2] https://lore.kernel.org/all/20240306134906.1179285-1-avromanov@salutedevices.com/
>   [3] https://lore.kernel.org/all/20240307130726.1582487-1-avromanov@salutedevices.com/
> 
> Alexey Romanov (6):
>   ubi: allow to read from volume with offset
>   ubi: allow to write to volume with offset
>   drivers: introduce UBI block abstraction
>   disk: don't try search for partition type if already set
>   disk: support UBI partitions
>   spinand: bind UBI block
> 
>  cmd/ubi.c                   |  77 +++++++++++++++++++--
>  disk/part.c                 |   7 ++
>  drivers/block/blk-uclass.c  |   1 +
>  drivers/mtd/nand/spi/core.c |   8 ++-
>  drivers/mtd/ubi/Makefile    |   1 +
>  drivers/mtd/ubi/block.c     | 130 ++++++++++++++++++++++++++++++++++++
>  drivers/mtd/ubi/part.c      |  99 +++++++++++++++++++++++++++
>  env/ubi.c                   |  16 ++---
>  include/part.h              |   2 +
>  include/ubi_uboot.h         |   8 ++-
>  10 files changed, 332 insertions(+), 17 deletions(-)
>  create mode 100644 drivers/mtd/ubi/block.c
>  create mode 100644 drivers/mtd/ubi/part.c
> 
> -- 
> 2.34.1
> 

-- 
Thank you,
Alexey

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

* Re: [PATCH v2 0/6] Introduce UBI block device
  2024-05-06 13:58 ` Alexey Romanov
@ 2024-05-06 13:59   ` Michael Nazzareno Trimarchi
  2024-05-06 14:04   ` Heiko Schocher
  1 sibling, 0 replies; 16+ messages in thread
From: Michael Nazzareno Trimarchi @ 2024-05-06 13:59 UTC (permalink / raw)
  To: Alexey Romanov
  Cc: dario.binacchi, frieder.schrempf, kmpark, hs, joe.hershberger,
	dunaev, sjg, bmeng, xypron.glpk, tobias, jpewhacker,
	marek.vasut+renesas, kever.yang, jbx6244, abdellatif.elkhlifi,
	mikhail.kshevetskiy, jagan, kernel, u-boot

Hi Alexey

Sorry will will put on CI

Michael

On Mon, May 6, 2024 at 3:58 PM Alexey Romanov
<avromanov@salutedevices.com> wrote:
>
> Hello! Ping.
>
> On Mon, Mar 25, 2024 at 05:41:42PM +0300, Alexey Romanov wrote:
> > Hello!
> >
> > This series adds support for the UBI block 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 ubi 0 part_name
> >
> > Tested only on SPI NAND, so bind is made only for
> > SPI NAND drivers. Can be used with mtdblock device [1].
> >
> > ---
> >
> > Changes V1 -> V2 [2]:
> >
> >  - Rebased over mtdblock v2 patchset [3].
> >  - Compile UBI partitions support only if CONFIG_BLK option
> >    is enabled.
> >
> > - Links:
> >
> >   [1] https://lore.kernel.org/all/20240227100441.1811047-1-avromanov@salutedevices.com/
> >   [2] https://lore.kernel.org/all/20240306134906.1179285-1-avromanov@salutedevices.com/
> >   [3] https://lore.kernel.org/all/20240307130726.1582487-1-avromanov@salutedevices.com/
> >
> > Alexey Romanov (6):
> >   ubi: allow to read from volume with offset
> >   ubi: allow to write to volume with offset
> >   drivers: introduce UBI block abstraction
> >   disk: don't try search for partition type if already set
> >   disk: support UBI partitions
> >   spinand: bind UBI block
> >
> >  cmd/ubi.c                   |  77 +++++++++++++++++++--
> >  disk/part.c                 |   7 ++
> >  drivers/block/blk-uclass.c  |   1 +
> >  drivers/mtd/nand/spi/core.c |   8 ++-
> >  drivers/mtd/ubi/Makefile    |   1 +
> >  drivers/mtd/ubi/block.c     | 130 ++++++++++++++++++++++++++++++++++++
> >  drivers/mtd/ubi/part.c      |  99 +++++++++++++++++++++++++++
> >  env/ubi.c                   |  16 ++---
> >  include/part.h              |   2 +
> >  include/ubi_uboot.h         |   8 ++-
> >  10 files changed, 332 insertions(+), 17 deletions(-)
> >  create mode 100644 drivers/mtd/ubi/block.c
> >  create mode 100644 drivers/mtd/ubi/part.c
> >
> > --
> > 2.34.1
> >
>
> --
> Thank you,
> Alexey



-- 
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael@amarulasolutions.com
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
info@amarulasolutions.com
www.amarulasolutions.com

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

* Re: [PATCH v2 0/6] Introduce UBI block device
  2024-05-06 13:58 ` Alexey Romanov
  2024-05-06 13:59   ` Michael Nazzareno Trimarchi
@ 2024-05-06 14:04   ` Heiko Schocher
  1 sibling, 0 replies; 16+ messages in thread
From: Heiko Schocher @ 2024-05-06 14:04 UTC (permalink / raw)
  To: Alexey Romanov, dario.binacchi, michael, frieder.schrempf,
	kmpark, joe.hershberger, dunaev, sjg, bmeng, xypron.glpk, tobias,
	jpewhacker, marek.vasut+renesas, kever.yang, jbx6244,
	abdellatif.elkhlifi, mikhail.kshevetskiy, jagan
  Cc: kernel, u-boot

Hello Alexey,

On 06.05.24 15:58, Alexey Romanov wrote:
> Hello! Ping.

okay from my side... I think I acked them already

@Dario: IIRC the patchset is delegated to you...

If it is okay, I can apply it in u-boot-ubi and send a pull request to
Tom, but please, send a Acked-by or Reviewed-by and delegate it back to me!

Thanks!

bye,
Heiko
> 
> On Mon, Mar 25, 2024 at 05:41:42PM +0300, Alexey Romanov wrote:
>> Hello!
>>
>> This series adds support for the UBI block 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 ubi 0 part_name
>>
>> Tested only on SPI NAND, so bind is made only for
>> SPI NAND drivers. Can be used with mtdblock device [1].
>>
>> ---
>>
>> Changes V1 -> V2 [2]:
>>
>>   - Rebased over mtdblock v2 patchset [3].
>>   - Compile UBI partitions support only if CONFIG_BLK option
>>     is enabled.
>>
>> - Links:
>>
>>    [1] https://lore.kernel.org/all/20240227100441.1811047-1-avromanov@salutedevices.com/
>>    [2] https://lore.kernel.org/all/20240306134906.1179285-1-avromanov@salutedevices.com/
>>    [3] https://lore.kernel.org/all/20240307130726.1582487-1-avromanov@salutedevices.com/
>>
>> Alexey Romanov (6):
>>    ubi: allow to read from volume with offset
>>    ubi: allow to write to volume with offset
>>    drivers: introduce UBI block abstraction
>>    disk: don't try search for partition type if already set
>>    disk: support UBI partitions
>>    spinand: bind UBI block
>>
>>   cmd/ubi.c                   |  77 +++++++++++++++++++--
>>   disk/part.c                 |   7 ++
>>   drivers/block/blk-uclass.c  |   1 +
>>   drivers/mtd/nand/spi/core.c |   8 ++-
>>   drivers/mtd/ubi/Makefile    |   1 +
>>   drivers/mtd/ubi/block.c     | 130 ++++++++++++++++++++++++++++++++++++
>>   drivers/mtd/ubi/part.c      |  99 +++++++++++++++++++++++++++
>>   env/ubi.c                   |  16 ++---
>>   include/part.h              |   2 +
>>   include/ubi_uboot.h         |   8 ++-
>>   10 files changed, 332 insertions(+), 17 deletions(-)
>>   create mode 100644 drivers/mtd/ubi/block.c
>>   create mode 100644 drivers/mtd/ubi/part.c
>>
>> -- 
>> 2.34.1
>>
> 

-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

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

end of thread, other threads:[~2024-05-06 15:23 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25 14:41 [PATCH v2 0/6] Introduce UBI block device Alexey Romanov
2024-03-25 14:41 ` [PATCH v2 1/6] ubi: allow to read from volume with offset Alexey Romanov
2024-03-25 14:41 ` [PATCH v2 2/6] ubi: allow to write to " Alexey Romanov
2024-03-25 14:41 ` [PATCH v2 3/6] drivers: introduce UBI block abstraction Alexey Romanov
2024-03-25 14:41 ` [PATCH v2 4/6] disk: don't try search for partition type if already set Alexey Romanov
2024-03-25 14:41 ` [PATCH v2 5/6] disk: support UBI partitions Alexey Romanov
2024-03-25 14:41 ` [PATCH v2 6/6] spinand: bind UBI block Alexey Romanov
2024-04-03 15:49   ` Frieder Schrempf
2024-04-04  3:23   ` Chuanhong Guo
2024-04-04  8:02     ` Alexey Romanov
2024-04-05  4:40       ` Chuanhong Guo
2024-03-26  4:21 ` [PATCH v2 0/6] Introduce UBI block device Heiko Schocher
2024-04-03  8:44   ` Alexey Romanov
2024-05-06 13:58 ` Alexey Romanov
2024-05-06 13:59   ` Michael Nazzareno Trimarchi
2024-05-06 14:04   ` Heiko Schocher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.