kernel: update 3.14 to 3.14.7
[openwrt.git] / target / linux / generic / patches-3.14 / 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 --- a/drivers/mtd/ubi/build.c
13 +++ b/drivers/mtd/ubi/build.c
14 @@ -1209,6 +1209,36 @@ static struct mtd_info * __init open_mtd
15         return mtd;
16  }
17  
18 +/*
19 + * This function tries attaching mtd partitions named either "ubi" or "data"
20 + * during boot.
21 + */
22 +static void __init ubi_auto_attach(void)
23 +{
24 +       int err;
25 +       struct mtd_info *mtd;
26 +       /* try attaching mtd device named "ubi" or "data" */
27 +       mtd = open_mtd_device("ubi");
28 +       if (IS_ERR(mtd))
29 +               mtd = open_mtd_device("data");
30 +
31 +       if (!IS_ERR(mtd)) {
32 +               /* auto-add only media types where UBI makes sense */
33 +               if (mtd->type == MTD_NANDFLASH ||
34 +                   mtd->type == MTD_DATAFLASH ||
35 +                   mtd->type == MTD_MLCNANDFLASH) {
36 +                       mutex_lock(&ubi_devices_mutex);
37 +                       ubi_msg("auto-attach mtd%d", mtd->index);
38 +                       err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0);
39 +                       mutex_unlock(&ubi_devices_mutex);
40 +                       if (err < 0) {
41 +                               ubi_err("cannot attach mtd%d", mtd->index);
42 +                               put_mtd_device(mtd);
43 +                       }
44 +               }
45 +       }
46 +}
47 +
48  static int __init ubi_init(void)
49  {
50         int err, i, k;
51 @@ -1298,6 +1328,12 @@ static int __init ubi_init(void)
52                 }
53         }
54  
55 +       /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd
56 +        * parameter was given */
57 +       if (config_enabled(CONFIG_MTD_ROOTFS_ROOT_DEV) &&
58 +           !ubi_is_module() && !mtd_devs)
59 +               ubi_auto_attach();
60 +
61         err = ubiblock_init();
62         if (err) {
63                 ubi_err("block: cannot initialize, error %d", err);