summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2023-05-24 09:54:48 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-05-24 09:54:48 +0200
commit89c8cbea752a31f18da169a90210b296a9c31e0e (patch)
tree07c6eaa2e5879af6f8720dd21c0c11c0c5bf9a5e /commands
parentda9b325a9ca70de3a872d4bc3db64da3c2511419 (diff)
parentf0d275c2054ee795454598af59344be0aa1eef09 (diff)
downloadbarebox-89c8cbea752a31f18da169a90210b296a9c31e0e.tar.gz
barebox-89c8cbea752a31f18da169a90210b296a9c31e0e.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig14
-rw-r--r--commands/Makefile1
-rw-r--r--commands/of_diff.c13
-rw-r--r--commands/of_display_timings.c26
-rw-r--r--commands/of_dump.c15
-rw-r--r--commands/of_fixup.c93
-rw-r--r--commands/of_overlay.c15
-rw-r--r--commands/oftree.c16
8 files changed, 123 insertions, 70 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 35d0079f78..4d3ff631a8 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2257,6 +2257,20 @@ config CMD_OF_DISPLAY_TIMINGS
-s path select display-timings and register oftree fixup
-f dtb work on dtb. Has no effect on -s option
+config CMD_OF_FIXUP
+ tristate
+ select OFTREE
+ depends on KALLSYMS
+ prompt "of_fixup"
+ help
+ List and enable/disable fixups
+
+ Usage: of_fixup [-de] [fixups...]
+
+ Options:
+ -d disable fixup
+ -e re-enable fixup
+
config CMD_OF_FIXUP_STATUS
tristate
select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index cac1d4f253..98625a0373 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_CMD_OF_PROPERTY) += of_property.o
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) += of_fixup.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
diff --git a/commands/of_diff.c b/commands/of_diff.c
index 6a78263200..19a4a26d20 100644
--- a/commands/of_diff.c
+++ b/commands/of_diff.c
@@ -16,9 +16,6 @@
static struct device_node *get_tree(const char *filename, struct device_node *root)
{
struct device_node *node;
- void *fdt;
- size_t size;
- int ret;
if (!strcmp(filename, "-")) {
node = of_get_root_node();
@@ -40,15 +37,7 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro
return node;
}
- ret = read_file_2(filename, &size, &fdt, FILESIZE_MAX);
- if (ret)
- return ERR_PTR(ret);
-
- node = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
- return node;
+ return of_read_file(filename);
}
static int do_of_diff(int argc, char *argv[])
diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index aab57b17d6..1fb0c4eb00 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -67,29 +67,11 @@ static int do_of_display_timings(int argc, char *argv[])
/* Check if external dtb given */
if (dtbfile) {
- void *fdt;
- size_t size;
-
- fdt = read_file(dtbfile, &size);
- if (!fdt) {
- pr_err("unable to read %s: %s\n", dtbfile,
- strerror(errno));
- return -errno;
- }
-
- if (file_detect_type(fdt, size) != filetype_oftree) {
- pr_err("%s is not a oftree file.\n", dtbfile);
- free(fdt);
- return -EINVAL;
- }
-
- root = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
- if (IS_ERR(root))
+ root = of_read_file(dtbfile);
+ if (IS_ERR(root)) {
+ printf("Cannot open %s: %pe\n", dtbfile, root);
return PTR_ERR(root);
-
+ }
} else {
root = of_get_root_node();
}
diff --git a/commands/of_dump.c b/commands/of_dump.c
index c2ca8485cd..86755ff1e4 100644
--- a/commands/of_dump.c
+++ b/commands/of_dump.c
@@ -37,7 +37,6 @@ static int do_of_dump(int argc, char *argv[])
int fix = 0;
struct device_node *root = NULL, *node, *of_free = NULL;
char *dtbfile = NULL;
- size_t size;
const char *nodename;
unsigned maxpropsize = ~0;
int names_only = 0, properties_only = 0;
@@ -72,19 +71,9 @@ static int do_of_dump(int argc, char *argv[])
nodename = argv[optind];
if (dtbfile) {
- void *fdt;
-
- fdt = read_file(dtbfile, &size);
- if (!fdt) {
- printf("unable to read %s: %s\n", dtbfile, strerror(errno));
- return -errno;
- }
-
- root = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
+ root = of_read_file(dtbfile);
if (IS_ERR(root)) {
+ printf("Cannot open %s: %pe\n", dtbfile, root);
ret = PTR_ERR(root);
goto out;
}
diff --git a/commands/of_fixup.c b/commands/of_fixup.c
new file mode 100644
index 0000000000..d667afb5b1
--- /dev/null
+++ b/commands/of_fixup.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * of_fixup.c - List and remove OF fixups
+ */
+
+#include <common.h>
+#include <kallsyms.h>
+#include <of.h>
+#include <command.h>
+#include <malloc.h>
+#include <complete.h>
+#include <getopt.h>
+#include <string.h>
+
+static int do_of_fixup(int argc, char *argv[])
+{
+ struct of_fixup *of_fixup;
+ int opt, enable = -1;
+ bool did_fixup = false;
+
+ while ((opt = getopt(argc, argv, "ed")) > 0) {
+ switch (opt) {
+ case 'e':
+ enable = 1;
+ break;
+ case 'd':
+ enable = 0;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ argv += optind;
+ argc -= optind;
+
+ if ((enable < 0 && argc > 0) || (enable >= 0 && argc == 0))
+ return COMMAND_ERROR_USAGE;
+
+ list_for_each_entry(of_fixup, &of_fixup_list, list) {
+ int i;
+ ulong addr = (ulong)of_fixup->fixup;
+ char sym[KSYM_SYMBOL_LEN];
+ const char *name;
+
+ name = kallsyms_lookup(addr, NULL, NULL, NULL, sym);
+ if (!name) {
+ sprintf(sym, "<0x%lx>", addr);
+ name = sym;
+ }
+
+ if (enable == -1) {
+ printf("%s(0x%p)%s\n", name, of_fixup->context,
+ of_fixup->disabled ? " [DISABLED]" : "");
+ continue;
+ }
+
+ for (i = 0; i < argc; i++) {
+ if (strcmp(name, argv[i]) != 0)
+ continue;
+
+ of_fixup->disabled = !enable;
+ did_fixup = true;
+ }
+ }
+
+ if (argc && !did_fixup) {
+ printf("none of the specified fixups found\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(of_fixup)
+BAREBOX_CMD_HELP_TEXT("Disable or re-enable an already registered fixup for the device tree.")
+BAREBOX_CMD_HELP_TEXT("Call without arguments to list all fixups")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-d", "disable fixup")
+BAREBOX_CMD_HELP_OPT("-e", "re-enable fixup")
+BAREBOX_CMD_HELP_OPT("fixups", "List of fixups to enable or disable")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_fixup)
+ .cmd = do_of_fixup,
+ BAREBOX_CMD_DESC("list and enable/disable fixups")
+ BAREBOX_CMD_OPTS("[-de] [fixups...]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_HELP(cmd_of_fixup_help)
+BAREBOX_CMD_END
diff --git a/commands/of_overlay.c b/commands/of_overlay.c
index b80f371c5c..fda9115a82 100644
--- a/commands/of_overlay.c
+++ b/commands/of_overlay.c
@@ -15,9 +15,7 @@
static int do_of_overlay(int argc, char *argv[])
{
int ret;
- struct fdt_header *fdt;
struct device_node *overlay;
- size_t size;
bool live_tree = false;
int opt;
@@ -36,17 +34,12 @@ static int do_of_overlay(int argc, char *argv[])
printf("Support for live tree overlays is disabled. Enable CONFIG_OF_OVERLAY_LIVE\n");
return 1;
}
-
- fdt = read_file(argv[optind], &size);
- if (!fdt) {
- printf("cannot read %s\n", argv[optind]);
- return 1;
- }
- overlay = of_unflatten_dtb(fdt, size);
- free(fdt);
- if (IS_ERR(overlay))
+ overlay = of_read_file(argv[optind]);
+ if (IS_ERR(overlay)) {
+ printf("Cannot open %s: %pe\n", argv[optind], overlay);
return PTR_ERR(overlay);
+ }
if (live_tree) {
ret = of_overlay_apply_tree(of_get_root_node(), overlay);
diff --git a/commands/oftree.c b/commands/oftree.c
index 7d4b08c9d3..7b12c86e1d 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -31,7 +31,6 @@
static int do_oftree(int argc, char *argv[])
{
struct fdt_header *fdt = NULL;
- size_t size;
int opt;
int probe = 0;
char *load = NULL;
@@ -76,18 +75,11 @@ static int do_oftree(int argc, char *argv[])
}
if (load) {
- fdt = read_file(load, &size);
- if (!fdt) {
- printf("unable to read %s\n", load);
- return 1;
- }
-
- root = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
- if (IS_ERR(root))
+ root = of_read_file(load);
+ if (IS_ERR(root)) {
+ printf("Cannot open %s: %pe\n", load, root);
return PTR_ERR(root);
+ }
ret = of_set_root_node(root);
if (ret) {