This page contains useful commands and tips on how to develop on the Mocha repository. It collects both design, software and verification instructions.
Firstly download all the artefacts from a particular release. Then follow the following steps to test on FPGA:
- Install dependencies:
- OpenFPGALoader, for example:
apt install openfpgaloader - Screen, for example:
apt install screen
- OpenFPGALoader, for example:
- Connect your Genesys 2 board with the POWER, UART and JTAG. Make sure to turn on the board using SW8.
- Configure udev rules (you might need admin rights for these):
cp 99-openfpgaloader.rules /etc/udev/rules.d/99-openfpgaloader.rules udevadm control --reload-rules udevadm trigger usermod -a -G plugdev $USER - Program the downloaded bitstream:
openFPGALoader -b genesys2 lowrisc_mocha_chip_mocha_genesys2_0.bit
- Look at UART output:
You should press the RESET button on the Genesys 2 board (BTN1) to see bootloader message "Boot ROM!". To exit screen press
screen $(ls /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_*-port0) 1000000ctrl-athenkand confirm withy.
In simulation you can do the following:
- Extract the example software:
tar -xzvf examples.tar.gz
- Make the simulator executable and run the "hello world" by running the following command:
chmod +x Vtop_chip_verilator ./Vtop_chip_verilator -E release/hello_world_verilator
- Check the UART output:
Which should contain content including "Hello CHERI Mocha!"
cat uart0.log
Programming new software over SPI is also possible using the boot ROM. Here are the steps to run the hello world example:
- Open up a screen terminal in parallel:
screen $(ls /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_*-port0) 1000000 - In another terminal program the SPI. Note you must run this command twice, and it is expected that the second run reports "Fail":
In the terminal where you opened screen you should see the following output:
openFPGALoader --spi --offset 0x4000 --write-flash release/hello_world.bin openFPGALoader --spi --offset 0x4000 --write-flash release/hello_world.bin
Boot ROM! First reset Jumping to: 0x%0x Hello CHERI Mocha! timer 100us timer 100us timer 100us timer 100us
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create the virtual environment.
uv venv
uv sync --all-extras
# Enter the environment (do it every time).
source .venv/bin/activatenix developAlternatively if you are using direnv then this can be automated by enabling direnv.
direnv allow .When entering the directory from then on you will automatically enter the dev shell. Changing directory outside the repository root will deactivate the dev shell for you.
Software binaries are built using CMake.
# Setup the buildsystem.
cmake -B build/sw -S sw
# Build the software.
cmake --build build/sw -j $(nproc)For software written in C, clang-format and clang-tidy are used format and lint the code. Wrapper scripts to run these on all C files in the project are provided for convenience.
To format and lint, run:
# Format all C files.
util/clang_format.py
# Lint all C files.
util/clang_tidy.pyWe use Verilator to simulate our hardware design and use FuseSoC as a build system:
# Build simulator.
fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:mocha:top_chip_verilator
# Run simulator.
build/lowrisc_mocha_top_chip_verilator_0/sim-verilator/Vtop_chip_verilator -E build/sw/device/examples/hello_world_verilatorOne specific feature of our simulator is that you can exit the simulation by using the following magic string:
Safe to exit simulator.\xd8\xaf\xfb\xa0\xc7\xe1\xa9\xd7
To run the verilator tests, first build the software, then run:
ctest --test-dir build/sw -R sim_verilatorOne way to program your FPGA is to use openFPGALoader.
In Linux you must allow openFPGALoader to access your USB device.
First copy the example rules file in this repository and execute some commands for the rules to take effect (you may need admin rights for the udevadm and usermod commands):
cp util/99-openfpgaloader.rules /etc/udev/rules.d/99-openfpgaloader.rules
udevadm control --reload-rules
udevadm trigger
usermod -a -G plugdev $USERMake sure that Vivado is on your path, then run:
fusesoc --cores-root=. run --target=synth --setup --build lowrisc:mocha:chip_mocha_genesys2 --BootRomInitFile=$PWD/build/sw/device/examples/hello_world.vmemConnect to the "UART" and "JTAG" USB ports on the Genesys2 board.
Open a UART terminal with 1Mbps baud rate:
screen /dev/ttyUSB0 1000000You may have to change the ttyUSB number.
Then load the bitstream onto Genesys 2:
openFPGALoader -b genesys2 build/lowrisc_mocha_chip_mocha_genesys2_0/synth-vivado/lowrisc_mocha_chip_mocha_genesys2_0.bitTo run block-level verification you can use the following command:
dvsim hw/vendor/lowrisc_ip/ip/uart/dv/uart_sim_cfg.hjson -i uart_smoke -r 1 --tool xceliumTo run block-level formal verification you can use the following command:
dvsim hw/top_chip/formal/top_chip_fpv_ip_cfgs.hjson --select-cfgs rv_plic_fpvTo run top-level verification you can use the following command:
dvsim hw/top_chip/dv/mocha_sim_cfgs.hjson --tool xceliumThis project is licensed under the Apache License, Version 2.0.
This license, as well as the licenses of all vendored sub-projects, can be found in the LICENSES sub-directory.
All code files must start with the following header (in the comment style applicable for the language):
// Copyright lowRISC contributors (COSMIC project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0For files that are generated by code or otherwise cannot have comments added to them (e.g images, lock files, markdown),
this information should be specified in the top-level REUSE.toml, but this should be used sparingly.
The hw/vendor directory contains its own REUSE.toml for vendored sub-projects.
To check that all files contain copyright and licensing information, run:
reuse lint