Skip to contentSkip to conversation

UBI:Force ubi driver load after mtd device drivers

PATCH Applied Jiang Lu 4 participants 8 messages Aug 8, 2012 – Aug 28, 2012

Subsystems (2)
lore
Share & tools
lore

Jiang Lu

author
#0 lore raw

PATCH 1/1 UBI:Force ubi driver load after mtd device drivers

To implement rootfs on mtd device with UBIFS, kernel need create a UBIFS device when booting:

drivers/mtd/ubi/build.c ubi_init()

for (i = 0; i < mtd_devs; i++) {
	...
	mtd = open_mtd_device(p->name);
	if (IS_ERR(mtd)) {
		err = PTR_ERR(mtd);
		goto out_detach;
	}

	ubi_attach_mtd_dev()
	...
}

module_init(ubi_init);

Kernel can not create the UBIFS device without corresponding mtd partiton.

Some NAND device can not guarenteen the mtd patition created before UBIFS deivce driver loading. Such as SPI NAND deivce, the mtd partition will create after SPI bus driver loaded.

UBI device driver must load after other mtd device drivers to make sure the mtd partition already exist when creating UBI deivce.

The patch updates the UBI device driver's initial routine to late_initcall level.

---
 drivers/mtd/ubi/build.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/ubi/build.c +1 -1
index 0fde9fc..efbcaef 100644
@@ -1275,7 +1275,7 @@ out:
 	ubi_err("UBI error: cannot initialize UBI, error %d", err);
 	return err;
 }
-module_init(ubi_init);
+late_initcall(ubi_init);
 
 static void __exit ubi_exit(void)
 {
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 40 lines · Jiang Lu

To implement rootfs on mtd device with UBIFS, kernel need create a UBIFS device when booting:

drivers/mtd/ubi/build.c ubi_init()

for (i = 0; i < mtd_devs; i++) {
        ...
        mtd = open_mtd_device(p->name);
        if (IS_ERR(mtd)) {
                err = PTR_ERR(mtd);
                goto out_detach;
        }

        ubi_attach_mtd_dev()
        ...
}

module_init(ubi_init);

Kernel can not create the UBIFS device without corresponding mtd partiton.

Some NAND device can not guarenteen the mtd patition created before UBIFS deivce driver loading. Such as SPI NAND deivce, the mtd partition will create after SPI bus driver loaded.

UBI device driver must load after other mtd device drivers to make sure the mtd partition already exist when creating UBI deivce.

The patch updates the UBI device driver's initial routine to late_initcall level.

---
 drivers/mtd/ubi/build.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/ubi/build.c +0 -0
index 0fde9fc..efbcaef 100644

drivers/mtd/ubi/build.c out: · line 1278

Quoted 5 lines
drivers/mtd/ubi/build.c +1 -1
@@ -1275,7 +1275,7 @@ out:
        ubi_err("UBI error: cannot initialize UBI, error %d", err);
        return err;
 }
-module_init(ubi_init);
+late_initcall(ubi_init);

Cant we use a simple initrd in such a case?
Within the initrd you can load the ubi module after your SPI NAND is done.

Signature · 2 lines
Thanks,
//richard
#2 lore raw
Quoted 36 lines · richard -rw- weinberger
Quoted 35 lines · Jiang Lu

To implement rootfs on mtd device with UBIFS, kernel need create a UBIFS device when booting:

drivers/mtd/ubi/build.c ubi_init()

for (i = 0; i < mtd_devs; i++) {
         ...
         mtd = open_mtd_device(p->name);
         if (IS_ERR(mtd)) {
                 err = PTR_ERR(mtd);
                 goto out_detach;
         }

         ubi_attach_mtd_dev()
         ...
}

module_init(ubi_init);

Kernel can not create the UBIFS device without corresponding mtd partiton.

Some NAND device can not guarenteen the mtd patition created before UBIFS deivce driver loading. Such as SPI NAND deivce, the mtd partition will create after SPI bus driver loaded.

UBI device driver must load after other mtd device drivers to make sure the mtd partition already exist when creating UBI deivce.

The patch updates the UBI device driver's initial routine to late_initcall level.

---
  drivers/mtd/ubi/build.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/mtd/ubi/build.c out: · line 1278

Quoted 10 lines
drivers/mtd/ubi/build.c +1 -1
index 0fde9fc..efbcaef 100644
@@ -1275,7 +1275,7 @@ out:
         ubi_err("UBI error: cannot initialize UBI, error %d", err);
         return err;
  }
-module_init(ubi_init);
+late_initcall(ubi_init);

Cant we use a simple initrd in such a case?
Within the initrd you can load the ubi module after your SPI NAND is done.

This could be a workround. But for the ubi device driver, kernel should invoke ubi_init() after all mtd partition ready.

#3 lore raw
In reply to Jiang Lu

drivers/mtd/ubi/build.c out: · line 1278

Quoted 10 lines · Jiang Lu
drivers/mtd/ubi/build.c +1 -1
index 0fde9fc..efbcaef 100644
@@ -1275,7 +1275,7 @@ out:
 	ubi_err("UBI error: cannot initialize UBI, error %d", err);
 	return err;
 }
-module_init(ubi_init);
+late_initcall(ubi_init);

The problem is that UBIFS, which is usually used on top of UBI, also uses 'late_initcall()'. If we do this change, how do we guarantee that UBIFS is initialized after UBI?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#4 lore raw
Quoted 15 lines · Artem Bityutskiy

drivers/mtd/ubi/build.c out: · line 1278

Quoted 10 lines · Jiang Lu
drivers/mtd/ubi/build.c +1 -1
index 0fde9fc..efbcaef 100644
@@ -1275,7 +1275,7 @@ out:
 	ubi_err("UBI error: cannot initialize UBI, error %d", err);
 	return err;
 }
-module_init(ubi_init);
+late_initcall(ubi_init);

The problem is that UBIFS, which is usually used on top of UBI, also uses 'late_initcall()'. If we do this change, how do we guarantee that UBIFS is initialized after UBI?

It looks like the right way to fix the issue is to change the way UBI initializes. We should not try to open the MTD device, scan it and attach in the initcall. We should instead delay this till the first open. So when you open the device for the firs time, you actually end up with the scanning, etc.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#5 lore raw
In reply to Artem Bityutskiy
Quoted 15 lines · Artem Bityutskiy

drivers/mtd/ubi/build.c out: · line 1278

Quoted 10 lines · Jiang Lu
drivers/mtd/ubi/build.c +1 -1
index 0fde9fc..efbcaef 100644
@@ -1275,7 +1275,7 @@ out:
 	ubi_err("UBI error: cannot initialize UBI, error %d", err);
 	return err;
 }
-module_init(ubi_init);
+late_initcall(ubi_init);

The problem is that UBIFS, which is usually used on top of UBI, also uses 'late_initcall()'. If we do this change, how do we guarantee that UBIFS is initialized after UBI?

Although, I think it is not really a problem and UBIFS can be initialized at any point - it does not depend on UBI being initialized.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
author
#6 lore raw
Quoted 15 lines · Artem Bityutskiy
Quoted 14 lines · Artem Bityutskiy

drivers/mtd/ubi/build.c out: · line 1278

Quoted 10 lines · Jiang Lu
drivers/mtd/ubi/build.c +1 -1
index 0fde9fc..efbcaef 100644
@@ -1275,7 +1275,7 @@ out:
  	ubi_err("UBI error: cannot initialize UBI, error %d", err);
  	return err;
  }
-module_init(ubi_init);
+late_initcall(ubi_init);

The problem is that UBIFS, which is usually used on top of UBI, also uses 'late_initcall()'. If we do this change, how do we guarantee that UBIFS is initialized after UBI?

Quoted 3 lines

Although, I think it is not really a problem and UBIFS can be initialized at any point - it does not depend on UBI being initialized.

Yes, it works fine with this change. UFIFS can be mount as rootfs device on SPI flash after ubi_init() change to late_initcall().

Jiang Lu

#7 lore raw
In reply to Jiang Lu
Quoted 2 lines · Jiang Lu

To implement rootfs on mtd device with UBIFS, kernel need create a UBIFS device when booting:

Pushed to linux-ubi.git, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy