Create RTEMS on BeagleV Fire authored by Pavel Pisa's avatar Pavel Pisa
This page collect information for RTEMS compilation/build for [BeagleV-Fire](https://www.beagleboard.org/boards/beaglev-fire) board.
There are several separate steps required to build RTEMS for BeagleV-Fire board.
# RTEMS dependencies
Before installation please check whether you have all dependencies install. These can be find on
following website:
https://docs.rtems.org/docs/main/user/hosts/posix.html
You can also use following command (after cloning `rtems-source-builder` and entering the directory) to check whether your host computer is set up correctly:
```
source-builder/sb-check
```
## Trivial File Transfer Protocol (TFTP) setup
Trivial File Transfer Protocol (TFTP) allows to boot an application to BeagleV-Fire board without need to flash RTEMS application to eMMC. Following steps are necessary to install TFTP on Debian based systems.
```
sudo ufw allow tftp
sudo apt install tftpd-hpa
sudo apt install tftp
sudo chown tftp:tftp /srv/tftp
sudo systemctl restart tftpd-hpa
```
Following configuration can be used for TFTP (available in `/etc/default/tftpd-hpa`):
```
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
```
Then you can create `beglev-fire/rtems` directory in `/srv/tftp` to which you will copy your application image and FPGA image. For more convenient access add `tftp` directory to user access.
```
sudo chown -R $USER:$USER /srv/tftp
```
# RTEMS build
## Project Download and Builder Setup
```
mkdir rtems-git
cd rtems-git
git clone https://gitlab.rtems.org/rtems/rtos/rtems.git
git clone https://gitlab.rtems.org/rtems/tools/rtems-source-builder.git rsb
git clone https://gitlab.rtems.org/rtems/pkg/rtems-libbsd.git
sudo mkdir /opt/rtems
sudo mkdir /opt/rtems/7
sudo chown -R $USER:$USER /opt/rtems/7
cd rsb/rtems
../source-builder/sb-set-builder \
--prefix=/opt/rtems/7 \
--log=rtems-riscv-build-log.txt \
--pkg-tar-files \
7/rtems-riscv.bset
```
Note that this build may take a lot of time even on good computers. RTEMS has to build all its dependencies (gcc, gdb, binutils etc). This step is done only once and everything is build into `/opt/rtems/7`. Therefore you can do this more times for different RTEMS version, placing each one into different directory in `opt`.
This build takes a lot of computer resources, therefore it might make it unusable for the time of the build.
## BSP build
This chapter describes BSP build for BeagleV-Fire board. However build for other boards/architectures is similar, you can use `./rtems-bsps` command to list all supported BSPs.
```
cd rtems-git/rtems
./waf bspdefaults --rtems-bsps=riscv/beaglevfire > config.ini
```
open config.ini and set
```
RTEMS_POSIX_API = True
RTEMS_SMP = True
```
Then execute:
```
./waf configure --prefix "/opt/rtems/7"
./waf
./waf install
```
## BSD-Lib build (networking stack) (Optional)
```
cd rtems-git/rtems-libbsd
git submodule init
git submodule update rtems_waf
./waf configure --prefix="/opt/rtems/7" --rtems-bsps=riscv/beaglevfire --rtems-version=7 --buildset=buildset/default.ini
./waf
./waf install
```
Again these builds have to be done only once.
# Application Build and Boot
This section describes application build with OMK. All build operations are done in application root directory.
```
git clone https://gitlab.fel.cvut.cz/otrees/rtems/rtems-zynq-template.git
cd rtems-zynq-template
export PATH=$PATH:/opt/rtems/7/bin
make
cp _compiled/xilinx_zynq_zedboard/bin/zynq-template.img /srv/tftp/zynq/rtems
```
You might need to install `u-boot-tools` package to build the template application.
## BeagleV-Fire Internal eMMC Boot
The BeagleV-Fire boots applications from eMMC soldered on the board. The actual boot process starts by starting Microchip's HSS (Hart Software Services) loaded from eNVM. The HSS software can establish OpenSBI environment and start HSS payload from eMMC on specified RV64 cores (the HARTs u54_1, u54_2, u54_3 and u54_4 are complete RV64GC cores then there is one management RV63IMAC core). The payload is started in specified mode, for the Linux kernel or U-boot typically in M-mode.
But RTEMS expect full control over the chip so it requires to start in M-mode (machine mode).
The [hss-payload-generator](https://github.com/polarfire-soc/hart-software-services/tree/master/tools/hss-payload-generator) is required to prepare payload for HSS service. It can be compiled from referenced sources even without need of whole [Libero](https://www.microchip.com/en-us/products/fpgas-and-plds/fpga-and-soc-design-tools/fpga) package.
The minimal HSS build configuration for RTEMS stored in `rtems-config.yaml` file
```
# First, we can optionally set a name for our image, otherwise one will be created dynamically
set-name: 'PolarFire-SoC-HSS::RTEMSImage'
# Next, we'll define the entry point addresses for each hart, as follows:
hart-entry-points: {u54_1: '0x1000000000', u54_2: '0x1000000000', u54_3: '0x1000000000', u54_4: '0x1000000000'}
# Finally, we'll define some payloads (source ELF files) that will be placed at certain regions in memory
payloads:
rtems-app.elf: {exec-addr: '0x1000000000', owner-hart: u54_1, secondary-hart: u54_2, secondary-hart: u54_3, secondary-hart: u54_4, priv-mode: prv_m, skip-opensbi: true, payload-name: "rtems-app"}
```
Then RTEMS linked application/example (hello.exe or appfoo.exe) can be copied to some file, in the example `rtems-app.elf`.
Then payload generator is invoked
```
hss-payload-generator -c rtems-config.yaml rtems-payload.bin
```
It is time to reset the BeagleV-Fire board now and break the first stage to HSS payload boot process. Wait for
```
Press a key to enter CLI, ESC to skip
Timeout in 1 second
```
Send some character, press enter, over serial console and command the firmware to start USB mas storage load mode
```
usbdmsc
```
Then the new mass storage device is announced over USB connection
The HSS payload can be copied to the first primary partition by command
```
sudo dd if=rtems-payload.bin of=/dev/sdX1
```
WARNING: Be VERY CAREFULL there to chose correct device the mistake can lead to overwrite of your host system and make it unbootable.
## BeagleV-Fire TFTP Boot