diff mbox series

[U-Boot,v7,11/13] cmd: mtdparts: try to probe the MTD devices as a fallback

Message ID 20180831145741.17350-12-miquel.raynal@bootlin.com
State Changes Requested
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series Cleaner MTD devices management | expand

Commit Message

Miquel Raynal Aug. 31, 2018, 2:57 p.m. UTC
Current implementation of mtdparts command errors out if the desired MTD
device is not found. Fallback to the new probe function in this case
before erroring out.

This will the save the user the need to call something like 'mtd list'
before mtdparts.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Jagan Teki <jagan@openedev.com>
---
 cmd/mtdparts.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

Stefan Roese Sept. 1, 2018, 9:02 a.m. UTC | #1
On 31.08.2018 16:57, Miquel Raynal wrote:
> Current implementation of mtdparts command errors out if the desired MTD
> device is not found. Fallback to the new probe function in this case
> before erroring out.
> 
> This will the save the user the need to call something like 'mtd list'
> before mtdparts.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Acked-by: Jagan Teki <jagan@openedev.com>
> ---
>   cmd/mtdparts.c | 16 +++++++++++++---
>   1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
> index f7ed1a0779..a1102c3fc5 100644
> --- a/cmd/mtdparts.c
> +++ b/cmd/mtdparts.c
> @@ -79,6 +79,10 @@
>   #include <linux/err.h>
>   #include <linux/mtd/mtd.h>
>   
> +#if defined(CONFIG_MTD)
> +#include <mtd.h>
> +#endif
> +
>   #if defined(CONFIG_CMD_NAND)
>   #include <linux/mtd/rawnand.h>
>   #include <nand.h>
> @@ -307,9 +311,15 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
>   
>   	sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
>   	*mtd = get_mtd_device_nm(mtd_dev);
> -	if (IS_ERR(*mtd)) {
> -		printf("Device %s not found!\n", mtd_dev);
> -		return 1;
> +	if (IS_ERR_OR_NULL(*mtd)) {
> +#ifdef CONFIG_MTD
> +		mtd_probe_devices();
> +		*mtd = get_mtd_device_nm(mtd_dev);
> +#endif
> +		if (IS_ERR_OR_NULL(*mtd)) {
> +			printf("Device %s not found!\n", mtd_dev);
> +			return 1;
> +		}
>   	}
>   	put_mtd_device(*mtd);
>   
> 

This is most likely the use case for CMD_MTD without MTD, correct?

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan
Miquel Raynal Sept. 3, 2018, 7:02 a.m. UTC | #2
Hi Stefan,

Stefan Roese <sr@denx.de> wrote on Sat, 1 Sep 2018 11:02:43 +0200:

> On 31.08.2018 16:57, Miquel Raynal wrote:
> > Current implementation of mtdparts command errors out if the desired MTD
> > device is not found. Fallback to the new probe function in this case
> > before erroring out.  
> > > This will the save the user the need to call something like 'mtd list'  
> > before mtdparts.  
> > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>  
> > Acked-by: Jagan Teki <jagan@openedev.com>
> > ---
> >   cmd/mtdparts.c | 16 +++++++++++++---
> >   1 file changed, 13 insertions(+), 3 deletions(-)  
> > > diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c  
> > index f7ed1a0779..a1102c3fc5 100644
> > --- a/cmd/mtdparts.c
> > +++ b/cmd/mtdparts.c
> > @@ -79,6 +79,10 @@
> >   #include <linux/err.h>
> >   #include <linux/mtd/mtd.h>  
> >   > +#if defined(CONFIG_MTD)  
> > +#include <mtd.h>
> > +#endif
> > +
> >   #if defined(CONFIG_CMD_NAND)
> >   #include <linux/mtd/rawnand.h>
> >   #include <nand.h>
> > @@ -307,9 +311,15 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)  
> >   >   	sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);  
> >   	*mtd = get_mtd_device_nm(mtd_dev);
> > -	if (IS_ERR(*mtd)) {
> > -		printf("Device %s not found!\n", mtd_dev);
> > -		return 1;
> > +	if (IS_ERR_OR_NULL(*mtd)) {
> > +#ifdef CONFIG_MTD
> > +		mtd_probe_devices();
> > +		*mtd = get_mtd_device_nm(mtd_dev);
> > +#endif
> > +		if (IS_ERR_OR_NULL(*mtd)) {
> > +			printf("Device %s not found!\n", mtd_dev);
> > +			return 1;
> > +		}
> >   	}
> >   	put_mtd_device(*mtd);  
> >   >   
> This is most likely the use case for CMD_MTD without MTD, correct?

Not exactly, I think the use case you were looking for is explained in
my previous answer and this #ifdef stands for the opposite situation,
where someone using the 'legacy' commands wants to interact with
devices with DM compliant drivers: the MTD device won't be registered
before (and thus, not accessible) the mtd_probe_device() call.

For other devices the use will have to probe manually the device, eg.
for SPI-NOR: 'sf probe 0'.

> 
> Reviewed-by: Stefan Roese <sr@denx.de>
> 
> Thanks,
> Stefan


Thanks,
Miquèl
diff mbox series

Patch

diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index f7ed1a0779..a1102c3fc5 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -79,6 +79,10 @@ 
 #include <linux/err.h>
 #include <linux/mtd/mtd.h>
 
+#if defined(CONFIG_MTD)
+#include <mtd.h>
+#endif
+
 #if defined(CONFIG_CMD_NAND)
 #include <linux/mtd/rawnand.h>
 #include <nand.h>
@@ -307,9 +311,15 @@  static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
 
 	sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
 	*mtd = get_mtd_device_nm(mtd_dev);
-	if (IS_ERR(*mtd)) {
-		printf("Device %s not found!\n", mtd_dev);
-		return 1;
+	if (IS_ERR_OR_NULL(*mtd)) {
+#ifdef CONFIG_MTD
+		mtd_probe_devices();
+		*mtd = get_mtd_device_nm(mtd_dev);
+#endif
+		if (IS_ERR_OR_NULL(*mtd)) {
+			printf("Device %s not found!\n", mtd_dev);
+			return 1;
+		}
 	}
 	put_mtd_device(*mtd);