[U-Boot] [PATCH v2 28/29] riscv: qemu: detect and boot the kernel passed by QEMU

Bin Meng bmeng.cn at gmail.com
Sun Nov 4 14:39:19 UTC 2018


Hi Lukas,

On Tue, Oct 30, 2018 at 8:57 PM Lukas Auer
<lukas.auer at aisec.fraunhofer.de> wrote:
>
> QEMU embeds the location of the kernel image in the device tree. Store
> this address in the environment as variable kernel_start and use it in
> CONFIG_BOOTCOMMAND to boot the kernel. Use the device tree passed by the
> prior boot stage to boot Linux.
>
> Signed-off-by: Lukas Auer <lukas.auer at aisec.fraunhofer.de>
> ---
>
> Changes in v2:
> - Rebase onto u-boot-dm/next
> - Boot Linux with the device tree provided by the prior boot stage
>
>  board/emulation/qemu-riscv/Kconfig      |  1 +
>  board/emulation/qemu-riscv/qemu-riscv.c | 29 +++++++++++++++++++++++++
>  configs/qemu-riscv32_defconfig          |  1 +
>  configs/qemu-riscv64_defconfig          |  1 +
>  include/configs/qemu-riscv.h            | 10 ++++++++-
>  5 files changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/board/emulation/qemu-riscv/Kconfig b/board/emulation/qemu-riscv/Kconfig
> index 37a80db6a9..be5839b7db 100644
> --- a/board/emulation/qemu-riscv/Kconfig
> +++ b/board/emulation/qemu-riscv/Kconfig
> @@ -29,5 +29,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy
>         imply CMD_EXT2
>         imply CMD_EXT4
>         imply CMD_FAT
> +       imply BOARD_LATE_INIT
>
>  endif
> diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
> index 2ce093e19a..ee20983095 100644
> --- a/board/emulation/qemu-riscv/qemu-riscv.c
> +++ b/board/emulation/qemu-riscv/qemu-riscv.c
> @@ -19,3 +19,32 @@ int board_init(void)
>
>         return 0;
>  }
> +
> +int board_late_init(void)
> +{
> +       ulong kernel_start;
> +       ofnode chosen_node;
> +       int ret;
> +
> +       chosen_node = ofnode_path("/chosen");
> +       if (!ofnode_valid(chosen_node)) {
> +               printf("No chosen node found\n");
> +               return 0;
> +       }
> +
> +#ifdef CONFIG_ARCH_RV64I
> +       ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
> +                             (u64 *)&kernel_start);
> +#else
> +       ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
> +                             (u32 *)&kernel_start);
> +#endif
> +       if (ret) {
> +               printf("Can't find kernel start address in device tree\n");

I think we need use 'debug' instead of 'printf' here, for situation
that kernel is not passed to QEMU.

> +               return 0;
> +       }
> +
> +       env_set_hex("kernel_start", kernel_start);
> +
> +       return 0;
> +}

[snip]

Regards,
Bin


More information about the U-Boot mailing list