491-ubi-auto-create-ubiblock-device-for-rootfs.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From: Daniel Golle <[email protected]>
  2. Subject: ubi: auto-create ubiblock device for rootfs
  3. Signed-off-by: Daniel Golle <[email protected]>
  4. ---
  5. drivers/mtd/ubi/block.c | 42 ++++++++++++++++++++++++++++++++++++++++++
  6. 1 file changed, 42 insertions(+)
  7. --- a/drivers/mtd/ubi/block.c
  8. +++ b/drivers/mtd/ubi/block.c
  9. @@ -609,10 +609,47 @@ match_volume_desc(struct ubi_volume_info
  10. return true;
  11. }
  12. +#define UBIFS_NODE_MAGIC 0x06101831
  13. +static inline int ubi_vol_is_ubifs(struct ubi_volume_desc *desc)
  14. +{
  15. + int ret;
  16. + uint32_t magic_of, magic;
  17. + ret = ubi_read(desc, 0, (char *)&magic_of, 0, 4);
  18. + if (ret)
  19. + return 0;
  20. + magic = le32_to_cpu(magic_of);
  21. + return magic == UBIFS_NODE_MAGIC;
  22. +}
  23. +
  24. +static void __init ubiblock_create_auto_rootfs(struct ubi_volume_info *vi)
  25. +{
  26. + int ret, is_ubifs;
  27. + struct ubi_volume_desc *desc;
  28. +
  29. + if (strcmp(vi->name, "rootfs") &&
  30. + strcmp(vi->name, "fit"))
  31. + return;
  32. +
  33. + desc = ubi_open_volume(vi->ubi_num, vi->vol_id, UBI_READONLY);
  34. + if (IS_ERR(desc))
  35. + return;
  36. +
  37. + is_ubifs = ubi_vol_is_ubifs(desc);
  38. + ubi_close_volume(desc);
  39. + if (is_ubifs)
  40. + return;
  41. +
  42. + ret = ubiblock_create(vi);
  43. + if (ret)
  44. + pr_err("UBI error: block: can't add '%s' volume, err=%d\n",
  45. + vi->name, ret);
  46. +}
  47. +
  48. static void
  49. ubiblock_create_from_param(struct ubi_volume_info *vi)
  50. {
  51. int i, ret = 0;
  52. + bool got_param = false;
  53. struct ubiblock_param *p;
  54. /*
  55. @@ -625,6 +662,7 @@ ubiblock_create_from_param(struct ubi_vo
  56. if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id))
  57. continue;
  58. + got_param = true;
  59. ret = ubiblock_create(vi);
  60. if (ret) {
  61. pr_err(
  62. @@ -633,6 +671,10 @@ ubiblock_create_from_param(struct ubi_vo
  63. }
  64. break;
  65. }
  66. +
  67. + /* auto-attach "rootfs" volume if existing and non-ubifs */
  68. + if (!got_param && IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV))
  69. + ubiblock_create_auto_rootfs(vi);
  70. }
  71. static int ubiblock_notify(struct notifier_block *nb,