[PATCH 09/17] overlay: only apply compatible trees
Sascha Hauer
s.hauer at pengutronix.de
Wed Mar 10 13:28:21 GMT 2021
This adds support for a global.of_overlay_compatible variable which is a
space separated list of compatible strings. Device tree overlays not
matching any won't be applied (unless the overlay doesn't have a
compatible property at all).
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/of/overlay.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 8f4ee3f0a2..7a89cbe948 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -11,6 +11,9 @@
#include <common.h>
#include <of.h>
#include <errno.h>
+#include <globalvar.h>
+#include <magicvar.h>
+#include <string.h>
static struct device_node *find_target(struct device_node *root,
struct device_node *fragment)
@@ -160,6 +163,33 @@ static int of_overlay_apply_fragment(struct device_node *root,
return of_overlay_apply(target, overlay);
}
+static char *of_overlay_compatible;
+
+static bool of_overlay_is_compatible(struct device_node *ovl)
+{
+ char *p, *n, *compatibles;
+ bool res = false;
+
+ if (!of_overlay_compatible || !*of_overlay_compatible)
+ return true;
+ if (!of_find_property(ovl, "compatible", NULL))
+ return true;
+
+ p = compatibles = xstrdup(of_overlay_compatible);
+
+ while ((n = strsep_unescaped(&p, " "))) {
+ if (of_device_is_compatible(ovl, n)) {
+ res = true;
+ break;
+ }
+ }
+
+ free(compatibles);
+
+ return res;
+}
+
+
/**
* Apply the overlay on the passed devicetree root
* @root: the devicetree onto which the overlay will be applied
@@ -172,6 +202,9 @@ int of_overlay_apply_tree(struct device_node *root,
struct device_node *fragment;
int err = 0;
+ if (!of_overlay_is_compatible(overlay))
+ return -ENODEV;
+
resolved = of_resolve_phandles(root, overlay);
if (!resolved)
return -EINVAL;
@@ -250,3 +283,13 @@ int of_register_overlay(struct device_node *overlay)
{
return of_register_fixup(of_overlay_fixup, overlay);
}
+
+static int of_overlay_init(void)
+{
+ globalvar_add_simple_string("of_overlay_compatible", &of_overlay_compatible);
+
+ return 0;
+}
+device_initcall(of_overlay_init);
+
+BAREBOX_MAGICVAR(global.of_overlay_compatible, "space separated list of compatibles an overlay must match");
--
2.29.2
More information about the barebox
mailing list