如何脱离petalinux环境直接编译vcu-gst-app
Xilinx从2018.1开始,提供了一套基于zcu106的vcu参考设计,目前最新版本是2021.2。
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841711/Zynq+UltraScale+MPSoC+VCU+TRD
里面提供了一套基于GStreamer的程序,即vcu-gst-app。但是这个需要基于petalinux环境编译:
petalinux-build -c vcu-gst-app
如何脱离petalinux直接编译呢,这里以PetaLinux2020.2为例,其他版本也是类似的操作
一、工具准备
1.创建工程
这步与正常的创建petalinux工程一样。详细步骤可以参考
Petalinux快速入门向导 (4) 第三章.PetaLinux开发基本流程
2.编译并安装sdk
编译对应的sdk,后续需要用到这个编译器来编译我们的代码
petalinux-build --sdk
petalinux-package --sysroot
在我的电脑上,工程目录是/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/
安装后的sdk路径是./images/linux/sdk
完整路径是/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk
二、源代码准备
1. 默认的源代码目录
默认源代码位于project-spec/meta-user/recipes-apps/vcu-gst-app目录下
目录结构为
├── files
│ ├── AUTHORS
│ ├── autogen.sh
│ ├── configure.ac
│ ├── COPYING
│ ├── Makefile.am
│ ├── vcu_apm_lib.zip
│ ├── vcu_gst_app.zip
│ ├── vcu_gst_lib.zip
│ └── vcu_video_lib.zip
├── README
└── vcu-gst-app.bb
1 directory, 11 files
2.整理后的代码目录
创建新目录/opt/work/p202/vcu-gst-app,再创建app,把vcu_gst_app.zip解压到目录下
创建lib子目录,把另外3个压缩包解压到目录下。
完整的目录结构为
.
├── app
│ └── vcu_gst_app
│ ├── include
│ │ ├── configs.h
│ │ └── vcu_gst_app.h
│ ├── input.cfg
│ └── src
│ └── vcu_gst_app.c
├── autogen.sh
├── configure.ac
├── lib
│ ├── vcu_apm_lib
│ │ ├── include
│ │ │ ├── perfapm.h
│ │ │ ├── uio_common.h
│ │ │ ├── uio_perfmon.h
│ │ │ └── uio_perfmon_hw.h
│ │ ├── README.md
│ │ └── src
│ │ ├── perfmon.c
│ │ ├── uio_common.c
│ │ └── uio_perfmon.c
│ ├── vcu_gst_lib
│ │ ├── include
│ │ │ ├── vgst_config.h
│ │ │ ├── vgst_err.h
│ │ │ ├── vgst_lib.h
│ │ │ ├── vgst_pipeline.h
│ │ │ ├── vgst_split_pipeline.h
│ │ │ └── vgst_utils.h
│ │ ├── README.md
│ │ └── src
│ │ ├── vgst_lib.c
│ │ ├── vgst_pipeline.c
│ │ ├── vgst_split_pipeline.c
│ │ └── vgst_utils.c
│ └── vcu_video_lib
│ ├── include
│ │ ├── drm_helper.h
│ │ ├── gpio_utils.h
│ │ ├── helper.h
│ │ ├── mediactl_helper.h
│ │ ├── v4l2_subdev_helper.h
│ │ ├── vcap_csi.h
│ │ ├── vcap_csi_int.h
│ │ ├── vcap_hdmi_int.h
│ │ ├── vcap_quad_csi.h
│ │ ├── vcap_quad_csi_int.h
│ │ ├── vcap_scd_int.h
│ │ ├── vcap_sdi_int.h
│ │ ├── vcap_tpg.h
│ │ ├── vcap_tpg_int.h
│ │ ├── video.h
│ │ ├── video_int.h
│ │ └── xilinx-v4l2-controls.h
│ └── src
│ ├── drm_helper.c
│ ├── gpio_utils.c
│ ├── mediactl_helper.c
│ ├── v4l2_subdev_helper.c
│ ├── vcap_csi.c
│ ├── vcap_hdmi.c
│ ├── vcap_quad_csi.c
│ ├── vcap_scd.c
│ ├── vcap_sdi.c
│ ├── vcap_tpg.c
│ ├── video.c
│ └── video_src.c
└── Makefile.am
14 directories, 55 files
三、配置Makefile
1.修改Makefile.am中的默认路径
1.1 修改路径recipe-sysroot
打开gedit Makefile.am ,搜索recipe-sysroot
共搜索到4处
vcu_gst_app_CFLAGS = $(VCU_GST_CFLAGS) -I$(vcu_gst_app_INC_DIR) -I$(vcu_apm_lib_INC_DIR) -I$(vcu_video_lib_INC_DIR) -I$(vcu_gst_lib_INC_DIR) -I../recipe-sysroot/usr/include/drm -I../recipe-sysroot/usr/include
libvcu_apm_lib_a_CFLAGS = $(VCU_GST_CFLAGS) -I$(vcu_apm_lib_INC_DIR)
libvideo_a_CFLAGS = $(VCU_GST_CFLAGS) -I$(vcu_video_lib_INC_DIR) -I../recipe-sysroot/usr/include/drm -I../recipe-sysroot/usr/include
因为这个路径与实际的路径不符,所以需要修改这几个地方
比如,在我的电脑,路径为/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux,所以要把
…/recipe-sysroot
替换成
/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux
替换后如下:
vcu_gst_app_CFLAGS = $(VCU_GST_CFLAGS) -I$(vcu_gst_app_INC_DIR) -I$(vcu_apm_lib_INC_DIR) -I$(vcu_video_lib_INC_DIR) -I$(vcu_gst_lib_INC_DIR) -I/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux/usr/include/drm -I/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux/usr/include
libvcu_apm_lib_a_CFLAGS = $(VCU_GST_CFLAGS) -I$(vcu_apm_lib_INC_DIR)
libvideo_a_CFLAGS = $(VCU_GST_CFLAGS) -I$(vcu_video_lib_INC_DIR) -I/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux/usr/include/drm -I/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux/usr/include
1.2修改路径…/vcu_gst_apps/
…/vcu_gst_apps/要求项目所在的目录名必须是vcu_gst_apps,这明显不合理,实际只需要使用当前路径**./**即可
vcu_gst_app_INC_DIR = ../vcu_gst_apps/app/vcu_gst_app/include
vcu_apm_lib_INC_DIR = ../vcu_gst_apps/lib/vcu_apm_lib/include
vcu_video_lib_INC_DIR = ../vcu_gst_apps/lib/vcu_video_lib/include
vcu_gst_lib_INC_DIR = ../vcu_gst_apps/lib/vcu_gst_lib/include
把…/vcu_gst_apps修改为./
vcu_gst_app_INC_DIR = ./app/vcu_gst_app/include
vcu_apm_lib_INC_DIR = ./lib/vcu_apm_lib/include
vcu_video_lib_INC_DIR = ./lib/vcu_video_lib/include
vcu_gst_lib_INC_DIR = ./lib/vcu_gst_lib/include
2.运行autogen.sh
./autogen.sh --host=arm
xlx@u16:/opt/work/p202/vcu-gst-app$ ./autogen.sh --host=arm
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force --warnings=no-portability
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
autoreconf: running: /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/x86_64-petalinux-linux/usr/bin/autoconf --force --warnings=no-portability
autoreconf: running: /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/x86_64-petalinux-linux/usr/bin/autoheader --force --warnings=no-portability
autoreconf: running: automake --add-missing --copy --force-missing --warnings=no-portability
configure.ac:20: installing './compile'
configure.ac:24: installing './config.guess'
configure.ac:24: installing './config.sub'
configure.ac:14: installing './install-sh'
configure.ac:14: installing './missing'
Makefile.am: installing './depcomp'
Makefile.am:95: warning: variable 'libvcu_gst_lib_a_LDFLAGS' is defined but no program or
Makefile.am:95: library has 'libvcu_gst_lib_a' as canonical name (possible typo)
autoreconf: running: gnu-configize
autoreconf: no config.status: cannot re-make
autoreconf: Leaving directory `.'
configure: loading site script /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/site-config-aarch64-xilinx-linux
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/opt/work/p202/vcu-gst-app':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
configure failed
3.运行configure生成Makefile
./configure --host=arm
xlx@u16:/opt/work/p202/vcu-gst-app$ ./configure --host=arm
configure: loading site script /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/site-config-aarch64-xilinx-linux
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-strip... aarch64-xilinx-linux-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... yes
checking whether make supports the include directive... yes (GNU style)
checking for arm-gcc... aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux accepts -g... yes
checking for aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux option to accept ISO C89... none needed
checking whether aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux understands -c and -o together... yes
checking dependency style of aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux... gcc3
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-none
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux... aarch64-xilinx-linux-ld --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux
checking if the linker (aarch64-xilinx-linux-ld --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... aarch64-xilinx-linux-nm
checking the name lister (aarch64-xilinx-linux-nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to arm-unknown-none format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for aarch64-xilinx-linux-ld --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux option to reload object files... -r
checking for arm-objdump... aarch64-xilinx-linux-objdump
checking how to recognize dependent libraries... unknown
checking for arm-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for arm-ar... aarch64-xilinx-linux-ar
checking for archiver @FILE support... @
checking for arm-strip... (cached) aarch64-xilinx-linux-strip
checking for arm-ranlib... aarch64-xilinx-linux-ranlib
checking command to parse aarch64-xilinx-linux-nm output from aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux object... ok
checking for sysroot... /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for arm-mt... no
checking for mt... mt
configure: WARNING: using cross tools not prefixed with host triplet
checking if mt is a manifest tool... no
checking how to run the C preprocessor... aarch64-xilinx-linux-gcc -E -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux supports -fno-rtti -fno-exceptions... no
checking for aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux option to produce PIC... -fPIC -DPIC
checking if aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux PIC flag -fPIC -DPIC works... yes
checking if aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux static flag -static works... no
checking if aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux supports -c -o file.o... yes
checking if aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux supports -c -o file.o... (cached) yes
checking whether the aarch64-xilinx-linux-gcc -march=armv8-a+crc -mtune=cortex-a72.cortex-a53 --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux linker (aarch64-xilinx-linux-ld --sysroot=/opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/aarch64-xilinx-linux) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... no
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for pkg-config...
checking for arm-pkg-config... no
checking for pkg-config... /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/sysroots/x86_64-petalinux-linux/usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for
gstreamer-1.0 >= 1.0.0
gstreamer-base-1.0 >= 1.0.0
... yes
checking to see if compiler understands -Wall... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
四.make
1.初始化sdk的环境变量
source运行environment-setup-aarch64-xilinx-linux配置
source /opt/work/p202/xilinx-vcu-zcu106-v2020.2-final/images/linux/sdk/environment-setup-aarch64-xilinx-linux
2.make
执行make即可编译生成后会生成vcu-gst-app
用readelf命令可以查看文件格式
xlx@u16:/opt/work/p202/vcu-gst-app$ readelf -h vcu_gst_app
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x4010
Start of program headers: 64 (bytes into file)
Start of section headers: 679008 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 37
Section header string table index: 36