Blog posts by @retrage

mirror of https://retrage.github.io/

HiFive1でZephyr

HiFive1とは,SiFiveによって開発されたRISC-V搭載のArduino互換ボードである. 一方,Zephyrは,Linux Foundationにより開発が進められている組み込み向けOSである. upstreamのZephyrはHiFive1に対応している. ここでは,ZephyrをHiFive1向けにビルドしてみる.

ホスト環境はx86_64で

Distributor ID:  Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:    16.04
Codename:   xenial

である.

RISC-V向けtoolchainのビルド

最初にRISC-V向けのtoolchainをビルドする.

基本的に以下のREADME通り.

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

ここでは$HOME/rv32以下にインストールすることとする. ターゲットのHiFive1は32-bit RV32IMACである.

$ ./configure --prefix=$HOME/rv32 --with-arch=rv32imac --with-abi=ilp32d
$ make linux

Zephyrの取得と環境構築

以下の通り,必要となるパッケージをインストールする.

$ git clone https://github.com/zephyrproject-rtos/zephyr.git
$ sudo apt install git cmake ninja-build gperf ccache doxygen dfu-util device-tree-compiler python3-ply python3-pip python3-setuptools python3-wheel xz-utils file make gcc-multilib autoconf automake libtool
$ cd zephyr
$ pip3 install --user -r scripts/requirements.txt

Applicationのビルド

以下の通り,環境変数を与える.

$ cd hello/build
$ export ZEPHYR_BASE=~/src/zephyr
$ export BOARD="hifive1"
$ export ZEPHYR_TOOLCHAIN_VARIANT=riscv32
$ export GCCRISCV32_TOOLCHAIN_PATH=~/rv32
$ cmake "Unix Makefies" ..
$ make

これで,ビルドされbuild/zephyr/zephyr.elfが生成される.