summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-04 12:45:13 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-17 08:29:42 +0200
commitb383d7739c355fee9f81986e6e8d030185373ca5 (patch)
treea22c8bd7afcddc1299eafa0ec0185c786e991676
parent4a0edad5d6b057fc117ab01727cc4ab682f36d4d (diff)
downloadbarebox-b383d7739c355fee9f81986e6e8d030185373ca5.tar.gz
barebox-b383d7739c355fee9f81986e6e8d030185373ca5.tar.xz
RISC-V: add Linux kernel boot support
The Linux kernel RISC-V header has the same structure as on ARM64. The barebox header for the architecture also follows the same structure. Add the architecture-specific glue for barebox to be able to boot both RISC-V Linux and barebox. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210504104513.2640-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/riscv/lib/Makefile1
-rw-r--r--arch/riscv/lib/bootm.c51
2 files changed, 52 insertions, 0 deletions
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 49750d576a..a399de7399 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_HAS_ARCH_SJLJ) += setjmp.o longjmp.o
obj-$(CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS) += memcpy.o memset.o memmove.o
obj-$(CONFIG_RISCV_SBI) += sbi.o
obj-$(CONFIG_CMD_RISCV_CPUINFO) += cpuinfo.o
+obj-$(CONFIG_BOOTM) += bootm.o
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
new file mode 100644
index 0000000000..b3e41de4a8
--- /dev/null
+++ b/arch/riscv/lib/bootm.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: 2018 Sascha Hauer <s.hauer@pengutronix.de>
+
+#include <common.h>
+#include <bootm.h>
+
+static int do_bootm_linux(struct image_data *data)
+{
+ void (*fn)(unsigned long a0, unsigned long dtb, unsigned long a2);
+ phys_addr_t devicetree;
+
+ fn = booti_load_image(data, &devicetree);
+ if (IS_ERR(fn))
+ return PTR_ERR(fn);
+
+ shutdown_barebox();
+
+ fn(0, devicetree, 0);
+
+ return -EINVAL;
+}
+
+static struct image_handler riscv_linux_handler = {
+ .name = "RISC-V Linux image",
+ .bootm = do_bootm_linux,
+ .filetype = filetype_riscv_linux_image,
+};
+
+static struct image_handler riscv_fit_handler = {
+ .name = "FIT image",
+ .bootm = do_bootm_linux,
+ .filetype = filetype_oftree,
+};
+
+static struct image_handler riscv_barebox_handler = {
+ .name = "RISC-V barebox image",
+ .bootm = do_bootm_linux,
+ .filetype = filetype_riscv_barebox_image,
+};
+
+static int riscv_register_image_handler(void)
+{
+ register_image_handler(&riscv_linux_handler);
+ register_image_handler(&riscv_barebox_handler);
+
+ if (IS_ENABLED(CONFIG_FITIMAGE))
+ register_image_handler(&riscv_fit_handler);
+
+ return 0;
+}
+late_initcall(riscv_register_image_handler);