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
7 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
9 drivers/mtd/ubi/build.c | 36 ++++++++++++++++++++++++++++++++++++
10 1 file changed, 36 insertions(+)
12 Index: linux-4.9.17/drivers/mtd/ubi/build.c
13 ===================================================================
14 --- linux-4.9.17.orig/drivers/mtd/ubi/build.c
15 +++ linux-4.9.17/drivers/mtd/ubi/build.c
16 @@ -1212,6 +1212,49 @@ static struct mtd_info * __init open_mtd
21 + * This function tries attaching mtd partitions named either "ubi" or "data"
24 +static void __init ubi_auto_attach(void)
27 + struct mtd_info *mtd;
29 + /* try attaching mtd device named "ubi" or "data" */
30 + mtd = open_mtd_device("ubi");
32 + mtd = open_mtd_device("data");
38 + /* check for a valid ubi magic */
39 + err = mtd_read(mtd, 0, 4, &len, (void *) magic);
40 + if (!err && len == 4 && strncmp(magic, "UBI#", 4)) {
41 + pr_err("UBI error: no valid UBI magic found inside mtd%d", mtd->index);
42 + put_mtd_device(mtd);
46 + /* auto-add only media types where UBI makes sense */
47 + if (mtd->type == MTD_NANDFLASH ||
48 + mtd->type == MTD_NORFLASH ||
49 + mtd->type == MTD_DATAFLASH ||
50 + mtd->type == MTD_MLCNANDFLASH) {
51 + mutex_lock(&ubi_devices_mutex);
52 + pr_notice("UBI: auto-attach mtd%d\n", mtd->index);
53 + err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0);
54 + mutex_unlock(&ubi_devices_mutex);
56 + pr_err("UBI error: cannot attach mtd%d", mtd->index);
57 + put_mtd_device(mtd);
63 static int __init ubi_init(void)
66 @@ -1295,6 +1338,12 @@ static int __init ubi_init(void)
70 + /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd
71 + * parameter was given */
72 + if (IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV) &&
73 + !ubi_is_module() && !mtd_devs)
76 err = ubiblock_init();
78 pr_err("UBI error: block: cannot initialize, error %d", err);