summaryrefslogtreecommitdiffstats
path: root/common/oftree.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/oftree.c')
-rw-r--r--common/oftree.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/common/oftree.c b/common/oftree.c
index 51f825c3f3..91b3fcc9fa 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -207,11 +207,16 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
int instance = reset_source_get_instance();
struct device_d *dev;
const char *serialno;
+ const char *compat;
serialno = barebox_get_serial_number();
if (serialno)
of_property_write_string(root, "serial-number", serialno);
+ compat = barebox_get_of_machine_compatible();
+ if (compat)
+ of_prepend_machine_compatible(root, compat);
+
node = of_create_node(root, "/chosen");
if (!node)
return -ENOMEM;
@@ -483,3 +488,34 @@ int of_autoenable_i2c_by_component(char *path)
return ret;
}
+
+int of_prepend_machine_compatible(struct device_node *root, const char *compat)
+{
+ int cclen = 0, clen = strlen(compat) + 1;
+ const char *curcompat;
+ void *buf;
+
+ if (!root) {
+ root = of_get_root_node();
+ if (!root)
+ return -ENODEV;
+ }
+
+ if (of_device_is_compatible(root, compat))
+ return 0;
+
+ curcompat = of_get_property(root, "compatible", &cclen);
+
+ buf = xzalloc(cclen + clen);
+
+ memcpy(buf, compat, clen);
+
+ if (curcompat)
+ memcpy(buf + clen, curcompat, cclen);
+
+ of_set_property(root, "compatible", buf, cclen + clen, true);
+
+ free(buf);
+
+ return 0;
+}