summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-04-20 22:32:19 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-05-22 13:29:46 +0200
commita26ff8e539a76eb26e8e1e002b67810f88671918 (patch)
tree610d0a7ee526eed1427d72f435e764ceccdccb11 /commands
parentf43f04774135043c0acf46c3527be88ddb2e2d5f (diff)
downloadbarebox-a26ff8e539a76eb26e8e1e002b67810f88671918.tar.gz
barebox-a26ff8e539a76eb26e8e1e002b67810f88671918.tar.xz
commands: add new of_fixup command to list and disable DT fixups
barebox can already dry run fixups with of_diff - +, but there's no way to selectively disable a fixup to rule out it causing issues. For platforms supporting kallsyms, we can readily allow enabling and disabling fixups by name, so let's add a command that does just that to aid in debugging. Suggested-by: Daniel BrĂ¡t <danek.brat@gmail.com> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230420203219.2255564-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig14
-rw-r--r--commands/Makefile1
-rw-r--r--commands/of_fixup.c93
3 files changed, 108 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 76dfca2dfd..c72c2b7758 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2255,6 +2255,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_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