Skip to content

Commit

Permalink
riscv: qemu: detect and boot the kernel passed by QEMU
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Lukas Auer <[email protected]>
Series-to: u-boot
Series-cc: bmeng
Cover-letter:
General fixes / cleanup for RISC-V and improvements to qemu-riscv

This patch series includes general fixes and cleanup for RISC-V. It also
adds support for booting Linux on qemu-riscv. At the moment, only
single-core systems are supported. Support for multi-core systems will
be added with a future patch series.

To boot Linux on qemu-riscv, Linux must be compiled into BBL as a
payload. BBL must be included in a FIT image and supplied to QEMU with
the -kernel parameter. Its location in memory is embedded in the device
tree, which QEMU passes to u-boot.
To test this, QEMU and riscv-pk (BBL) must be modified. QEMU is modified
to add support for loading binary files (FIT images in this case) in
addition to ELF files. riscv-pk must be modified to adjust the link
address and to ignore the kernel address from the device tree. A pull
request for QEMU, which implements this, is available at [1]. A modified
version of riscv-pk is available at [2].

[1]: riscvarchive/riscv-qemu#175
[2]: https://github.com/lukasauer/riscv-pk/tree/riscv-u-boot
END
  • Loading branch information
lukasauer committed Oct 19, 2018
1 parent c833e8b commit c4d55b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions board/emulation/qemu-riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ config SYS_TEXT_BASE
config BOARD_SPECIFIC_OPTIONS # dummy
def_bool y
imply SYS_NS16550
imply BOARD_LATE_INIT

endif
30 changes: 30 additions & 0 deletions board/emulation/qemu-riscv/qemu-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,39 @@
*/

#include <common.h>
#include <dm.h>
#include <fdtdec.h>

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");
return 0;
}

env_set_hex("kernel_start", kernel_start);

return 0;
}
1 change: 1 addition & 0 deletions configs/qemu-riscv32_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ CONFIG_NR_DRAM_BANKS=1
CONFIG_FIT=y
CONFIG_DISPLAY_CPUINFO=y
CONFIG_DISPLAY_BOARDINFO=y
CONFIG_HUSH_PARSER=y
CONFIG_OF_PRIOR_STAGE=y
1 change: 1 addition & 0 deletions configs/qemu-riscv64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ CONFIG_NR_DRAM_BANKS=1
CONFIG_FIT=y
CONFIG_DISPLAY_CPUINFO=y
CONFIG_DISPLAY_BOARDINFO=y
CONFIG_HUSH_PARSER=y
CONFIG_OF_PRIOR_STAGE=y
7 changes: 7 additions & 0 deletions include/configs/qemu-riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@
"fdt_high=0xffffffffffffffff\0" \
"initrd_high=0xffffffffffffffff\0"

#define CONFIG_BOOTCOMMAND \
"if env exists kernel_start; then " \
"bootm ${kernel_start};" \
"else " \
"echo Kernel address not found in the device tree;" \
"fi;"

#endif /* __CONFIG_H */

0 comments on commit c4d55b3

Please sign in to comment.