系列文章 : 資訊工程自學筆記
這一篇是希望,可以在 QEMU 上運行 RISC-V 的 linux kernel。
其實編譯的過程跟 gem5 差不多 XD
有點小差異的地方是,OpenSBI 不用再把 kernel 當做 payload 了。
# Clone the QEMU repository
git clone git@github.com:qemu/qemu.git
cd qemu
git checkout v10.0.0
python -m venv ./my-venv
source ./my-venv/bin/activate
pip install --upgrade setuptools
pip install --upgrade distlib
# Configure and build QEMU for riscv64
./configure --target-list=riscv64-softmmu
make -j$(nproc)
deactivate
cd ..
git clone git@github.com:buildroot/buildroot.git
cd buildroot
git checkout 56c6862bc81ef41c0fe012677eafa24381b1f76c
# use default configuration for RISC-V 64-bit virt QEMU/gem5
make qemu_riscv64_virt_defconfig
sed -i 's/^BR2_TARGET_ROOTFS_EXT2_2=y/# BR2_TARGET_ROOTFS_EXT2_2 is not set/' .config
sed -i 's/.*BR2_TARGET_ROOTFS_EXT2_4.*/BR2_TARGET_ROOTFS_EXT2_4=y/' .config
make olddefconfig
make -j$(nproc)
git clone --depth 1 -b v6.8 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
# generate default RISC-V configuration
make ARCH=riscv CROSS_COMPILE=$(realpath ../buildroot/output/host/bin)/riscv64-buildroot-linux-gnu- defconfig
# Compile both the vmlinux ELF (needed for debugging) and the Image (used as payload)
make ARCH=riscv CROSS_COMPILE=$(realpath ../buildroot/output/host/bin)/riscv64-buildroot-linux-gnu- vmlinux Image -j$(nproc)
git clone https://github.com/riscv-software-src/opensbi.git
cd opensbi
git checkout 0b041e58c0787f76325da5081e41a13bf304d328
make CROSS_COMPILE=$(realpath ../buildroot/output/host/bin)/riscv64-buildroot-linux-gnu- PLATFORM=generic FW_TEXT_START=0x80000000 -j$(nproc)
$(pwd)/qemu/build/qemu-system-riscv64 \
-M virt \
-bios $(pwd)/opensbi/build/platform/generic/firmware/fw_jump.elf \
-kernel $(pwd)/linux/arch/riscv/boot/Image \
-append "root=/dev/vda ro console=ttyS0" \
-drive file=$(pwd)/buildroot/output/images/rootfs.ext4,format=raw,id=hd0,if=none \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=net0 \
-device virtio-net-device,netdev=net0 \
-nographic
or
$(pwd)/qemu/build/qemu-system-riscv64 \
-M virt \
-bios $(pwd)/opensbi/build/platform/generic/firmware/fw_jump.bin \
-kernel $(pwd)/linux/arch/riscv/boot/Image \
-append "root=/dev/vda ro console=ttyS0" \
-drive file=$(pwd)/buildroot/output/images/rootfs.ext4,format=raw,id=hd0,if=none \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=net0 \
-device virtio-net-device,netdev=net0 \
-nographic
git clone git@github.com:TommyWu-fdgkhdkgh/qemu-boot-riscv-linux.git
cd qemu-boot-riscv-linux
make buildroot/build
make linux/build
make opensbi/build
make qemu/build
make qemu/run