Armadilloフォーラム

Kernel更新後、Bluetoothが使えない

gt777

2023年6月15日 18時55分

お世話になっております。

Armadillo-IoTゲートウェイ G4 LTE+WLANモデル 開発セット を使って開発しております。
ストレージ暗号化後、Bluetoothが使用できなくなってしまいました。

もともとWLAN(mlan0)も見えなくなっていたのですが、
https://armadillo.atmark-techno.com/blog/10899/14608
こちらの手順を参照し、/sbin/depmod -ae -F System.map -b "$BROOTFS/ax2/resources" "$KVER"でモジュールがロードされるようにした後、mlan0は使用できるようになりました。
しかし、コンテナ上のPythonアプリケーションからBLEスキャンを実施しようとすると「No Bluetooth adapters found.」というエラーが出力されてしまいます。

BLEモジュールの状態を確認する方法はありますでしょうか。

暗号化していない(カーネル更新をしていない)Armadilloで同じコンテナを起動したところ特にエラーはありませんでしたので、Pythonプログラムの問題ではないと考えております。

root@armadillo:/# python
Python 3.11.3 (main, Jun  1 2023, 23:25:03) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from bleak import BleakScanner
>>> import asyncio
>>> async def _ble_scan():
...     async with BleakScanner() as scanner:
...         await asyncio.sleep(1)
...     scanned_data = scanner.discovered_devices_and_advertisement_data
...     print(scanned_data)
...
>>> asyncio.run(_ble_scan())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<stdin>", line 2, in _ble_scan
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 152, in __aenter__
    await self._backend.start()
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 179, in start
    adapter_path = manager.get_default_adapter()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 299, in get_default_adapter
    raise BleakError("No Bluetooth adapters found.")
bleak.exc.BleakError: No Bluetooth adapters found.
コメント

gt777

2023年6月16日 8時58分

補足

・ホストOS側で確認しても、Bluetoothが正常に取得できていないようでした。

armadillo:~# service bluetooth start
bluetooth                | * Starting Bluetooth ...                                                                            [ ok ]
armadillo:~# bluetoothctl
Agent registered
[bluetooth]# scan on
No default controller available
[bluetooth]# exit

・カーネルコンフィグ、/boot/overlays.txtが「製品マニュアル 11.10. BT」の通りになっていることは確認済
・lsmod、modinfoを暗号化未実施(カーネル更新未実施)のデバイスと比較してみましたが、特に差分なし

他に確認すべき項目があればご教示ください。

at_dominique.m…

2023年6月16日 9時26分

gt777さん、

お世話になっています、
アットマークテクノのマルティネです。

> ・/boot/overlays.txtが「製品マニュアル 11.10. BT」の通りになっていることは確認済

ディスク暗号化のある個体ですね?
すみません、手順の問題です。ディスク暗号化の場合は overlays.txt を読み取りできないため、「fdt_overlays」の u-boot 変数をあらかじめ登録する必要があります。
PCI の設定はメインの dts にあるため wifi の方が dtbo 無しでも動きますが、bluetooth には overlay が必要です。

/boot/overlays.txt を /boot/uboot_env.d/50_overlays 等に移動させて、変数を保存すれば使えるようになると思います。

armadillo:~# mv /boot/overlays.txt /boot/uboot_env.d/50_overlays
# 設定のすぐに適用
armadillo:~# fw_setenv -s /boot/uboot_env.d/50_overlays
Environment OK, copy 0
# 確認
armadillo:~# fw_printenv fdt_overlays
Environment OK, copy 1
fdt_overlays=armadillo_iotg_g4-aw-xm458.dtbo
# 永続化。これからの変数は swupdate で設定されつづきます。
armadillo:~# persist_file -v /boot/overlays.txt /boot/uboot_env.d/50_overlays
removed '/mnt/boot/overlays.txt'
'/boot/uboot_env.d/50_overlays' -> '/mnt/boot/uboot_env.d/50_overlays'

u-boot のログに「Applying fdt overlay: armadillo_iotg_g4-aw-xm458.dtbo」のメッセージが表示するようになるはずで、linux では「/sys/class/bluetooth/hci0」のリンクが作成されるはずです。

設定ファイルの場所でご迷惑をお掛けしてすみません。

よろしくお願いします。

gt777

2023年6月16日 10時00分

マルティネさん

手順のご教示ありがとうございます。
実施してみましたが、相変わらずエラーとなります。

> u-boot のログに「Applying fdt overlay: armadillo_iotg_g4-aw-xm458.dtbo」のメッセージが表示するようになるはずで、linux では「/sys/class/bluetooth/hci0」のリンクが作成されるはずです。
再起動してみたところ、u-boot のログに「Applying fdt overlay: armadillo_iotg_g4-aw-xm458.dtbo」出力されましたが、
Armadillo上にlinux 「/sys/class/bluetooth/hci0」のリンクが作成されておりませんでした。

armadillo:~# ls -ltrh /sys/class/bluetooth
total 0

何か手順が不足しているでしょうか?

また、本手順は、Armadillo上でファイルを直接修正する方法しかないでしょうか?
暗号化のインストール時に合わせて適用する手順はあるでしょうか。

ファイル ファイルの説明
fdt_overlays修正ログ.log

at_dominique.m…

2023年6月16日 10時27分

gt777さん、

> 再起動してみたところ、u-boot のログに「Applying fdt overlay: armadillo_iotg_g4-aw-xm458.dtbo」出力されましたが、

(すみません、暗号化の場合は「Appending」でしたね)

> Armadillo上にlinux 「/sys/class/bluetooth/hci0」のリンクが作成されておりませんでした。

カーネルイメージに組み込まれてない overlay はロードできませんので、エラーしていますね:

   Hash(es) for Image 0 (kernel): 
   Hash(es) for Image 1 (fdt): 
   Hash(es) for Image 2 (ramdisk): 
   Hash(es) for Image 3 (armadillo_iotg_g4-nousb.dtbo): 
   Hash(es) for Image 4 (armadillo_iotg_g4-sw1-wakeup.dtbo): 
...
## Loading fdt from FIT Image at 40480000 ...
Could not find configuration node
load of <NULL> failed
## Loading fdt from FIT Image at 40480000 ...
Could not find configuration node
load of <NULL> failed

overlays.txt を読み取れないと同じく、/boot/xxx.dtb を読み取れないので、カーネルイメージに組み込まれています(同時に、使える dtbo にもセキュアブートのための証明を行っています)

imx-boot ディレクトリにある secureboot.conf の「LINUX_DTB_OVERLAYS」変数を直してください:
- nousb / sw1-wakeup のデフォルトに入れているオーバーレイは使われていなさそうなので、削除していいです
- lte/aw-xm458 の方を追加してください。

secureboot.sh linux で再生成して、再び swdesc_boot_linux でインストールしてください
(以前話していた uboot のバージョンを暗号化で確認できない問題がありますので、mkswu リポジトリの「test」ブランチを git pull で更新するか、エラーになった際のとおりに「MKSWU_NO_ARCH_CHECK=1 swupdate -d ...」で更新していいはずです)

> また、本手順は、Armadillo上でファイルを直接修正する方法しかないでしょうか?
> 暗号化のインストール時に合わせて適用する手順はあるでしょうか。

ファイルを動かしているだけですので、rootfs を保存したいばあいに「swdesc_command mv /boot/overlays.txt /boot/uboot_env.d/50_overlays」、そうでない場合は build-rootfs ディレクトリの ax2/resources/boot/uboot_env.d ディレクトリにファイルを追加するだけでもいいです。

よろしくお願いします。

gt777

2023年6月16日 12時33分

マルティネさん

以下のファイルを修正し、再作成したImage.signedとbaseos-x2-3.17.3-at.6.yyyymmdd.tar.zstを組み込んだところ、正常にBluetoothが使用できるようになりました。
ありがとうございました。
※LTE用のdtboも取り込めていなかったようなので、そちらも併せて設定しました

・imx-boot ディレクトリにある secureboot.conf の「LINUX_DTB_OVERLAYS」変数を修正

atmark@atde9:~/imx-boot-2020.04-at14$ cat secureboot.conf
(略)
LINUX_DTB_OVERLAYS=(
        armadillo_iotg_g4-lte-ext-board.dtbo
        armadillo_iotg_g4-aw-xm458.dtbo
)
(略)

・build-rootfs ディレクトリの ax2/resources/boot/uboot_env.d ディレクトリにファイルを追加

atmark@atde9:~/build-rootfs-v3.17-at.6$ cat ax2/resources/boot/uboot_env.d/50_overlays
fdt_overlays=armadillo_iotg_g4-lte-ext-board.dtbo armadillo_iotg_g4-aw-xm458.dtbo

bootログ

   Hash(es) for Image 0 (kernel):
   Hash(es) for Image 1 (fdt):
   Hash(es) for Image 2 (ramdisk):
   Hash(es) for Image 3 (armadillo_iotg_g4-lte-ext-board.dtbo):
   Hash(es) for Image 4 (armadillo_iotg_g4-aw-xm458.dtbo):
Appending overlay armadillo_iotg_g4-lte-ext-board.dtbo
Appending overlay armadillo_iotg_g4-aw-xm458.dtbo
(略)
## Loading fdt from FIT Image at 40480000 ...
   Using 'armadillo_iotg_g4-lte-ext-board.dtbo' configuration
   Trying 'armadillo_iotg_g4-lte-ext-board.dtbo' fdt subimage
     Description:  armadillo_iotg_g4-lte-ext-board.dtbo
(略)
## Loading fdt from FIT Image at 40480000 ...
   Using 'armadillo_iotg_g4-aw-xm458.dtbo' configuration
   Trying 'armadillo_iotg_g4-aw-xm458.dtbo' fdt subimage
     Description:  armadillo_iotg_g4-aw-xm458.dtbo
(略)