0 installation guide
Cloned repo: https://github.com/vyomasystems-lab/riscv_setup
Table of Contents
How Dependencies Were Identified
Examining the Makefile
Looking at the tool definitions revealed:
GCC := riscv64-unknown-elf-gcc # cross-compiler for RISC-V
OBJDUMP := riscv64-unknown-elf-objdump # for generating disassembly
SPIKE := spike # the ISA simulator
Attempting a Dry Run
The error messages made it pretty clear what was missing.
Searching for Packages
apt search riscv | grep gcc
# Found: gcc-riscv64-unknown-elf in Ubuntu repositories
apt search spike
# Not found - needs to be built from source
# Spike's GitHub README lists build dependencies:
# - device-tree-compiler
# - libboost-regex-dev
# - libboost-system-dev
Prerequisites
My System specs: Ubuntu 24.04.3 LTS, 512GB disk space, 8GB memory
# Check if basic tools are already installed
make --version # for build automation
git --version # for cloning repositories
# Install them if they're missing
sudo apt update
sudo apt install -y build-essential git # C/C++ compiler, make, git
Installation Steps
Step 1: RISC-V GNU Toolchain
This package provides several tools:
- riscv64-unknown-elf-gcc
- C/C++ compiler targeting RISC-V bare-metal
- riscv64-unknown-elf-as
- RISC-V assembler
- riscv64-unknown-elf-ld
- linker for RISC-V
- riscv64-unknown-elf-objdump
- converts binaries to readable assembly
- riscv64-unknown-elf-objcopy
- for converting object file formats
Check that everything installed correctly:
You should see the path /usr/bin/riscv64-unknown-elf-gcc
and version 13.x.x or higher.
Step 2: Spike Build Dependencies
These are needed to compile Spike from source:
- device-tree-compiler
- handles hardware configuration descriptions
- libboost-regex-dev
- parses ISA strings like "rv64imafdczicsr_zifencei"
- libboost-system-dev
- provides system operations and error handling
Verify the installation:
Step 3: Building Spike from Source
Spike isn't available in Ubuntu's package repositories, so it needs to be compiled manually.
# Get the source code
cd /tmp
git clone https://github.com/riscv-software-src/riscv-isa-sim.git
cd riscv-isa-sim
# Set up the build
mkdir build && cd build
../configure --prefix=/usr/local # where to install
make -j$(nproc) # compile using all available cores
# Install system-wide
sudo make install
sudo ldconfig # update the library cache
This installs several useful tools:
- /usr/local/bin/spike
- the main RISC-V ISA simulator
- /usr/local/bin/spike-dasm
- disassembler utility
- /usr/local/bin/elf2hex
- converts ELF files to hex format
- /usr/local/lib/libriscv.so
- simulation library
Confirm everything is working:
Verification
Running a Complete Test
If everything is set up properly, you'll see:
The compilation uses riscv64-unknown-elf-gcc
, disassembly uses riscv64-unknown-elf-objdump
, and execution happens in Spike.
Check what was generated:
ls work/add/
# add.elf - the compiled RISC-V binary
# add.disass - human-readable assembly
# add.dump - instruction-by-instruction execution trace
cat work/add/add.disass | less
head -50 work/add/add.dump
Troubleshooting
Commands Not Found
If a tool is installed but can't be found:
# Check if they actually exist
ls /usr/bin/riscv64-unknown-elf-gcc
ls /usr/local/bin/spike
# Add to PATH if needed
export PATH="/usr/local/bin:/usr/bin:$PATH"
echo 'export PATH="/usr/local/bin:/usr/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
TEST Parameter Missing
If make complains that TEST isn't set:
Summary
The following tools should now be available:
Tool | Purpose | Location |
---|---|---|
riscv64-unknown-elf-gcc |
RISC-V C/C++ compiler | /usr/bin/ |
riscv64-unknown-elf-objdump |
Disassembler | /usr/bin/ |
spike |
ISA simulator | /usr/local/bin/ |
elf2hex |
ELF to hex converter | /usr/local/bin/ |
Basic usage examples: