A little bit context about what I am going to do. Previously I bought a Nezha D1 SBC, and managed to port rv6 educational kernel on it.
Recently I got a VisionFive2 board and plan to do it the same but use Zig rather than C.
The first issue I encountered is how to quickly load my kernel to the board and up & running. Previously on Nezha, they have xfel tool to easily do that. After research, I found UART boot may be an option.
At the very beginning, I tried to replace VisionFive2 uboot SPL and write my spl implementing Xmodem. and it can help receive my kernel binary and move it to DRAM at 0x40000000. The simple idea took me a couple of days and I have done the xmodem part, but had no documentation to guide me how to initialise DRAM, and other peripherals, although I can find some clues from visionfive2 uboot repo. The documentation about system control registers is too short and not too much helpful. Here is my attempt: rvz/splz at master · chaoyangnz/rvz · GitHub
Then when I found uboot actually has a UART boot supporting YModem. Once I got this, things become simple.
I added CONFIG_SPL_YMODEM_SUPPORT=y
in starfive_visionfive2_defconfig, and then re-build u-boot, it should be generating u-boot/spl/u-boot-spl.bin
, which now supports YModem transmit.
Use spl_tool
to add header: spl_tool -c -f spl/u-boot-spl.bin
Now the generated u-boot-spl.bin.normal.out
can be loaded in UART via Xmodem when you see polling character CCCC
.
Once the spl is loaded, it will be waiting you to load your kernel using Ymodem.
I just made a tool to automate the loading. You can download the CLI in rvz/tools/vf2-programmer/vf2-programmer at master · chaoyangnz/rvz · GitHub
Usage:
vf2-programmer -h
Example:
vf2-programmer -l 1 -t -f your_kernel.bin
Then your kernel is running at 0x40000000 now.
Hopefully it helps for whoever playing with bare metal and also hope StarFive to share more documentation and clearly reveal some internals.