ユーザ用ツール

サイト用ツール


max3xx_devel:customize_firmware:add_openjdk_jre:start

JVM の追加


AWS IoT Greengrass など、JVM 環境が必要になるケースがあります。
OpenJDK で対応しますが、コンパイラなど JDK の部分は使用しないのでランタイム部分 (OpenJDK-JRE) のみ追加したファームウェアを作成してみます。

手順

root filesystem の準備

root filesystem を展開しておきます。

root@jammy64-dev:/home/user1/work/MAX3xx# ls -l max3xx_jammy_openjdk_rootfs/
total 60
lrwxrwxrwx  1 root root    7 Dec 15  2021 bin -> usr/bin
drwxr-xr-x  2 root root 4096 May 10 19:48 boot
drwxr-xr-x  4 root root 4096 Dec 15  2021 dev
drwxr-xr-x 78 root root 4096 May 11 08:05 etc
drwxr-xr-x  3 root root 4096 Dec 15  2021 home
lrwxrwxrwx  1 root root    7 Dec 15  2021 lib -> usr/lib
drwxr-xr-x  2 root root 4096 Dec 15  2021 media
drwxr-xr-x  5 root root 4096 Jul  6  2022 mnt
drwxr-xr-x  3 root root 4096 Jun 29  2022 opt
drwxr-xr-x  2 root root 4096 Apr 15  2020 proc
drwx------  4 root root 4096 Jan 17 11:00 root
drwxr-xr-x 11 root root 4096 Nov  7  2022 run
lrwxrwxrwx  1 root root    8 Dec 15  2021 sbin -> usr/sbin
drwxr-xr-x  2 root root 4096 Dec 15  2021 srv
drwxr-xr-x  2 root root 4096 Apr 15  2020 sys
drwxrwxrwt  2 root root 4096 May 11 08:05 tmp
drwxr-xr-x 11 root root 4096 Nov  7  2022 usr
drwxr-xr-x 12 root root 4096 Jun 29  2022 var
root@jammy64-dev:/home/user1/work/MAX3xx# 


root filesystem への chroot

root filesystem のカスタマイズ の方法で、ARM64 環境へ chroot します。

root@jammy64-dev:/home/user1/work/MAX3xx# ./chroot_arm64.sh max3xx_jammy_openjdk_rootfs/
root@jammy64-dev:/# uname -a
Linux jammy64-dev 5.15.0-70-lowlatency #77~20.04.1-Ubuntu SMP PREEMPT Wed Apr 5 18:52:27 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
root@jammy64-dev:/# 


OpenJDK(JRE) パッケージの追加

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

root filesystem のアーカイブにはパッケージデータベースが入っていないので、更新しておきます。

root@jammy64-dev:/# apt update
Hit:1 http://ports.ubuntu.com/ubuntu-ports jammy InRelease
Hit:2 http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa/ubuntu jammy InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@jammy64-dev:/# 


openjdk-jre パッケージの検索

openjdk-jre を検索します。

root@jammy64-dev:/# apt search openjdk|grep jre

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

default-jre/jammy 2:1.11-72build2 arm64
default-jre-headless/jammy 2:1.11-72build2 arm64
openjdk-11-jre/jammy-updates,jammy-security 11.0.18+10-0ubuntu1~22.04 arm64
openjdk-11-jre-headless/jammy-updates,jammy-security 11.0.18+10-0ubuntu1~22.04 arm64
openjdk-11-jre-zero/jammy-updates,jammy-security 11.0.18+10-0ubuntu1~22.04 arm64
openjdk-17-jre/jammy-updates,jammy-security 17.0.6+10-0ubuntu1~22.04 arm64
openjdk-17-jre-headless/jammy-updates,jammy-security 17.0.6+10-0ubuntu1~22.04 arm64
openjdk-17-jre-zero/jammy-updates,jammy-security 17.0.6+10-0ubuntu1~22.04 arm64
openjdk-18-jre/jammy-updates,jammy-security 18.0.2+9-2~22.04 arm64
openjdk-18-jre-headless/jammy-updates,jammy-security 18.0.2+9-2~22.04 arm64
openjdk-18-jre-zero/jammy-updates,jammy-security 18.0.2+9-2~22.04 arm64
openjdk-19-jre/jammy-updates,jammy-security 19.0.2+7-0ubuntu3~22.04 arm64
openjdk-19-jre-headless/jammy-updates,jammy-security 19.0.2+7-0ubuntu3~22.04 arm64
openjdk-19-jre-zero/jammy-updates,jammy-security 19.0.2+7-0ubuntu3~22.04 arm64
openjdk-8-jre/jammy-updates,jammy-security 8u362-ga-0ubuntu1~22.04 arm64
openjdk-8-jre-headless/jammy-updates,jammy-security 8u362-ga-0ubuntu1~22.04 arm64
openjdk-8-jre-zero/jammy-updates,jammy-security 8u362-ga-0ubuntu1~22.04 arm64

バージョンとしては 8, 11, 17, 18, 19 が使用可能で、“default”1) では 11 が選択されることがわかります。

※ MA- シリーズにはディスプレイがないので、“headless” で問題ありません。


パッケージのインストール

例として、“default-jre-headless” をインストールしてみます。

root@jammy64-dev:/# apt install default-jre-headless
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  alsa-topology-conf alsa-ucm-conf ca-certificates-java fontconfig-config fonts-dejavu-core java-common libasound2
  libasound2-data libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libfontconfig1 libfreetype6
  libgraphite2-3 libharfbuzz0b libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4 libnss3 libpng16-16
  openjdk-11-jre-headless
Suggested packages:
  default-jre libasound2-plugins alsa-utils cups-common liblcms2-utils libnss-mdns fonts-dejavu-extra
  fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei fonts-indic
The following NEW packages will be installed:
  alsa-topology-conf alsa-ucm-conf ca-certificates-java default-jre-headless fontconfig-config fonts-dejavu-core
  java-common libasound2 libasound2-data libavahi-client3 libavahi-common-data libavahi-common3 libcups2
  libfontconfig1 libfreetype6 libgraphite2-3 libharfbuzz0b libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4 libnss3
  libpng16-16 openjdk-11-jre-headless
0 upgraded, 24 newly installed, 0 to remove and 3 not upgraded.
Need to get 45.6 MB of archives.
After this operation, 182 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

ファームウェアにした場合は、だいたい 46MB ほど容量が増加するようです。

Do you want to continue? [Y/n] y
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libpng16-16 arm64 1.6.37-3build5 [189 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 alsa-topology-conf all 1.2.5.1-2 [15.5 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libasound2-data all 1.2.6.1-1ubuntu1 [19.1 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libasound2 arm64 1.2.6.1-1ubuntu1 [378 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 alsa-ucm-conf all 1.2.6.3-1ubuntu1.5 [41.7 kB]
Get:6 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 java-common all 0.72build2 [6782 B]
Get:7 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libavahi-common-data arm64 0.8-5ubuntu5 [23.9 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libavahi-common3 arm64 0.8-5ubuntu5 [23.3 kB]
Get:9 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libavahi-client3 arm64 0.8-5ubuntu5 [27.4 kB]
Get:10 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libcups2 arm64 2.4.1op1-1ubuntu4.1 [264 kB]
Get:11 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 liblcms2-2 arm64 2.12~rc1-2build2 [157 kB]
Get:12 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libjpeg-turbo8 arm64 2.1.2-0ubuntu1 [129 kB]
Get:13 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libjpeg8 arm64 8c-2ubuntu10 [2264 B]
Get:14 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libfreetype6 arm64 2.11.1+dfsg-1ubuntu0.2 [383 kB]
Get:15 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 fonts-dejavu-core all 2.37-2build1 [1041 kB]
Get:16 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 fontconfig-config all 2.13.1-4.2ubuntu5 [29.1 kB]
Get:17 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libfontconfig1 arm64 2.13.1-4.2ubuntu5 [135 kB]
Get:18 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libnspr4 arm64 2:4.32-3build1 [115 kB]
Get:19 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libnss3 arm64 2:3.68.2-0ubuntu1.2 [1172 kB]
Get:20 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 libgraphite2-3 arm64 1.3.14-1build2 [68.9 kB]
Get:21 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 libharfbuzz0b arm64 2.7.4-1ubuntu3.1 [353 kB]
Get:22 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 openjdk-11-jre-headless arm64 11.0.18+10-0ubuntu1~22.04 [41.0 MB]
Get:23 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 default-jre-headless arm64 2:1.11-72build2 [3044 B]    
Get:24 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 ca-certificates-java all 20190909ubuntu1.1 [12.0 kB]
Fetched 45.6 MB in 10s (4779 kB/s)                                                                                  
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
E: Unlocking the slave of master fd 35 failed! - unlockpt (22: Invalid argument)
Selecting previously unselected package libpng16-16:arm64.
(Reading database ... 15949 files and directories currently installed.)
Preparing to unpack .../00-libpng16-16_1.6.37-3build5_arm64.deb ...
Unpacking libpng16-16:arm64 (1.6.37-3build5) ...
Selecting previously unselected package alsa-topology-conf.
Preparing to unpack .../01-alsa-topology-conf_1.2.5.1-2_all.deb ...
Unpacking alsa-topology-conf (1.2.5.1-2) ...
Selecting previously unselected package libasound2-data.
Preparing to unpack .../02-libasound2-data_1.2.6.1-1ubuntu1_all.deb ...
Unpacking libasound2-data (1.2.6.1-1ubuntu1) ...
Selecting previously unselected package libasound2:arm64.
Preparing to unpack .../03-libasound2_1.2.6.1-1ubuntu1_arm64.deb ...
... 中略 ...
Selecting previously unselected package ca-certificates-java.
Preparing to unpack .../23-ca-certificates-java_20190909ubuntu1.1_all.deb ...
Unpacking ca-certificates-java (20190909ubuntu1.1) ...
Setting up libgraphite2-3:arm64 (1.3.14-1build2) ...
Setting up liblcms2-2:arm64 (2.12~rc1-2build2) ...
Setting up java-common (0.72build2) ...
... 中略 ...
Setting up libavahi-client3:arm64 (0.8-5ubuntu5) ...
Setting up libcups2:arm64 (2.4.1op1-1ubuntu4.1) ...
Setting up ca-certificates-java (20190909ubuntu1.1) ...
/usr/bin/head: cannot open '/etc/ssl/certs/java/cacerts' for reading: No such file or directory
Adding debian:GTS_Root_R3.pem
... 中略 ...
Adding debian:SSL.com_EV_Root_Certification_Authority_RSA_R2.pem
Adding debian:COMODO_ECC_Certification_Authority.pem
done.
Setting up default-jre-headless (2:1.11-72build2) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Processing triggers for ca-certificates (20211016ubuntu0.22.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.
Setting up openjdk-11-jre-headless:arm64 (11.0.18+10-0ubuntu1~22.04) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: error: error creating symbolic link '/usr/share/man/man1/java.1.gz.dpkg-tmp': No such file or directory <---- ※ エラーが出ている
dpkg: error processing package openjdk-11-jre-headless:arm64 (--configure):
 installed openjdk-11-jre-headless:arm64 package post-installation script subprocess returned error exit status 2
Errors were encountered while processing:
 openjdk-11-jre-headless:arm64
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@jammy64-dev:/# 


ファームウェアの容量削減のため man page を削除するようにしている関係で、“update-alternatives” コマンドがエラーになりパッケージ追加が完了していません。
ダミーでファイルを作成し、設定を完了させます。

root@jammy64-dev:/# mkdir -p /usr/share/man/man1
root@jammy64-dev:/# touch /usr/share/man/man1/java.1.gz.dpkg-tmp

インストールの続きを再実行します。

root@jammy64-dev:/# apt install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
E: Unlocking the slave of master fd 35 failed! - unlockpt (22: Invalid argument)
Setting up openjdk-11-jre-headless:arm64 (11.0.18+10-0ubuntu1~22.04) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/jjs to provide /usr/bin/jjs (jjs) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/pack200 to provide /usr/bin/pack200 (pack200) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/bin/unpack200 to provide /usr/bin/unpack200 (unpack200) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-arm64/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode
root@jammy64-dev:/# 

インストールが完了しました。


動作確認

動作するか確認します。

root@jammy64-dev:/# java --version
openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed mode)
root@jammy64-dev:/# 

動作が確認できました。この環境をファームウェアとしてビルドして完成です。


ファームウェアのビルド

ファームウェアの作成 を参考に、ファームウェアをビルドします。

root@jammy64-dev:/# exit
exit
root@jammy64-dev:/home/user1/work/MAX3xx# 
root@jammy64-dev:/home/user1/work/MAX3xx# ./build_firm.sh -b -k /home/user1/src/MAX3xx/linux-kernel-ti-6.1.y -r max3xx_jammy_openjdk_rootfs -o firmware/max3xx_jammy_openjdk_v6_0_0.img
MAX3xx Firmware build script
* kernelrelease: 6.1.12
  CALL    scripts/checksyscalls.sh
* copying kernel image
* copying DeviceTree blob (arch/arm64/boot/dts/ti/k3-am642-centurysys-metis-00.dtb)
* copying DeviceTree blob (arch/arm64/boot/dts/ti/k3-am642-centurysys-metis-01.dtb)
* copying DeviceTree blob (arch/arm64/boot/dts/ti/k3-am642-centurysys-metis-ext-01.dtbo)
* copying DeviceTree blob (arch/arm64/boot/dts/ti/k3-am642-centurysys-metis-ext-02.dtbo)
* copying DeviceTree blob (arch/arm64/boot/dts/ti/k3-am642-centurysys-metis-mod-01.dtbo)
* copying DeviceTree blob (arch/arm64/boot/dts/ti/k3-am642-centurysys-metis-mod-02.dtbo)
* remove old kernel modules
...
* Firmware filename: /home/user1/work/MAX3xx/firmware/max3xx_jammy_openjdk_v6_0_0.img
Archive:  /home/user1/work/MAX3xx/firmware/max3xx_jammy_openjdk_v6_0_0.img
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
 1679360  Stored  1679360   0% 2023-05-11 10:30 b1a1bbd3  kmod.img
 3824824  Stored  3824824   0% 2023-05-11 10:31 49e281b8  initramfs.img
131538944  Stored 131538944   0% 2023-05-11 10:30 7c2f106c  rootfs.img
17235976  Defl:N  7342466  57% 2023-05-11 10:30 c14b7eed  kernel.img
  143629  Defl:N    32743  77% 2023-05-11 10:30 9bbc644e  .config
   54817  Defl:N    12585  77% 2023-05-11 10:30 70571b03  k3-am642-centurysys-metis-00.dtb
   55231  Defl:N    12691  77% 2023-05-11 10:30 9cf86377  k3-am642-centurysys-metis-01.dtb
    7132  Defl:N     1662  77% 2023-05-11 10:30 b006b511  k3-am642-centurysys-metis-ext-01.dtbo
    7838  Defl:N     1834  77% 2023-05-11 10:30 24ce757a  k3-am642-centurysys-metis-ext-02.dtbo
     579  Defl:N      280  52% 2023-05-11 10:30 045db4c9  k3-am642-centurysys-metis-mod-01.dtbo
     579  Defl:N      280  52% 2023-05-11 10:30 045db4c9  k3-am642-centurysys-metis-mod-02.dtbo
  349067  Defl:N    25317  93% 2023-05-11 10:31 5a9f1021  sbom.json
--------          -------  ---                            -------
154897976         144472986   7%                            12 files
done.
please remove working directory '/home/user1/work/MAX3xx/build_1683768635' manually.
root@jammy64-dev:/home/user1/work/MAX3xx# 

ファームウェアが作成できました。


1)
default-jre-headless
max3xx_devel/customize_firmware/add_openjdk_jre/start.txt · 最終更新: 2023/05/11 10:33 by admin