---
# System prepended metadata

title: IBEX Simulation **Ubuntu** Docker Environment Setup
tags: [CPU, IBEX-core, RISC-V, JJLAB-Research]

---

# IBEX Simulation **Ubuntu** Docker Environment Setup

###### tags: `JJLAB-Research` `IBEX-core` `RISC-V` `CPU`

I use the **ubuntu20.04** docker container on the ic59 work station of NTHU-CS as the workspace. But it seems that ubuntu cannot run VCS simulation. So in this part we can only use common simulation.

## Cloning Repositories We Need
First, clone the **ibex repository**.
```
mkdir ibex && cd ibex
git clone https://github.com/lowRISC/ibex
```

___
## Docker container setup

First, **create a Dockerfile**.
```
mkdir docker_env_ubuntu && cd docker_env_ubuntu
vim Dockerfile
```

And the **content of the Dockerfile** should be like this.
```
FROM ubuntu:20.04
MAINTAINER enoch

SHELL ["/bin/bash","-c"]

RUN yum update -y
RUN yum -y install vim
RUN yum -y install tcsh
RUN yum -y install wget

SHELL ["/bin/tcsh","-c"]

RUN apt-get -y install autoconf bison clang curl
RUN apt-get -y install doxygen flex git gcc g++ libelf-dev
RUN apt-get -y install make ninja-build
RUN apt-get -y install srecord tree
RUN apt-get install help2man

RUN apt-get install python3-pip
RUN pip3 install --upgrade pip
RUN pip3 install PyYAML
RUN pip3 install wheel
```
And then **build an image** by this Dockerfile.
```
docker build -t enoch/ubuntu . --no-cache
```

And then **create a container** with the image just built.
```
docker run -d --net=host --hostname ibex --name ibex_ubuntu -v /home/jjlab/IBEX_HOME/ibex:/ibex -v /home/jjlab/IBEX_HOME/shared:/shared -it ibex/ubuntu tcsh
```

After creating a container, **execute** it.
```
docker exec -it enoch_ubuntu tcsh
```
___
## Into the docker container

Clone the **verilator repository**.
```
cd /opt
git clone https://github.com/verilator/verilator
```

Install Verilator
```
unsetenv VERILATOR_ROOT
cd /opt/verilator
git pull         # Make sure git repository is up-to-date
git tag          # See what versions exist
#git checkout master      # Use development branch (e.g. recent bug fixes)
#git checkout stable      # Use most recent stable release
#git checkout v{version}  # Switch to specified release version (v5.006 is good)

autoconf         # Create ./configure script
./configure      # Configure and create Makefile
make -j `nproc`  # Build Verilator itself (if error, try just 'make')
make install
```
___
## Run Simulation

Building simulation binary
```
fusesoc --cores-root=. run --target=sim --setup --build lowrisc:ibex:ibex_simple_system --RV32M=1 --RV32E=0
```
*lowrisc:ibex:ibexsimplesystem* : the name of core


Building software
```
make -C examples/sw/simple_system/hello_test
```

Run Simulation
```
./build/lowrisc_ibex_ibex_simple_system_0/sim-verilator/Vibex_simple_system --raminit=./examples/sw/simple_system/hello_test/hello_test.vmem
```

 ## Export/Import docker image
 ```
 docker export enoch_ubuntu > ubuntu.tar
 
 cat ubuntu.tar | docker import - enoch/ubuntu
 
 ```
 ## Problems
 ![image](https://hackmd.io/_uploads/SJnNSuUR6.png)
 
 ### In the process of building simulation
 undefined reference to `mhpmcounter_num'
 collect2: error: ld returned 1 exit status
 
 ![image](https://hackmd.io/_uploads/SJmShG_0p.png)
 
 ![image](https://hackmd.io/_uploads/r1Mphzd0p.png)


