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

Lukas Auer lukas.auer at aisec.fraunhofer.de
Fri Oct 19 22:07:43 UTC 2018


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 <lukas.auer at aisec.fraunhofer.de>
---

 board/emulation/qemu-riscv/Kconfig      |  1 +
 board/emulation/qemu-riscv/qemu-riscv.c | 30 +++++++++++++++++++++++++
 configs/qemu-riscv32_defconfig          |  1 +
 configs/qemu-riscv64_defconfig          |  1 +
 include/configs/qemu-riscv.h            |  7 ++++++
 5 files changed, 40 insertions(+)

diff --git a/board/emulation/qemu-riscv/Kconfig b/board/emulation/qemu-riscv/Kconfig
index af23363fcf..aba3e757a1 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -18,5 +18,6 @@ config SYS_TEXT_BASE
 config BOARD_SPECIFIC_OPTIONS # dummy
 	def_bool y
 	imply SYS_NS16550
+	imply BOARD_LATE_INIT
 
 endif
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
index a7dc1d847e..ed1a0e7729 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -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;
+}
diff --git a/configs/qemu-riscv32_defconfig b/configs/qemu-riscv32_defconfig
index b55644378a..13dd53a550 100644
--- a/configs/qemu-riscv32_defconfig
+++ b/configs/qemu-riscv32_defconfig
@@ -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
diff --git a/configs/qemu-riscv64_defconfig b/configs/qemu-riscv64_defconfig
index a542ac4893..06eb3042fa 100644
--- a/configs/qemu-riscv64_defconfig
+++ b/configs/qemu-riscv64_defconfig
@@ -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
diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
index ba6a18f2e6..2d5ac6a181 100644
--- a/include/configs/qemu-riscv.h
+++ b/include/configs/qemu-riscv.h
@@ -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 */
-- 
2.17.2



More information about the U-Boot mailing list