505e347e40ebcbaadad50e941b7d614a116f9ead
[openwrt/staging/jow.git] /
1 From 26422ac78e9d8767bd4aabfbae616b15edbf6a1b Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Sat, 22 Oct 2022 23:13:18 +0200
4 Subject: [PATCH] mtd: core: set ROOT_DEV for partitions marked as rootfs in DT
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This adds support for "linux,rootfs" binding that is used to mark flash
10 partition containing rootfs. It's useful for devices using device tree
11 that don't have bootloader passing root info in cmdline.
12
13 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
14 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
15 Link: https://lore.kernel.org/linux-mtd/20221022211318.32009-2-zajec5@gmail.com
16 ---
17 drivers/mtd/mtdcore.c | 12 ++++++++++++
18 1 file changed, 12 insertions(+)
19
20 --- a/drivers/mtd/mtdcore.c
21 +++ b/drivers/mtd/mtdcore.c
22 @@ -28,6 +28,7 @@
23 #include <linux/leds.h>
24 #include <linux/debugfs.h>
25 #include <linux/nvmem-provider.h>
26 +#include <linux/root_dev.h>
27
28 #include <linux/mtd/mtd.h>
29 #include <linux/mtd/partitions.h>
30 @@ -748,6 +749,17 @@ int add_mtd_device(struct mtd_info *mtd)
31 not->add(mtd);
32
33 mutex_unlock(&mtd_table_mutex);
34 +
35 + if (of_find_property(mtd_get_of_node(mtd), "linux,rootfs", NULL)) {
36 + if (IS_BUILTIN(CONFIG_MTD)) {
37 + pr_info("mtd: setting mtd%d (%s) as root device\n", mtd->index, mtd->name);
38 + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
39 + } else {
40 + pr_warn("mtd: can't set mtd%d (%s) as root device - mtd must be builtin\n",
41 + mtd->index, mtd->name);
42 + }
43 + }
44 +
45 /* We _know_ we aren't being removed, because
46 our caller is still holding us here. So none
47 of this try_ nonsense, and no bitching about it