diff mbox series

[v2,6/6] spinand: bind UBI block

Message ID 20240325144148.3738195-7-avromanov@salutedevices.com
State New
Delegated to: Dario Binacchi
Headers show
Series Introduce UBI block device | expand

Commit Message

Alexey Romanov March 25, 2024, 2:41 p.m. UTC
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(-)

Comments

Frieder Schrempf April 3, 2024, 3:49 p.m. UTC | #1
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;
Chuanhong Guo April 4, 2024, 3:23 a.m. UTC | #2
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
>
Alexey Romanov April 4, 2024, 8:02 a.m. UTC | #3
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
Chuanhong Guo April 5, 2024, 4:40 a.m. UTC | #4
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!
diff mbox series

Patch

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;