Skip to contentSkip to conversation

VideoCore FDT interop for Raspberry Pi

PATCH Superseded Tomaz Solc 4 participants 9 messages Feb 21, 2019 – Feb 26, 2019

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tomaz Solc

author
#0 lore raw

cover VideoCore FDT interop for Raspberry Pi

Dear all,

these patches make Barebox aware of the device tree and boot arguments that are constructed by the VideoCore firmware on Raspberry Pi. This fixes many problems with hardware that is initialized from VideoCore when booting a kernel shipped with Raspbian (e.g. when using dtoverlay directives in config.txt, bcm2708_fb arguments, etc.) They are based on previous work done by Pascal Vizeli [1].

Passing of FDT between PBL and rpi_devices_init is somewhat ugly, but as far as I can see, the patch mentioned in [2] has not been merged yet.

Overview of the changes:

- PBL saves the VideoCore FDT into a scrap RAM area just above Barebox memory (this was an alternative approach suggested in [2]).
- rpi_devices_init copies the FDT from scrap RAM into a file (/vd.dtb)
- I had to add arm_mem_endmem_get() so that code in rpi_devices_init can get the pointer to the end of Barebox memory.
- The new of_bootargs command makes it possible for an environment to include the kernel command-line from the VideoCore FDT.

[1] http://lists.infradead.org/pipermail/barebox/2018-June/033460.html
[2] http://lists.infradead.org/pipermail/barebox/2018-June/033469.html

Best regards
Tomaz

*** BLURB HERE ***

Tomaz Solc (3):
ARM: start: save end of memory passed to start.
ARM: rpi: save fdt that was passed from VideoCore
commands: add of_bootargs command.

 Documentation/boards/bcm2835.rst          |  8 +++
 arch/arm/boards/raspberry-pi/lowlevel.c   | 68 +++++++++++++++------
 arch/arm/boards/raspberry-pi/lowlevel.h   |  9 +++
 arch/arm/boards/raspberry-pi/rpi-common.c | 34 +++++++++++
 arch/arm/cpu/start.c                      |  8 +++
 arch/arm/include/asm/barebox-arm.h        |  1 +
 commands/Kconfig                          | 13 ++++
 commands/Makefile                         |  1 +
 commands/of_bootargs.c                    | 99 +++++++++++++++++++++++++++++++
 9 files changed, 222 insertions(+), 19 deletions(-)
 create mode 100644 arch/arm/boards/raspberry-pi/lowlevel.h
 create mode 100644 commands/of_bootargs.c
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#1 lore raw

PATCH 1/3 ARM: start: save end of memory passed to start.

Knowing the address of the end of the memory area used by Barebox is useful if PBL stores some extra data after it, so that board init code can later retrieve it from there.

---
 arch/arm/cpu/start.c               | 8 ++++++++
 arch/arm/include/asm/barebox-arm.h | 1 +
 2 files changed, 9 insertions(+)
arch/arm/cpu/start.c +8 -0
index 768fa9e1b..6573c2ef7 100644
@@ -38,6 +38,7 @@
 
 unsigned long arm_stack_top;
 static unsigned long arm_barebox_size;
+static unsigned long arm_endmem;
 static void *barebox_boarddata;
 static unsigned long barebox_boarddata_size;
 
@@ -131,6 +132,12 @@ unsigned long arm_mem_ramoops_get(void)
 }
 EXPORT_SYMBOL_GPL(arm_mem_ramoops_get);
 
+unsigned long arm_mem_endmem_get(void)
+{
+	return arm_endmem;
+}
+EXPORT_SYMBOL_GPL(arm_mem_endmem_get);
+
 static int barebox_memory_areas_init(void)
 {
 	if(barebox_boarddata)
@@ -163,6 +170,7 @@ __noreturn void barebox_non_pbl_start(unsigned long membase,
 
 	pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize);
 
+	arm_endmem = endmem;
 	arm_stack_top = arm_mem_stack_top(membase, endmem);
 	arm_barebox_size = barebox_size;
 	malloc_end = barebox_base;
arch/arm/include/asm/barebox-arm.h +1 -0
index e065b479e..a11d34923 100644
@@ -86,6 +86,7 @@ static inline void boarddata_create(void *adr, u32 machine)
 u32 barebox_arm_machine(void);
 
 unsigned long arm_mem_ramoops_get(void);
+unsigned long arm_mem_endmem_get(void);
 
 struct barebox_arm_boarddata_compressed_dtb {
 #define BAREBOX_ARM_BOARDDATA_COMPRESSED_DTB_MAGIC 0x7b66bcbd
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#4 lore raw

PATCH 3/3 commands: add of_bootargs command.

In reply to Tomaz Solc

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 adds an of_bootargs command that extracts a bootargs property from a device tree and saves it to a global variable.

For example, a bootloader environment can use this command to extract the bootargs to linux.bootargs.vc, which then gets included into the final bootargs for the kernel using CONFIG_FLEXIBLE_BOOTARGS.

---
 Documentation/boards/bcm2835.rst |  4 ++
 commands/Kconfig                 | 13 ++++++
 commands/Makefile                |  1 +
 commands/of_bootargs.c           | 99 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 117 insertions(+)
 create mode 100644 commands/of_bootargs.c
Documentation/boards/bcm2835.rst +4 -0
index 95e910896..b8a6c18ea 100644
@@ -34,5 +34,9 @@ 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 by the Linux bootargs (see :ref:`booting_linux`). You can extract the VideoCore command-line from the device tree using the following command::
+
+    of_bootargs /vc.dtb linux.bootargs.vc
+
 .. _Raspberry Pi firmware: https://codeload.github.com/raspberrypi/firmware/zip/80e1fbeb78f9df06701d28c0ed3a3060a3f557ef
 .. _documentation for config.txt: https://www.raspberrypi.org/documentation/configuration/config-txt/
commands/Kconfig +13 -0
index c14332c9d..0ae6d526f 100644
@@ -2015,6 +2015,19 @@ config CMD_OF_DUMP
 	  Options:
 		-f <dtb>	work on <dtb> instead of internal devicetree
 
+config CMD_OF_BOOTARGS
+	tristate
+	select OFTREE
+	prompt "of_bootargs"
+	help
+	  Extract bootargs from a device tree into a global variable
+
+	  Usage: of_bootargs [DTB] [VAR]
+
+	  DTB is path to a device tree file (e.g. /vc.dtb).
+	  VAR is a name of the global variable to set (e.g. linux.bootargs.vc)
+
+
 config CMD_OF_NODE
 	tristate
 	select OFTREE
commands/Makefile +1 -0
index 358671bb5..f554f6041 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
 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_BOOTARGS)	+= of_bootargs.o
 obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS)	+= of_display_timings.o
 obj-$(CONFIG_CMD_OF_FIXUP_STATUS)	+= of_fixup_status.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
commands/of_bootargs.c new file +99 -0

99 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
author
#2 lore raw

PATCH 2/3 ARM: rpi: save fdt that was passed from VideoCore

In reply to Tomaz Solc

On Raspberry Pi, VideoCore firmware creates a device tree that contains information about peripherals that were initialized by VideoCore based on settings in config.txt. Normally this device tree is passed to the Linux kernel via a pointer in the r2 register. A bootloader needs to pass this device tree to the kernel, or some peripherals will not work correctly.

Since the VideoCore device tree is not compatible with barebox, we can't just pass it to barebox_arm_entry() as the internal barebox device tree.

This commit makes the prebootloader code copy the device tree from VideoCore into a scrap RAM area just above the area reserved for the bootloader. Board initialization code in the bootloader proper then copies it into a file /vc.dtb. The bootloader environment is then free to pass this file to the kernel at boot (e.g. via bootm -o).

---
 Documentation/boards/bcm2835.rst          |  4 ++
 arch/arm/boards/raspberry-pi/lowlevel.c   | 68 ++++++++++++++++++++++---------
 arch/arm/boards/raspberry-pi/lowlevel.h   |  9 ++++
 arch/arm/boards/raspberry-pi/rpi-common.c | 34 ++++++++++++++++
 4 files changed, 96 insertions(+), 19 deletions(-)
 create mode 100644 arch/arm/boards/raspberry-pi/lowlevel.h
Documentation/boards/bcm2835.rst +4 -0
index ea80d5834..95e910896 100644
@@ -30,5 +30,9 @@ Raspberry Pi
 
   6. Turn board's power on.
 
+VideoCore firmware creates a device tree based on the entries in ``config.txt``. This file is available to the Barebox environment in the file ``/vc.dtb``. For example, to boot a kernel shipped with Raspbian::
+
+    bootm -o /vc.dtb /boot/kernel7.img
+
 .. _Raspberry Pi firmware: https://codeload.github.com/raspberrypi/firmware/zip/80e1fbeb78f9df06701d28c0ed3a3060a3f557ef
 .. _documentation for config.txt: https://www.raspberrypi.org/documentation/configuration/config-txt/
arch/arm/boards/raspberry-pi/lowlevel.c +49 -19

92 lines not on this page · raw message

arch/arm/boards/raspberry-pi/lowlevel.h new file +9 -0
new file mode 100644
index 000000000..9ef9135b2
@@ -0,0 +1,9 @@
+#ifndef __ARCH_ARM_BOARDS_LOWLEVEL_H__
+#define __ARCH_ARM_BOARDS_LOWLEVEL_H__
+
+#include <linux/sizes.h>
+
+#define VIDEOCORE_FDT_SZ SZ_1M
+#define VIDEOCORE_FDT_ERROR 0xdeadfeed
+
+#endif /* __ARCH_ARM_BOARDS_LOWLEVEL_H__ */
arch/arm/boards/raspberry-pi/rpi-common.c +34 -0
index b5d16a15c..f17384857 100644
@@ -16,21 +16,26 @@
 #include <common.h>
 #include <init.h>
 #include <fs.h>
+#include <of.h>
 #include <linux/stat.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
 #include <envfs.h>
 #include <malloc.h>
+#include <libfile.h>
 #include <gpio.h>
 #include <net.h>
 #include <led.h>
 #include <asm/armlinux.h>
+#include <asm/barebox-arm.h>
 #include <generated/mach-types.h>
+#include <linux/sizes.h>
 
 #include <mach/core.h>
 #include <mach/mbox.h>
 
 #include "rpi.h"
+#include "lowlevel.h"
 
 struct msg_get_arm_mem {
 	struct bcm2835_mbox_hdr hdr;
@@ -370,12 +375,41 @@ static int rpi_env_init(void)
 	return 0;
 }
 
+static void rpi_vc_fdt(void)
+{
+	void *saved_vc_fdt;
+	struct fdt_header *oftree;
+	unsigned long magic, size;
+
+	/* VideoCore FDT was copied in PBL just above Barebox memory */
+	saved_vc_fdt = (void *)(arm_mem_endmem_get());
+
+	oftree = saved_vc_fdt;
+	magic = be32_to_cpu(oftree->magic);
+	if (magic != FDT_MAGIC) {
+		printf("videocore fdt saved in pbl has invalid magic\n");
+
+		if (magic == VIDEOCORE_FDT_ERROR) {
+			printf("there was an error copying fdt in pbl: %d\n",
+					be32_to_cpu(oftree->totalsize));
+		}
+		return;
+	}
+
+	size = be32_to_cpu(oftree->totalsize);
+	if (write_file("/vc.dtb", saved_vc_fdt, size)) {
+		printf("failed to save videocore fdt to a file\n");
+		return;
+	}
+}
+
 static int rpi_devices_init(void)
 {
 	rpi_model_init();
 	bcm2835_register_fb();
 	armlinux_set_architecture(MACH_TYPE_BCM2708);
 	rpi_env_init();
+	rpi_vc_fdt();
 	return 0;
 }
 late_initcall(rpi_devices_init);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [PATCH 3/3] commands: add of_bootargs command.

In reply to Tomaz Solc
Quoted 11 lines · Tomaz Solc

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 adds an of_bootargs command that extracts a bootargs property from a device tree and saves it to a global variable.

For example, a bootloader environment can use this command to extract the bootargs to linux.bootargs.vc, which then gets included into the final bootargs for the kernel using CONFIG_FLEXIBLE_BOOTARGS.

Do we need an extra command for this? Can't you just unflatten the VideoCore provided device tree in the board code you have added in 2/3 and set global.linux.bootargs.vc from there? It seems to be just the right thing without further user intervention.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [PATCH 3/3] commands: add of_bootargs command.

Hi Sascha,

Quoted 4 lines · Sascha Hauer
Quoted 3 lines · Tomaz Solc

This commit adds an of_bootargs command that extracts a bootargs property from a device tree and saves it to a global variable.

Quoted 8 lines
Quoted 3 lines

For example, a bootloader environment can use this command to extract the bootargs to linux.bootargs.vc, which then gets included into the final bootargs for the kernel using CONFIG_FLEXIBLE_BOOTARGS.

Do we need an extra command for this? Can't you just unflatten the VideoCore provided device tree in the board code you have added in 2/3 and set global.linux.bootargs.vc from there? It seems to be just the right thing without further user intervention.

I wanted to keep things flexible. I thought having an explicit command to import the args into Barebox is better than doing this automatically in rpi-common.c.

As far as I know [1], upstream kernels use their own device tree and don't need bootargs and fdt from VideoCore. On the other hand, I'm using the Raspbian-supplied kernels that do depend on these two things. That's also why I liked the approach where the VideoCore fdt is saved into a file, where it can be passed to boot or not, depending on the environment.

If you think of_bootargs is too specific for a command, I can make it more general and have it save an arbitrary property from a fdt into a global variable (something similar to readf). That might be useful for something else as well.

[1] https://elinux.org/RPi_Upstream_Kernel_Compilation#Building_your_bootloader

Best regards
Tomaž

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw

Re: [PATCH 3/3] commands: add of_bootargs command.

Quoted 11 lines · Tomaž Šolc

Hi Sascha,

Quoted 8 lines · Sascha Hauer
Quoted 6 lines · Tomaz Solc

This commit adds an of_bootargs command that extracts a bootargs property from a device tree and saves it to a global variable.

For example, a bootloader environment can use this command to extract the bootargs to linux.bootargs.vc, which then gets included into the final bootargs for the kernel using CONFIG_FLEXIBLE_BOOTARGS.

Quoted 8 lines
Quoted 4 lines

Do we need an extra command for this? Can't you just unflatten the VideoCore provided device tree in the board code you have added in 2/3 and set global.linux.bootargs.vc from there? It seems to be just the right thing without further user intervention.

I wanted to keep things flexible. I thought having an explicit command to import the args into Barebox is better than doing this automatically in rpi-common.c.

You can still set nv.linux.bootargs.vc="" if you want to drop the vc provided bootargs later. Or other way round, set some other variable, say global.vc.bootargs, to the vc provided bootargs, and in some initscript set global.linux.bootargs.vc to $global.vc.bootargs.

Quoted 6 lines

As far as I know [1], upstream kernels use their own device tree and don't need bootargs and fdt from VideoCore. On the other hand, I'm using the Raspbian-supplied kernels that do depend on these two things. That's also why I liked the approach where the VideoCore fdt is saved into a file, where it can be passed to boot or not, depending on the environment.

Yes, that's fine. Having the devicetree available is a good thing.

Quoted 5 lines

If you think of_bootargs is too specific for a command, I can make it more general and have it save an arbitrary property from a fdt into a global variable (something similar to readf). That might be useful for something else as well.

Could be integrated into of_property maybe.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 2/3] ARM: rpi: save fdt that was passed from VideoCore

In reply to Tomaz Solc

Hi,

Quoted 23 lines · Tomaz Solc

On Raspberry Pi, VideoCore firmware creates a device tree that contains information about peripherals that were initialized by VideoCore based on settings in config.txt. Normally this device tree is passed to the Linux kernel via a pointer in the r2 register. A bootloader needs to pass this device tree to the kernel, or some peripherals will not work correctly.

Since the VideoCore device tree is not compatible with barebox, we can't just pass it to barebox_arm_entry() as the internal barebox device tree.

This commit makes the prebootloader code copy the device tree from VideoCore into a scrap RAM area just above the area reserved for the bootloader. Board initialization code in the bootloader proper then copies it into a file /vc.dtb. The bootloader environment is then free to pass this file to the kernel at boot (e.g. via bootm -o).

---
 Documentation/boards/bcm2835.rst          |  4 ++
 arch/arm/boards/raspberry-pi/lowlevel.c   | 68 ++++++++++++++++++++++---------
 arch/arm/boards/raspberry-pi/lowlevel.h   |  9 ++++
 arch/arm/boards/raspberry-pi/rpi-common.c | 34 ++++++++++++++++
 4 files changed, 96 insertions(+), 19 deletions(-)
 create mode 100644 arch/arm/boards/raspberry-pi/lowlevel.h

[...]

Quoted 11 lines
arch/arm/boards/raspberry-pi/rpi-common.c +3 -0
index b5d16a15c..f17384857 100644
@@ -370,12 +375,41 @@ static int rpi_env_init(void)
 	return 0;
 }
 
+static void rpi_vc_fdt(void)
+{
+	void *saved_vc_fdt;

arch/arm/boards/raspberry-pi/rpi-common.c static int rpi_env_init(void) · line 390

Quoted 10 lines
arch/arm/boards/raspberry-pi/rpi-common.c +10 -0
+	struct fdt_header *oftree;
+	unsigned long magic, size;
+
+	/* VideoCore FDT was copied in PBL just above Barebox memory */
+	saved_vc_fdt = (void *)(arm_mem_endmem_get());
+
+	oftree = saved_vc_fdt;
+	magic = be32_to_cpu(oftree->magic);
+	if (magic != FDT_MAGIC) {
+		printf("videocore fdt saved in pbl has invalid magic\n");

It's more idiomatic to use pr_err() here

arch/arm/boards/raspberry-pi/rpi-common.c static int rpi_env_init(void) · line 394

Quoted 4 lines
arch/arm/boards/raspberry-pi/rpi-common.c +4 -0
+
+		if (magic == VIDEOCORE_FDT_ERROR) {
+			printf("there was an error copying fdt in pbl: %d\n",
+					be32_to_cpu(oftree->totalsize));

and here

arch/arm/boards/raspberry-pi/rpi-common.c static int rpi_env_init(void) · line 401

Quoted 7 lines
arch/arm/boards/raspberry-pi/rpi-common.c +7 -0
+		}
+		return;
+	}
+
+	size = be32_to_cpu(oftree->totalsize);
+	if (write_file("/vc.dtb", saved_vc_fdt, size)) {
+		printf("failed to save videocore fdt to a file\n");

and here.

- Roland

Quoted 23 lines
arch/arm/boards/raspberry-pi/rpi-common.c +5 -0
+		return;
+	}
+}
+
 static int rpi_devices_init(void)
 {
 	rpi_model_init();
 	bcm2835_register_fb();
 	armlinux_set_architecture(MACH_TYPE_BCM2708);
 	rpi_env_init();
+	rpi_vc_fdt();
 	return 0;
 }
 late_initcall(rpi_devices_init);
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Roland Hieber                     | [email protected]     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

Re: [PATCH 3/3] commands: add of_bootargs command.

In reply to Tomaz Solc
Quoted 75 lines · Tomaz Solc

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 adds an of_bootargs command that extracts a bootargs property from a device tree and saves it to a global variable.

For example, a bootloader environment can use this command to extract the bootargs to linux.bootargs.vc, which then gets included into the final bootargs for the kernel using CONFIG_FLEXIBLE_BOOTARGS.

---
 Documentation/boards/bcm2835.rst |  4 ++
 commands/Kconfig                 | 13 ++++++
 commands/Makefile                |  1 +
 commands/of_bootargs.c           | 99 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 117 insertions(+)
 create mode 100644 commands/of_bootargs.c
Documentation/boards/bcm2835.rst +4 -0
index 95e910896..b8a6c18ea 100644
@@ -34,5 +34,9 @@ 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 by the Linux bootargs (see :ref:`booting_linux`). You can extract the VideoCore command-line from the device tree using the following command::
+
+    of_bootargs /vc.dtb linux.bootargs.vc
+
 .. _Raspberry Pi firmware: https://codeload.github.com/raspberrypi/firmware/zip/80e1fbeb78f9df06701d28c0ed3a3060a3f557ef
 .. _documentation for config.txt: https://www.raspberrypi.org/documentation/configuration/config-txt/
commands/Kconfig +13 -0
index c14332c9d..0ae6d526f 100644
@@ -2015,6 +2015,19 @@ config CMD_OF_DUMP
 	  Options:
 		-f <dtb>	work on <dtb> instead of internal devicetree
 
+config CMD_OF_BOOTARGS
+	tristate
+	select OFTREE
+	prompt "of_bootargs"
+	help
+	  Extract bootargs from a device tree into a global variable
+
+	  Usage: of_bootargs [DTB] [VAR]
+
+	  DTB is path to a device tree file (e.g. /vc.dtb).
+	  VAR is a name of the global variable to set (e.g. linux.bootargs.vc)
+
+
 config CMD_OF_NODE
 	tristate
 	select OFTREE
commands/Makefile +1 -0
index 358671bb5..f554f6041 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
 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_BOOTARGS)	+= of_bootargs.o
 obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS)	+= of_display_timings.o
 obj-$(CONFIG_CMD_OF_FIXUP_STATUS)	+= of_fixup_status.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
commands/of_bootargs.c new file +0 -0
new file mode 100644
index 000000000..93e7b74b1

commands/of_bootargs.c line 4

Quoted 4 lines
commands/of_bootargs.c new file +4 -0
@@ -0,0 +1,99 @@
+/*
+ * of_dump.c - dump devicetrees to the console
+ *
+ * Copyright (c) 2014 Sascha Hauer <[email protected]>, Pengutronix

Is this true? :-)

And please add a SPDX-License-Identifier to the new files. See [9] for an explanation (and replace "Linux" by "barebox" in your head when reading it :))

[9]: https://www.kernel.org/doc/html/latest/process/license-rules.html

commands/of_bootargs.c line 7

Quoted 3 lines
commands/of_bootargs.c new file +3 -0
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.

Leave out this paragraph, that file does not exist.

- Roland

Quoted 101 lines
commands/of_bootargs.c new file +92 -0
+ *
+ * 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 <complete.h>
+#include <linux/ctype.h>
+#include <errno.h>
+#include <linux/err.h>
+#include <globalvar.h>
+
+static int do_of_bootargs(int argc, char *argv[])
+{
+	int ret = 0;
+	struct device_node *root = NULL, *node;
+	char *dtbfile, *varname;
+	void *fdt;
+
+	size_t size;
+	const char *cmdline;
+
+	if (argc != 3) {
+		return COMMAND_ERROR_USAGE;
+	}
+
+	dtbfile = argv[1];
+	varname = argv[2];
+
+	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);
+		root = NULL;
+		goto out;
+	}
+
+	node = of_find_node_by_path_from(root, "/chosen");
+	if (!node) {
+		printf("no /chosen node\n");
+		ret = -ENOENT;
+		goto out;
+	}
+
+	cmdline = of_get_property(node, "bootargs", NULL);
+	if (!cmdline) {
+		printf("no bootargs property in the /chosen node\n");
+		ret = -ENOENT;
+		goto out;
+	}
+
+	globalvar_add_simple(varname, cmdline);
+
+out:
+	if (root)
+		of_delete_node(root);
+
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(of_bootargs)
+BAREBOX_CMD_HELP_TEXT("DTB is path to a device tree file (e.g. /vc.dtb).")
+BAREBOX_CMD_HELP_TEXT("VAR is a name of the global variable to set (e.g. linux.bootargs.vc)")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_bootargs)
+	.cmd		= do_of_bootargs,
+	BAREBOX_CMD_DESC("extract bootargs from a device tree into a global variable")
+	BAREBOX_CMD_OPTS("[DTB] [VAR]")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_COMPLETE(devicetree_file_complete)
+	BAREBOX_CMD_HELP(cmd_of_bootargs_help)
+BAREBOX_CMD_END
Signature · 7 lines
2.11.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Roland Hieber                     | [email protected]     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox