基本的にはRISC-Vのページに記載の手順でビルドしていくだけ。
とりあえず今回は、SCR1向けのビルド環境を立ち上げたいので、それ向けに構築していく
$ git clone https://github.com/riscv/riscv-tools.git $ cd riscv-tools $ git submodule update --init --recursive
SCR1はRV32I or RV32Eをベースに以下のオプションをつけることができる。
- M : 整数の乗除算
- C : 圧縮命令(16bit命令/ARMのthumb命令みたいなの)
このriscv-toolsリポジトリは、ソフト開発に必要な各種RISV-Vのツールをひとまとめにしたリポジトリになっており、サブモジュールをcloneした後に、build.shを実行すると
- riscv-openocd : OpenOCD をRISC-V向けにforkしたもの
- riscv-fesvr : front-end server
- riscv-isa-sim : ISAシミュレータ
- riscv-gnu-toolchain : GNUのコンパイラツール
- riscv-pk : proxy kernel
- riscv-tests : RISC-VのISAのテスト一式
がビルドされる(エラーがなければ)
$ git submodule update --init --recursive $ export RISCV=/path/to/install/riscv/toolchain $ export PATH=$PATH:$RISCV/bin
関連パッケージをインストール
$ sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev
RISC-Vのページの手順に従うと、上記設定の後に build.sh
を実行することになるがこのファイルの中身は64bitCPU向けの物になっているので代わりにbuild-rv32ima.sh
を実行する
$ build-rv32ima.sh
と、エラー発生。。。
/bin/sh: 1: test: false: unexpected operator *** This configuration is not supported in the following subdirectories: zlib target-libquadmath target-libatomic target-libcilkrts target-libitm target-libsanitizer target-libvtv target-libmpx gnattools gotools target-libada target-libhsail-rt target-libgfortran target-libbacktrace target-libgo target-libffi target-libobjc target-libgomp target-liboffloadmic target-libssp (Any other directories should still work fine.) libtool: install: warning: remember to run `libtool --finish /home/dnn-admin/workspace/hw/study/1001_riscv-tools/libexec/gcc/riscv32-unknown-elf/7.2.0' configure: error: *** LIBRARY_PATH shouldn't contain the current directory when *** building gcc. Please change the environment variable *** and run configure again. make[1]: *** [configure-gcc] エラー 1 make: *** [stamps/build-gcc-newlib-stage1] エラー 2
最初、よく見ずにLD_LIBRARY_PATH
かと思ったので、現在のパスなんか設定してないし!!って思ったらLIBRARY_PATH
だったのね。。
エラーメッセージで検索してみると、以下が見つかった。
この記事の最後の方の回答に以下のものがあった。
philippbayer commented on 9 Jun 2017
A year later and a blog post reminded me of this issue - https://joshumax.github.io/general/2017/06/08/how-torch-broke-ls.html
It turns out that an empty entry in LD_LIBRARY_PATH is converted into the current directory. Good to know!
It turns out that an empty entry in LD_LIBRARY_PATH is converted into the current directory. Good to know!
ですって!!
これはLD_LIBRARY_PATH
の話だが、まさか、、、と思いLIBRARY_PATH
に適当な値を設定して再度ビルド。
$ export LIBRARY_PATH=~/. $ build-rv32ima.sh
Installing project riscv-openocd Makefile:4431: 警告: ターゲット 'check-recursive' のためのレシピを置き換えます Makefile:3842: 警告: ターゲット 'check-recursive' のための古いレシピは無視されます Makefile:4431: 警告: ターゲット 'check-recursive' のためのレシピを置き換えます Makefile:3842: 警告: ターゲット 'check-recursive' のための古いレシピは無視されます Makefile:4431: 警告: ターゲット 'check-recursive' のためのレシピを置き換えます Makefile:3842: 警告: ターゲット 'check-recursive' のための古いレシピは無視されます Makefile:4431: 警告: ターゲット 'check-recursive' のためのレシピを置き換えます Makefile:3842: 警告: ターゲット 'check-recursive' のための古いレシピは無視されます Makefile:4431: 警告: ターゲット 'check-recursive' のためのレシピを置き換えます Makefile:3842: 警告: ターゲット 'check-recursive' のための古いレシピは無視されます RISC-V Toolchain installation completed!
通った!!! ビルドしたツールを使用して、動作確認をしてみる
$ echo -e '#include <stdio.h>\n int main(void) { printf("Hello world!\\n"); return 0; }' > hello.c $ riscv32-unknown-elf-gcc -o hello hello.c $ spike pk hello Hello World!!
無事Hello World!
が表示されて、動作確認も完了。
ビルドしたツールを使って生成したバイナリを使ってSCR1のシミュレーションを実行していく