Message ID | 20180906070854.9717-11-miquel.raynal@bootlin.com |
---|---|
State | Accepted |
Delegated to: | Jagannadha Sutradharudu Teki |
Headers | show |
Series | SPI-NAND support | expand |
On Thu, 6 Sep 2018 09:08:52 +0200 Miquel Raynal <miquel.raynal@bootlin.com> 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> > Reviewed-by: Stefan Roese <sr@denx.de> > --- > 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 In its current state, it should #ifdef CONFIG_CMD_MTD, since mtd_probe_devices() is implemented in cmd/mtd.c. Anyway, as I suggested, I think it's better to just move that in mtd_uboot.c and drop the #ifdef. > + mtd_probe_devices(); > + *mtd = get_mtd_device_nm(mtd_dev); > +#endif BTW, I'm not sure why we need to call mtd_probe_devices() here. If we really want to deprecate this command, then I'd recommend not adding new features to it. > + if (IS_ERR_OR_NULL(*mtd)) { > + printf("Device %s not found!\n", mtd_dev); > + return 1; > + } > } > put_mtd_device(*mtd); >
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);