Zephyr OSを使ってみた
Zephyr OSというリアルタイムOSを使うことになったので、その環境構築時の手順のメモ。
$ wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.10.1/zephyr-sdk-0.10.1-setup.run $ ./zephyr-sdk-0.10.1-setup.run -- -d ~/zephyr-sdk-0.10.1
環境変数に設定しておくために、.bashrcに以下の設定を記入しておく。
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr export ZEPHYR_SDK_INSTALL_DIR=${HOME}/zephyr-sdk-0.10.1
$ pip3 install --user west $ west init zephyrproject $ cd zephyrproject $ west update $ sudo pip3 install --user -r zephyr/scripts/requirements.txt
ビルドを行う。
$ cd zephyr $ source zephyr-env.sh $ west build -b litex_vexriscv samples/subsys/shell/shell_module -- west build: build configuration: source directory: /mnt/src/zephyrproject/zephyr/samples/subsys/shell/shell_module build directory: /mnt/src/zephyrproject/zephyr/build (created) BOARD: litex_vexriscv (origin: command line) -- west build: generating a build system Zephyr version: 1.14.99 -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.6.8", minimum required is "3.4") -- Selected BOARD litex_vexriscv -- Found west: /home/tsunekoh/.local/bin/west (found suitable version "0.5.7", minimum required is "0.5.6") -- Loading /mnt/src/zephyrproject/zephyr/boards/riscv32/litex_vexriscv/litex_vexriscv.dts as base -- Overlaying /mnt/src/zephyrproject/zephyr/dts/common/common.dts Parsing Kconfig tree in /mnt/src/zephyrproject/zephyr/samples/subsys/shell/shell_module/Kconfig Loaded configuration '/mnt/src/zephyrproject/zephyr/boards/riscv32/litex_vexriscv/litex_vexriscv_defconfig' Merged configuration '/mnt/src/zephyrproject/zephyr/samples/subsys/shell/shell_module/prj.conf' Configuration saved to '/mnt/src/zephyrproject/zephyr/build/zephyr/.config' -- Cache files will be written to: /home/tsunekoh/.cache/zephyr -- The C compiler identification is GNU 8.3.0 -- The CXX compiler identification is GNU 8.3.0 -- The ASM compiler identification is GNU -- Found assembler: /mnt/src/zephyr-sdk/riscv32-zephyr-elf/bin/riscv32-zephyr-elf-gcc -- Performing Test toolchain_is_ok -- Performing Test toolchain_is_ok - Success Including module: esp-idf in path: /mnt/src/zephyrproject/modules/hal/esp-idf/zephyr Including module: fatfs in path: /mnt/src/zephyrproject/modules/fs/fatfs Including module: qmsi in path: /mnt/src/zephyrproject/modules/hal/qmsi Including module: cypress in path: /mnt/src/zephyrproject/modules/hal/cypress Including module: silabs in path: /mnt/src/zephyrproject/modules/hal/silabs Including module: st in path: /mnt/src/zephyrproject/modules/hal/st Including module: stm32 in path: /mnt/src/zephyrproject/modules/hal/stm32 Including module: libmetal in path: /mnt/src/zephyrproject/modules/hal/libmetal Including module: lvgl in path: /mnt/src/zephyrproject/modules/lib/gui/lvgl Including module: mbedtls in path: /mnt/src/zephyrproject/modules/crypto/mbedtls Including module: mcumgr in path: /mnt/src/zephyrproject/modules/lib/mcumgr Including module: nffs in path: /mnt/src/zephyrproject/modules/fs/nffs Including module: open-amp in path: /mnt/src/zephyrproject/modules/lib/open-amp Including module: segger in path: /mnt/src/zephyrproject/modules/debug/segger Including module: tinycbor in path: /mnt/src/zephyrproject/modules/lib/tinycbor -- Configuring done -- Generating done -- Build files have been written to: /mnt/src/zephyrproject/zephyr/build -- west build: building application [1/114] Preparing syscall dependency handling [109/114] Linking C executable zephyr/zephyr_prebuilt.elf Memory region Used Size Region Size %age Used RAM: 69936 B 256 MB 0.03% IDT_LIST: 41 B 2 KB 2.00% [114/114] Linking C executable zephyr/zephyr.elf
ここで、dtcのコンパイラのバージョンが古く、cmakeに失敗する場合がある。その場合には、新規にdtcを入れ直す。ソースコードを落としてきて、dtcをビルドし /usr/local/bin
あたりに配置すれば良い。 dtcのソースコードはここからダウンロードできる。
新しいバージョンのdtcを入れたにもかかわらずビルドに失敗する場合には、zephyr sdkのdtcを参照しにいっている可能性がある。その場合には、zephyr sdkのdtcの名前を適当に変更すれば良い。
Renodeでシミュレーション
実際に起動するのかを確かめたいのだが、残念ながら実機環境を持っていない。仕方ないので、Renodeでシミュレーションできるかどうかを確かめてみる。
Renodeからリリースビルドを落としてきて、プラットフォームごとに用意されたインストーラーを起動すればインストール自体は問題なくできるはず。
ターミナルを開き、renodeを起動する。
$ cd /mnt/src/zephyrproject/zephyr/build # <-- 先程のzephyrのビルドされたものがディレクトリに移動 $ renode
ターミナルが開くので、先程のビルド時に指定したボード名を指定し、ELFをロードしシミュレーションをスタートする。
(monitor) mach create "litex-vexriscv" (litex-vexriscv) machine LoadPlatformDescription @platforms/cpus/litex_vexriscv.rep l (litex-vexriscv) sysbus LoadELF @zephyr.elf (litex-vexriscv) showAnalyzer sysbus.uart (litex-vexriscv) start Starting emulation... (litex-vexriscv)
terminalが開き、kernel version
とか叩くとzephyrのバージョンを表示することができる。
今回、RISC-V Getting Started Guildeを大いに参考にした。