diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-05-29 21:31:09 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-05-29 21:31:09 +0300 |
| commit | 3ace1ddd76b9c04f3ed23883de6279b4485612e8 (patch) | |
| tree | 2f4af69d70967c2455cb83d8c18a5416c8d1b54d /arch/riscv64 | |
| parent | b7f53b9a9001708dea5303faf52f1b508eefb712 (diff) | |
| download | kmi-3ace1ddd76b9c04f3ed23883de6279b4485612e8.tar.gz kmi-3ace1ddd76b9c04f3ed23883de6279b4485612e8.zip | |
start trying to boot on visionfive 2
+ Not bootable quite yet. Among other things, I couldn't
get the current starfive u-boot fork to boot, so
try adding support for booting with precompiled u-boot
via the `go` command. Initial testing with qemu shows that
this should be possible, and if it works, might be useful
in the (far) future with other slightly janky SBCs.
Also, NS16550 is 8250-based, and I'm really only using the base
8250, so rename and add visionfive 2 uart to list of compatibles.
Visionfive 2 is still completely untested.
Diffstat (limited to 'arch/riscv64')
| -rwxr-xr-x | arch/riscv64/conf/mkimage.sh | 4 | ||||
| -rw-r--r-- | arch/riscv64/init/init.c | 17 | ||||
| -rw-r--r-- | arch/riscv64/init/start.S | 20 | ||||
| -rw-r--r-- | arch/riscv64/kernel/vmem.c | 3 |
4 files changed, 40 insertions, 4 deletions
diff --git a/arch/riscv64/conf/mkimage.sh b/arch/riscv64/conf/mkimage.sh index badac4c..1726e57 100755 --- a/arch/riscv64/conf/mkimage.sh +++ b/arch/riscv64/conf/mkimage.sh @@ -14,6 +14,10 @@ SSIZE=$(fdisk -l rootfs.img | awk '$1=="Units:" {print $8}') OFFSET=$(fdisk -l rootfs.img | awk '$1=="rootfs.img1" {print $2}') mount -o loop,offset=$((${SSIZE}*${OFFSET})) rootfs.img fs +# copy over files outside the .itb to mess around with manual booting +cp kmi.bin fs +cp arch/riscv64/conf/initrd fs + # not entirely pleased with this solution, although eventually I should probably # move `run` out of the kernel repo and into some `kmios` repo with a runtime # and proper initrd etc. so this is good enough for now diff --git a/arch/riscv64/init/init.c b/arch/riscv64/init/init.c index 92f8053..278b9db 100644 --- a/arch/riscv64/init/init.c +++ b/arch/riscv64/init/init.c @@ -54,7 +54,8 @@ static void init_bootmem(uintptr_t load_addr, uintptr_t ram_base) extern char *__kernel; extern char *__kernel_size; - uintptr_t top = load_addr + (uintptr_t)&__kernel + (uintptr_t)&__kernel_size; + uintptr_t top = load_addr + (uintptr_t)&__kernel + + (uintptr_t)&__kernel_size; /* this could be risky, as we might overwrite some bits of initrd or fdt * if they're allocated too close to the kernel payload. @@ -119,3 +120,17 @@ void init(void *fdt, pm_t load_addr) jump_to_kernel(fdt, ram_base, (void *)VM_KERN); } + +#if GENERIC_UBOOT +void init_go(int argc, char **argv, pm_t load_addr) +{ + if (argc != 2) + return; + + void *fdt = (void *)strtouintptr(argv[1]); + + /* fdt is passed as second argument, load address first but since we + * already have it due to our ingenious _start, no need to parse it */ + init(fdt, load_addr); +} +#endif diff --git a/arch/riscv64/init/start.S b/arch/riscv64/init/start.S index 7439d93..b6394f7 100644 --- a/arch/riscv64/init/start.S +++ b/arch/riscv64/init/start.S @@ -1,17 +1,33 @@ /* SPDX-License-Identifier: copyleft-next-0.3.1 */ /* Copyright 2021 - 2022, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ +/* generic u-boot passes argc and argv as if we were a regular + * program, so our load address must be placed third. + * If we have a 'custom' u-boot with kmi support, the fdt + * will be passed to us directly, so the load address can go second. + */ +#if GENERIC_UBOOT +# define LOAD_REG a2 +# define INIT init_go +#else +# define LOAD_REG a1 +# define INIT init +#endif + .section .init .global _start /* Entry point to the kernel loader. */ _start: /* get load address */ -auipc a1, 0 +auipc LOAD_REG, 0 /* keep using bootloader stack for now */ //li sp, PM_STACK_TOP /* make sure there's no garbage in tp, important for id assignment */ li tp, 0 -call init +call INIT +// INIT shouldn't return, but if we do we might as well just jump back to u-boot +// or wherever +ret .section .text .global jump_to_kernel diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c index d0cac2c..235884b 100644 --- a/arch/riscv64/kernel/vmem.c +++ b/arch/riscv64/kernel/vmem.c @@ -427,7 +427,8 @@ stat_t populate_kvmem(struct vmem *b) size_t flags = VM_V | VM_R | VM_W | VM_X | VM_G; for (size_t i = KSTART_PAGE; i < IO_PAGE; ++i) b->leaf[i] = (struct vmem *)to_pte( - get_ram_base() + TOP_PAGE_SIZE * (i - KSTART_PAGE), flags); + get_ram_base() + TOP_PAGE_SIZE * (i - KSTART_PAGE), + flags); /* map in IO region */ map_io_dbg(b); |
