From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 6/6] of: partition: add Linux CONFIG_OF_PARTITION-compatible adaptive fixup mode
Date: Mon, 17 Feb 2025 19:08:33 +0100 [thread overview]
Message-ID: <20250217180833.3955657-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250217180833.3955657-1-a.fatoum@pengutronix.de>
Linux supports OF partitions for MMC since Linux v6.13-rc1 with commit
2e3a191e89f9 ("block: add support for partition table defined in OF"),
but in a manner incompatible to barebox:
If CONFIG_OF_PARTITION is enabled and a fixed-partitions node exists,
the EFI/MBR partition table is completely ignored.
In barebox, they are allowed to coexist, as long as they don't conflict.
To resolve this conflict, we change the default fixup scheme to an
"adaptive" scheme that uses new-style fixups, but with the compatible
depending on the parent device:
- If the partitions node in the kernel DT already has a compatible,
use the same compatible as not to clobber new Linux OF partitions,
which would be parsed by CONFIG_OF_PARTITION
- If the device is an MTD device, use "fixed-partitions", so Linux
sees the same partitions and to maintain backwards compatibility
- For everything else (i.e. EEPROMs and SD/eMMC), use
"barebox,fixed-partitions"
This scheme is fully backwards-compatible with older kernels and
userspace:
- barebox,fixed-partitions replaces fixed-partitions only
for nodes that Linux didn't parse before anyway
- fixed-partitions will continue to be emitted for MTD,
which Linux did parse before
- barebox-state doesn't actually look for the "fixed-partitions"
compatible to find out if a patition is in a container.
Instead it checks the parent node name to be equal
to "partitions"...
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
.../devicetree/bindings/mtd/partition.rst | 27 +++++++++++++++++--
drivers/of/partition.c | 22 +++++++++++----
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/Documentation/devicetree/bindings/mtd/partition.rst b/Documentation/devicetree/bindings/mtd/partition.rst
index fb228c63a344..33b8a207f177 100644
--- a/Documentation/devicetree/bindings/mtd/partition.rst
+++ b/Documentation/devicetree/bindings/mtd/partition.rst
@@ -3,9 +3,16 @@
Representing flash partitions in devicetree
===========================================
-In addition to the upstream binding, another property is added:
+In addition to the upstream binding, barebox supports parsing OF partitions
+for EEPROMs and for SD/MMC as well. SD/MMC OF partitions in barebox are
+allowed to co-exist with GPT/MBR partitions as long as they don't overlap.
-Optional properties:
+This is different from the Linux behavior where OF partitions have precedence
+over GPT/MBR. For this reason, barebox also accepts the compatible
+``barebox,fixed-partitions``, which is handled inside barebox identically to
+``fixed-partitions``, but is ignored by Linux.
+
+Additionally, barebox supports an extra optional property:
* ``partuuid``: The global partition UUID for this partition.
For GPT partitions, the partuuid is the 16-byte GPT Partition UUID (e.g.
@@ -26,6 +33,9 @@ the partition table node is named appropriately:
``boot0-partitions`` and ``boot1-partitions`` are deprecated. Use ``partitions-boot1``
and ``partitions-boot2`` instead which is supported under Linux as well.
+In addition to the upstream ``fixed-partitions`` compatible binding,
+barebox also supports a ``barebox,fixed-partitions`` binding.
+
Examples:
.. code-block:: none
@@ -54,3 +64,16 @@ Examples:
};
};
};
+
+ sd {
+ partitions {
+ compatible = "barebox,fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ barebox-env@1000 {
+ label = "barebox-environment";
+ reg = <0x1000 0x20000>;
+ };
+ };
+ };
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index fa4847e20a2b..a0890bfcdef0 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -16,8 +16,6 @@
#include <init.h>
#include <globalvar.h>
-static unsigned int of_partition_binding;
-
/**
* enum of_binding_name - Name of binding to use for OF partition fixup
* @MTD_OF_BINDING_NEW: Fix up new-style partition bindings
@@ -25,13 +23,20 @@ static unsigned int of_partition_binding;
* @MTD_OF_BINDING_LEGACY: Fix up legacy partition bindings
* directly into the parent node without container
* @MTD_OF_BINDING_DONTTOUCH: Don't touch partition nodes at all - no fixups
+ * @MTD_OF_BINDING_ADAPTIVE: Do a new-style fixup with compatible being either:
+ * - the same compatible as in the kernel DT if available
+ * - "fixed-partitions" for MTD
+ * - "barebox,fixed-partitions" otherwise
*/
enum of_binding_name {
MTD_OF_BINDING_NEW,
MTD_OF_BINDING_LEGACY,
MTD_OF_BINDING_DONTTOUCH,
+ MTD_OF_BINDING_ADAPTIVE,
};
+static unsigned int of_partition_binding = MTD_OF_BINDING_ADAPTIVE;
+
struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
{
struct devfs_partition partinfo = {};
@@ -172,6 +177,7 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
{
struct cdev *partcdev;
struct device_node *part, *partnode;
+ const char *compat = "fixed-partitions";
int ret;
int n_cells, n_parts = 0;
@@ -199,10 +205,16 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
of_delete_node(partnode);
partnode = np;
break;
+ case MTD_OF_BINDING_ADAPTIVE:
+ /* If there's already a compatible property, leave it as-is */
+ if (of_property_present(partnode, "compatible"))
+ break;
+ if (!cdev->mtd)
+ compat = "barebox,fixed-partitions";
+ fallthrough;
case MTD_OF_BINDING_NEW:
partnode = partnode ?: of_new_node(np, "partitions");
- ret = of_property_write_string(partnode, "compatible",
- "fixed-partitions");
+ ret = of_property_write_string(partnode, "compatible", compat);
if (ret)
return ret;
break;
@@ -302,7 +314,7 @@ int of_partitions_register_fixup(struct cdev *cdev)
}
static const char *of_binding_names[] = {
- "new", "legacy", "donttouch"
+ "new", "legacy", "donttouch", "adaptive"
};
static int of_partition_init(void)
--
2.39.5
next prev parent reply other threads:[~2025-02-17 18:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 18:08 [PATCH 0/6] " Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 1/6] of: factor out of_node_is_fixed_partitions check Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 2/6] of: of_path: support barebox,fixed-partitions Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 3/6] ARM: IMX8MP: var-dart-dt8mcustomboard.dts: use new-style partition binding Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 4/6] ARM: dts: prefix all non-MTD fixed-partitions with barebox, Ahmad Fatoum
2025-02-17 18:08 ` [PATCH 5/6] of: partition: refactor of_partition_binding checks into switch Ahmad Fatoum
2025-02-17 18:08 ` Ahmad Fatoum [this message]
2025-02-17 19:25 ` [PATCH 0/6] of: partition: add Linux CONFIG_OF_PARTITION-compatible adaptive fixup mode Marco Felsch
2025-02-17 19:57 ` Ahmad Fatoum
2025-02-20 8:26 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250217180833.3955657-7-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox