How to use QEMU for SHAKTI Processor?

  • Post author:
  • Reading time:5 mins read
  • Post category:Tutorials
You are currently viewing How to use QEMU for SHAKTI Processor?

QEMU is a free and open-source emulator and virtualizer that can perform hardware virtualization. It is capable of emulating a complete machine in software without any need for hardware virtualization support. It is a type 2 hypervisor that runs within user space and performs virtual hardware emulation. QEMU as a whole is released under the GNU General Public License, version 2. It is multi-platform software intended to be buildable on all modern Linux platforms, OS-X, Win32 (via the Mingw64 toolchain), and a variety of other UNIX targets.

Step 1: Building QEMU for SHAKTI

Firstly, clone the repository. Then proceed to create a directory called "build".

git clone https://gitlab.com/shaktiproject/software/qemu.git
cd qemu
git checkout shakti/c-class
mkdir build
cd build
../configure --target-list="riscv32-softmmu riscv64-softmmu"
make

Then add this line to bashrc,

 export PATH=$PATH:<path/to/qemu>/build

For instance, export PATH=$PATH:/home/username/qemu/build

Step 2: Check if the installation is successful

qemu-system-riscv64 -M help

This command displays the available machines that qemu can simulate, shakti_c is what we require.

Fig. Displays the available machines in QEMU

 Step 3: Compile a UART Application and run it on Qemu

Assuming the shakti-sdk is installed, we are going to run the hello (software/examples/uart_applns/hello)on qemu.

Also, we need to disable PLIC for QEMU to work. So goto shakti-sdk/bsp/core/start.S and make sure PLIC is cleared (comment or delete the following lines).

Fig. PLIC cleared in start.S

Then proceed to compile the program,

make software TARGET=vajra PROGRAM=hello

After compiling, run the uart example using the following command,

qemu-system-riscv64 -M shakti_c -nographic -bios path/to/shakti-sdk/software/examples/uart_applns/hello/output/hello.shakti

For instance, qemu-system-riscv64 -M shakti_c -nographic -bios ~/Music/shakti-sdk/software/examples/uart_applns/hello/output/hello.shakti

Fig. Output on QEMU for hello.shakti

Step 4.1: Build the OpenSBI test payload for QEMU

Firstly, clone the OpenSBI directory and then proceed to build the payload.

cd opensbi
wget -c https://gitlab.com/behindbytes/shakti-binaries/-/raw/master/dts/shakti.dtb
export CROSS_COMPILE=riscv64-unknown-elf-
export FW_FDT_PATH=./shakti.dtb
make PLATFORM=generic

Step 4.2: Run the test payload on QEMU

qemu-system-riscv64 -M shakti_c -nographic -bios path/to/fw_payload.elf
Fig. Test payload (OpenSBI) running on QEMU