[RFC PATCH 4/7] commands: add oftree -o option for overlays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extend the oftree command to allow to register devicetree overlays.

Signed-off-by: Michael Tretter <m.tretter@xxxxxxxxxxxxxx>
---
 commands/oftree.c | 37 ++++++++++++++++++++++++++++++++++---
 include/of.h      |  2 +-
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/commands/oftree.c b/commands/oftree.c
index 299c2edfcd..e61393ce6a 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -48,10 +48,11 @@ static int do_oftree(int argc, char *argv[])
 	int probe = 0;
 	char *load = NULL;
 	char *save = NULL;
+	char *overlay = NULL;
 	int ret;
 	struct device_node *root;
 
-	while ((opt = getopt(argc, argv, "pfl:s:")) > 0) {
+	while ((opt = getopt(argc, argv, "pfl:o:s:")) > 0) {
 		switch (opt) {
 		case 'l':
 			load = optarg;
@@ -64,13 +65,21 @@ static int do_oftree(int argc, char *argv[])
 				return COMMAND_ERROR_USAGE;
 			}
 			break;
+		case 'o':
+			if (IS_ENABLED(CONFIG_OF_OVERLAY)) {
+				overlay = optarg;
+			} else {
+				printf("oftree overlay support disabled\n");
+				return COMMAND_ERROR_USAGE;
+			}
+			break;
 		case 's':
 			save = optarg;
 			break;
 		}
 	}
 
-	if (!probe && !load && !save)
+	if (!probe && !load && !save && !overlay)
 		return COMMAND_ERROR_USAGE;
 
 	if (save) {
@@ -109,6 +118,27 @@ static int do_oftree(int argc, char *argv[])
 		}
 	}
 
+	if (overlay) {
+		fdt = read_file(overlay, &size);
+		if (!fdt) {
+			printf("unable to read %s\n", overlay);
+			return 1;
+		}
+
+		root = of_unflatten_dtb(fdt);
+		if (IS_ERR(root))
+			return PTR_ERR(root);
+
+		free(fdt);
+
+		ret = of_register_overlay(root);
+		if (ret) {
+			printf("cannot apply oftree overlay: %s\n", strerror(-ret));
+			of_delete_node(root);
+			goto out;
+		}
+	}
+
 	if (probe) {
 		ret = of_probe();
 		if (ret)
@@ -125,13 +155,14 @@ BAREBOX_CMD_HELP_START(oftree)
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-l <DTB>",  "Load <DTB> to internal devicetree")
 BAREBOX_CMD_HELP_OPT ("-s <DTB>",  "save internal devicetree to <DTB>")
+BAREBOX_CMD_HELP_OPT ("-o <DTBO>",  "register devicetree overlay <DTBO>")
 BAREBOX_CMD_HELP_OPT ("-p",  "probe devices from stored device tree")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(oftree)
 	.cmd		= do_oftree,
 	BAREBOX_CMD_DESC("handle device trees")
-	BAREBOX_CMD_OPTS("[-lsp]")
+	BAREBOX_CMD_OPTS("[-lspo]")
 	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
 	BAREBOX_CMD_HELP(cmd_oftree_help)
 BAREBOX_CMD_END
diff --git a/include/of.h b/include/of.h
index 13ba46a669..ec7872e613 100644
--- a/include/of.h
+++ b/include/of.h
@@ -884,7 +884,7 @@ struct of_overlay_notify_data {
 
 #ifdef CONFIG_OF_OVERLAY
 struct device_node *of_resolve_phandles(struct device_node *root,
-				        struct device_node *overlay);
+					struct device_node *overlay);
 int of_register_overlay(struct device_node *overlay);
 int of_overlay_notifier_register(struct notifier_block *nb);
 int of_overlay_notifier_unregister(struct notifier_block *nb);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux