目次: Zephyr
Zephyr RTOSのインストール、ビルドの手順が少し変わったので改めて紹介したいと思います。
基本的にはZephyrのGetting Startedに記載の通りですが、実行する上での補足や引っかかるところを説明したいと思います。
以降、作業するディレクトリは~/workとします。
ZephyrのGetting Startedを順に実行します。既存のPython環境を壊さないようにInstall within virtual environmentの手順を使うことをお勧めします。
# apt-get install git cmake ninja-build gperf \ ccache dfu-util device-tree-compiler wget \ python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 # apt-get install python3-venv $ cd ~/work/zephyr-sdk-0.16.4/ $ python3 -m venv _venv $ source ~/work/zephyr-sdk-0.16.4/_venv/bin/activate
Python venvを有効にするとシェルのプロンプトの頭に(_venv)のような環境名が付くようになります。venv用のディレクトリはどこに作成しても良いです。私はZephyr SDKの下に作ることが多いです。作成済みのvenvを再度使うときはsource ~/work/zephyr-sdk-0.16.4/_venv/bin/activateを実行します。
続きを実行しましょう。westを使ってZephyrと周辺ツール群をダウンロードします。
$ pip install west $ cd ~/work $ west init zephyr === Initializing in /home/katsuhiro/work/zephyr --- Cloning manifest repository from https://github.com/zephyrproject-rtos/zephyr Cloning into '/home/katsuhiro/work/zephyr/.west/manifest-tmp'... remote: Enumerating objects: 968377, done. remote: Counting objects: 100% (17/17), done. remote: Compressing objects: 100% (13/13), done. remote: Total 968377 (delta 8), reused 8 (delta 4), pack-reused 968360 Receiving objects: 100% (968377/968377), 600.07 MiB | 20.80 MiB/s, done. Resolving deltas: 100% (733897/733897), done. Updating files: 100% (31355/31355), done. --- setting manifest.path to zephyr === Initialized. Now run "west update" inside /home/katsuhiro/work/zephyr. $ cd ~/work/zephyr $ west update (大量にリポジトリがクローンされますのでしばし待ちます) $ west zephyr-export Zephyr (/home/katsuhiro/work/zephyr/zephyr/share/zephyr-package/cmake) has been added to the user package registry in: ~/.cmake/packages/Zephyr ZephyrUnittest (/home/katsuhiro/work/zephyr/zephyr/share/zephyrunittest-package/cmake) has been added to the user package registry in: ~/.cmake/packages/ZephyrUnittest $ pip install -r ~/work/zephyr/zephyr/scripts/requirements.txt (大量にモジュールがインストールされますのでしばし待ちます)
基本的にはコマンドを実行して待つだけです。たぶん。
SDKをインストールします。アーカイブはGitHubのreleaseページから取得できます。特にこだわりがなければ、現状の最新版である0.16.4を使ってください。
アーカイブがたくさんあって迷うと思いますが、今回はサイズが小さくてインストールするツールチェーンを選択できるzephyr-sdk-0.16.4_linux-x86_64_minimal.tar.xzを使います。
$ wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.4/zephyr-sdk-0.16.4_linux-x86_64_minimal.tar.xz $ tar xf zephyr-sdk-0.16.4_linux-x86_64_minimal.tar.xz $ cd ~/work/zephyr-sdk-0.16.4/ $ ./setup.sh -c -t riscv64-zephyr-elf Zephyr SDK 0.16.4 Setup Installing 'riscv64-zephyr-elf' toolchain ... toolchain_linux-x86 100%[===================>] 105.07M 24.7MB/s 時間 4.3s All done.
何も引数を付けずにすべてインストールしても良いです(が、結構時間が掛かります)。今回はRISC-V向けのツールチェーンがあれば良いので-t riscv64-zephyr-elfを付けることで時間短縮しました。注意点としては-cオプションを忘れないようにしてください。Zephyrビルド時にエラーが発生します。
次にhosttoolsをインストールします。要らない場合もありますが、今回はQEMUを使って動作確認したいのでインストールしましょう。
$ ./zephyr-sdk-x86_64-hosttools-standalone-0.9.sh Zephyr Yocto Toolchain SDK installer version 0.9 ================================================ Enter target directory for SDK (default: /opt/zephyr-sdk/0.9): /home/katsuhiro/work/zephyr-sdk-0.16.4/host You are about to install the SDK to "/home/katsuhiro/work/zephyr-sdk-0.16.4/host". Proceed [Y/n]? y Extracting SDK..................done Setting it up...done SDK has been successfully set up and is ready to be used. Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g. $ . /home/katsuhiro/work/zephyr-sdk-0.16.4/host/environment-setup-x86_64-pokysdk-linux
上記の作業を全て終えた後のディレクトリ構造はこんな感じです。
$ tree -L 2 ~/work /home/katsuhiro/work |-- zephyr | |-- bootloader | |-- modules | |-- tools | `-- zephyr ★Zephyr RTOSのコード |-- zephyr-sdk-0.16.4 | |-- _venv | |-- cmake | |-- host ★hosttools | |-- riscv64-zephyr-elf ★RISC-V用ツールチェーン | |-- sdk_toolchains | |-- sdk_version | |-- setup.sh | `-- zephyr-sdk-x86_64-hosttools-standalone-0.9.sh `-- zephyr-sdk-0.16.4_linux-x86_64_minimal.tar.xz
Zephyr開発環境はセットアップ手順は短くなったとは思うんですけど、中身は複雑になってトラブルが起きたときの解決が困難になった印象です。昔より依存するツールが増えているのかな……?
使用したいツールに応じて環境を有効化すると良いです。
#### Python venv環境を有効化 $ source ~/work/zephyr-sdk-0.16.4/_venv/bin/activate #### QEMUなどhosttoolsを使う場合、hosttoolsを有効化 $ source ~/work/zephyr-sdk-0.16.4/host/environment-setup-x86_64-pokysdk-linux #### デバッガなどを直接実行するならばツールチェーンにパスを通す $ export PATH=~/work/zephyr-sdk-0.16.4/riscv64-zephyr-elf/bin:$PATH
私はいちいち選ぶのが面倒なので、全部有効にしております。
Zephyr開発環境が正常にセットアップできたかどうか確かめるため、QEMU向けにビルドしましょう。
$ cd ~/work/zephyr/zephyr $ west build -p always -b qemu_riscv64 samples/hello_world/ (ログは省略)
ビルドできたので実行したいところですが、なぜかwestを使ってQEMUで実行する方法が見当たりません。仕方ないのでcmakeでビルド&実行します。こちらのやり方も覚えておいて損はないでしょう……。
$ cd ~/work/zephyr/zephyr $ rm -r build $ cmake -B build -G Ninja -DBOARD=qemu_riscv64 samples/hello_world Loading Zephyr default modules (Zephyr repository). -- Application: /home/katsuhiro/work/zephyr/zephyr/samples/hello_world -- CMake version: 3.22.1 -- Found Python3: /home/katsuhiro/work/zephyr-sdk-0.16.4/_venv/bin/python (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter -- Cache files will be written to: /home/katsuhiro/.cache/zephyr -- Zephyr version: 3.5.99 (/home/katsuhiro/work/zephyr/zephyr) -- Found west (found suitable version "1.2.0", minimum required is "0.14.0") -- Board: qemu_riscv64 -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK -- Found host-tools: zephyr 0.16.4 (/home/katsuhiro/work/zephyr-sdk-0.16.4) -- Found toolchain: zephyr 0.16.4 (/home/katsuhiro/work/zephyr-sdk-0.16.4) -- Found Dtc: /home/katsuhiro/work/zephyr-sdk-0.16.4/host/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") -- Found BOARD.dts: /home/katsuhiro/work/zephyr/zephyr/boards/riscv/qemu_riscv64/qemu_riscv64.dts -- Generated zephyr.dts: /home/katsuhiro/work/zephyr/zephyr/build/zephyr/zephyr.dts -- Generated devicetree_generated.h: /home/katsuhiro/work/zephyr/zephyr/build/zephyr/include/generated/devicetree_generated.h -- Including generated dts.cmake file: /home/katsuhiro/work/zephyr/zephyr/build/zephyr/dts.cmake Parsing /home/katsuhiro/work/zephyr/zephyr/Kconfig Loaded configuration '/home/katsuhiro/work/zephyr/zephyr/boards/riscv/qemu_riscv64/qemu_riscv64_defconfig' Merged configuration '/home/katsuhiro/work/zephyr/zephyr/samples/hello_world/prj.conf' Configuration saved to '/home/katsuhiro/work/zephyr/zephyr/build/zephyr/.config' Kconfig header saved to '/home/katsuhiro/work/zephyr/zephyr/build/zephyr/include/generated/autoconf.h' -- Found GnuLd: /home/katsuhiro/work/zephyr-sdk-0.16.4/riscv64-zephyr-elf/bin/../lib/gcc/riscv64-zephyr-elf/12.2.0/../../../../riscv64-zephyr-elf/bin/ld.bfd (found version "2.38") -- The C compiler identification is GNU 12.2.0 -- The CXX compiler identification is GNU 12.2.0 -- The ASM compiler identification is GNU -- Found assembler: /home/katsuhiro/work/zephyr-sdk-0.16.4/riscv64-zephyr-elf/bin/riscv64-zephyr-elf-gcc -- Using ccache: /usr/bin/ccache -- Configuring done -- Generating done -- Build files have been written to: /home/katsuhiro/work/zephyr/zephyr/build $ ninja -C build ninja: Entering directory `build' [1/99] Preparing syscall dependency handling [2/99] Generating include/generated/version.h -- Zephyr version: 3.5.99 (/home/katsuhiro/work/zephyr/zephyr), build: zephyr-v3.5.0-3603-g603c3af895b0 [98/99] Linking C executable zephyr/zephyr.elf Memory region Used Size Region Size %age Used RAM: 36140 B 256 MB 0.01% IDT_LIST: 0 GB 2 KB 0.00% Generating files from /home/katsuhiro/work/zephyr/zephyr/build/zephyr/zephyr.elf for board: qemu_riscv64 [99/99] cd /home/katsuhiro/work/zephyr.../zephyr/zephyr/build/zephyr/zephyr.elf $ ninja -C build run ninja: Entering directory `build' [0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: riscv64 *** Booting Zephyr OS build zephyr-v3.5.0-3603-g603c3af895b0 *** Hello World! qemu_riscv64
実行できました。もしエラーが出る場合は次のトラブルシューティングもご参照ください。
Zephyr SDKセットアップ時に-cオプションを付けない = Zephyr SDK cmake packageのインストールを忘れていると、Zephyrのビルド時に長々とエラーが出て怒られます。
CMake Error at /home/katsuhiro/work/zephyr/zephyr/cmake/modules/FindZephyr-sdk.c make:109 (find_package): Could not find a package configuration file provided by "Zephyr-sdk" (requested version 0.16) with any of the following names: Zephyr-sdkConfig.cmake zephyr-sdk-config.cmake Add the installation prefix of "Zephyr-sdk" to CMAKE_PREFIX_PATH or set "Zephyr-sdk_DIR" to a directory containing one of the above files. If "Zephyr-sdk" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): /home/katsuhiro/work/zephyr/zephyr/cmake/modules/FindHostTools.cmake:53 (find_package) /home/katsuhiro/work/zephyr/zephyr/cmake/modules/dts.cmake:9 (find_package) /home/katsuhiro/work/zephyr/zephyr/cmake/modules/zephyr_default.cmake:129 (include) /home/katsuhiro/work/zephyr/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include) /home/katsuhiro/work/zephyr/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) CMakeLists.txt:5 (find_package)
Zephyr SDKのセットアップは2回実行しても問題ないので-cオプションを付けてやり直しましょう。
< | 2023 | > | ||||
<< | < | 12 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |
合計:
本日:
管理者: Katsuhiro Suzuki(katsuhiro( a t )katsuster.net)
This is Simple Diary 1.0
Copyright(C) Katsuhiro Suzuki 2006-2023.
Powered by PHP 8.2.20.
using GD bundled (2.1.0 compatible)(png support.)