aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md19
-rwxr-xr-xarch/riscv64/conf/initbin3600 -> 3648 bytes
-rw-r--r--arch/riscv64/conf/init.c7
-rw-r--r--arch/riscv64/conf/initrdbin4096 -> 4096 bytes
-rw-r--r--docs/boot.md10
-rw-r--r--docs/visionfive2.md60
6 files changed, 76 insertions, 20 deletions
diff --git a/README.md b/README.md
index 7216c1a..9d279d6 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,10 @@
-# `kmi`
+# kmi
-`kmi` is a ***K***ernel with ***MI***grating threads I've been writing as a hobby project.
+`kmi` is a ***K*** ernel with ***MI*** grating threads I've been writing as a hobby project.
To see it in action, have a look at [kmi-example](https://github.com/Kimplul/kmi-example).
-Currently the kernel only works in `qemu` with RISC-V 64 bit. There is some code for
+Currently the kernel has been run on `qemu` with the `virt` board and on a
+StarFive VisionFive2 with RISC-V 64 bit. There is some code for
RISC-V 32 bit support, but at the moment I'm focusing on 64 bit and 32 is less tested.
# Building
@@ -40,17 +41,7 @@ runtime when undefined behavior is detected. Only available with `RELEASE=0`.
booting the kernel through u-boot's `go` command. This would in theory allow
using essentially any precompiled u-boot as a bootloader, but requires some
extra effort by the user to manage loading different parts to where they should
-go. I should probably come up with a full example, but approximately:
-
-1. Load `kmi.bin` to address `A`
-2. Load `initrd` to address `B`
-3. Load FDT to address `C` (either provided by u-boot or a separate file)
-4. Add `initrd` to FDT's `chosen` node
-5. Boot with `go ${A} ${C}`.
-
-Note that u-boot likes to skip the `0x` prefix for
-hexadecimal values, which can confuse my string converter.
-Check that the strings you pass to `go` have their correct prefixes.
+go. See `docs/visionfive2.md` for an example.
+ `run`: Load a test program into `qemu` and run it. Requires some outside support at
the moment, please see [kmi-example](https://github.com/Kimplul/kmi-example).
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init
index c77c048..76de753 100755
--- a/arch/riscv64/conf/init
+++ b/arch/riscv64/conf/init
Binary files differ
diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c
index b2f4024..8177992 100644
--- a/arch/riscv64/conf/init.c
+++ b/arch/riscv64/conf/init.c
@@ -256,6 +256,8 @@ void callback(long status, long tid, long d0, long d1, long d2, long d3)
#define csr_read(csr, \
res) __asm__ volatile ("csrr %0, " csr : "=r" (res) :: "memory")
+#define CSR_CYCLE "0xc00"
+
void _start()
{
sys_noop();
@@ -264,17 +266,20 @@ void _start()
uint64_t second = sys_timebase();
print_value("Timebase", second);
- uint64_t n = 0, i, start;
+ uint64_t n = 0, i, start, cn, cstart, cend;
start = i = sys_ticks();
print_value("Start ticks", start);
+ csr_read(CSR_CYCLE, cstart);
while (i < start + second) {
i = sys_ticks();
n++;
}
+ csr_read(CSR_CYCLE, cend);
print_value("End ticks", i);
print_value("Syscalls per second", n);
+ print_value("Executed cycles per second", cend - cstart);
puts("Setting callback...");
sys_ipc_server(callback);
diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd
index fb6f525..e4d76a2 100644
--- a/arch/riscv64/conf/initrd
+++ b/arch/riscv64/conf/initrd
Binary files differ
diff --git a/docs/boot.md b/docs/boot.md
index 2131d93..f79f475 100644
--- a/docs/boot.md
+++ b/docs/boot.md
@@ -1,11 +1,11 @@
I need to figure out how to write MarkDown files, but the general procedure of a
boot is that we
-1) Assume we start of in real memory mode, i.e. no MMU active.
+1. Assume we start of in real memory mode, i.e. no MMU active.
-2) arch/whatever/init/init.c kickstarts us into virtual memory with a direct
-mapping, with offset VM_DMAP aliasing to physical address 0.
+2. arch/whatever/init/init.c kickstarts us into virtual memory with a direct
+mapping, with offset `VM_DMAP` aliasing to physical address 0.
-3) The kernel proper is moved to its correct location in this direct mapping.
+3. The kernel proper is moved to its correct location in this direct mapping.
-4) The kernel proper is jumped to, after which the kernel does whatever.
+4. The kernel proper is jumped to, after which the kernel does whatever.
diff --git a/docs/visionfive2.md b/docs/visionfive2.md
new file mode 100644
index 0000000..51067f1
--- /dev/null
+++ b/docs/visionfive2.md
@@ -0,0 +1,60 @@
+# StarFive VisionFive2
+
+## Booting
+
+Ideally I would fork StarFive's u-boot fork and add 'native' support for my
+kernel, but it turns out that their fork is at the time of writing borked and
+I wasn't able to get anything to boot with it. As such, we'll use their prebuilt
+bootloader and boot in a more generic way.
+
+The following is how to boot with an SD card. The board seems to support
+serial and ethernet booting, but I haven't looked into how they work.
+
+1. Build `kmi` with `GENERIC_UBOOT=1`.
+
+2. Create three partitions on an SD card of your choice:
+```
+sudo sgdisk --clean \
+ --new=1:4096:8191 --change-name=1:"spl" --typecode=1:2E54B353-1271-4842-806F-E436D6AF6985 \
+ --new=2:8192:16383 --change-name=2:"uboot" --typecode=2:5B193300-FC78-40CD-8002-E86C45580B47 \
+ --new=3:16384:0 --change-name=3:"data" \
+ /dev/sdX
+```
+
+3. Prepare partitions with data:
+```
+sudo dd if=u-boot-spl.bin.normal.out of=/dev/sdX1
+sudo dd if=visionfive2_fw_payload.img of=/dev/sdX2
+sudo mkfs.ext2 /dev/sdX3
+```
+
+4. Copy `kmi.bin` and `initrd` to SD card:
+```
+sudo mount /dev/sdX3 /mnt/sdcard # or wherever
+sudo cp kmi.bin arch/riscv64/conf/initrd /mnt/sdcard
+sudo umount /mnt/sdcar
+sync
+```
+
+With the SD card ready to go, reset the device and manually run these commands:
+
+1. `fdt move 0xcce379d0 ${fdt_addr_r}`
+2. `load mmc 1:3 0x47000000 kmi.bin`
+3. `load mmc 1:3 0x48000000 initrd`
+4. `fdt chosen 0x48000000 0x48001000`
+5. `go 0x47000000 ${fdt_addr_r}`
+
+These commands are pretty hard coded and might not work in the future, in which
+case I should come and update them.
+
+Other things to note:
+
+U-boot likes to skip the `0x` prefix for
+hexadecimal values, which can confuse my string converter.
+Check that the strings you pass to `go` have their correct prefixes.
+
+Depending on the u-boot version, the `fdt chosen` command either takes
+the end address or the size of the `initrd`.
+
+It should be possible to add the above commands to a script to run
+automatically, though I haven't personally done this yet.