はじめに
話題のRISC-Vのボードを動かして見ました。
ハードウエア
RISC-VのSBCはいろいろありますが、MangoPiが最も低価格でとりあえず動かして見たい人にはお勧めです。
何よりNervesの公式でイメージがサポートされてます。
OSイメージの作成
以下は、ドキュメント通りでできました。
注意点は、MangoPiのTargetがOTP26なので、ホストもOTP26が必要です。asdfのバージョン指定を26にします(ドキュメント通りにいかなかったのはこの点だけでした)。
以下の作業は、WSLのubuntu22.04で実行しました。
$ sudo apt update
$ sudo apt install build-essential automake autoconf git squashfs-tools ssh-askpass pkg-config curl libmnl-dev
asdfで、erlangとElixirをインストールします。
masa@DESKTOP-HP:~/hello_nerves$ asdf install erlang 26.0.2
asdf_26.0.2 is not a kerl-managed Erlang/OTP installation
No build named asdf_26.0.2
Downloading 26.0.2 to /home/masa/.asdf/downloads/erlang/26.0.2...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 102M 100 102M 0 0 23.8M 0 0:00:04 0:00:04 --:--:-- 27.0M
Extracting source code
Building Erlang/OTP 26.0.2 (asdf_26.0.2), please wait...
APPLICATIONS DISABLED (See: /home/masa/.asdf/plugins/erlang/kerl-home/builds/asdf_26.0.2/otp_build_26.0.2.log)
* jinterface : No Java compiler found
* odbc : ODBC library - link check failed
APPLICATIONS INFORMATION (See: /home/masa/.asdf/plugins/erlang/kerl-home/builds/asdf_26.0.2/otp_build_26.0.2.log)
* wx : No OpenGL headers found, wx will NOT be usable
* No GLU headers found, wx will NOT be usable
* wxWidgets was not compiled with --enable-webview or wxWebView developer package is not installed, wxWebView will NOT be available
* wxWidgets must be installed on your system.
* Please check that wx-config is in path, the directory
* where wxWidgets libraries are installed (returned by
* 'wx-config --libs' or 'wx-config --static --libs' command)
* is in LD_LIBRARY_PATH or equivalent variable and
* wxWidgets version is 3.0.2 or above.
DOCUMENTATION INFORMATION (See: /home/masa/.asdf/plugins/erlang/kerl-home/builds/asdf_26.0.2/otp_build_26.0.2.log)
* documentation :
* xsltproc is missing.
* fop is missing.
* xmllint is missing.
* The documentation cannot be built.
Erlang/OTP 26.0.2 (asdf_26.0.2) has been successfully built
Cleaning up compilation products for 26.0.2
Cleaned up compilation products for 26.0.2 under /home/masa/.asdf/plugins/erlang/kerl-home/builds
masa@DESKTOP-HP:~/hello_nerves$
masa@DESKTOP-HP:~/hello_nerves$ asdf install elixir 1.15.4-otp-26
==> Checking whether specified Elixir release exists...
==> Downloading 1.15.4-otp-26 to /home/masa/.asdf/downloads/elixir/1.15.4-otp-26/elixir-precompiled-1.15.4-otp-26.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6642k 100 6642k 0 0 11.5M 0 --:--:-- --:--:-- --:--:-- 11.5M
==> Copying release into place
masa@DESKTOP-HP:~/hello_nerves$ asdf global elixir 1.15.4-otp-26
ドキュメントに実行するように書いてあるコマンドを順に実行します。
masa@DESKTOP-HP:~$ mix local.hex
Are you sure you want to install "https://builds.hex.pm/installs/1.14.0/hex-2.0.6.ez"? [Yn] y
* creating .asdf/installs/elixir/1.15.4-otp-26/.mix/archives/hex-2.0.6
masa@DESKTOP-HP:~$ mix local.rebar
* creating .asdf/installs/elixir/1.15.4-otp-26/.mix/elixir/1-15/rebar3
masa@DESKTOP-HP:~$
masa@DESKTOP-HP:~$ mix archive.install hex nerves_bootstrap
Resolving Hex dependencies...
Resolution completed in 0.01s
New:
nerves_bootstrap 1.11.5
* Getting nerves_bootstrap (Hex package)
All dependencies are up to date
Compiling 12 files (.ex)
Generated nerves_bootstrap app
Generated archive "nerves_bootstrap-1.11.5.ez" with MIX_ENV=prod
Are you sure you want to install "nerves_bootstrap-1.11.5.ez"? [Yn] y
* creating /home/masa/.asdf/installs/elixir/1.15.4-otp-26/.mix/archives/nerves_bootstrap-1.11.5
masa@DESKTOP-HP:~$
Creating a new Nerves app
masa@DESKTOP-HP:/mnt/d/wsl$ mix nerves.new hello_nerves
* creating hello_nerves/config/config.exs
* creating hello_nerves/config/host.exs
* creating hello_nerves/config/target.exs
* creating hello_nerves/lib/hello_nerves.ex
* creating hello_nerves/lib/hello_nerves/application.ex
* creating hello_nerves/test/test_helper.exs
* creating hello_nerves/test/hello_nerves_test.exs
* creating hello_nerves/rel/vm.args.eex
* creating hello_nerves/rootfs_overlay/etc/iex.exs
* creating hello_nerves/.gitignore
* creating hello_nerves/.formatter.exs
* creating hello_nerves/mix.exs
* creating hello_nerves/README.md
Fetch and install dependencies? [Yn] y
* running mix deps.get
* running mix format
Your Nerves project was created successfully.
You should now pick a target. See https://hexdocs.pm/nerves/targets.html#content
for supported targets. If your target is on the list, set `MIX_TARGET`
to its tag name:
For example, for the Raspberry Pi 3 you can either
$ export MIX_TARGET=rpi3
Or prefix `mix` commands like the following:
$ MIX_TARGET=rpi3 mix firmware
If you will be using a custom system, update the `mix.exs`
dependencies to point to desired system's package.
Now download the dependencies and build a firmware archive:
$ cd hello_nerves
$ mix deps.get
$ mix firmware
If your target boots up using an SDCard (like the Raspberry Pi 3),
then insert an SDCard into a reader on your computer and run:
$ mix burn
Plug the SDCard into the target and power it up. See target documentation
above for more information and other targets.
masa@DESKTOP-HP:/mnt/d/wsl$
mix deps.getとmix firmwareを実行します。
MIX_TARGET=mangopi_mq_pro
を忘れないように指定します。
masa@DESKTOP-HP:~$ cd hello_nerves/
masa@DESKTOP-HP:~/hello_nerves$ export MIX_TARGET=mangopi_mq_pro
masa@DESKTOP-HP:~/hello_nerves$ mix deps.get
Resolving Hex dependencies...
Resolution completed in 0.107s
Unchanged:
beam_notify 1.1.0
castore 1.0.3
circular_buffer 0.4.1
elixir_make 0.7.7
gen_state_machine 3.0.0
jason 1.4.1
mdns_lite 0.8.8
muontrap 1.3.2
nerves 1.10.3
nerves_logging 0.2.1
nerves_motd 0.1.13
nerves_pack 0.7.0
nerves_runtime 0.13.4
nerves_ssh 0.4.3
nerves_system_bbb 2.18.1
nerves_system_br 1.23.2
nerves_system_grisp2 0.7.2
nerves_system_mangopi_mq_pro 0.5.1
nerves_system_osd32mp1 0.14.1
nerves_system_rpi 1.23.1
nerves_system_rpi0 1.23.1
nerves_system_rpi2 1.23.1
nerves_system_rpi3 1.23.1
nerves_system_rpi3a 1.23.1
nerves_system_rpi4 1.23.1
nerves_system_x86_64 1.23.1
nerves_time 0.4.6
nerves_toolchain_aarch64_nerves_linux_gnu 1.8.0
nerves_toolchain_armv6_nerves_linux_gnueabihf 1.8.0
nerves_toolchain_armv7_nerves_linux_gnueabihf 1.8.0
nerves_toolchain_ctng 1.9.3
nerves_toolchain_riscv64_nerves_linux_gnu 1.8.0
nerves_toolchain_x86_64_nerves_linux_musl 1.8.0
nerves_uevent 0.1.0
one_dhcpd 2.0.2
property_table 0.2.3
ring_logger 0.10.2
shoehorn 0.9.1
ssh_subsystem_fwup 0.6.1
toolshed 0.3.1
uboot_env 1.0.1
vintage_net 0.13.3
vintage_net_direct 0.10.7
vintage_net_ethernet 0.11.2
vintage_net_wifi 0.11.5
All dependencies are up to date
==> jason
Compiling 10 files (.ex)
Generated jason app
==> castore
Compiling 1 file (.ex)
Generated castore app
==> elixir_make
Compiling 6 files (.ex)
Generated elixir_make app
==> nerves
HOST_CC port.o
HOST_LD port
Compiling 50 files (.ex)
Generated nerves app
==> hello_nerves
Nerves environment
MIX_TARGET: mangopi_mq_pro
MIX_ENV: dev
Checking for prebuilt Nerves artifacts...
Found nerves_system_mangopi_mq_pro in cache
/home/masa/.nerves/artifacts/nerves_system_mangopi_mq_pro-portable-0.5.1
Found nerves_toolchain_riscv64_nerves_linux_gnu in cache
/home/masa/.nerves/artifacts/nerves_toolchain_riscv64_nerves_linux_gnu-linux_x86_64-1.8.0
masa@DESKTOP-HP:~/hello_nerves$
fwupのインストール
fwupをインストールする必要がりました。手順を記録してなかったんですが、
Debian/Ubuntu AMD64 .deb
をダウンロードしてapt installでインストールしました。
ファームウエアの作成
次のコマンドを実行してファームウエアを作成します。sdカードに書き込む部分がWSL環境でいまいち不明だったので -d ファイル名
を指定して、イメージをファイルで出力しています。
イメージファイルのSDカードに書き込みは、お好みのソフトで行ってください。
$ mix firmware.burn -d myfirmware.img
起動方法
MangoPiにはHDMIポートがありますが、NervesイメージはシリアルポートのみサポートでHDMI出力には何も出力されません。USBのシリアル変換を使ってMangoPiと接続します
ピン番号 | 信号名 | 接続先 | メモ |
---|---|---|---|
6 | GND | GND | |
8 | Tx | USBシリアルのRx | |
10 | Rx | USBシリアルのTx | 1kΩの抵抗を直列に入れる必要があった |
10 pinを直接USBシリアルのTxと接続するとMangoPiの電源を入れても、緑色のLEDが点灯せず、起動しませんでした。1KΩの抵抗を介して接続したらうまく行きました。使用したUSBシリアル変換はTxの信号が通常Hiレベル(3.3V)となっています。この状態と合わないのかもしれません。
通信条件
スピード | 115200bps |
---|---|
ビット | 8bit |
パリティ | 無し |
ストップビット | 1bit |
通信条件を設定してシリアル端末ソフトを起動
nervesが起動しiexのシェルの操作もできました。