summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-10-17 08:10:24 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-10-17 08:10:24 +0200
commit854cdfbe265ebd99619bc6edc594d59b07c156fe (patch)
tree072c0cab0db0e2b703db22add9608d16e8712140 /commands
parent54709a8e5ed1e1d6c07bc24321aede08f27a1d58 (diff)
parent27112f5b5541d736a560dbc9f059d879d4b354a3 (diff)
downloadbarebox-854cdfbe265ebd99619bc6edc594d59b07c156fe.tar.gz
Merge branch 'for-next/of-overlay'
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig12
-rw-r--r--commands/Makefile1
-rw-r--r--commands/of_overlay.c89
3 files changed, 102 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index ad65fec..0189b47 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2106,6 +2106,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 85adc32..2f09801 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -79,6 +79,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 0000000..de3c3dc
--- /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