目次

Azure IoT Edge 対応


Microsoft の Azure IoT Edge を使用するためのパッケージを入れたファームウェアを作成してみます。
詳細は IoT Edge をインストールする を参照してください。

準備

root filesystem の準備

root filesystem の準備 を参考に、root filesystem を準備しておきます。

【実行例】

user1@max3xx-devel:~/work$ mkdir max3xx_jammy_iotedge_rootfs
user1@max3xx-devel:~/work$ cd max3xx_jammy_iotedge_rootfs
user1@max3xx-devel:~/work/max3xx_jammy_iotedge_rootfs$ sudo tar axvf ../rootfs/max3xx_rootfs_jammy_v6_0_0.tar.xz 
...
./etc/dpkg/dpkg.cfg
./tmp/
./.host/
./proc/
./srv/
user1@max3xx-devel:~/work/max3xx_jammy_iotedge_rootfs$ 
user1@max3xx-devel:~/work$ sudo ./chroot_arm64.sh max3xx_jammy_iotedge_rootfs/
root@max3xx-devel:/# 


Microsoft パッケージ署名キーの追加

パッケージリポジトリを追加し、信頼できるキーの一覧に Microsoft パッケージ署名キーを追加します。

root@max3xx-devel:/# wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
--2023-04-13 16:25:14--  https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
Resolving packages.microsoft.com (packages.microsoft.com)... 23.99.120.248
Connecting to packages.microsoft.com (packages.microsoft.com)|23.99.120.248|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3692 (3.6K) [application/octet-stream]
Saving to: 'packages-microsoft-prod.deb'

packages-microsoft-prod.deb   100%[==============================================>]   3.61K  --.-KB/s    in 0s      

2023-04-13 16:25:15 (34.3 MB/s) - 'packages-microsoft-prod.deb' saved [3692/3692]

root@max3xx-devel:/# 
root@max3xx-devel:/# dpkg -i packages-microsoft-prod.deb
Selecting previously unselected package packages-microsoft-prod.
(Reading database ... 15956 files and directories currently installed.)
Preparing to unpack packages-microsoft-prod.deb ...
Unpacking packages-microsoft-prod (1.0-ubuntu22.04.1) ...
Setting up packages-microsoft-prod (1.0-ubuntu22.04.1) ...
root@max3xx-devel:/# 

インストールしたら、パッケージは不要なので削除しておきます。

root@max3xx-devel:/# rm packages-microsoft-prod.deb
root@max3xx-devel:/# 


パッケージデータベースの更新

apt update で更新しておきます。更新されるパッケージがある場合、更新しておきます。

root@max3xx-devel:/# apt update
Get:1 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease [3611 B]                                     
Get:2 http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa/ubuntu jammy InRelease [23.8 kB]                         
...
Get:34 http://ports.ubuntu.com/ubuntu-ports jammy-security/multiverse arm64 Packages [8792 B]                       
Get:35 http://ports.ubuntu.com/ubuntu-ports jammy-security/multiverse Translation-en [4068 B]                       
Fetched 26.8 MB in 24s (1097 kB/s)                                                                                  
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
14 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@max3xx-devel:/# 
root@max3xx-devel:/# apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  initramfs-tools initramfs-tools-bin initramfs-tools-core
The following packages will be upgraded:
  libldap-2.5-0 libldap-common libnss-systemd libpam-systemd libsystemd0 libudev1 sudo systemd systemd-sysv tzdata
  udev
11 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 8038 kB of archives.
After this operation, 35.8 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libnss-systemd arm64 249.11-0ubuntu3.9 [133 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libsystemd0 arm64 249.11-0ubuntu3.9 [314 kB]
....
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for initramfs-tools (0.136ubuntu6.7) ...
root@max3xx-devel:/# 


コンテナーエンジンのインストール

Azure IoT Edge は OCI 互換のコンテナーランタイムに依存しています。
Moby エンジンが IoT Edge で公式にサポートされている唯一のコンテナーエンジンなので、Moby エンジンをインストールします。

root@max3xx-devel:/# apt install moby-engine
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apparmor git git-man libcurl3-gnutls liberror-perl libgdbm-compat4 libgdbm6 libperl5.34 moby-buildx moby-cli
  moby-containerd moby-runc patch perl perl-modules-5.34 pigz
Suggested packages:
  apparmor-profiles-extra apparmor-utils gettext-base git-daemon-run | git-daemon-sysvinit git-doc git-email
  git-gui gitk gitweb git-cvs git-mediawiki git-svn gdbm-l10n aufs-tools cgroupfs-mount | cgroup-lite ed
  diffutils-doc perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libtap-harness-archive-perl
The following NEW packages will be installed:
  apparmor git git-man libcurl3-gnutls liberror-perl libgdbm-compat4 libgdbm6 libperl5.34 moby-buildx moby-cli
  moby-containerd moby-engine moby-runc patch perl perl-modules-5.34 pigz
0 upgraded, 17 newly installed, 0 to remove and 3 not upgraded.
Need to get 93.6 MB of archives.
After this operation, 368 MB of additional disk space will be used.
Do you want to continue? [Y/n] 


ログドライバー設定の変更

そのままでは Moby コンテナーエンジンのコンテナーログサイズの制限が設定されないため、時間の経過と共にデバイスがログでいっぱいになりディスク容量が不足する可能性があります。
そのため、syslog に出力するように設定を変更しておきます。

root@max3xx-devel:/# cd /etc/docker/
root@max3xx-devel:/etc/docker# nano -w daemon.json

daemon.json
{
    "log-driver": "local"
}


IoT Edge ランタイムのインストール

apt install でインストールします。

root@max3xx-devel:~# apt install aziot-edge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  aziot-identity-service libtss2-esys-3.0.2-0 libtss2-mu0 libtss2-rc0 libtss2-sys1 libtss2-tcti-cmd0
  libtss2-tcti-device0 libtss2-tcti-mssim0 libtss2-tcti-swtpm0 libtss2-tctildr0 tpm-udev
The following NEW packages will be installed:
  aziot-edge aziot-identity-service libtss2-esys-3.0.2-0 libtss2-mu0 libtss2-rc0 libtss2-sys1 libtss2-tcti-cmd0
  libtss2-tcti-device0 libtss2-tcti-mssim0 libtss2-tcti-swtpm0 libtss2-tctildr0 tpm-udev
0 upgraded, 12 newly installed, 0 to remove and 3 not upgraded.
Need to get 7979 kB of archives.
After this operation, 33.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
Do you want to continue? [Y/n] y
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 tpm-udev all 0.6 [3080 B]
Get:2 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-mu0 arm64 3.2.0-1ubuntu1 [57.6 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-tcti-cmd0 arm64 3.2.0-1ubuntu1 [16.2 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-tcti-device0 arm64 3.2.0-1ubuntu1 [15.1 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-tcti-mssim0 arm64 3.2.0-1ubuntu1 [15.3 kB]
Get:6 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-tcti-swtpm0 arm64 3.2.0-1ubuntu1 [15.2 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-sys1 arm64 3.2.0-1ubuntu1 [39.1 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-esys-3.0.2-0 arm64 3.2.0-1ubuntu1 [133 kB]
Get:9 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-rc0 arm64 3.2.0-1ubuntu1 [11.3 kB]
Get:10 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libtss2-tctildr0 arm64 3.2.0-1ubuntu1 [16.1 kB]
Get:11 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main arm64 aziot-identity-service arm64 1.4.3-1 [3988 kB]
Get:12 https://packages.microsoft.com/ubuntu/22.04/prod jammy/main arm64 aziot-edge arm64 1.4.9-1 [3670 kB]         
Fetched 7979 kB in 9s (896 kB/s)                                                                                    
.....
Created symlink /etc/systemd/system/sockets.target.wants/aziot-keyd.socket → /lib/systemd/system/aziot-keyd.socket.
Created symlink /etc/systemd/system/sockets.target.wants/aziot-tpmd.socket → /lib/systemd/system/aziot-tpmd.socket.
Setting up aziot-edge (1.4.9-1) ...
===============================================================================

                              Azure IoT Edge

  IMPORTANT: Please configure the device with provisioning information.

  Please create a new system configuration.

  You can quickly configure the device for manual provisioning with
   a connection string using:

    sudo iotedge config mp --connection-string '...'

  For other provisioning options, copy the template file 
  at /etc/aziot/config.toml.edge.template to /etc/aziot/config.toml,
  update it with your device information, then apply the configuration to
  the IoT Edge services with:

    sudo iotedge config apply

===============================================================================
Created symlink /etc/systemd/system/sockets.target.wants/aziot-edged.mgmt.socket → /lib/systemd/system/aziot-edged.mg
mt.socket.
Created symlink /etc/systemd/system/multi-user.target.wants/aziot-edged.service → /lib/systemd/system/aziot-edged.ser
vice.
Created symlink /etc/systemd/system/sockets.target.wants/aziot-edged.workload.socket → /lib/systemd/system/aziot-edge
d.workload.socket.
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
root@max3xx-devel:~# 


コンテナーエンジン用 eMMC mount 設定

コンテナーエンジンのストレージ領域が必要になるので、eMMC の後半部分のデータ領域を使用する設定をしておきます。

root@max3xx-devel:~# cd /var/lib/
root@max3xx-devel:/var/lib# mkdir docker
root@max3xx-devel:/var/lib# chmod 710 docker/
root@max3xx-devel:/var/lib# ls -l        
total 92
drwxr-xr-x 5 root      root    4096 Apr 13 16:48 apt
drwxr-xr-x 7 root      root    4096 Apr 13 16:48 aziot
drwxr-xr-x 2 root      root    4096 Jun  8  2022 bluetooth
drwxr-x--- 2 _chrony   _chrony 4096 Aug 25  2020 chrony
drwxr-xr-x 2 root      root    4096 Dec 15  2021 dbus
drwx--x--- 2 root      root    4096 Apr 13 17:19 docker <-----
drwxr-xr-x 7 root      root    4096 Apr 13 16:48 dpkg
drwxr-xr-x 2 root      root    4096 Feb  8 22:57 git
drwxr-xr-x 2 root      root    4096 Apr  4 13:16 initramfs-tools
drwxr-xr-x 2 root      root    4096 Jan 21  2019 logrotate
drwxr-xr-x 2 root      root    4096 Apr 15  2020 misc
drwxr-xr-x 2 mosquitto root    4096 Mar  4  2020 mosquitto
drwxr-xr-x 2 root      root    4096 Apr 12  2022 nginx
drwxr-xr-x 2 root      root    4096 Apr 13 16:30 pam
drwxr-xr-x 3 root      root    4096 Dec 15  2021 polkit-1
drwxr-xr-x 2 root      root    4096 Sep 21  2022 pppcounter
drwx------ 2 root      root    4096 Dec 15  2021 private
drwxr-xr-x 2 root      root    4096 Nov  7 13:12 python
-rw-r--r-- 1 root      root       0 Nov  7 12:06 shells.state
drwxr-xr-x 3 root      root    4096 Dec 15  2021 sudo
drwxr-xr-x 7 root      root    4096 Nov  7 12:08 systemd
drwxr-xr-x 2 tss       tss     4096 Jan 26  2022 tpm
drwxr-xr-x 3 root      root    4096 Nov  7 13:11 ucf
drwxr-xr-x 3 root      root    4096 Dec 15  2021 vim
root@max3xx-devel:/var/lib# 


.mount ユニットを作成し、起動時に eMMC のデータ領域が /var/lib/docker に mount されるようにしておきます。

root@max3xx-devel:/var/lib# cd /etc/systemd/system
root@max3xx-devel:/etc/systemd/system# nano -w var-lib-docker.mount
var-lib-docker.mount
[Unit]
Description=Docker eMMC
 
[Mount]
What=/dev/mmcblk0p2
Where=/var/lib/docker
Type=ext4
Options=noatime
 
[Install]
WantedBy=multi-user.target
root@max3xx-devel:/etc/systemd/system# systemctl enable var-lib-docker.mount 
Created symlink /etc/systemd/system/multi-user.target.wants/var-lib-docker.mount → /etc/systemd/system/var-lib-docker.mount.
root@max3xx-devel:/etc/systemd/system# 


Web Server(nginx) 設定変更

Iot Edge のランタイムが内部で 443(HTTPS) を使用してしまうので、nginx の HTTPS での待受を無効化しておきます。

root@max3xx-devel:~# cd /etc/nginx/sites-enabled/
root@max3xx-devel:/etc/nginx/sites-enabled# ls -l
total 0
lrwxrwxrwx 1 root root 34 Jun 29  2022 default -> /etc/nginx/sites-available/default <------ HTTPS の有効化
lrwxrwxrwx 1 root root 39 Jun 29  2022 default.http -> /etc/nginx/sites-available/default.http
root@max3xx-devel:/etc/nginx/sites-enabled# rm default
root@max3xx-devel:/etc/nginx/sites-enabled# ls -l
total 0
lrwxrwxrwx 1 root root 39 Jun 29  2022 default.http -> /etc/nginx/sites-available/default.http
root@max3xx-devel:/etc/nginx/sites-enabled# 


ファームウェアのビルド

ARM64 の chroot 環境から抜けて、ファームウェアの作成 と同じ手順でファームウェアをビルドします。

root@max3xx-devel:~# exit
exit
user1@max3xx-devel:~/work$
user1@max3xx-devel:~/work$ sudo ./build_firm.sh -k ../src/linux-kernel -r max3xx_jammy_iotedge_rootfs -o firmware/max3xx_jammy_iotedge_v6_0_0.img