Now that I have built a RISC-V Linux boot environment, I am running it in the RTL environment. The Linux kernel boot looks like it is going well, so next I will take on loading the root file system, that is, building the rootfs.
First, the same thing has to work on Spike. To load an initrd in Spike, use the following command.
$ spike -m512 --isa=rv64gc --kernel Image --initrd rootfs.cpio fw_jump.elf
The Buildroot Linux built with the HiFive configuration hangs at the following point.
[ 0.123850] usbhid: USB HID core driver [ 0.124485] NET: Registered protocol family 10 [ 0.125090] Segment Routing with IPv6 [ 0.125345] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver [ 0.125975] NET: Registered protocol family 17 [ 0.126350] 9pnet: Installing 9P2000 support [ 0.126625] Key type dns_resolver registered [ 0.126930] debug_vm_pgtable: [debug_vm_pgtable ]: Validating architecture page table helpers [ 0.127865] Freeing unused kernel memory: 220K [ 0.157280] Run /init as init process Starting syslogd: OK Starting klogd: OK Running sysctl: OK Saving random seed: [ 0.224010] random: dd: uninitialized urandom read (512 bytes read) OK Starting network: Waiting for interface eth0 to appear............... timeout! run-parts: /etc/network/if-pre-up.d/wait_iface: exit status 1 FAIL can't open /dev/ttySIF0: No such file or directory can't open /dev/ttySIF0: No such file or directory can't open /dev/ttySIF0: No such file or directory can't open /dev/ttySIF0: No such file or directory
The Buildroot Linux built with the Spike configuration gets all the way through.
[ 0.097635] usbhid: USB HID core driver [ 0.098335] NET: Registered PF_INET6 protocol family [ 0.099145] Segment Routing with IPv6 [ 0.099430] In-situ OAM (IOAM) with IPv6 [ 0.099770] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver [ 0.100575] NET: Registered PF_PACKET protocol family [ 0.101090] 9pnet: Installing 9P2000 support [ 0.101440] Key type dns_resolver registered [ 0.101890] debug_vm_pgtable: [debug_vm_pgtable ]: Validating architecture page table helpers [ 0.103815] Freeing unused kernel image (initmem) memory: 2144K [ 0.112675] Run /init as init process Starting syslogd: OK Starting klogd: OK Running sysctl: OK Saving random seed: [ 0.192880] random: dd: uninitialized urandom read (512 bytes read) OK Starting network: OK Welcome to Buildroot buildroot login:
As for how the initrd is loaded, Spike's implementation looks like this.
spike_main/spike.cc
if (initrd && check_file_exists(initrd)) { initrd_size = get_file_size(initrd); for (auto& m : mems) { if (initrd_size && (initrd_size + 0x1000) < m.second->size()) { initrd_end = m.first + m.second->size() - 0x1000; initrd_start = initrd_end - initrd_size; read_file_bytes(initrd, 0, m.second, initrd_start - m.first, initrd_size); break; } } }
This is exactly the same as how the kernel is loaded, loading from 0x1000. In terms of physical addresses, it should be loaded at 0x80001000, so let's change the SoC environment accordingly.
This is an English translation of the original Japanese post: RISC-VのLinuxブート環境をbuildrootで構築する (11. initrdの導入)