2022-10-19 12:25:46

by Rafał Miłecki

[permalink] [raw]
Subject: [PATCH 1/2] dt-bindings: mtd: partitions: support marking root device partition

From: Rafał Miłecki <[email protected]>

Linux needs to know what to use as root device. On embedded devices with
flash the only common way to specify that is cmdline & root= parameter.

That solution works with U-Boot which is Linux & cmdline aware but isn't
available with all market bootloaders. Also that method is fragile:
1. Requires specific probing order on multi-flash devices
2. Uses hardcoded partitions indexes

A lot of devices use different partitioning methods. It may be
"fixed-partitions" or some dynamic partitioning (e.g. based on parts
table). For such cases allow "linux,root-device" property to mark
correct flash partition.

Signed-off-by: Rafał Miłecki <[email protected]>
---
.../devicetree/bindings/mtd/partitions/fixed-partitions.yaml | 1 +
.../devicetree/bindings/mtd/partitions/partition.yaml | 4 ++++
2 files changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/mtd/partitions/fixed-partitions.yaml b/Documentation/devicetree/bindings/mtd/partitions/fixed-partitions.yaml
index ad3ccd250802..e627085df4fc 100644
--- a/Documentation/devicetree/bindings/mtd/partitions/fixed-partitions.yaml
+++ b/Documentation/devicetree/bindings/mtd/partitions/fixed-partitions.yaml
@@ -84,6 +84,7 @@ examples:
partition@0 {
label = "filesystem";
reg = <0x00000000 0x1 0x00000000>;
+ linux,root-device;
};
};

diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml
index f1a02d840b12..671906acf1bd 100644
--- a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml
+++ b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml
@@ -52,6 +52,10 @@ properties:
immune to paired-pages corruptions
type: boolean

+ linux,root-device:
+ description: Marks partition that is a root device with filesystem to mount
+ and boot user space from
+
if:
not:
required: [ reg ]
--
2.34.1


2022-10-19 13:17:05

by Rafał Miłecki

[permalink] [raw]
Subject: [PATCH 2/2] mtd: core: set ROOT_DEV for partitions marked as root devices in DT

From: Rafał Miłecki <[email protected]>

This adds support for "linux,root-device" binding that is used to mark
root device MTD partition. It's useful for devices using device tree
that don't have bootloader passing root info in cmdline.

Signed-off-by: Rafał Miłecki <[email protected]>
---
drivers/mtd/mtdcore.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 07249af4f890..034b06aff660 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -28,6 +28,7 @@
#include <linux/leds.h>
#include <linux/debugfs.h>
#include <linux/nvmem-provider.h>
+#include <linux/root_dev.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
@@ -735,6 +736,12 @@ int add_mtd_device(struct mtd_info *mtd)
not->add(mtd);

mutex_unlock(&mtd_table_mutex);
+
+ if (of_find_property(mtd_get_of_node(mtd), "linux,rootfs", NULL)) {
+ pr_info("mtd: setting mtd%d (%s) as root device\n", mtd->index, mtd->name);
+ ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
+ }
+
/* We _know_ we aren't being removed, because
our caller is still holding us here. So none
of this try_ nonsense, and no bitching about it
--
2.34.1