mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH v3 7/8] commands: add of_overlay command for device tree overlays
Date: Fri, 13 Sep 2019 15:14:45 +0200	[thread overview]
Message-ID: <20190913131446.8202-8-m.tretter@pengutronix.de> (raw)
In-Reply-To: <20190913131446.8202-1-m.tretter@pengutronix.de>

Add a new command "of_overlay" for applying device tree overlays,
because it does not really fit into any other device tree related
command and would create a mess with the command options.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>

---
Changelog:

v2->v3:
- select OF_OVERLAY from CMD_OF_OVERLAY
- fix name of of_firmware_load_overlay()

v1->v2: none
---
 commands/Kconfig      | 12 ++++++
 commands/Makefile     |  1 +
 commands/of_overlay.c | 89 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+)
 create mode 100644 commands/of_overlay.c

diff --git a/commands/Kconfig b/commands/Kconfig
index e03110fd46..298e0fb9e9 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2088,6 +2088,18 @@ config CMD_OF_FIXUP_STATUS
 	  Register a fixup to enable or disable a device tree node.
 	  Nodes are enabled on default. Disabled with -d.
 
+config CMD_OF_OVERLAY
+	tristate
+	select OF_OVERLAY
+	prompt "of_overlay"
+	help
+	  of_overlay - register device tree overlay as fixup
+
+	  Usage: of_overlay [-S path] FILE
+
+	  Options:
+		  -S path	load firmware using this search path
+
 config CMD_OFTREE
 	tristate
 	select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index 5cd35b78a7..ebdc437e55 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -78,6 +78,7 @@ obj-$(CONFIG_CMD_OF_NODE)	+= of_node.o
 obj-$(CONFIG_CMD_OF_DUMP)	+= of_dump.o
 obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS)	+= of_display_timings.o
 obj-$(CONFIG_CMD_OF_FIXUP_STATUS)	+= of_fixup_status.o
+obj-$(CONFIG_CMD_OF_OVERLAY)	+= of_overlay.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
 obj-$(CONFIG_CMD_IOMEM)		+= iomemport.o
 obj-$(CONFIG_CMD_LINUX_EXEC)	+= linux_exec.o
diff --git a/commands/of_overlay.c b/commands/of_overlay.c
new file mode 100644
index 0000000000..de3c3dcee5
--- /dev/null
+++ b/commands/of_overlay.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 Michael Tretter <m.tretter@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <command.h>
+#include <common.h>
+#include <environment.h>
+#include <fdt.h>
+#include <firmware.h>
+#include <fs.h>
+#include <getopt.h>
+#include <libfile.h>
+#include <of.h>
+
+static int do_of_overlay(int argc, char *argv[])
+{
+	int opt, ret;
+	struct fdt_header *fdt;
+	struct device_node *overlay;
+	const char *search_path = NULL;
+
+	while ((opt = getopt(argc, argv, "S:")) > 0) {
+		switch (opt) {
+		case 'S':
+			search_path = optarg;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (argc != optind + 1)
+		return COMMAND_ERROR_USAGE;
+
+	fdt = read_file(argv[optind], NULL);
+	if (!fdt) {
+		printf("cannot read %s\n", argv[optind]);
+		return 1;
+	}
+
+	overlay = of_unflatten_dtb(fdt);
+	free(fdt);
+	if (IS_ERR(overlay))
+		return PTR_ERR(overlay);
+
+	if (search_path) {
+		ret = of_firmware_load_overlay(overlay, search_path);
+		if (ret)
+			goto err;
+	}
+
+	ret = of_register_overlay(overlay);
+	if (ret) {
+		printf("cannot apply oftree overlay: %s\n", strerror(-ret));
+		goto err;
+	}
+
+	return 0;
+
+err:
+	of_delete_node(overlay);
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(of_overlay)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-S path", "load firmware using this search path")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_overlay)
+	.cmd = do_of_overlay,
+	BAREBOX_CMD_DESC("register device tree overlay as fixup")
+	BAREBOX_CMD_OPTS("[-S path] FILE")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_HELP(cmd_of_overlay_help)
+BAREBOX_CMD_END
-- 
2.20.1


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

  parent reply	other threads:[~2019-09-13 13:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13 13:14 [PATCH v3 0/8] Device Tree Overlay Support Michael Tretter
2019-09-13 13:14 ` [PATCH v3 1/8] of: add support for devicetree overlays Michael Tretter
2019-09-13 13:14 ` [PATCH v3 2/8] blspec: " Michael Tretter
2019-09-13 13:14 ` [PATCH v3 3/8] of: add iterator for overlays Michael Tretter
2019-09-13 13:14 ` [PATCH v3 4/8] firmware: add function to find firmware by devicetree node Michael Tretter
2019-09-13 13:14 ` [PATCH v3 5/8] firmware: add support to load firmware from dt overlay Michael Tretter
2019-09-13 13:14 ` [PATCH v3 6/8] blspec: load firmware if specified in " Michael Tretter
2019-09-13 13:14 ` Michael Tretter [this message]
2019-09-13 13:14 ` [PATCH v3 8/8] dtc: optionally add add __symbols__ to build-in devicetree Michael Tretter
2019-09-16  7:07 ` [PATCH v3 0/8] Device Tree Overlay Support 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=20190913131446.8202-8-m.tretter@pengutronix.de \
    --to=m.tretter@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