kernel: import pending patches adding support for NVMEM on UBI and MMC
[openwrt/staging/dangole.git] / target / linux / generic / pending-6.1 / 491-ubi-auto-create-ubiblock-device-for-rootfs.patch
index 17e8d8bedb6c163415ac8bb62c0160aec2d67986..a43da2a57259a96a23c59da1e3de97407a9af8ad 100644 (file)
@@ -8,8 +8,8 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
 
 --- a/drivers/mtd/ubi/block.c
 +++ b/drivers/mtd/ubi/block.c
-@@ -653,6 +653,47 @@ static void __init ubiblock_create_from_
-       }
+@@ -644,10 +644,47 @@ match_volume_desc(struct ubi_volume_info
+       return true;
  }
  
 +#define UBIFS_NODE_MAGIC  0x06101831
@@ -24,46 +24,54 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
 +      return magic == UBIFS_NODE_MAGIC;
 +}
 +
-+static void __init ubiblock_create_auto_rootfs(void)
++static void __init ubiblock_create_auto_rootfs(struct ubi_volume_info *vi)
 +{
-+      int ubi_num, ret, is_ubifs;
++      int ret, is_ubifs;
 +      struct ubi_volume_desc *desc;
-+      struct ubi_volume_info vi;
 +
-+      for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) {
-+              desc = ubi_open_volume_nm(ubi_num, "rootfs", UBI_READONLY);
-+              if (IS_ERR(desc))
-+                      desc = ubi_open_volume_nm(ubi_num, "fit", UBI_READONLY);;
++      if (strcmp(vi->name, "rootfs") &&
++          strcmp(vi->name, "fit"))
++              return;
 +
-+              if (IS_ERR(desc))
-+                      continue;
++      desc = ubi_open_volume(vi->ubi_num, vi->vol_id, UBI_READONLY);
++      if (IS_ERR(desc))
++              return;
 +
-+              ubi_get_volume_info(desc, &vi);
-+              is_ubifs = ubi_vol_is_ubifs(desc);
-+              ubi_close_volume(desc);
-+              if (is_ubifs)
-+                      break;
++      is_ubifs = ubi_vol_is_ubifs(desc);
++      ubi_close_volume(desc);
++      if (is_ubifs)
++              return;
 +
-+              ret = ubiblock_create(&vi);
-+              if (ret)
-+                      pr_err("UBI error: block: can't add '%s' volume, err=%d\n",
-+                              vi.name, ret);
-+              /* always break if we get here */
-+              break;
-+      }
++      ret = ubiblock_create(vi);
++      if (ret)
++              pr_err("UBI error: block: can't add '%s' volume, err=%d\n",
++                      vi->name, ret);
 +}
 +
- static void ubiblock_remove_all(void)
+ static void
+ ubiblock_create_from_param(struct ubi_volume_info *vi)
  {
-       struct ubiblock *next;
-@@ -685,6 +726,10 @@ int __init ubiblock_init(void)
-        */
-       ubiblock_create_from_param();
+       int i, ret = 0;
++      bool got_param = false;
+       struct ubiblock_param *p;
  
-+      /* auto-attach "rootfs" volume if existing and non-ubifs */
-+      if (IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV))
-+              ubiblock_create_auto_rootfs();
-+
        /*
-        * Block devices are only created upon user requests, so we ignore
-        * existing volumes.
+@@ -660,6 +697,7 @@ ubiblock_create_from_param(struct ubi_vo
+               if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id))
+                       continue;
++              got_param = true;
+               ret = ubiblock_create(vi);
+               if (ret) {
+                       pr_err(
+@@ -668,6 +706,10 @@ ubiblock_create_from_param(struct ubi_vo
+               }
+               break;
+       }
++
++      /* auto-attach "rootfs" volume if existing and non-ubifs */
++      if (!got_param && IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV))
++              ubiblock_create_auto_rootfs(vi);
+ }
+ static int ubiblock_notify(struct notifier_block *nb,