ramips: add support for ELECOM WMC-S1267GS2
[openwrt/openwrt.git] / target / linux / generic / pending-6.6 / 491-ubi-auto-create-ubiblock-device-for-rootfs.patch
1 From: Daniel Golle <daniel@makrotopia.org>
2 Subject: ubi: auto-create ubiblock device for rootfs
3
4 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
5 ---
6 drivers/mtd/ubi/block.c | 42 ++++++++++++++++++++++++++++++++++++++++++
7 1 file changed, 42 insertions(+)
8
9 --- a/drivers/mtd/ubi/block.c
10 +++ b/drivers/mtd/ubi/block.c
11 @@ -609,10 +609,47 @@ match_volume_desc(struct ubi_volume_info
12 return true;
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(struct ubi_volume_info *vi)
28 +{
29 + int ret, is_ubifs;
30 + struct ubi_volume_desc *desc;
31 +
32 + if (strcmp(vi->name, "rootfs") &&
33 + strcmp(vi->name, "fit"))
34 + return;
35 +
36 + desc = ubi_open_volume(vi->ubi_num, vi->vol_id, UBI_READONLY);
37 + if (IS_ERR(desc))
38 + return;
39 +
40 + is_ubifs = ubi_vol_is_ubifs(desc);
41 + ubi_close_volume(desc);
42 + if (is_ubifs)
43 + return;
44 +
45 + ret = ubiblock_create(vi);
46 + if (ret)
47 + pr_err("UBI error: block: can't add '%s' volume, err=%d\n",
48 + vi->name, ret);
49 +}
50 +
51 static void
52 ubiblock_create_from_param(struct ubi_volume_info *vi)
53 {
54 int i, ret = 0;
55 + bool got_param = false;
56 struct ubiblock_param *p;
57
58 /*
59 @@ -625,6 +662,7 @@ ubiblock_create_from_param(struct ubi_vo
60 if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id))
61 continue;
62
63 + got_param = true;
64 ret = ubiblock_create(vi);
65 if (ret) {
66 pr_err(
67 @@ -633,6 +671,10 @@ ubiblock_create_from_param(struct ubi_vo
68 }
69 break;
70 }
71 +
72 + /* auto-attach "rootfs" volume if existing and non-ubifs */
73 + if (!got_param && IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV))
74 + ubiblock_create_auto_rootfs(vi);
75 }
76
77 static int ubiblock_notify(struct notifier_block *nb,