Information Sources
The main guide
https://andreas.welcomes-you.com/boot-sw-debian-risc-v-lichee-rv-2
Apropriate source of info:
https://linux-sunxi.org/Allwinner_Nezha#Manual_build
Short brief
Overview
The board has a single core Allwinner D1 SoC, which is based on 64-bit Alibaba T-Head C906 core at 1GHz frequency. The SoC does not have typical 3D accelerator/gpu, but it has G2D blitter, not sure if it is actually supported in open source.
Software contains mainly from two major parts: operating system and basic sw(bootloaders, kernel, drivers).
Boot process
The SoC start its boot looking into two places on an SD card with offsets 8192 (and way later YYYY) to load a Boot0/SPL image. It can be built either from smaeul's repositories (sun20i_d1_spl or u-boot fork) or probably from generic u-boot repository(this need to be checked, since support for D1 has been added, but I actually never checked that).
The SPL will also load RISC-V SBI, which is build from OpenSBI project. Using a correct version (rather most modern) is essential, since there are many errors being handled on SBI level. Early SBIs(typically packed into old images) were having various issues, which was blocking various software, for instance version 0.9 had a strange glitch and Debian's dpkg was constantly crashing, while the rest of the system seems to be working fine. With the other version X11 were crashing making it impossible to boot lxde desktop (yeah, lol).
The next step is to boot fully featured u-boot
Building software parts
Boot0
build build build
git clone https://github.com/smaeul/sun20i_d1_spl
git checkout mainline
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- p=sun20iw1p1 mmc
OpenSBI
git clone https://github.com/smaeul/opensbi
git checkout d1-wip
make CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y FW_OPTIONS=0x2
U-Boot
git clone https://github.com/smaeul/u-boot.git
git checkout d1-2022-04-05
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- lichee_rv_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- OPENSBI=../opensbi/build/platform/generic/firmware/fw_dynamic.bin all
Flashing
Boot0
dd if=nboot/boot0_sdcard_sun20iw1p1.bin of=/dev/sda bs=1024 seek=8
TOC1
First create TOC1 image:
./u-boot/tools/mkimage -T sunxi_toc1 -d licheerv_toc1.cfg u-boot.toc1
Than flash it
dd if=u-boot.toc1 of=/dev/sda bs=512 seek=32800
New way of building bootloader
Clone and build the image:git clone https://github.com/smaeul/u-boot.git
git checkout d1-wip
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- lichee_rv_dock_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- OPENSBI=opensbi/build/platform/generic/firmware/fw_dynamic.bin all
Flash the image to the SD card:
dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8
Content of boot_script.cmd:
echo "Loading kernel from mmc 0:1 to address $kernel_addr_r"
load mmc 0:1 ${kernel_addr_r} Image
setenv bootargs "earlycon=sbi console=ttyS0,115200n8 hdmi.audio=EDID:0 disp.screen0_output_mode=1920x1080p60 root=/dev/mmcblk0p2 delayacct slub_debug"
echo "Booting kernel with bootargs as $bootargs; and fdtcontroladdr is $fdtcontroladdr"
setenv kernel_comp_addr_r "0x44000000"
setenv kernel_comp_size "0xb000000"
booti ${kernel_addr_r} - ${fdtcontroladdr}
Then create binary script for u-boot:
u-boot/tools/mkimage -T script -O linux -d boot_script.cmd boot.scr