lowRISC的Ibex項目Hello World的仿真

lowRISC的Ibex項目Hello World的仿真

記錄一下Ibex在Linux上仿真Hello World的具體流程

參考

運行環境

本文采樣的運行環境是 Ubuntu18.04

安裝各種包

採樣下面的命令(以後可能會升級,什麼的。。。。。。)

sudo apt-get install autoconf bison build-essential clang-format curl \
    doxygen flex g++ git libelf1 libelf-dev libftdi1-2 libftdi1-dev libssl-dev \
    libusb-1.0-0 lsb-release make ninja-build pkgconf python3 python3-pip \
    python3-setuptools python3-wheel python3-yaml srecord tree xsltproc \
    zlib1g-dev xz-utils

git Ibex項目 並使用pip3安裝相關軟件包

mkdir  ibex
cd  ibex
git clone https://github.com/lowRISC/ibex

安裝相關python庫

pip3 install --user -r python-requirements.txt

安裝 RISC-V tool chain(這一步很慢。。。)

安裝的地方另起一個(不在ibex裏面)
最好使用sudo make
我之前使用 make出現了很多錯誤,因爲權限不夠。

安裝先決條件:一股腦裝就完事了,沒有裝就讓它裝,裝過了輸入此命令會提示裝過了。這波不虧,有點賺

sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev
git clone https://github.com/riscv/riscv-gnu-toolchain

./configure --prefix=/opt/riscv --with-arch=rv32imc --with-abi=ilp32
sudo make

添加安裝路徑到PATH(看了一個博客說一共有3種方法)
方法在這裏。。。
本人採用的是第3種中,因爲不想chmod

vi ~/.bash_profile

PATH=$PATH:~/.local/bin

source ~/.bash_profile

使用下面的命令驗證編譯工具是否安裝成功

which riscv32-unknown-elf-gcc

出現/opt/riscv/bin/riscv32-unknown-elf-gcc則說明成功了

安裝仿真軟件Verilator

什麼是Verilator?老哥點這裏
再次安裝相關依賴:(可能會重複安裝,系統會提醒,沒有關係的)

sudo apt-get install git make autoconf g++ flex bison

sudo apt-get install libfl2

sudo apt-get install libfl-dev

獲取安裝包

git clone https://git.veripool.org/git/verilator
unset VERILATOR_ROOT

安裝,衝!!

cd verilator

git pull

git tag

git checkout master

git checkout stable

git checkout v{version}

autoconf        # Create ./configure script

./configure

make

make test

sudo make install

安裝FuseSoc工具

FuseSoc的作用跟Makefile的功能相似,由於Ibex已配置成FuseSoc可用的狀態,所以不用白不用,白嫖就完事。

git clone https://github.com/olofk/fusesoc

cd fusesoc

sudo pip install -e .

這裏同樣也需要加路徑(FuseSoc的默認安裝路徑是~/.local/bin)

輸入which fusesoc驗證是否裝好

出現 .local/bin/fusesoc就說明ok了

開始跑Hello simple system

cd  ibex

## Building Simulation
fusesoc --cores-root=. run --target=sim --setup --build lowrisc:ibex:ibex_simple_system --RV32M=1 --RV32E=0

## Building hello world
make -C examples/sw/simple_system/hello_test

## Running the Simulator
./build/lowrisc_ibex_ibex_simple_system_0/sim-verilator/Vibex_simple_system [-t] --raminit=<sw_vmem_file>

這裏的<sw_vmem_file>是RISC-V的可執行文件路徑,使用./examples/sw/simple_system/hello_test/hello_test.vmem 對於編譯好的hello world,使用,編譯出來的可執行文件是Vibex_simple_system,–raminit=<sw_vmem_file>用於把編譯好的hello world RISC-V可執行代碼load到RAM裏去。-t是用來生成GTKWave可看的waveform,可以不用加。 大功告成,最後Ibex的輸出寫在ibex_simple_system.log裏,可以打開看看是否符合期望。由於Ibex帶了仿真的trace功能,指令trace信息還會存在trace_core_00000000.log。(這裏抄的別人的,覺得說得很好)

輸入上述命令的運行中間過程與結果
輸入上述命令的運行結果

仿真的C語言截圖
仿真的C語言截圖

運行的仿真結果,都把需要輸出的都打印了出來
運行的仿真結果,都把需要輸出的都打印了出來

trace_core的輸出:riscv CORE運行時的指令流、指令對應的機器碼,寄存器的操作以及對應的值
trace_core的輸出
okk!!!!!!大功告成

接下跑一下Google的開源安全芯片項目:OPentitan——就是我,點我!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章