目次: Zephyr
海外で最近話題らしいZephyr OSを動かしてみました。
Linuxに似ている、という説明をどこかで見ましたが、ビルドシステムに関して言えば全く似ていません……。コードは似ているのかもしれませんが、見ていません。
動かし方は Zephyr OSのGetting Started にあります。
Zephyr OSをビルドするためには、いくつかPythonのパッケージをインストールする必要があります。pipを実行しても良いという方はpip3 install --user -r zephyr/scripts/requirements.txt で、依存するモジュールをインストールしてくれるそうです。
私は以前pipでPython環境が壊れて嫌な思いをしたので、apt-getで頑張りました。参考までに下記のパッケージをインストールしています。環境はDebian Testing amd64版です。
python3-colorama python3-yaml python3-pyelftools python3-sphinx-rtd-theme sphinx-rtd-theme-common python3-breathe ninja-build sphinx-common
パッケージが足りない場合の探し方ですけども、パッケージが足りないときはPythonのエラーメッセージにModuleNotFoundError: No module named 'aaaa' こんなメッセージが出ることが多いです。apt-file search aaaaを実行すると、パッケージ名がずらーっと出てきますので、その中からpython3- で始まるパッケージを探してください(Python3モジュールのパッケージはpython3-xxxxという名前が多い)。
Getting Startedの通り
git clone https://github.com/zephyrproject-rtos/zephyr
です。
Getting StartedにはZephyr SDKとやらをインストールせよと書いてありますが、色々大切な部分が全部ぶっ飛んでいてわからなくなっている感じがします。幸いcrosstool-NGにも対応していると書いてあったので、crosstool-NGを使ってみました。
基本的には以前紹介した(2018年7月15日の日記参照)、AArch64 Linux用の環境と同じ手順ですが、./ct-ng menuconfigで設定する項目が多少違います。
$ ./ct-ng menuconfig Target options ---> Target Architecture ---> armにする Bitness: ---> 32-bitにする Toolchain options ---> Tuple's vendor string zephyrにする Operating System ---> Target OS ---> bare-metalにする $ ./ct-ng build [00:34] /
しばらく待つとarm-zephyr-eabiというプレフィクスを持つクロスコンパイラが生成されるはずです。
Zephyr OSのビルドに使用するクロスコンパイラを、~/.zephyrrcに環境変数を定義して指定します。変な作りだなあ……。
export ZEPHYR_TOOLCHAIN_VARIANT=xtools
export XTOOLS_TOOLCHAIN_PATH=/home/katsuhiro/x-tools
注意点としてはXTOOLS_TOOLCHAIN_PATHのx-toolsの後のパスは勝手にarm-zephyr-eabiが使われ、自由に指定できないことです。この点についてはLinuxのCROSS_COMPILE環境変数とは異なるうえ、Zephyrの方が後発にも関わらず退化しています。どうしてこうなった……。
ビルドする前に2手ほど準備が必要です。1手目は環境変数のセットアップです。
cd zephyr source zephyr-env.sh
2手目はcmakeの実行です。
$ cd sample/hello_world $ mkdir build $ cd build $ cmake -GNinja -DBOARD=qemu_cortex_m3 ../ Zephyr version: 1.13.99 -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.7.2", minimum required is "3.4") -- Selected BOARD qemu_cortex_m3 Parsing Kconfig tree in /home/katsuhiro/share/projects/oss/zephyr/Kconfig Loading /home/katsuhiro/share/projects/oss/zephyr/boards/arm/qemu_cortex_m3/qemu_cortex_m3_defconfig as base Merging /home/katsuhiro/share/projects/oss/zephyr/samples/hello_world/prj.conf Configuration written to '/home/katsuhiro/share/projects/oss/zephyr/samples/hello_world/build/zephyr/.config' -- Loading /home/katsuhiro/share/projects/oss/zephyr/boards/arm/qemu_cortex_m3/qemu_cortex_m3.dts as base -- Overlaying /home/katsuhiro/share/projects/oss/zephyr/dts/common/common.dts -- Cache files will be written to: /home/katsuhiro/.cache/zephyr -- The C compiler identification is GNU 8.2.0 -- The CXX compiler identification is GNU 8.2.0 -- The ASM compiler identification is GNU -- Found assembler: /home/katsuhiro/x-tools/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -- Performing Test toolchain_is_ok -- Performing Test toolchain_is_ok - Success -- Configuring done -- Generating done -- Build files have been written to: /home/katsuhiro/share/projects/oss/zephyr/samples/hello_world/build
CMakeを採用しているプロジェクトは大抵、ソースコードのトップディレクトリにあるCMakeLists.txtを指定しますが、Zephyr OSの場合、sample/* の下にあるCMakeLists.txtを使わなければなりません。わからんわ、そんなの。変な作りだな……。
間違ってZephyr OSのトップディレクトリにあるCMakeLists.txtを指定すると、こんなエラーメッセージで怒られます。
$ cmake -GNinja -DBOARD=qemu_cortex_m3 ../ CMake Error at CMakeLists.txt:13 (message): A user error has occured. cmake was invoked with '/home/katsuhiro/share/projects/oss/zephyr' specified as the source directory, but it must be invoked with an application source directory, such as '/home/katsuhiro/share/projects/oss/zephyr/samples/hello_world'. Debug variables: CMAKE_CACHEFILE_DIR: CMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 3.13) should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more information run "cmake --help-policy CMP0000". This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring incomplete, errors occurred!
エラーメッセージからは、何が悪いのか全く分かりません……。
ビルドと実行は難しくありません。どちらかというとここまでたどり着くのがかなり面倒くさいです。
$ cd sample/hello_world/build $ ninja [1/103] Preparing syscall dependency handling [98/103] Linking C executable zephyr/zephyr_prebuilt.elf Memory region Used Size Region Size %age Used FLASH: 8604 B 256 KB 3.28% SRAM: 4160 B 64 KB 6.35% IDT_LIST: 120 B 2 KB 5.86% [103/103] Linking C executable zephyr/zephyr.elf $ ninja run [0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: cortex-m3 qemu-system-arm: warning: nic stellaris_enet.0 has no peer ***** Booting Zephyr OS zephyr-v1.13.0-3162-g73956a398e ***** Hello World! qemu_cortex_m3
何をしているのか全然わかりません。仕方ないのでbuild.ninjaファイルからqemuを実行しているところを発掘してみたら、下記のコマンドを実行しているようです。
$ /usr/bin/qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -vga none -net none -pidfile qemu.pid -serial mon:stdio -kernel /home/katsuhiro/share/projects/oss/zephyr/samples/hello_world/build/zephyr/zephyr.elf qemu-system-arm: warning: nic stellaris_enet.0 has no peer ***** Booting Zephyr OS zephyr-v1.13.0-3162-g73956a398e ***** Hello World! qemu_cortex_m3
期待される結果が良くわからないんですが、これで動いたと言って良いんだろうか…??
< | 2019 | > | ||||
<< | < | 01 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | 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.15.
using GD bundled (2.1.0 compatible)(png support.)