mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Tomaz Solc <tomaz.solc@tablix.org>
To: barebox@lists.infradead.org
Subject: [PATCH v2 3/3] ARM: rpi: save bootargs from VC FDT to vc.bootargs
Date: Wed, 27 Feb 2019 14:22:15 +0100	[thread overview]
Message-ID: <20190227132215.9765-4-tomaz.solc@tablix.org> (raw)
In-Reply-To: <20190227132215.9765-1-tomaz.solc@tablix.org>

When booting a Raspberry Pi, it is useful to extract bootargs from the
device tree that was created by the VideoCore firmware. These bootargs
contain for example settings for the framebuffer that the kernel needs
to properly set the video output.

This commit extracts the bootargs in the board initialization code and
saves them to the vc.bootargs global variable.

For example, a bootloader environment can then add the contents of this
variable to linux.bootargs.vc, which then gets included into the final
bootargs for the kernel using CONFIG_FLEXIBLE_BOOTARGS.
---
 Documentation/boards/bcm2835.rst          |  6 ++++
 arch/arm/boards/raspberry-pi/rpi-common.c | 47 +++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/Documentation/boards/bcm2835.rst b/Documentation/boards/bcm2835.rst
index 95e910896..e9ad1d4d5 100644
--- a/Documentation/boards/bcm2835.rst
+++ b/Documentation/boards/bcm2835.rst
@@ -34,5 +34,11 @@ VideoCore firmware creates a device tree based on the entries in ``config.txt``.
 
     bootm -o /vc.dtb /boot/kernel7.img
 
+VideoCore device tree also contains the kernel command-line that is constructed from ``cmdline.txt`` and other parameters internally determined by the VideoCore firmware. Normally in Barebox this command-line gets overwritten on boot by the Linux bootargs (see :ref:`booting_linux`).
+
+The original command-line from VideoCore device tree is available to the Barebox environment in the ``vc.bootargs`` global variable. For example, to append it to the Linux bootargs::
+
+    global linux.bootargs.vc="$global.vc.bootargs"
+
 .. _Raspberry Pi firmware: https://codeload.github.com/raspberrypi/firmware/zip/80e1fbeb78f9df06701d28c0ed3a3060a3f557ef
 .. _documentation for config.txt: https://www.raspberrypi.org/documentation/configuration/config-txt/
diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index fffa882a7..9d334cde1 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -30,6 +30,7 @@
 #include <asm/barebox-arm.h>
 #include <generated/mach-types.h>
 #include <linux/sizes.h>
+#include <globalvar.h>
 
 #include <mach/core.h>
 #include <mach/mbox.h>
@@ -375,11 +376,50 @@ static int rpi_env_init(void)
 	return 0;
 }
 
+/* Extract /chosen/bootargs from the VideoCore FDT into vc.bootargs
+ * global variable. */
+static int rpi_vc_fdt_bootargs(void *fdt)
+{
+	int ret = 0;
+	struct device_node *root = NULL, *node;
+	const char *cmdline;
+
+	root = of_unflatten_dtb(fdt);
+	if (IS_ERR(root)) {
+		ret = PTR_ERR(root);
+		root = NULL;
+		goto out;
+	}
+
+	node = of_find_node_by_path_from(root, "/chosen");
+	if (!node) {
+		pr_err("no /chosen node\n");
+		ret = -ENOENT;
+		goto out;
+	}
+
+	cmdline = of_get_property(node, "bootargs", NULL);
+	if (!cmdline) {
+		pr_err("no bootargs property in the /chosen node\n");
+		ret = -ENOENT;
+		goto out;
+	}
+
+	globalvar_add_simple("vc.bootargs", cmdline);
+
+out:
+	if (root)
+		of_delete_node(root);
+
+	return ret;
+}
+
 static void rpi_vc_fdt(void)
 {
 	void *saved_vc_fdt;
 	struct fdt_header *oftree;
 	unsigned long magic, size;
+	int ret;
 
 	/* VideoCore FDT was copied in PBL just above Barebox memory */
 	saved_vc_fdt = (void *)(arm_mem_endmem_get());
@@ -401,6 +441,13 @@ static void rpi_vc_fdt(void)
 		pr_err("failed to save videocore fdt to a file\n");
 		return;
 	}
+
+	ret = rpi_vc_fdt_bootargs(saved_vc_fdt);
+	if (ret) {
+		pr_err("failed to extract bootargs from videocore fdt: %d\n",
+									ret);
+		return;
+	}
 }
 
 static int rpi_devices_init(void)
-- 
2.11.0


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

  parent reply	other threads:[~2019-02-27 13:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 13:22 [PATCH v2 0/3] VideoCore FDT interop for Raspberry Pi Tomaz Solc
2019-02-27 13:22 ` [PATCH v2 1/3] ARM: start: save end of memory passed to start Tomaz Solc
2019-02-27 13:22 ` [PATCH v2 2/3] ARM: rpi: save fdt that was passed from VideoCore Tomaz Solc
2019-02-27 13:22 ` Tomaz Solc [this message]
2019-03-04  7:48 ` [PATCH v2 0/3] VideoCore FDT interop for Raspberry Pi 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=20190227132215.9765-4-tomaz.solc@tablix.org \
    --to=tomaz.solc@tablix.org \
    --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