aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic
diff options
context:
space:
mode:
authorChristian Marangi <ansuelsmth@gmail.com>2022-09-21 10:43:55 +0200
committerRafał Miłecki <rafal@milecki.pl>2022-09-21 10:43:55 +0200
commitedf3363959d3c43235dac2e973851ad572f082ae (patch)
treedd7b2c9ce09170c012f1532ab7e61c450bdf1c81 /target/linux/generic
parent8e5de897691a359d849fe97a7e235537f4f9cc14 (diff)
downloadupstream-edf3363959d3c43235dac2e973851ad572f082ae.tar.gz
upstream-edf3363959d3c43235dac2e973851ad572f082ae.tar.bz2
upstream-edf3363959d3c43235dac2e973851ad572f082ae.zip
kernel: backport mtd dynamic partition patch
Backport upstream solution that permits to declare nvmem cells with dynamic partition defined by special parser. This provide an OF node for NVMEM and connect it to the defined dynamic partition. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Signed-off-by: Rafał Miłecki <rafal@milecki.pl> (cherry picked from commit 1a9ee367343edce263f82cc91a49d796c9d45ea3)
Diffstat (limited to 'target/linux/generic')
-rw-r--r--target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch106
-rw-r--r--target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch2
-rw-r--r--target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch2
-rw-r--r--target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch2
4 files changed, 109 insertions, 3 deletions
diff --git a/target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch b/target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch
new file mode 100644
index 0000000000..475f72f272
--- /dev/null
+++ b/target/linux/generic/backport-5.4/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch
@@ -0,0 +1,106 @@
+From ad9b10d1eaada169bd764abcab58f08538877e26 Mon Sep 17 00:00:00 2001
+From: Christian Marangi <ansuelsmth@gmail.com>
+Date: Wed, 22 Jun 2022 03:06:28 +0200
+Subject: mtd: core: introduce of support for dynamic partitions
+
+We have many parser that register mtd partitions at runtime. One example
+is the cmdlinepart or the smem-part parser where the compatible is defined
+in the dts and the partitions gets detected and registered by the
+parser. This is problematic for the NVMEM subsystem that requires an OF
+node to detect NVMEM cells.
+
+To fix this problem, introduce an additional logic that will try to
+assign an OF node to the MTD if declared.
+
+On MTD addition, it will be checked if the MTD has an OF node and if
+not declared will check if a partition with the same label / node name is
+declared in DTS. If an exact match is found, the partition dynamically
+allocated by the parser will have a connected OF node.
+
+The NVMEM subsystem will detect the OF node and register any NVMEM cells
+declared statically in the DTS.
+
+Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+Link: https://lore.kernel.org/linux-mtd/20220622010628.30414-4-ansuelsmth@gmail.com
+---
+ drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 61 insertions(+)
+
+--- a/drivers/mtd/mtdcore.c
++++ b/drivers/mtd/mtdcore.c
+@@ -589,6 +589,66 @@ static int mtd_nvmem_add(struct mtd_info
+ return 0;
+ }
+
++static void mtd_check_of_node(struct mtd_info *mtd)
++{
++ struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
++ const char *pname, *prefix = "partition-";
++ int plen, mtd_name_len, offset, prefix_len;
++ struct mtd_info *parent;
++ bool found = false;
++
++ /* Check if MTD already has a device node */
++ if (dev_of_node(&mtd->dev))
++ return;
++
++ /* Check if a partitions node exist */
++ parent = mtd_get_master(mtd);
++ parent_dn = dev_of_node(&parent->dev);
++ if (!parent_dn)
++ return;
++
++ partitions = of_get_child_by_name(parent_dn, "partitions");
++ if (!partitions)
++ goto exit_parent;
++
++ prefix_len = strlen(prefix);
++ mtd_name_len = strlen(mtd->name);
++
++ /* Search if a partition is defined with the same name */
++ for_each_child_of_node(partitions, mtd_dn) {
++ offset = 0;
++
++ /* Skip partition with no/wrong prefix */
++ if (!of_node_name_prefix(mtd_dn, "partition-"))
++ continue;
++
++ /* Label have priority. Check that first */
++ if (of_property_read_string(mtd_dn, "label", &pname)) {
++ of_property_read_string(mtd_dn, "name", &pname);
++ offset = prefix_len;
++ }
++
++ plen = strlen(pname) - offset;
++ if (plen == mtd_name_len &&
++ !strncmp(mtd->name, pname + offset, plen)) {
++ found = true;
++ break;
++ }
++ }
++
++ if (!found)
++ goto exit_partitions;
++
++ /* Set of_node only for nvmem */
++ if (of_device_is_compatible(mtd_dn, "nvmem-cells"))
++ mtd_set_of_node(mtd, mtd_dn);
++
++exit_partitions:
++ of_node_put(partitions);
++exit_parent:
++ of_node_put(parent_dn);
++}
++
+ /**
+ * add_mtd_device - register an MTD device
+ * @mtd: pointer to new MTD device info structure
+@@ -672,6 +732,7 @@ int add_mtd_device(struct mtd_info *mtd)
+ mtd->dev.devt = MTD_DEVT(i);
+ dev_set_name(&mtd->dev, "mtd%d", i);
+ dev_set_drvdata(&mtd->dev, mtd);
++ mtd_check_of_node(mtd);
+ of_node_get(mtd_get_of_node(mtd));
+ error = device_register(&mtd->dev);
+ if (error)
diff --git a/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch b/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch
index 6a78a675e0..f65fc6c8be 100644
--- a/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch
+++ b/target/linux/generic/backport-5.4/414-v6.1-mtd-allow-getting-MTD-device-associated-with-a-speci.patch
@@ -25,7 +25,7 @@ Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
-@@ -1006,6 +1006,34 @@ int __get_mtd_device(struct mtd_info *mt
+@@ -1067,6 +1067,34 @@ int __get_mtd_device(struct mtd_info *mt
EXPORT_SYMBOL_GPL(__get_mtd_device);
/**
diff --git a/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch b/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch
index 95863d6edb..1189ce0f89 100644
--- a/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch
+++ b/target/linux/generic/pending-5.4/480-mtd-set-rootfs-to-be-root-dev.patch
@@ -20,7 +20,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
#include <linux/nvmem-provider.h>
#include <linux/mtd/mtd.h>
-@@ -699,6 +700,15 @@ int add_mtd_device(struct mtd_info *mtd)
+@@ -760,6 +761,15 @@ int add_mtd_device(struct mtd_info *mtd)
of this try_ nonsense, and no bitching about it
either. :) */
__module_get(THIS_MODULE);
diff --git a/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch b/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch
index d17106bfbc..a73775783e 100644
--- a/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch
+++ b/target/linux/generic/pending-5.4/495-mtd-core-add-get_mtd_device_by_node.patch
@@ -17,7 +17,7 @@ Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
-@@ -1081,6 +1081,44 @@ out_unlock:
+@@ -1142,6 +1142,44 @@ out_unlock:
}
EXPORT_SYMBOL_GPL(get_mtd_device_nm);