Add support to extract bootargs

Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
This commit is contained in:
Pascal Vizeli 2018-06-08 21:21:13 +00:00
parent a57864c199
commit 9d595d8bef
4 changed files with 163 additions and 3 deletions

View File

@ -1,3 +0,0 @@
#!/bin/sh
global linux.bootargs.rpi="bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000"

View File

@ -3,3 +3,4 @@
memcpy -d /tmp/rpi.dtb 0x02008000 0 0x8000
oftree -f -l /tmp/rpi.dtb
of_overlay /data/barebox-state-rpi.dtbo
fix_bootargs

View File

@ -6,6 +6,7 @@ CONFIG_MMU=y
CONFIG_MALLOC_TLSF=y
CONFIG_KALLSYMS=y
CONFIG_CMD_OF_OVERLAY=y
CONFIG_CMD_FIX_BOOTARGS=y
# CONFIG_SPI is not set
CONFIG_MCI=y
CONFIG_MCI_BCM283X=y

View File

@ -0,0 +1,161 @@
From 5facf78a36c30c47849c338bf685f69849173f87 Mon Sep 17 00:00:00 2001
From: Pascal Vizeli <pvizeli@syshack.ch>
Date: Fri, 8 Jun 2018 20:45:32 +0000
Subject: [PATCH 1/1] command: add fix_bootargs
Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch>
---
commands/Kconfig | 13 +++++
commands/Makefile | 1 +
commands/fix_bootargs.c | 105 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+)
create mode 100644 commands/fix_bootargs.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 951a86963..4cc55a358 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2137,6 +2137,19 @@ config CMD_SEED
help
Seed the pseudo random number generator (PRNG)
+config CMD_FIX_BOOTARGS
+ tristate
+ select GLOBALVAR
+ select OFTREE
+ prompt "fix_bootargs"
+ help
+ Read bootargs from device tree and set to 'linux.bootargs.chosen'
+
+ Usage: fix_bootargs [-f DTB]
+
+ Options:
+ -f DTB Read it from a dtb file.
+
# end Miscellaneous commands
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index eb4796389..fafa8b145 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -122,4 +122,5 @@ obj-$(CONFIG_CMD_SPD_DECODE) += spd_decode.o
obj-$(CONFIG_CMD_MMC_EXTCSD) += mmc_extcsd.o
obj-$(CONFIG_CMD_NAND_BITFLIP) += nand-bitflip.o
obj-$(CONFIG_CMD_SEED) += seed.o
+obj-$(CONFIG_CMD_FIX_BOOTARGS) += fix_bootargs.o
obj-$(CONFIG_CMD_IP_ROUTE_GET) += ip-route-get.o
diff --git a/commands/fix_bootargs.c b/commands/fix_bootargs.c
new file mode 100644
index 000000000..f58a4ab1d
--- /dev/null
+++ b/commands/fix_bootargs.c
@@ -0,0 +1,105 @@
+/*
+ * of_dump.c - dump devicetrees to the console
+ *
+ * Copyright (c) 2018 Pascal Vizeli <pvizeli@syshack.ch>, Hass.io
+ *
+ * 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 <common.h>
+#include <libfile.h>
+#include <of.h>
+#include <command.h>
+#include <malloc.h>
+#include <linux/ctype.h>
+#include <errno.h>
+#include <globalvar.h>
+#include <getopt.h>
+#include <linux/err.h>
+
+static int do_fix_bootargs(int argc, char *argv[])
+{
+ int opt;
+ int ret = 0;
+ struct device_node *root = NULL, *node = NULL, *of_free = NULL;
+ struct property *prop = NULL;
+ char *dtbfile = NULL;
+ size_t size;
+
+ while ((opt = getopt(argc, argv, "f")) > 0) {
+ switch (opt) {
+ case 'f':
+ dtbfile = optarg;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ 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);
+
+ free(fdt);
+
+ if (IS_ERR(root)) {
+ ret = PTR_ERR(root);
+ goto end;
+ }
+
+ of_free = root;
+ } else {
+ root = of_get_root_node();
+ }
+
+ node = of_find_node_by_path_or_alias(root, "/chosen");
+ if (!node) {
+ printf("Cannot find chosen\n");
+ ret = -ENOENT;
+ goto end;
+ }
+
+ prop = of_find_property(node, "bootargs", NULL);
+ if (!prop) {
+ printf("Cannot find bootargs\n");
+ ret = -ENOENT;
+ goto end;
+ }
+
+ ret = globalvar_add_simple("linux.bootargs.chosen", prop->value);
+
+end:
+ if (of_free)
+ of_delete_node(of_free);
+ return ret;
+}
+
+BAREBOX_CMD_HELP_START(fix_bootargs)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-f dtb", "work on dtb instead of internal devicetree\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(fix_bootargs)
+ .cmd = do_fix_bootargs,
+ BAREBOX_CMD_DESC("dump devicetree nodes")
+ BAREBOX_CMD_OPTS("[-f DTB]")
+ BAREBOX_CMD_HELP(cmd_fix_bootargs_help)
+BAREBOX_CMD_END
--
2.17.1