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: librecmc-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 --- a/drivers/mtd/ubi/build.c
13 +++ b/drivers/mtd/ubi/build.c
14 @@ -1209,6 +1209,48 @@ static struct mtd_info * __init open_mtd
19 + * This function tries attaching mtd partitions named either "ubi" or "data"
22 +static void __init ubi_auto_attach(void)
25 + struct mtd_info *mtd;
27 + /* try attaching mtd device named "ubi" or "data" */
28 + mtd = open_mtd_device("ubi");
30 + mtd = open_mtd_device("data");
36 + /* check for a valid ubi magic */
37 + err = mtd_read(mtd, 0, 4, &len, (void *) magic);
38 + if (!err && len == 4 && strncmp(magic, "UBI#", 4)) {
39 + ubi_err("no valid UBI magic found inside mtd%d", mtd->index);
40 + put_mtd_device(mtd);
44 + /* auto-add only media types where UBI makes sense */
45 + if (mtd->type == MTD_NANDFLASH ||
46 + mtd->type == MTD_DATAFLASH ||
47 + mtd->type == MTD_MLCNANDFLASH) {
48 + mutex_lock(&ubi_devices_mutex);
49 + ubi_msg("auto-attach mtd%d", mtd->index);
50 + err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0);
51 + mutex_unlock(&ubi_devices_mutex);
53 + ubi_err("cannot attach mtd%d", mtd->index);
54 + put_mtd_device(mtd);
60 static int __init ubi_init(void)
63 @@ -1298,6 +1340,12 @@ static int __init ubi_init(void)
67 + /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd
68 + * parameter was given */
69 + if (config_enabled(CONFIG_MTD_ROOTFS_ROOT_DEV) &&
70 + !ubi_is_module() && !mtd_devs)
73 err = ubiblock_init();
75 ubi_err("block: cannot initialize, error %d", err);