diff mbox series

[U-Boot,v3,19/19] ARM: tegra: Import cbootargs value from cboot DTB

Message ID 20190321180118.26475-20-thierry.reding@gmail.com
State Superseded
Delegated to: Tom Warren
Headers show
Series ARM: tegra: Miscellaneous improvements | expand

Commit Message

Thierry Reding March 21, 2019, 6:01 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

Read the boot arguments passed by cboot via the /chosen/bootargs
property and store it in the cbootargs environment variable.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 arch/arm/mach-tegra/cboot.c | 47 +++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
diff mbox series

Patch

diff --git a/arch/arm/mach-tegra/cboot.c b/arch/arm/mach-tegra/cboot.c
index 9735380bda59..8bfcbcdc6e6d 100644
--- a/arch/arm/mach-tegra/cboot.c
+++ b/arch/arm/mach-tegra/cboot.c
@@ -8,7 +8,9 @@ 
 #include <fdt_support.h>
 #include <fdtdec.h>
 #include <stdlib.h>
+#include <string.h>
 
+#include <linux/ctype.h>
 #include <linux/sizes.h>
 
 #include <asm/arch/tegra.h>
@@ -536,10 +538,49 @@  out:
 	return err;
 }
 
+static char *strip(const char *ptr)
+{
+	const char *end;
+
+	while (*ptr && isblank(*ptr))
+		ptr++;
+
+	/* empty string */
+	if (*ptr == '\0')
+		return strdup(ptr);
+
+	end = ptr;
+
+	while (end[1])
+		end++;
+
+	while (isblank(*end))
+		end--;
+
+	return strndup(ptr, end - ptr + 1);
+}
+
+static char *cboot_get_bootargs(const void *fdt)
+{
+	const char *args;
+	int offset, len;
+
+	offset = fdt_path_offset(fdt, "/chosen");
+	if (offset < 0)
+		return NULL;
+
+	args = fdt_getprop(fdt, offset, "bootargs", &len);
+	if (!args)
+		return NULL;
+
+	return strip(args);
+}
+
 int cboot_late_init(void)
 {
 	const void *fdt = (const void *)cboot_boot_x0;
 	uint8_t mac[ETH_ALEN];
+	char *bootargs;
 	int err;
 
 	set_calculated_env_vars();
@@ -554,5 +595,11 @@  int cboot_late_init(void)
 	if (!err)
 		eth_env_set_enetaddr("ethaddr", mac);
 
+	bootargs = cboot_get_bootargs(fdt);
+	if (bootargs) {
+		env_set("cbootargs", bootargs);
+		free(bootargs);
+	}
+
 	return 0;
 }