目次: 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オプションを付けてやり直しましょう。
この記事にコメントする
目次: GCC
最近はRISC-V向けのクロスコンパイラをビルドすることが多かったのですが、昔を思い出してARM向けも作るか〜と気軽にやってみたらハマりました。
最初にトライしたのはarm-unknown-linux-gnueabi(昔の32bit ARM向け、ARM9とか)で、特に問題なくビルドできました。次にトライしたのはaarch64-unknown-linux-gnu(64bit ARM向け、最近のCortexとか)ですが、リンクエラーが発生してcrt1.oやcrti.oが見つからないと言ってきます。
$ aarch64-unknown-linux-gnu-gcc -Wall -O2 -g -static a.c /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/bin/ld: cannot find crti.o: No such file or directory /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/bin/ld: cannot find -lc: No such file or directory collect2: error: ld returned 1 exit status
最初はglibcのビルドに失敗したのかと思いましたが、crt1.oはsysroot/usr/lib64ディレクトリの下に存在していました。
$ find -name crt1.o ./aarch64-unknown-linux-gnu/sysroot/usr/lib64/crt1.o
ファイルが存在しているのに見つからないのは、GCCが自動的に付与する-Lオプションが間違っている可能性大です。-vオプションでGCCのオプションを調べます。
--sysroot=/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot -Bstatic -X -EL -maarch64linux crt1.o crti.o /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/crtbeginT.o -L/path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1 -L/path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/lib/../lib64 -L/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/lib/../lib64 ★★相対パスが入っている★★ -L/path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/lib -L/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/lib /tmp/ccQ9tEVu.o --start-group -lgcc -lgcc_eh -lc --end-group /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/crtend.o crtn.o
困ったことにsysroot/usr/lib64を指定する-Lオプションがありません。なぜでしょう。
手掛かりになりそうなのは、sysroot/lib64ディレクトリの指定の仕方で、lib/../lib64のように一度libを経由しています。実はsysroot/usr/lib64も同じでsysroot/usr/libを経由している可能性があります。
ディレクトリの構造を調べるとsysroot/libは存在するものの、sysroot/usr/libは存在しませんでした。試しに空のsysroot/usr/libディレクトリを作成し、再度コンパイルするとエラーが解消しました。やったー。エラーだった時と何が違うか知るために-vオプションでGCCのオプションを調べます。
--sysroot=/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot -Bstatic -X -EL -maarch64linux /path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/lib/../lib64/crt1.o /path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/lib/../lib64/crti.o /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/crtbeginT.o -L/path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1 -L/path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/lib/../lib64 -L/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/lib/../lib64 -L/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/lib/../lib64 ★★やっぱりlib/../lib64になっている★★ -L/path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/../../../../aarch64-unknown-linux-gnu/lib -L/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/lib -L/path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/lib /tmp/ccLe9HUo.o --start-group -lgcc -lgcc_eh -lc --end-group /path/to/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.0.1/crtend.o /path/to/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot/usr/lib/../lib64/crtn.o
やはりsysroot/usr/lib64を指定するパスにはsysroot/usr/libが含まれていました。原因は「最終のディレクトリに辿り着く途中のパスが存在しないから」と言えそうです。しかしどうしてGCCが勝手に-Lオプションを消すのかは謎のままで、若干スッキリしません。うーん。
この記事にコメントする
目次: サンタ
去年(2022年12月24日の日記参照)と同様に、飛行機の位置をリアルタイムに表示するFlightradar24というサービス(サイトへのリンク)にてサンタが出現しました。クリスマス・イブの日にサンタが出現するのは毎年恒例のお約束演出です。私が見たときはインド上空を飛んでいました。
2021年のサンタは表示された対地速度は40ktsなのに、サンタの位置から計算した速度はマッハ2 = 1300ktsと変な状態でしたが、2023年と今年は対地速度の表示は727kts(1346.4km/h, マッハ1.1くらい)です。

00:32:10時点の位置(緯度27.15451度、経度76.90161度)

00:33:10時点の位置(緯度26.26621度、経度76.42773度)
去年同様、ある程度の時間をあけ(今回は1分間)でどれくらい進んだか計算します。今回も距離の計算には国土地理院のページを使いました、緯度経度から距離を一発で計算してくれて便利です(サイトへのリンク)。
2地点間の距離は約109.1km、時間差は60秒から計算すると、対地速度は約6,540km/hです。地上でのマッハ5(ただし、サンタが飛んでいる高さ38,000ftsだとマッハ数はもっと高く出る)です。世界最速の飛行機であるロッキードSR-71ブラックバードでさえマッハ3.3といわれているので、サンタさんバチクソ速いですね。
推測ですが24日、25日で北極から世界一周してまた北極へ行くために、緯度、経度は対地速度に関係なく適当に変えているんじゃないか?という気がしてきました。別の時間に測ったら全然違う速度になってませんかね?面倒なので検証しませんけど……。来年の速度も気になります。覚えていたらまた計算してみましょう。
この記事にコメントする
この記事にコメントする
昼頃だったか?Twitterで何かトラブルが起きていたらしくて、初ログインしたときのような画面になっていました。
Twitterの使い始めがどんな画面だったか全く覚えていませんが、たぶんこんな画面なんでしょう。今だと別アカウントを登録しない限り、見る機会がない画面でしょうね。
この記事にコメントする
辞書(家にあるのは新明解国語辞典 第四版)を引いていると、語句の漢字表記に○とか▽のような謎の記号が書いてあります。今までずっと意味がわかっていなかったのですが、三省堂が素敵な解説文をサイトに載せてくれていました。
詳細は解説(第29回 ×とか▽とか、これは何だ? - 【 】見出し(漢字表記)についている○▽× - 三省堂 ことばのコラム)を読んでいただければと思いますが、そのなかに▽は音訓表に載っていない読みのこと、と書いてあります。音訓表とはなんぞ?
検索してみると、文化庁が作成している常用漢字の読み方(文化庁 | 国語施策・日本語教育 | 国語施策情報 | 常用漢字表の音訓索引)のことらしいです。
常用漢字の一覧(文化庁 | 国語施策・日本語教育 | 国語施策情報 | 内閣告示・内閣訓令 | 常用漢字表(平成22年内閣告示第2号))を文化庁が作成しているのは知っていたんですけど、読み方まで一覧にしてくれていたんですね。知らなかったなあ……。
この記事にコメントする
| < | 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 | - | - | - | - | - | - |
25年10月15日
25年10月18日
22年5月5日
25年10月19日
23年4月11日
06年4月22日
25年10月17日
25年10月6日
25年10月13日
20年10月23日
25年10月12日
20年8月29日
19年1月13日
18年10月13日
18年9月3日
18年8月20日
18年7月23日
18年7月22日
18年10月14日
18年11月10日
wiki
Linux JM
Java API
2002年
2003年
2004年
2005年
2006年
2007年
2008年
2009年
2010年
2011年
2012年
2013年
2014年
2015年
2016年
2017年
2018年
2019年
2020年
2021年
2022年
2023年
2024年
2025年
過去日記について
アクセス統計
サーバ一覧
サイトの情報合計:
本日: