kernel: update 4.0 to 4.0.5
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-4.0 / 491-ubi-auto-create-ubiblock-device-for-rootfs.patch
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
7 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
8 ---
9 drivers/mtd/ubi/block.c | 42 ++++++++++++++++++++++++++++++++++++++++++
10 1 file changed, 42 insertions(+)
11
12 --- a/drivers/mtd/ubi/block.c
13 +++ b/drivers/mtd/ubi/block.c
14 @@ -616,6 +616,44 @@ static void __init ubiblock_create_from_
15 }
16 }
17
18 +#define UBIFS_NODE_MAGIC 0x06101831
19 +static inline int ubi_vol_is_ubifs(struct ubi_volume_desc *desc)
20 +{
21 + int ret;
22 + uint32_t magic_of, magic;
23 + ret = ubi_read(desc, 0, (char *)&magic_of, 0, 4);
24 + if (ret)
25 + return 0;
26 + magic = le32_to_cpu(magic_of);
27 + return magic == UBIFS_NODE_MAGIC;
28 +}
29 +
30 +static void __init ubiblock_create_auto_rootfs(void)
31 +{
32 + int ubi_num, ret, is_ubifs;
33 + struct ubi_volume_desc *desc;
34 + struct ubi_volume_info vi;
35 +
36 + for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) {
37 + desc = ubi_open_volume_nm(ubi_num, "rootfs", UBI_READONLY);
38 + if (IS_ERR(desc))
39 + continue;
40 +
41 + ubi_get_volume_info(desc, &vi);
42 + is_ubifs = ubi_vol_is_ubifs(desc);
43 + ubi_close_volume(desc);
44 + if (is_ubifs)
45 + break;
46 +
47 + ret = ubiblock_create(&vi);
48 + if (ret)
49 + pr_err("UBI error: block: can't add '%s' volume, err=%d\n",
50 + vi.name, ret);
51 + /* always break if we get here */
52 + break;
53 + }
54 +}
55 +
56 static void ubiblock_remove_all(void)
57 {
58 struct ubiblock *next;
59 @@ -646,6 +684,10 @@ int __init ubiblock_init(void)
60 */
61 ubiblock_create_from_param();
62
63 + /* auto-attach "rootfs" volume if existing and non-ubifs */
64 + if (config_enabled(CONFIG_MTD_ROOTFS_ROOT_DEV))
65 + ubiblock_create_auto_rootfs();
66 +
67 /*
68 * Block devices are only created upon user requests, so we ignore
69 * existing volumes.