LoginSignup
1
1

More than 1 year has passed since last update.

Chipyard でSoCを生成してみる

Last updated at Posted at 2021-02-15

Chipyardを使ってSoCを生成してみた際、いくつかハマる点があったのでメモっておきます。

Vivadoのインストール

参照 https://reference.digilentinc.com/vivado/installing-vivado/start

Digilentのガイドに従えば無事導入されるが、ホストがUbuntu 20.04だとライブラリがないとエラーになって動かない。その際は下記のおまじないを唱える。その後 コマンドラインで vivado と打って起動するなら準備 OK。

sudo ln -s /lib/x86_64-linux-gnu/libtinfo.so.6 /lib/x86_64-linux-gnu/libtinfo.so.5

Initial Repository Setup

参照 https://chipyard.readthedocs.io/en/latest/Chipyard-Basics/Initial-Repo-Setup.html

Chipyard実行に必要なパッケージを入れておく。下記のsetup.shファイルを作成して実行。curl autoconfを追加。Pythonは3.8に。

setup.sh
#!/bin/bash

set -ex

sudo apt-get install -y curl autoconf

sudo apt-get install -y build-essential bison flex
sudo apt-get install -y libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev vim git default-jdk default-jre
# install sbt: https://www.scala-sbt.org/release/docs/Installing-sbt-on-Linux.html
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
sudo apt-get update
sudo apt-get install -y sbt
sudo apt-get install -y texinfo gengetopt
sudo apt-get install -y libexpat1-dev libusb-dev libncurses5-dev cmake
# deps for poky
sudo apt-get install -y python3.8 patch diffstat texi2html texinfo subversion chrpath git wget
# deps for qemu
sudo apt-get install -y libgtk-3-dev gettext
# deps for firemarshal
sudo apt-get install -y python3-pip python3.8-dev rsync libguestfs-tools expat ctags
# install DTC
sudo apt-get install -y device-tree-compiler

# install verilator
git clone http://git.veripool.org/git/verilator
cd verilator
git checkout v4.034
autoconf && ./configure && make -j$(nproc) && sudo make install

実行する。

sudo bash setup.sh

verilatorのコンパイルで少々時間がかかる。次にchipyardをCloneする。

git clone https://github.com/ucb-bar/chipyard.git
cd chipyard
./scripts/init-submodules-no-riscv-tools.sh

ツールチェインをBuildする。何故か QEMUのCloneでコケたので,下記の例はQEMUなし。

export MAKEFLAGS=-j8
./scripts/build-toolchains.sh --ignore-qemu riscv-tools

45分ほどかかった。環境変数をセットして準備完了。

source ./env.sh

Software RTL Simulation

参考 https://chipyard.readthedocs.io/en/latest/Simulation/Software-RTL-Simulation.html#sw-rtl-sim-intro

Chipyardの例題のSoC(64Bitのシングルコア)を生成してSimulationしてみる。これはVerilatorを利用する場合。

cd sims/verilator
make

最初はSBTをDLするのでちょっと時間がかかる。以降は10分位でVerilog生成。Simulationを実行してみる。

$ ./simulator-chipyard-RocketConfig $RISCV/riscv64-unknown-elf/share/riscv-tests/isa/rv64ui-p-simple
This emulator compiled with JTAG Remote Bitbang client. To enable, use +jtag_rbb_enable=1.
Listening on port 40081
[UART] UART0 is here (stdin/stdout).

ひとまず。動いたらしい。できたコアがちゃんと動くかまとめてテストするには。

make run-asm-tests
make run-bmark-tests

PASSEDになればOK。 コードを新しくして実行する場合は

git pull
git submodule update --recursive

波形を見たいとき

make debug CONFIG=RocketConfig VERILATOR_FST_MODE=1
./simulator-chipyard-RocketConfig-debug --vcd=rv64ui-p-simple.fst --verbose $RISCV/riscv64-unknown-elf/share/riscv-tests/isa/rv64ui-p-simple 

生成された rv64ui-p-simple.fst ファイルをGtkWaveで開けばOK。

OSXで実行する場合

ここまではOSX (Mac)でも実行可能。いくつか方法があるがToolchainのBuildでハマると抜け出せないので、Docker Image を使うのが簡単。

sudo docker pull ucbbar/chipyard-image:1.5.0
sudo docker run -it ucbbar/chipyard-image bash

Chipyardのイメージが起動したら

cd chipyard
source env.sh
cd sims/verilator
make

で生成できる。

FPGAのBitファイルの作成

参照 https://chipyard.readthedocs.io/en/latest/Prototyping/General.html

なぜかFPGA用のデザインは fpgaの下にある。最初に必要なモジュールをCloneする。

./scripts/init-fpga.sh

つぎに、ARTY用のBitfileを生成してみる。Sifive Freedomに近い?

cd fpga
make SUB_PROJECT=arty bitstream

10分位で完了。 generated-src/chipyard.fpga.arty.ArtyFPGATestHarness.TinyRocketArtyConfig/obj/ArtyFPGATestHarness.bit が生成される。

VLSI

PD(物理設計)の実行には、必要ないくつかのレポのアクセスに承認が必要である。ひとまず Verilog RTL の生成までなら下記で実行できる。init-vlsi.shでエラーになるレポのアクセスをコメントアウトしておく。

./scripts/init-vlsi.sh
cd vlsi
make verilog

感想

UCBの一連のChiselな実装がChipyardの元にまとまっている。Toolchainを毎回 Build するのは苦痛なので、Dockerのイメージを利用するのも手かもしれない。おそらく設計はSIMからFPGAを経てVLSIとつながってゆくと思うが、今のChipyardでそのへんをどのように扱うべきなのかよくわからない。

EOF

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1