Skip to main content

Command Palette

Search for a command to run...

Booting RTEMS on Sifive-U QEMU

Updated
3 min read

Hello, Today I will be telling you how to run RTEMS on the new Sifive_u BSP using QEMU, so let's get started without any delay.

Prerequisite

In order to run the BSP, we need to fulfill the requirement for the environment. They are as follows:

  • RTEMS-6 RISC Toolchains

  • RTEMS devel QEMU

Building the toolchains and QEMU

First of all, install all of the dependencies which will be required to build the toolchains and QEMU required by RTEMS as per the documentation page. After installing all the dependencies, run the following command in order to build all the toolchains and QEMU.

git clone git://git.rtems.org/rtems-source-builder.git rsb
cd rsb/rtems
# Build the Toolchains
../source-builder/sb-set-builder --prefix=$HOME/rtems-development/toolchains 6/rtems-riscv
# Build QEMU
../source-builder/sb-set-builder --prefix=$HOME/rtems-development/toolchains devel/qemu
export PATH=$HOME/rtems-development/toolchains/bin:"$PATH"

Building the BSP

After building all the requirements, It's now time to build RTEMS, so you need to either download my custom RTEMS or you can use my patch (shared below), save it as Sifive.patch and apply it on your own branch using git apply Sifive.patch.

Getting RTEMS using My fork

# Download the My RTEMS fork
git clone https://github.com/amna-mannan/rtems
cd rtems
git checkout amna

Getting RTEMS using my Patch

save the below code as Sifive.patch and apply it on your own RTEMS branch using git apply Sifive.patch

diff --git a/spec/build/bsps/riscv/optextirqmax.yml b/spec/build/bsps/riscv/optextirqmax.yml
index 5a0fc9a766..3f79026811 100644
--- a/spec/build/bsps/riscv/optextirqmax.yml
+++ b/spec/build/bsps/riscv/optextirqmax.yml
@@ -8,6 +8,8 @@ copyrights:
 default:
 - enabled-by: riscv/mpfs64imafdc
   value: 187
+- enabled-by : riscv/sifiveu
+  value: 53
 - enabled-by: true
   value: 128
 description: |
diff --git a/spec/build/bsps/riscv/optramsize.yml b/spec/build/bsps/riscv/optramsize.yml
index 876a447087..08218d6b42 100644
--- a/spec/build/bsps/riscv/optramsize.yml
+++ b/spec/build/bsps/riscv/optramsize.yml
@@ -17,6 +17,8 @@ default:
   value: 0x01000000
 - enabled-by: riscv/kendrytek210
   value: 0x00600000
+- enabled-by: riscv/sifiveu
+  value: 0x10000000
 - enabled-by: true
   value: 0x04000000
 description: ''
diff --git a/spec/build/bsps/riscv/riscv/abi.yml b/spec/build/bsps/riscv/riscv/abi.yml
index bca6512f20..0cb5f77482 100644
--- a/spec/build/bsps/riscv/riscv/abi.yml
+++ b/spec/build/bsps/riscv/riscv/abi.yml
@@ -22,7 +22,9 @@ default:
   - -march=rv64imafd
   - -mabi=lp64d
   - -mcmodel=medany
-- enabled-by: riscv/rv64imac
+- enabled-by: 
+  - riscv/rv64imac
+  - riscv/sifiveu
   value:
   - -march=rv64imac
   - -mabi=lp64
diff --git a/spec/build/bsps/riscv/riscv/bspsifiveu.yml b/spec/build/bsps/riscv/riscv/bspsifiveu.yml
new file mode 100644
index 0000000000..3c285bac98
--- /dev/null
+++ b/spec/build/bsps/riscv/riscv/bspsifiveu.yml
@@ -0,0 +1,19 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+arch: riscv
+bsp: sifiveu
+build-type: bsp
+cflags: []
+copyrights:
+- Copyright (C) 2023 Amna Mannan
+cppflags: []
+enabled-by: true
+family: riscv
+includes: []
+install: []
+links:
+- role: build-dependency
+  uid: ../../opto2
+- role: build-dependency
+  uid: grp
+source: []
+type: build
diff --git a/spec/build/bsps/riscv/riscv/optsifiveuart.yml b/spec/build/bsps/riscv/riscv/optsifiveuart.yml
index 8ff27d0275..2fabaac5fa 100644
--- a/spec/build/bsps/riscv/riscv/optsifiveuart.yml
+++ b/spec/build/bsps/riscv/riscv/optsifiveuart.yml
@@ -9,6 +9,7 @@ default:
 - enabled-by:
   - riscv/kendrytek210
   - riscv/frdme310arty
+  - riscv/sifiveu
   value: true
 - enabled-by: true
   value: false
diff --git a/spec/build/cpukit/optsmp.yml b/spec/build/cpukit/optsmp.yml
index 28b9bd4cd8..84a018ccc2 100644
--- a/spec/build/cpukit/optsmp.yml
+++ b/spec/build/cpukit/optsmp.yml
@@ -50,6 +50,7 @@ enabled-by:
 - riscv/rv64imafdc_medany
 - riscv/rv64imafd_medany
 - riscv/kendrytek210
+- riscv/sifiveu
 - sparc/erc32
 - sparc/gr712rc
 - sparc/gr740

After getting the sources, you'll need to build the BSP as follows:

# Make sure toolchains are in your PATH
command -v riscv-rtems6-gcc && echo "found" || echo "not found"
echo "[riscv/sifiveu]" > config.ini 
echo "RTEMS_SMP = True" >> config.ini
./waf configure && ./waf clean && ./waf

Running the BSP

After compiling the BSP, Now it's time to run the BSP.

# Make sure toolchains are in your PATH
command -v qemu-system-riscv64 && echo "found" || echo "not found"
cd rtems
cd build/riscv/sifiveu/testsuites/samples
qemu-system-riscv64 -serial stdio -m 2G -smp 2 -no-reboot -net none -machine sifive_u -bios none -kernel hello.exe

That's It. You'll Be greeted with Hello from RTEMS.

NOTE: The QEMU from the RSB is the recommended method of running the BSP

Some Caveats

The flag RTEMS_SMP = True must be placed in the config.ini file otherwise when running the BSP will result in some weird errors. You can try it out on your own if you would like.