Skip to contentSkip to conversation

VideoCore FDT interop for Raspberry Pi

PATCH Applied Tomaz Solc 2 participants 5 messages Feb 27, 2019 – Mar 4, 2019

Subsystems (5)
lore
Share & tools
lore

Tomaz Solc

author
#0 lore raw

v2 cover VideoCore FDT interop for Raspberry Pi

Changes from the first patch series:

- Drop of_bootargs command in favour of automatically extracting VideoCore bootargs to vc.bootargs global in board initialization. Sorry for forgetting to update the copyright header in of_bootargs.c. This file is gone now.
- Replace printf() with pr_err() for printing error messages in rpi-common.c.

Best regards
Tomaz

Tomaz Solc (3):
ARM: start: save end of memory passed to start.
ARM: rpi: save fdt that was passed from VideoCore
ARM: rpi: save bootargs from VC FDT to vc.bootargs

 Documentation/boards/bcm2835.rst          | 10 ++++
 arch/arm/boards/raspberry-pi/lowlevel.c   | 68 ++++++++++++++++++--------
 arch/arm/boards/raspberry-pi/lowlevel.h   |  9 ++++
 arch/arm/boards/raspberry-pi/rpi-common.c | 81 +++++++++++++++++++++++++++++++
 arch/arm/cpu/start.c                      |  8 +++
 arch/arm/include/asm/barebox-arm.h        |  1 +
 6 files changed, 158 insertions(+), 19 deletions(-)
 create mode 100644 arch/arm/boards/raspberry-pi/lowlevel.h
Signature · 7 lines
2.11.0


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

PATCH v2 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
#2 lore raw

PATCH v2 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..fffa882a7 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) {
+		pr_err("videocore fdt saved in pbl has invalid magic\n");
+
+		if (magic == VIDEOCORE_FDT_ERROR) {
+			pr_err("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)) {
+		pr_err("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
author
#3 lore raw

PATCH v2 3/3 ARM: rpi: save bootargs from VC FDT to vc.bootargs

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 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(+)
Documentation/boards/bcm2835.rst +6 -0
index 95e910896..e9ad1d4d5 100644
@@ -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/
arch/arm/boards/raspberry-pi/rpi-common.c +47 -0

70 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
Applied
#4 lore raw
In reply to Tomaz Solc
Quoted 7 lines · Tomaz Solc

Changes from the first patch series:

- Drop of_bootargs command in favour of automatically extracting VideoCore bootargs to vc.bootargs global in board initialization. Sorry for forgetting to update the copyright header in of_bootargs.c. This file is gone now.
- Replace printf() with pr_err() for printing error messages in rpi-common.c.

Quoted 7 lines

Best regards
Tomaz

Tomaz Solc (3):
ARM: start: save end of memory passed to start.
ARM: rpi: save fdt that was passed from VideoCore
ARM: rpi: save bootargs from VC FDT to vc.bootargs

Applied, thanks

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