-
Notifications
You must be signed in to change notification settings - Fork 10
PoC : How to build and test ACPI enabled kernel
1) You will need to install a RISC-V toolchain. It is recommended to install a toolchain from your distro. This can be done by using your distro’s installed (apt, dnf, pacman or something similar) and searching for riscv64 and installing gcc.
First, create a working directory, where we’ll download and build all the sources.
WORK_DIR=$PWD/riscv64-acpi mkdir -p $WORK_DIR cd $WORK_DIR
Then download all the required sources, which are:
git clone --branch riscv_acpi https://github.com/ventanamicro/qemu.git qemu git clone --branch riscv_acpi https://github.com/ventanamicro/linux.git linux git clone --recurse-submodule [email protected]:tianocore/edk2.git edk2
Build QEMU with the RISC-V target:
cd $WORK_DIR/qemu ./configure --target-list=riscv64-softmmu make -j $(nproc)
Build EDK2 firmware for the RISC-V target as per instructions here.
Resize the EDK2 firmware image to 32M (Modify the path to RISCV_VIRT_CODE.fd and RISCV_VIRT_VARS.fd accordingly)
truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd truncate -s 32M Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd
Build Linux for the RISC-V target.
cd $WORK_DIR/linux make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- defconfig make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j $(nproc)
You can use any rootfs of your choice. This example uses buildroot.
ACPI is supported on system with 3 different interrupt controllers. Just change the -machine option as below while running qemu.
1) With APLIC and IMSIC: -machine virt,aia=aplic-imsic
2) With APLIC only: -machine virt,aia=aplic
3) With PLIC: -machine virt
$WORK_DIR/qemu/build/qemu-system-riscv64 -nographic \ -M virt,pflash0=pflash0,pflash1=pflash1,aia=aplic-imsic \ -m 4G -smp 8 \ -serial mon:stdio \ -device virtio-gpu-pci -full-screen \ -device qemu-xhci \ -device usb-kbd \ -numa node,mem=2G \ -numa node,mem=2G \ -blockdev node-name=pflash0,driver=file,read-only=on,filename=Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_CODE.fd \ -blockdev node-name=pflash1,driver=file,filename=Build/RiscVVirtQemu/RELEASE_GCC5/FV/RISCV_VIRT_VARS.fd \ -netdev user,id=net0 -device virtio-net-pci,netdev=net0 \ -kernel linux/arch/riscv/boot/Image \ -initrd rootfs.cpio \ -append "root=/dev/ram ro console=ttyS0 rootwait earlycon=uart8250,mmio,0x10000000"