[PATCH] MIPS: add generic device tree 2nd stage support
Sascha Hauer
s.hauer at pengutronix.de
Wed Mar 13 00:55:11 PDT 2024
On Mon, Mar 11, 2024 at 12:54:34AM +0300, Antony Pavlov wrote:
> Building and running barebox for 32-bit malta:
>
> export ARCH=mips
> export CROSS_COMPILE=mips-linux-gnu-
> make -s qemu-malta_defconfig
> sed -i "s/# \(CONFIG_BOARD_MIPS_GENERIC_DT\) is not set/\1=y/" .config
> make -s oldconfig
> make -s
> qemu-system-mips -M malta -cpu 24Kf -m 256M \
> -nographic -serial mon:stdio \
> -bios images/barebox-qemu-malta.img \
> -net user,tftp=$(pwd) -net nic,model=e1000
>
> Building and running barebox for 64-bit malta:
>
> export ARCH=mips
> export CROSS_COMPILE=mips-linux-gnu-
> make -s qemu-malta64el_defconfig
> sed -i "s/# \(CONFIG_BOARD_MIPS_GENERIC_DT\) is not set/\1=y/" .config
> make -s oldconfig
> make -s
> qemu-system-mips64el -M malta -cpu MIPS64R2-generic -m 256M \
> -nographic -serial mon:stdio \
> -bios images/barebox-qemu-malta.img.swapped \
> -net user,tftp=$(pwd) -net nic,model=e1000
>
> Use bootm to run barebox-dt-2nd.img (external device tree):
>
> barebox at qemu malta:/ dhcp
> barebox at qemu malta:/ cp /mnt/tftp/images/barebox-dt-2nd.img barebox.img
> barebox at qemu malta:/ cp /mnt/tftp/arch/mips/dts/qemu-malta.dtb .
> barebox at qemu malta:/ imd barebox.img
> barebox at qemu malta:/ bootm -o qemu-malta.dtb barebox.img
>
> Use bootm to run barebox-qemu-malta.img (encapsulated device tree):
>
> barebox at qemu malta:/ dhcp
> barebox at qemu malta:/ cp /mnt/tftp/images/barebox-qemu-malta.img barebox.img
> barebox at qemu malta:/ imd barebox.img
> barebox at qemu malta:/ bootm barebox.img
>
> N.B. Use just the same commands for both 32-bit and 64-bit malta boards.
>
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> ---
> arch/mips/Kconfig | 10 ++++++++++
> arch/mips/boards/Makefile | 2 ++
> arch/mips/boards/board-dt-2nd.S | 35 +++++++++++++++++++++++++++++++++
> arch/mips/boot/main_entry-pbl.c | 4 ++++
> arch/mips/lib/bootm.c | 13 ++++++++++--
> 5 files changed, 62 insertions(+), 2 deletions(-)
>
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index 63ba6aa9d5a..14062dee347 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -319,6 +319,16 @@ config 64BIT
>
> endchoice
>
> +config BOARD_MIPS_GENERIC_DT
> + select BOARD_GENERIC_DT
> + depends on OFDEVICE
> + bool "Build generic MIPS device tree 2nd stage image"
> + help
> + This enables compilation of a generic image that can be started 2nd
> + stage from barebox or from qemu. It picks up a device tree passed
> + in a1 like the Kernel does.
> + The image will be called images/barebox-dt-2nd.img
> +
> menu "MIPS specific settings"
>
> config CMD_MIPS_CPUINFO
> diff --git a/arch/mips/boards/Makefile b/arch/mips/boards/Makefile
> index 9402035856c..c4ce599c934 100644
> --- a/arch/mips/boards/Makefile
> +++ b/arch/mips/boards/Makefile
> @@ -13,3 +13,5 @@ obj-$(CONFIG_BOARD_QEMU_MALTA) += qemu-malta/
> obj-$(CONFIG_BOARD_RZX50) += ritmix-rzx50/
> obj-$(CONFIG_BOARD_TPLINK_MR3020) += tplink-mr3020/
> obj-$(CONFIG_BOARD_TPLINK_WDR4300) += tplink-wdr4300/
> +
> +pbl-$(CONFIG_BOARD_MIPS_GENERIC_DT) += board-dt-2nd.o
> diff --git a/arch/mips/boards/board-dt-2nd.S b/arch/mips/boards/board-dt-2nd.S
> new file mode 100644
> index 00000000000..a1465f09e36
> --- /dev/null
> +++ b/arch/mips/boards/board-dt-2nd.S
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Startup Code for generic MIPS device tree 2nd stage image
> + *
> + * Copyright (C) 2024 Antony Pavlov <antonynpavlov at gmail.com>
> + */
> +
> +#include <asm/asm.h>
> +#include <asm/pbl_macros.h>
> +#include <linux/sizes.h>
> +
> +ENTRY_FUNCTION(start_dt_2nd)
> +
> + /* save device tree address in v1 */
> + move v1, a1
> +
> + mips_cpu_setup
> +
> + copy_to_link_location start_dt_2nd
> +
> + stack_setup
> +
> + /* pbl_main_entry() computes fdt_len by itself
> + * if fdt == fdt_end */
> + move a0, v1 /* fdt */
> + move a1, v1 /* fdt_end */
> + PTR_LI a2, SZ_256M /* ram_size */
Could this be taken from dt finally? I think it's good enough for now,
but would be a nice improvement.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list