kernel: backport the ubiblock patches from 3.14->3.10
[openwrt.git] / target / linux / generic / patches-3.10 / 490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
1 From 8a52e4100d7c3a4a1dfddfa02b8864a9b0068c13 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sat, 17 May 2014 03:36:18 +0200
4 Subject: [PATCH 1/5] ubi: auto-attach mtd device named "ubi" or "data" on boot
5 To: openwrt-devel@lists.openwrt.org
6
7 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
8 ---
9  drivers/mtd/ubi/build.c | 36 ++++++++++++++++++++++++++++++++++++
10  1 file changed, 36 insertions(+)
11
12 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
13 index 6e30a3c..999a36b 100644
14 --- a/drivers/mtd/ubi/build.c
15 +++ b/drivers/mtd/ubi/build.c
16 @@ -1209,6 +1209,36 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
17         return mtd;
18  }
19  
20 +/*
21 + * This function tries attaching mtd partitions named either "ubi" or "data"
22 + * during boot.
23 + */
24 +static void __init ubi_auto_attach(void)
25 +{
26 +       int err;
27 +       struct mtd_info *mtd;
28 +       /* try attaching mtd device named "ubi" or "data" */
29 +       mtd = open_mtd_device("ubi");
30 +       if (IS_ERR(mtd))
31 +               mtd = open_mtd_device("data");
32 +
33 +       if (!IS_ERR(mtd)) {
34 +               /* auto-add only media types where UBI makes sense */
35 +               if (mtd->type == MTD_NANDFLASH ||
36 +                   mtd->type == MTD_DATAFLASH ||
37 +                   mtd->type == MTD_MLCNANDFLASH) {
38 +                       mutex_lock(&ubi_devices_mutex);
39 +                       ubi_msg("auto-attach mtd%d", mtd->index);
40 +                       err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0);
41 +                       mutex_unlock(&ubi_devices_mutex);
42 +                       if (err < 0) {
43 +                               ubi_err("cannot attach mtd%d", mtd->index);
44 +                               put_mtd_device(mtd);
45 +                       }
46 +               }
47 +       }
48 +}
49 +
50  static int __init ubi_init(void)
51  {
52         int err, i, k;
53 @@ -1298,6 +1328,12 @@ static int __init ubi_init(void)
54                 }
55         }
56  
57 +       /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd
58 +        * parameter was given */
59 +       if (config_enabled(CONFIG_MTD_ROOTFS_ROOT_DEV) &&
60 +           !ubi_is_module() && !mtd_devs)
61 +               ubi_auto_attach();
62 +
63         err = ubiblock_init();
64         if (err) {
65                 ubi_err("block: cannot initialize, error %d", err);
66 -- 
67 1.9.2
68