Milk-V Duo 64MでUbuntuを使ってみる

Ubuntuのインストール

しばらくbuildrootを使っていましたが、buildrootでは、SPIデバイスが使えないので、OSをUbuntuに変えました。
Milk-Vの公式イメージはbuildrootですが、これ以外のOSイメージがこ ちらに公開されています。
そこで、今回はUbuntuを使うことにしました。
Ubuntuイメージはこ ちらからダウンロードすることができます。
今回使用したのは「milkv-duo-ubuntu-22.04-riscv64-v0.0.4-spiritdude」のイメージです。
注意点が以下の様に書かれています。
・apt / apt-get are awfully slow on Milk-V Duo at step “Building dependency tree...“, takes 4+mins for each apt install call as apt requires 50+MB RAM to build that dependency tree, which goes hard on all available RAM + swap.
・these are very experimental disk images

SDカードへの書き込みはrufusを使いましたが、イメージファイルが圧縮されていないので、SDカードへの書き込みは結構時間が掛かります。
SDカードが準備できたら、USB-TTL変換アダプターを本体のデバッグポートに接続します。
GPIOのピン配置はこち らに公開されていますが、デバッグポートはピン番号16(TX)、17(RX)です。
USB-TTLアダプターをWindowsマシンに接続し、TeraTermを起動してから、ボードのUSB経由で電源を供給します。
ずらずらとブートメッセージが表示されてログインプロンプトが表示されます。


root/milkvのユーザが事前に登録されています。


提供されているUbuntuのバージョンはUbuntu22.04です。


Ubuntuでは以下の様に最初からSwapが確保されています。


/etc/fstabを見てみましたが/dev/mmcblk0p3のマウントが間違っています。


/etc/fstabの最後のエントリをコメントアウトして再起動し、以下のコマンドでSwapを再登録してみました。
どうも/dev/mmcblk0p3のパーティションは272Mしかないみたいです。


16GのSDカードを使いましたが、アサインされているパーテイションは7G程度です。
9G程度のパーティションは確保できそうです。


パーティション情報を表示するためにfdiskを起動しましたが、インストールされていません。
パーティション情報の確認とパーテイションの再構築を行うことができません。


やはりfdiskをインストールして、パーテイションの再構築を行う必要がありそうです。
aptを使ってfdiskをインストールしました。
# apt install fdisk -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libfdisk1
The following NEW packages will be installed:
  fdisk libfdisk1
0 upgraded, 2 newly installed, 0 to remove and 82 not upgraded.
Need to get 324 kB of archives.
After this operation, 935 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy/main riscv64 libfdisk1 riscv64 2.37.2-4ubuntu3 [188 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports jammy/main riscv64 fdisk riscv64 2.37.2-4ubuntu3 [135 kB]
Fetched 324 kB in 8s (41.6 kB/s)
Selecting previously unselected package libfdisk1:riscv64.
(Reading database ... 15831 files and directories currently installed.)
Preparing to unpack .../libfdisk1_2.37.2-4ubuntu3_riscv64.deb ...
Unpacking libfdisk1:riscv64 (2.37.2-4ubuntu3) ...
Selecting previously unselected package fdisk.
Preparing to unpack .../fdisk_2.37.2-4ubuntu3_riscv64.deb ...
Unpacking fdisk (2.37.2-4ubuntu3) ...
Setting up libfdisk1:riscv64 (2.37.2-4ubuntu3) ...
Setting up fdisk (2.37.2-4ubuntu3) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...

fdiskを使ってパーティションを再構築します。
一旦パーティションを削除して、7Gのパーテイションを作成しました。
このパーティションはSDカードの末尾に作られるので、SDカードの容量に依存します。
# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Command (m for help): p

Disk /dev/mmcblk0: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x769cf592

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *           1   262144   262144  128M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        262145 14942208 14680064    7G 83 Linux
/dev/mmcblk0p3      14942209 15466496   524288  256M  0 Empty

Command (m for help): d
Partition number (1-3, default 3): 3

Partition 3 has been deleted.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (14942209-31116287, default 14944256):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (14944256-31116287, default 31116287): +7G

Created a new partition 3 of type 'Linux' and of size 7 GiB.

Command (m for help): w
The partition table has been altered.
Failed to remove partition 3 from system: Device or resource busy
Failed to add partition 3 to system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.

# mkswap /dev/mmcblk0p3
Setting up swapspace version 1, size = 7 GiB (7516188672 bytes)
no label, UUID=724c38f1-83d9-4cfb-813c-35908952d58b

# swapon /dev/mmcblk0p3

Swapが7Gになりました。


/etc/fstabに以下のエントリを追加すると、再起動したときに自動的にマウントします。


提供されているUbuntuのイメージはRNDIS(リモートNDIS)機能が有効になっていて、
USBポートに対して「192.168.42.1」のIPアドレス がアサインされます。
WindowsやLinuxホストのIPアドレスを同じセグメントに変更することで、USBポートを使ったネットワークが使えるようになります。


RNDISを使ったネットワーク共有についてはこちらで紹介していま す。
母艦側のネットワーク共有を有効にすることで、Milk-Vから外部にネットワークが繋がります。


Swapが大きくなったので、aptデータベースをアップデートしてみました。
無事にアップデートが終わりました。


python pipはインストールされていません。


python pipをインストールしてみました。


4時間ぐらい掛かりましたが、全てインストールできました。


pip 22.0.2がインストールされました。


pip本体をアップデートしました。
pip本体が22.0.2から24.1にアップデートされました。


Adafruit-PlatformDetectをインストールしました。


Adafruit-PlatformDetectは動作中のLinuxのチップとボードを自動判定するライブラリです。
以下のスクリプト(platformdetect.py)で、このライブラリの動作を確認することができます。
from adafruit_platformdetect import Detector
detector = Detector()
print("Chip id: ", detector.chip.id)
print("Board id: ", detector.board.id)

Pico-Miniを識別しましたが、unable to resolve hostのメッセージが出ています。
root@milkv-duo:~# sudo -E python3 ./platformdetect.py
sudo: unable to resolve host milkv-duo: Name or service not known
Chip id:  CV1800B
Board id:  MILKV_DUO
root@milkv-duo:~#

/etc/hostsに127.0.1.1を登録すると、このメッセージは無くなります。
root@milkv-duo:~# sudo sh -c 'echo 127.0.1.1 $(hostname) >> /etc/hosts'
sudo: unable to resolve host milkv-duo: Name or service not known
root@milkv-duo:~# sudo -E python3 ./platformdetect.py
Chip id:  CV1800B
Board id:  MILKV_DUO

Adafruit-Blinkaをインストールしてみました。
Adafruit-BlinkaはSPIやI2Cを制御できるpythonライブラリですが、8.44.0以降、インストール方法が変わり、
gcc/g++が動く環境が必要になりました。
また、numpyを同時にインストールするのでものすごく時間が掛かります。
そこで、numpyをインストールしない8.43.0をインストールしました。


確認のためにpipでインストールしたパッケージを確認します。
Blinkaライブラリと関連するライブラリが登録されています。


デバイスファイルを確認してみました。
buildrootと同様に、SPIデバイスが間違っています。
pwm、ledsのデバイスが有りません。


提供されているOSではSPIが使えないので、このボードはしばらくお蔵入りです。