YAGNI
You are(n't)? gonna need it…
The RISC-V GNU Toolchain, FreeRTOS and QEMU
About
Emulation eases the software development process when the target architecture is different than the host machine. This document explains how to setup a development Toolchain and use the Quick Emulator (QEMU) to run a FreeRTOS "demo" targeted to the RISCV-V architecture.
The explanation goes for two different operating systems, Gentoo GNU/Linux and OpenBSD.
Setup in Gentoo
Install the RISC-V GNU Toolchain
crossdev
enables a Gentoo system to provide cross-compilation tools; the first
step is to install it and create a dedicated repository for toolchains that are
to be built.
# install the packages emerge crossdev emerge eselect-repository # create the dedicated repository eselect repository create crossdev # build the risc-v toolchain for baremetal binaries crossdev --target riscv64-unknown-elf
Install QEMU for RISC-V
Gentoo allows to build a minimal RISC-V system emulator by setting
QEMU_SOFTMMU_TARGETS
in portage.use
:
USE_FILE=/etc/portage/portage.use/qemu echo 'app-emulation/qemu QEMU_SOFTMMU_TARGETS: riscv64 riscv32' >> $USE_FILE emerge -a qemu
Setup in OpenBSD
The OpenBSD's package system already provides packages for the RISC-V GNU Toolchain and the QEMU system, so the needed tools can be installed by running:
pkg_add riscv-elf-newlib qemu gmake
Run the FreeRTOS demo
Once the toolchain and the emulator are installed, it's should be now possible to build and run the corresponding FreeRTOS "demo".
# fetch the FreeRTOS sources git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules # build the demo targeted to the GNU Toolchain for RISC-V on QEMU cd FreeRTOS/Demo/RISC-V-Qemu-virt_GCC gmake # run the demo qemu-system-riscv32 -nographic -machine virt -net none \ -chardev stdio,id=con,mux=on -serial chardev:con \ -mon chardev=con,mode=readline -bios none \ -smp 4 -kernel ./build/RTOSDemo.axf
Terminate the emulation using the key combination Ctrl-a x
.
See also
- Crossdev
- The FreeRTOS repository