背景:FPGA的运行需要片上ARM的控制,所以需要针对片上ARM编写的源码并且需要片上ARM执行源码。
目的:运用ARM编译MTCNN的代码,然后在ARM上运行。
目录
一、创建虚拟机
二、虚拟机上编译通过程序
2.1 cmake的编写
2.2 运行
2.3 makefile可否单独对程序make
三、交叉编译openCV
四、运行简单的测试程序
4.1 连接ARM单片机
4.2 运行程序
挂载SD卡
拷贝opencv的lib入单片机
五、交叉编译MTCNN
3.1 交叉编译工具的查找
3.2 编译工具的更改
3.3 加入openCV交叉编译库
参考:
FPGA实践教程(四)片上ARM运行程序 https://blog.csdn.net/weixin_36474809/article/details/80743037
虚拟机相关操作,虚拟机联网,虚拟机安装openCV https://blog.csdn.net/weixin_36474809/article/details/83373908
流程:安装并运行虚拟机——虚拟机上程序gcc通过——虚拟机上程序arm-linux-gcc通过
ARM上运行程序属于嵌入式,
下载并安装VMware workstation
https://baike.baidu.com/item/VMware%20Workstation/9884359?fr=aladdin
打开虚拟机 路径 A:\virtual_machine\ARM-linux
虚拟机相关操作 https://blog.csdn.net/weixin_36474809/article/details/83373908
https://blog.csdn.net/wfei101/article/details/77150234/
https://www.cnblogs.com/cv-pr/p/6206921.html
# version
cmake_minimum_required(VERSION 2.8)
# project name
project(main)
#set environment variables
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(QMAKE_CXXFLAGS "-std=c++11")
#include and link directories(need to be changed when change file location)
include_directories(/home/osrc/Desktop/document/FPGA-mtcnn/include/)
link_directories(/home/osrc/Desktop/document/FPGA-mtcnn/lib/)
#openCV
find_package( OpenCV REQUIRED)
#source directory
AUX_SOURCE_DIRECTORY(./src DIR_SRCS)
#executable file name
add_executable( main ${DIR_SRCS})
#link libraries
target_link_libraries( main ${OpenCV_LIBS} )
#target_link_libraries( main openblas)
我们确保文件夹中只有makefileLists.txt,与src文件,然后cmake .
make直接就能运行。
红框文件均为后来生成的文件。
不可,若将cmakefile系列删除之后,只留makefile文件,程序便无法make。我们通过此步确认了cmake必须自始至终cmake
osrc@osrc-virtual-machine:~/Desktop/document/ARM-mtcnn$ make
CMake Error: The source directory "/home/osrc/Desktop/document/ARM-mtcnn" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
Makefile:266: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
巨难,此步骤过程繁琐,依赖项众多,且极易出现bug,耗时很久。相关过程详细记载见:
虚拟机交叉编译openCV详细步骤及bug解决详解 https://blog.csdn.net/weixin_36474809/article/details/835012073.2
我们编译过后的文件为test可执行文件。在交叉编译完openCV之后,此文件较为简单,具体生成过程见上面。
FPGA实践教程(二)连接片上ARM https://blog.csdn.net/weixin_36474809/article/details/80691642
FPGA实践教程(四)片上ARM运行程序 https://blog.csdn.net/weixin_36474809/article/details/80743037
插电并且连接usb。(虚拟机开启时,usb直接连接到虚拟机上,且一个usb只能连接一个虚拟机或者主机上)
我们需要将设备通过ssh连接到主机上,而不是虚拟机。
VMware连接USB的操作:
设备管理器中找到设备,安装相应的驱动,用SSH打开串口即可
程序拷入SD卡,然后挂载上单片机。
挂载u盘不成功(fat32格式也不行)
zynq> umount /mnt/usb/
umount: can't umount /mnt/usb/: Invalid argument
zynq> mount -t vfat /dev/sda1 /mnt/
mount: mounting /dev/sda1 on /mnt/ failed: No such file or directory
zynq> ls /mnt/
usb
zynq> df -h
Filesystem Size Used Available Use% Mounted on
none 249.5M 0 249.5M 0% /tmp
zynq> fdisk -l
Disk /dev/mmcblk0: 7906 MB, 7906263040 bytes
4 heads, 16 sectors/track, 241280 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 33 3232 102400 c Win95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary
/dev/mmcblk0p2 3233 241280 7617536 83 Linux
Partition 2 does not end on cylinder boundary
fdisk -l
mount -t vfat [硬件目录] [所挂载的文件夹]
zynq> fdisk -lrandom: nonblocking pool is initialized
Disk /dev/mmcblk0: 7906 MB, 7906263040 bytes
4 heads, 16 sectors/track, 241280 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 33 3232 102400 c Win95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary
/dev/mmcblk0p2 3233 241280 7617536 83 Linux
Partition 2 does not end on cylinder boundary
zynq> df -h
Filesystem Size Used Available Use% Mounted on
none 249.5M 0 249.5M 0% /tmp
zynq> mount -t vfat /dev/mmcblk0p1 /mnt/usb/
FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
zynq> ls /mnt/usb/
BOOT.bin test uramdisk.image.gz
System Volume Information uEnv.txt zynqnet
devicetree.dtb uImage
直接运行,运行不成功
zynq> ls
BOOT.bin test uramdisk.image.gz
System Volume Information uEnv.txt zynqnet
devicetree.dtb uImage
zynq> ./test
-/bin/ash: ./test: not found
报错原因: https://blog.csdn.net/yx_l128125/article/details/7418882
原因可能为程序需要的静态库或者动态库没有,所以我们需要将opencv的lib拷入单片机的lib
osrc@osrc-virtual-machine:~/Desktop/document/ARM-mtcnn$ sudo passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
osrc@osrc-virtual-machine:~/Desktop/document/ARM-mtcnn$ su root
Password:
root@osrc-virtual-machine:/home/osrc/Desktop/document/ARM-mtcnn# cd /mnt/workspace/
root@osrc-virtual-machine:/mnt/workspace# find . -name "arm-linux-g*"
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/lib/gcc/arm-linux-gnueabihf
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/bin/arm-linux-gnueabihf-objcopy
。。。
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/arm-linux-gnueabihf
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/arm-linux-gnueabihf/include/c++/5.2.1/arm-linux-gnueabihf
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/libexec/gcc/arm-linux-gnueabihf
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/share/man/man1/arm-linux-gnueabihf-nlmconv.1
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/share/man/man1/arm-linux-gnueabihf-gdbserver.1
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/share/man/man1/arm-linux-gnueabihf-objcopy.1
./Xilinx/SDx/2017.4/gnu/aarch32/5.2.1/lnx64/share/man/man1/arm-linux-gnueabihf-strip.1
。。。
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-objcopy
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-nm
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-cpp
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcov-tool
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcov
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-as
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ld
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-addr2line
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-readelf
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc-nm
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gprof
ranlib
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-objdump
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ar
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-c++filt
/c++/6.2.1/arm-linux-gnueabihf
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/libexec/gcc/arm-linux-gnueabihf
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/share/man/man1/arm-linux-gnueabihf-nlmconv.1
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/share/man/man1/arm-linux-gnueabihf-cpp.1
./Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/share/man/man5/arm-linux-gnueabihf-gdbinit.5
^C
root@osrc-virtual-machine:/mnt/workspace# cd Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# ls
arm-linux-gnueabihf-addr2line arm-linux-gnueabihf-gdb
arm-linux-gnueabihf-ar arm-linux-gnueabihf-gprof
arm-linux-gnueabihf-as arm-linux-gnueabihf-ld
arm-linux-gnueabihf-c++ arm-linux-gnueabihf-ld.bfd
arm-linux-gnueabihf-c++filt arm-linux-gnueabihf-nm
arm-linux-gnueabihf-cpp arm-linux-gnueabihf-objcopy
arm-linux-gnueabihf-elfedit arm-linux-gnueabihf-objdump
arm-linux-gnueabihf-g++ arm-linux-gnueabihf-ranlib
arm-linux-gnueabihf-gcc arm-linux-gnueabihf-readelf
arm-linux-gnueabihf-gcc-6.2.1 arm-linux-gnueabihf-size
arm-linux-gnueabihf-gcc-ar arm-linux-gnueabihf-strings
arm-linux-gnueabihf-gcc-nm arm-linux-gnueabihf-strip
arm-linux-gnueabihf-gcc-ranlib gdbserver
arm-linux-gnueabihf-gcov runtest
arm-linux-gnueabihf-gcov-tool
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# ./arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=./arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/../libexec/gcc/arm-linux-gnueabihf/6.2.1/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /proj/esdt_sdk/gnu_abe/ABE/builds/lin/arm/arm-linux/snapshots//gcc-linaro-snapshot-6.2-2016.11/configure SHELL=/bin/sh --with-bugurl=https://bugs.linaro.org --with-mpc=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libstdcxx-pch --disable-libmudflap --with-cloog=no --with-ppl=no --with-isl=no --disable-nls --enable-c99 --disable-libstdcxx-pch --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --enable-gnu-indirect-function --disable-multilib --with-tune=cortex-a9 --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=arm --disable-multilib --enable-multiarch CFLAGS=-O2 CXXFLAGS=-O2 --disable-silent-rules --enable-libquadmath --enable-libg2c --enable-symvers=gnu --enable-libstdcxx-pch --enable-libssp --disable-libmudflap --enable-checking=release --enable-cheaders=c_global --enable-poison-system-directories --enable-clocale=generic --enable-shared --enable-threads=posix --disable-multilib --enable-c99 --without-local-prefix --enable-lto --disable-bootstrap --with-linker-hash-style=gnu --with-ppl=no --with-cloog=no --without-isl --enable-nls --enable-__cxa_atexit --with-build-sysroot=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabihf/libc --enable-lto --enable-plugins --enable-linker-build-id --enable-long-long --enable-shared --with-sysroot=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabihf/libc --enable-languages=c,c++,lto --enable-checking=yes --disable-bootstrap --with-bugurl=https://bugs.linaro.org --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf --prefix=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 6.2.1 20161114 (Linaro GCC Snapshot 6.2-2016.11)
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# ls
arm-linux-gnueabihf-addr2line arm-linux-gnueabihf-gdb
arm-linux-gnueabihf-ar arm-linux-gnueabihf-gprof
arm-linux-gnueabihf-as arm-linux-gnueabihf-ld
arm-linux-gnueabihf-c++ arm-linux-gnueabihf-ld.bfd
arm-linux-gnueabihf-c++filt arm-linux-gnueabihf-nm
arm-linux-gnueabihf-cpp arm-linux-gnueabihf-objcopy
arm-linux-gnueabihf-elfedit arm-linux-gnueabihf-objdump
arm-linux-gnueabihf-g++ arm-linux-gnueabihf-ranlib
arm-linux-gnueabihf-gcc arm-linux-gnueabihf-readelf
arm-linux-gnueabihf-gcc-6.2.1 arm-linux-gnueabihf-size
arm-linux-gnueabihf-gcc-ar arm-linux-gnueabihf-strings
arm-linux-gnueabihf-gcc-nm arm-linux-gnueabihf-strip
arm-linux-gnueabihf-gcc-ranlib gdbserver
arm-linux-gnueabihf-gcov runtest
arm-linux-gnueabihf-gcov-tool
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# export PATH=${PATH}:Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# pwd
/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# export PATH=${PATH}:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin# arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/../libexec/gcc/arm-linux-gnueabihf/6.2.1/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /proj/esdt_sdk/gnu_abe/ABE/builds/lin/arm/arm-linux/snapshots//gcc-linaro-snapshot-6.2-2016.11/configure SHELL=/bin/sh --with-bugurl=https://bugs.linaro.org --with-mpc=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libstdcxx-pch --disable-libmudflap --with-cloog=no --with-ppl=no --with-isl=no --disable-nls --enable-c99 --disable-libstdcxx-pch --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --enable-gnu-indirect-function --disable-multilib --with-tune=cortex-a9 --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=arm --disable-multilib --enable-multiarch CFLAGS=-O2 CXXFLAGS=-O2 --disable-silent-rules --enable-libquadmath --enable-libg2c --enable-symvers=gnu --enable-libstdcxx-pch --enable-libssp --disable-libmudflap --enable-checking=release --enable-cheaders=c_global --enable-poison-system-directories --enable-clocale=generic --enable-shared --enable-threads=posix --disable-multilib --enable-c99 --without-local-prefix --enable-lto --disable-bootstrap --with-linker-hash-style=gnu --with-ppl=no --with-cloog=no --without-isl --enable-nls --enable-__cxa_atexit --with-build-sysroot=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabihf/libc --enable-lto --enable-plugins --enable-linker-build-id --enable-long-long --enable-shared --with-sysroot=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabihf/libc --enable-languages=c,c++,lto --enable-checking=yes --disable-bootstrap --with-bugurl=https://bugs.linaro.org --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf --prefix=/proj/esdt_sdk/gnu_abe/ABE/builds/abe_check/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 6.2.1 20161114 (Linaro GCC Snapshot 6.2-2016.11)
root@osrc-virtual-machine:/mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin#
在cmakeList.txt中,决定编译工具的为:
#set environment variables
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(QMAKE_CXXFLAGS "-std=c++11") #c++compiler
https://www.cnblogs.com/rickyk/p/3875334.html
更改为我们需要的交叉编译工具
#set environment variables
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
#set(QMAKE_CXXFLAGS "-std=c++11") #c++compiler
SET(CMAKE_CXX_COMPILER /mnt/workspace/Xilinx/SDK/2017.4/gnu/aarch32/lin/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-g++)
但是cmake之后在make时出现报错:
[ 80%] Building CXX object CMakeFiles/main.dir/src/mtcnn.cpp.o
cc1plus: warning: include location "/usr/local/include/opencv" is unsafe for cross-compilation [-Wpoison-system-directories]
cc1plus: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
[100%] Linking CXX executable main
/usr/local/lib/libopencv_videostab.so.2.4.9: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:191: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
说明我们需要对openCV库也进行交叉编译。
交叉编译openCV,我们在完成交叉编译之后再继续对MTCNN进行交叉编译。
#include and link directories(need to be changed when change file location)
include_directories(/home/osrc/Desktop/document/arm/opencv-install/include/)
link_directories(/home/osrc/Desktop/document/arm/opencv-install/lib/)
加入opencv交叉编译之后的库。
root@osrc-virtual-machine:/home/osrc/Desktop/document/ARM-mtcnn# make
[ 20%] Linking CXX executable main
CMakeFiles/main.dir/src/pikaqiu.cpp.o: In function `main':
pikaqiu.cpp:(.text+0x8c): undefined reference to `cv::imread(std::__cxx11::basic_string, std::allocator > const&, int)'
pikaqiu.cpp:(.text+0x184): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
pikaqiu.cpp:(.text+0x198): undefined reference to `cv::imshow(std::__cxx11::basic_string, std::allocator > const&, cv::_InputArray const&)'
依然是openCV的问题,交叉编译程序失败。
未完,后续更新。