2
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 0f3966579815f889bb2fcb4846152c35f65e79c4 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <daniel@makrotopia.org>
  3. Date: Thu, 15 May 2014 21:06:33 +0200
  4. Subject: [PATCH 2/5] ubi: auto-create ubiblock device for rootfs
  5. To: openwrt-devel@lists.openwrt.org
  6. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  7. ---
  8. drivers/mtd/ubi/block.c | 42 ++++++++++++++++++++++++++++++++++++++++++
  9. 1 file changed, 42 insertions(+)
  10. --- a/drivers/mtd/ubi/block.c
  11. +++ b/drivers/mtd/ubi/block.c
  12. @@ -628,6 +628,44 @@ static void __init ubiblock_create_from_
  13. }
  14. }
  15. +#define UBIFS_NODE_MAGIC 0x06101831
  16. +static inline int ubi_vol_is_ubifs(struct ubi_volume_desc *desc)
  17. +{
  18. + int ret;
  19. + uint32_t magic_of, magic;
  20. + ret = ubi_read(desc, 0, (char *)&magic_of, 0, 4);
  21. + if (ret)
  22. + return 0;
  23. + magic = le32_to_cpu(magic_of);
  24. + return magic == UBIFS_NODE_MAGIC;
  25. +}
  26. +
  27. +static void __init ubiblock_create_auto_rootfs(void)
  28. +{
  29. + int ubi_num, ret, is_ubifs;
  30. + struct ubi_volume_desc *desc;
  31. + struct ubi_volume_info vi;
  32. +
  33. + for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) {
  34. + desc = ubi_open_volume_nm(ubi_num, "rootfs", UBI_READONLY);
  35. + if (IS_ERR(desc))
  36. + continue;
  37. +
  38. + ubi_get_volume_info(desc, &vi);
  39. + is_ubifs = ubi_vol_is_ubifs(desc);
  40. + ubi_close_volume(desc);
  41. + if (is_ubifs)
  42. + break;
  43. +
  44. + ret = ubiblock_create(&vi);
  45. + if (ret)
  46. + pr_err("UBI error: block: can't add '%s' volume, err=%d\n",
  47. + vi.name, ret);
  48. + /* always break if we get here */
  49. + break;
  50. + }
  51. +}
  52. +
  53. static void ubiblock_remove_all(void)
  54. {
  55. struct ubiblock *next;
  56. @@ -658,6 +696,10 @@ int __init ubiblock_init(void)
  57. */
  58. ubiblock_create_from_param();
  59. + /* auto-attach "rootfs" volume if existing and non-ubifs */
  60. + if (config_enabled(CONFIG_MTD_ROOTFS_ROOT_DEV))
  61. + ubiblock_create_auto_rootfs();
  62. +
  63. /*
  64. * Block devices are only created upon user requests, so we ignore
  65. * existing volumes.