Re: [U-Boot] [PATCH v6 29/31] cmd: mtd: add 'mtd' command

2018-08-20 Thread Boris Brezillon
On Mon, 20 Aug 2018 18:08:14 +0200
Miquel Raynal  wrote:

> Hi Boris,
> 
> Boris Brezillon  wrote on Thu, 16 Aug 2018
> 18:22:03 +0200:
> 
> > On Thu, 16 Aug 2018 17:30:27 +0200
> > Miquel Raynal  wrote:
> >   
> > > There should not be a 'nand' command, a 'sf' command and certainly not
> > > a new 'spi-nand' command. Write a 'mtd' command instead to manage all
> > > MTD devices/partitions at once. This should be the preferred way to
> > > access any MTD device.
> > > 
> > > Signed-off-by: Miquel Raynal 
> > > Acked-by: Jagan Teki 
> > 
> > [...]
> >   
> > >  
> > > +config CMD_MTD
> > > + bool "mtd"
> > > + depends on CMD_MTDPARTS
> > 
> > Shouldn't we select it instead?  
> 
> No need anymore, I will entirely re-write the functions that are needed
> to have stateless clean MTD functions taking the best out of the MTD
> stack.
> 
> All of them will be in mtd-uclass.c, declared in include/mtd.h.

Hm, I would have put those functions in mtdpart.c, but, as long as
mtd-uclass.c is compiled even if CONFIG_DM is not enabled I'm fine with
that.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 29/31] cmd: mtd: add 'mtd' command

2018-08-20 Thread Miquel Raynal
Hi Boris,

Boris Brezillon  wrote on Thu, 16 Aug 2018
18:22:03 +0200:

> On Thu, 16 Aug 2018 17:30:27 +0200
> Miquel Raynal  wrote:
> 
> > There should not be a 'nand' command, a 'sf' command and certainly not
> > a new 'spi-nand' command. Write a 'mtd' command instead to manage all
> > MTD devices/partitions at once. This should be the preferred way to
> > access any MTD device.
> > 
> > Signed-off-by: Miquel Raynal 
> > Acked-by: Jagan Teki   
> 
> [...]
> 
> >  
> > +config CMD_MTD
> > +   bool "mtd"
> > +   depends on CMD_MTDPARTS  
> 
> Shouldn't we select it instead?

No need anymore, I will entirely re-write the functions that are needed
to have stateless clean MTD functions taking the best out of the MTD
stack.

All of them will be in mtd-uclass.c, declared in include/mtd.h.

> 
> > +   select MTD_PARTITIONS
> > +   help
> > + MTD commands support.
> > +  
> 


Thanks,
Miquèl
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 29/31] cmd: mtd: add 'mtd' command

2018-08-16 Thread Boris Brezillon
On Thu, 16 Aug 2018 17:30:27 +0200
Miquel Raynal  wrote:

> +/*
> + * Ensure the MTD device partition list has been initialized already (needed 
> for
> + * non DM-compliant devices).

I don't see what this has to do with DM vs non-DM drivers. All MTD
devices are registered to the MTD framework, right? So there's probably
a place where this list initialization can be done for everyone.

> + */
> +static void mtd_quirk_init_non_dm_device_lists(void)
> +{
> + struct mtd_info *mtd;
> +
> + mtd_for_each_device(mtd) {
> + if (!mtd_is_partition(mtd) && !mtd->partitions.next) {
> + INIT_LIST_HEAD(>partitions);
> + INIT_LIST_HEAD(>node);

Hm, how about moving this initialization in add_mtd_device()?

> + }
> + }
> +}
> +
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v6 29/31] cmd: mtd: add 'mtd' command

2018-08-16 Thread Boris Brezillon
On Thu, 16 Aug 2018 17:30:27 +0200
Miquel Raynal  wrote:

> There should not be a 'nand' command, a 'sf' command and certainly not
> a new 'spi-nand' command. Write a 'mtd' command instead to manage all
> MTD devices/partitions at once. This should be the preferred way to
> access any MTD device.
> 
> Signed-off-by: Miquel Raynal 
> Acked-by: Jagan Teki 
> ---
>  cmd/Kconfig |   7 +
>  cmd/Makefile|   1 +
>  cmd/mtd.c   | 513 
>  drivers/mtd/Makefile|   2 +-
>  include/linux/mtd/mtd.h |   1 +
>  5 files changed, 523 insertions(+), 1 deletion(-)
>  create mode 100644 cmd/mtd.c
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index ef43ed8dda..81351920ab 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -847,6 +847,13 @@ config CMD_MMC_SWRITE
> Enable support for the "mmc swrite" command to write Android sparse
> images to eMMC.
>  
> +config CMD_MTD
> + bool "mtd"
> + depends on CMD_MTDPARTS
> + select MTD_PARTITIONS
> + help
> +   MTD commands support.
> +
>  config CMD_NAND
>   bool "nand"
>   default y if NAND_SUNXI
> diff --git a/cmd/Makefile b/cmd/Makefile
> index 323f1fd2c7..32fd102189 100644
> --- a/cmd/Makefile
> +++ b/cmd/Makefile
> @@ -90,6 +90,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o
>  obj-$(CONFIG_CMD_MMC) += mmc.o
>  obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o
>  obj-$(CONFIG_MP) += mp.o
> +obj-$(CONFIG_CMD_MTD) += mtd.o
>  obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
>  obj-$(CONFIG_CMD_NAND) += nand.o
>  obj-$(CONFIG_CMD_NET) += net.o
> diff --git a/cmd/mtd.c b/cmd/mtd.c
> new file mode 100644
> index 00..b9d58725f0
> --- /dev/null
> +++ b/cmd/mtd.c
> @@ -0,0 +1,513 @@
> +// SPDX-License-Identifier:  GPL-2.0+
> +/*
> + * mtd.c
> + *
> + * Generic command to handle basic operations on any memory device.
> + *
> + * Copyright: Bootlin, 2018
> + * Author: Miquèl Raynal 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MTD_NAME_MAX_LEN 20
> +
> +static void mtd_dump_buf(u8 *buf, uint len, uint offset)
> +{
> + int i, j;
> +
> + for (i = 0; i < len; ) {
> + printf("0x%08x:\t", offset + i);
> + for (j = 0; j < 8; j++)
> + printf("%02x ", buf[i + j]);
> + printf(" ");
> + i += 8;
> + for (j = 0; j < 8; j++)
> + printf("%02x ", buf[i + j]);
> + printf("\n");
> + i += 8;
> + }
> +}
> +
> +static void mtd_show_parts(struct mtd_info *mtd, int level)
> +{
> + struct mtd_info *part;
> + int i;
> +
> + if (list_empty(>partitions))
> + return;
> +
> + list_for_each_entry(part, >partitions, node) {
> + for (i = 0; i < level; i++)
> + printf("\t");
> + printf("* %s\n", part->name);
> + for (i = 0; i < level; i++)
> + printf("\t");
> + printf("  > Offset: 0x%llx bytes\n", part->offset);
> + for (i = 0; i < level; i++)
> + printf("\t");
> + printf("  > Size: 0x%llx bytes\n", part->size);
> +
> + mtd_show_parts(part, level + 1);
> + }
> +}
> +
> +static void mtd_show_device(struct mtd_info *mtd)
> +{
> + /* Device */
> + printf("* %s", mtd->name);
> + if (mtd->dev)
> + printf(" [device: %s] [parent: %s] [driver: %s]",
> +mtd->dev->name, mtd->dev->parent->name,
> +mtd->dev->driver->name);
> + printf("\n");
> +
> + /* MTD device information */
> + printf("  > type: ");
> + switch (mtd->type) {
> + case MTD_RAM:
> + printf("RAM\n");
> + break;
> + case MTD_ROM:
> + printf("ROM\n");
> + break;
> + case MTD_NORFLASH:
> + printf("NOR flash\n");
> + break;
> + case MTD_NANDFLASH:
> + printf("NAND flash\n");
> + break;
> + case MTD_DATAFLASH:
> + printf("Data flash\n");
> + break;
> + case MTD_UBIVOLUME:
> + printf("UBI volume\n");
> + break;
> + case MTD_MLCNANDFLASH:
> + printf("MLC NAND flash\n");
> + break;
> + case MTD_ABSENT:
> + default:
> + printf("Unknown\n");
> + break;
> + }
> +
> + printf("  > Size: 0x%llx bytes\n", mtd->size);
> + printf("  > Block: 0x%x bytes\n", mtd->erasesize);
> + printf("  > Min I/O: 0x%x bytes\n", mtd->writesize);
> +
> + if (mtd->oobsize) {
> + printf("  > OOB size: %u bytes\n", mtd->oobsize);
> + printf("  > OOB available: %u bytes\n", mtd->oobavail);
> + }
> +
> + if (mtd->ecc_strength) {
> + printf("  > ECC strength: %u bits\n", mtd->ecc_strength);
> + printf("  > ECC step size: %u 

Re: [U-Boot] [PATCH v6 29/31] cmd: mtd: add 'mtd' command

2018-08-16 Thread Boris Brezillon
On Thu, 16 Aug 2018 17:30:27 +0200
Miquel Raynal  wrote:

> There should not be a 'nand' command, a 'sf' command and certainly not
> a new 'spi-nand' command. Write a 'mtd' command instead to manage all
> MTD devices/partitions at once. This should be the preferred way to
> access any MTD device.
> 
> Signed-off-by: Miquel Raynal 
> Acked-by: Jagan Teki 

[...]

>  
> +config CMD_MTD
> + bool "mtd"
> + depends on CMD_MTDPARTS

Shouldn't we select it instead?

> + select MTD_PARTITIONS
> + help
> +   MTD commands support.
> +

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v6 29/31] cmd: mtd: add 'mtd' command

2018-08-16 Thread Miquel Raynal
There should not be a 'nand' command, a 'sf' command and certainly not
a new 'spi-nand' command. Write a 'mtd' command instead to manage all
MTD devices/partitions at once. This should be the preferred way to
access any MTD device.

Signed-off-by: Miquel Raynal 
Acked-by: Jagan Teki 
---
 cmd/Kconfig |   7 +
 cmd/Makefile|   1 +
 cmd/mtd.c   | 513 
 drivers/mtd/Makefile|   2 +-
 include/linux/mtd/mtd.h |   1 +
 5 files changed, 523 insertions(+), 1 deletion(-)
 create mode 100644 cmd/mtd.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index ef43ed8dda..81351920ab 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -847,6 +847,13 @@ config CMD_MMC_SWRITE
  Enable support for the "mmc swrite" command to write Android sparse
  images to eMMC.
 
+config CMD_MTD
+   bool "mtd"
+   depends on CMD_MTDPARTS
+   select MTD_PARTITIONS
+   help
+ MTD commands support.
+
 config CMD_NAND
bool "nand"
default y if NAND_SUNXI
diff --git a/cmd/Makefile b/cmd/Makefile
index 323f1fd2c7..32fd102189 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -90,6 +90,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o
 obj-$(CONFIG_CMD_MMC) += mmc.o
 obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o
 obj-$(CONFIG_MP) += mp.o
+obj-$(CONFIG_CMD_MTD) += mtd.o
 obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
diff --git a/cmd/mtd.c b/cmd/mtd.c
new file mode 100644
index 00..b9d58725f0
--- /dev/null
+++ b/cmd/mtd.c
@@ -0,0 +1,513 @@
+// SPDX-License-Identifier:  GPL-2.0+
+/*
+ * mtd.c
+ *
+ * Generic command to handle basic operations on any memory device.
+ *
+ * Copyright: Bootlin, 2018
+ * Author: Miquèl Raynal 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTD_NAME_MAX_LEN 20
+
+static void mtd_dump_buf(u8 *buf, uint len, uint offset)
+{
+   int i, j;
+
+   for (i = 0; i < len; ) {
+   printf("0x%08x:\t", offset + i);
+   for (j = 0; j < 8; j++)
+   printf("%02x ", buf[i + j]);
+   printf(" ");
+   i += 8;
+   for (j = 0; j < 8; j++)
+   printf("%02x ", buf[i + j]);
+   printf("\n");
+   i += 8;
+   }
+}
+
+static void mtd_show_parts(struct mtd_info *mtd, int level)
+{
+   struct mtd_info *part;
+   int i;
+
+   if (list_empty(>partitions))
+   return;
+
+   list_for_each_entry(part, >partitions, node) {
+   for (i = 0; i < level; i++)
+   printf("\t");
+   printf("* %s\n", part->name);
+   for (i = 0; i < level; i++)
+   printf("\t");
+   printf("  > Offset: 0x%llx bytes\n", part->offset);
+   for (i = 0; i < level; i++)
+   printf("\t");
+   printf("  > Size: 0x%llx bytes\n", part->size);
+
+   mtd_show_parts(part, level + 1);
+   }
+}
+
+static void mtd_show_device(struct mtd_info *mtd)
+{
+   /* Device */
+   printf("* %s", mtd->name);
+   if (mtd->dev)
+   printf(" [device: %s] [parent: %s] [driver: %s]",
+  mtd->dev->name, mtd->dev->parent->name,
+  mtd->dev->driver->name);
+   printf("\n");
+
+   /* MTD device information */
+   printf("  > type: ");
+   switch (mtd->type) {
+   case MTD_RAM:
+   printf("RAM\n");
+   break;
+   case MTD_ROM:
+   printf("ROM\n");
+   break;
+   case MTD_NORFLASH:
+   printf("NOR flash\n");
+   break;
+   case MTD_NANDFLASH:
+   printf("NAND flash\n");
+   break;
+   case MTD_DATAFLASH:
+   printf("Data flash\n");
+   break;
+   case MTD_UBIVOLUME:
+   printf("UBI volume\n");
+   break;
+   case MTD_MLCNANDFLASH:
+   printf("MLC NAND flash\n");
+   break;
+   case MTD_ABSENT:
+   default:
+   printf("Unknown\n");
+   break;
+   }
+
+   printf("  > Size: 0x%llx bytes\n", mtd->size);
+   printf("  > Block: 0x%x bytes\n", mtd->erasesize);
+   printf("  > Min I/O: 0x%x bytes\n", mtd->writesize);
+
+   if (mtd->oobsize) {
+   printf("  > OOB size: %u bytes\n", mtd->oobsize);
+   printf("  > OOB available: %u bytes\n", mtd->oobavail);
+   }
+
+   if (mtd->ecc_strength) {
+   printf("  > ECC strength: %u bits\n", mtd->ecc_strength);
+   printf("  > ECC step size: %u bytes\n", mtd->ecc_step_size);
+   printf("  > Bitflip threshold: %u bits\n",
+  mtd->bitflip_threshold);
+   }
+
+   /* MTD partitions, if any */
+   mtd_show_parts(mtd, 1);
+}
+
+/*
+