lp6m’s blog

いろいろかきます

Ubuntu on ZYBO Z7-20からPCam 5Cの映像を取得したい(失敗)

Digilent社製ZYBO Z7-20でUbuntuを動作させ、PCamの映像を取得したい。
store.digilentinc.com
store.digilentinc.com

git cloneしてサンプルを試す:成功

Petalinuxツールを使用してZYBO上で動作するLinuxカーネル・rootfsを作成することができる。
Digilentgithubにサンプルがあるのでこれをcloneする。
github.com

デフォルトではRAMにrootfsを展開する設定(initramfs)になっているので、githubのREADMEのBoot the newly built files from SDに書いてあるとおりに、SD Bootに変更・system-user.dtsi のbootargsを変更した。

第一パーティションカーネルとイメージ(BOOT.BIN・image.ub)をコピー
第二パーティションにROOTFSをコピー(images/linus/rootfs.tar.gzを展開)

起動確認、githubのREADMEに書いてあるとおりのコマンドでPCamからの映像を取得成功

width=1920
height=1080
rate=15
media-ctl -d /dev/media0 -V '"ov5640 2-003c":0 [fmt:UYVY/'"$width"x"$height"'@1/'"$rate"' field:none]'
media-ctl -d /dev/media0 -V '"43c60000.mipi_csi2_rx_subsystem":0 [fmt:UYVY/'"$width"x"$height"' field:none]'
v4l2-ctl -d /dev/video0 --set-fmt-video=width="$width",height="$height",pixelformat='YUYV'
yavta -c14 -f YUYV -s "$width"x"$height" -F /dev/video0

rootfsをUbuntuに変更

Petalinuxでビルドしたrootfsではapt-getなどのパッケージ管理システムを使用することができない。
ARM用にビルドされたUbuntuのrootfsをダウンロードしてarmhf-rootfs-ubuntu-xenial.tar を第二パーティションに展開
参考;ZYBO-Z7を用いたLチカ(Ubuntu16.04編) - aster_ismの工作室

wget https://rcn-ee.com/rootfs/eewiki/minfs/ubuntu-16.04.3-minimal-armhf-2017-10-07.tar.xz

Ubuntuの起動確認・必要なソフトウェアのインストール

Ubuntuの起動を確認。

v4l-utilsをインストール

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install v4l-utils

※電源が不安定になりapt-get upgrade中にボードが再起動することがあるので、補助電源をボードに接続する・電流が大きいものを使用するなどして対処

yavtaのインストール・yavtaはapt-getでは入らない

sudo apt-get install build-essential
git clone https://github.com/fastr/yavta
cd yavta
make

*画像取得(失敗)
sudoをつけた以下のコマンドを実行

width=1920
height=1080
rate=15
sudo media-ctl -d /dev/media0 -V '"ov5640 2-003c":0 [fmt:UYVY/'"$width"x"$height"'@1/'"$rate"' field:none]'
sudo media-ctl -d /dev/media0 -V '"43c60000.mipi_csi2_rx_subsystem":0 [fmt:UYVY/'"$width"x"$height"' field:none]'
v4l2-ctl -d /dev/video0 --set-fmt-video=width="$width",height="$height",pixelformat='YUYV'
./yavta/yavta -c14 -f YUYV -s "$width"x"$height" -F /dev/video0

yavtaを実行するとエラーが起きる。

Error opening device /dev/video0: neither video capture nor video output supported.

yavtaの実装を見て調べたところ、 yavta.cの121行目でioctl()を使ってデバイスの属性を取得した際にカメラの属性が取得できていない

原因究明

必要なドライバがロードされていないのでは?と思いdmesgやls /sys/moduleの結果を比較したが特に理由は見つからない・・・

また、petalinux-config -c kernelによるカーネルの設定でXilinx Video IPのドライバを、カーネルにビルトインする設定からモジュールに変更してみた。
ビルドしたpetalinuxのrootfsの/libフォルダ内に読み込むべきドライバが生成されるので、それらをubuntuの/libにコピーしてみた。しかし、同様にエラーでカメラの映像を取得することができない・・・

dmesgおよびls /sys/moduleの結果をpetalinuxのときとUbuntuのとき両方を貼っておく。

  • 成功したほうのdmesg

petalinux_dmesg.log · GitHub

  • 失敗したほうのdmesg

ubuntu_dmesg.log · GitHub

  • 成功したほうのls /sys/module

petalinux_sys_module.log · GitHub

  • 失敗したほうのls /sys/module

ubuntu_sys_module.log · GitHub