【分享】PetaLinu小技巧7則


作者: 付漢傑 hankf@xilinx.com hankf@amd.com
測試環境: Vivado/PetaLinux 2021.2, Linux 5.10.0

如何修改u-boot的boot.scr

修改修改components/yocto/layers/meta-xilinx/meta-xilinx-bsp/recipes-bsp/u-boot/u-boot-zynq-scr/ boot.cmd.generic,可以修改u-boot的boot.scr。

如何查找Linux kernel編譯日志

按下列步驟,查找Linux kernel編譯日志存儲

  1. 進入petalinux工程的“build/tmp”子目錄
[hankf@localhost tmp]$ pwd
/home/hankf/proj/vck190/vck190-0316-peta/build/tmp
  1. 查找目錄“kernel-source”
[hankf@localhost tmp]$ find -name "kernel-source" 
./work-shared/versal-generic/kernel-source
  1. 進入目錄 kernel-source,並查看文件
[hankf@localhost tmp]$ cd work-shared/versal-generic/kernel-source/
[hankf@localhost kernel-source]$ ls 
arch   COPYING  Documentation  include  Kbuild     mm       oe-workdir  scripts   tools
block  CREDITS  drivers        init     Kconfig  lib                                             MAINTAINERS                         net      README      security  usr
certs  crypto   fs             ipc      kernel   LICENSES                                        Makefile                             oe-logs  samples     sound     virt
  1. 進入目錄“oe-logs”查找“log.do_compile_kernel*”文件

查看最近修改文件,或者log.do_compile_kernel* 文件。 最新的log.do_compile_kernel*文件,就是kernel的gcc編譯日志。

[hankf@localhost kernel-source]$ cd oe-logs/
[hankf@localhost oe-logs]$ ls -alrt | tail -n 10
-rw-rw-r--.  1 hankf hankf  26082 Mar 17 04:00 run.extend_recipe_sysroot.18319
-rw-rw-r--.  1 hankf hankf   5488 Mar 17 04:00 log.task_order
lrwxrwxrwx.  1 hankf hankf     34 Mar 17 04:00 log.do_compile_kernelmodules -> log.do_compile_kernelmodules.18330
lrwxrwxrwx.  1 hankf hankf     30 Mar 17 04:00 run.do_assemble_fitimage -> run.do_assemble_fitimage.18319
lrwxrwxrwx.  1 hankf hankf     34 Mar 17 04:00 run.do_compile_kernelmodules -> run.do_compile_kernelmodules.18330
-rwxrwxr-x.  1 hankf hankf  23283 Mar 17 04:00 run.do_compile_kernelmodules.18330
-rwxrwxr-x.  1 hankf hankf  24552 Mar 17 04:00 run.do_assemble_fitimage.18319
-rw-rw-r--.  1 hankf hankf   3950 Mar 17 04:00 log.do_assemble_fitimage.18319
-rw-rw-r--.  1 hankf hankf  17835 Mar 17 04:00 log.do_compile_kernelmodules.18330
drwxrwxr-x.  2 hankf hankf  36864 Mar 17 04:00 .

[hankf@localhost oe-logs]$ ls log.do_compile_kernel*
log.do_compile_kernelmodules        log.do_compile_kernelmodules.11901  log.do_compile_kernelmodules.19287  log.do_compile_kernelmodules.24979
log.do_compile_kernelmodules.11390  log.do_compile_kernelmodules.18330  log.do_compile_kernelmodules.19623
[1]+  Done                    gedit log.do_compile_kernelmodules.18330

[hankf@localhost oe-logs]$ gedit log.do_compile_kernelmodules.18330  &
[1] 20997

CentOS 7.9 下如何使用PetaLinux 2021.2

在CentOS 7.9 下使用PetaLinux 2021.2編譯工程,會得到告警“Seems like your machine does not have gcc 6 or greater version”,並且不能編譯。

[root@localhost vck190-0316-peta]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:        7.9.2009
Codename:       Core

[root@localhost vck190-0316-peta]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

[hankf@localhost vck190-0316-peta]$ petalinux-build 
[INFO] Sourcing buildtools
[INFO] Building project
WARNING: Seems like your machine does not have gcc 6 or greater version,
Please enable buildtools Extended in petalinux-config --> yocto settings
[INFO] Extracting yocto SDK to components/yocto. This may take time!
ERROR: Failed to Extract Yocto SDK.
ERROR: Failed to build project. Check the /home/hankf/proj/vck190/dapd-0305-colour-peta/build/build.log file for more details...

CentOS 7.9自帶的GCC是4.8.5,太舊了。PetaLinux要求gcc 6或者更高版本。 通過工具SCL,是可以在同一個系統上編譯,安裝,並且使用多個版本的軟件。使用下列命令,為CentOS 7.9安裝GCC 7.

sudo yum install centos-release-scl

sudo yum install devtoolset-7

然后通過下列命令啟動一個新的 shell,就可以使用GCC 7

scl enable devtoolset-7 bash

gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

注意,不能把“scl enable devtoolset-7 bash”加入".bashrc",它會導致命令行出現以下錯誤。

bash: fork: retry: No child processes
bash: fork: retry: No child processes
bash: fork: Resource temporarily unavailable

也可以在菜單“petalinux-config  → Yocto Settings  → Enable Buildtools Extended”, 使能“Enable Buildtools Extended”,從而使用PetaLinux自帶的GCC。

glibc git: No such file or directory

使用template新建的PetaLinux工程,編譯遇到錯誤“glibc/2.32-r0/git: No such file or directory”。
更多信息如下。
再次執行petalinux-build,能正常編譯通過。

NOTE: Running ../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git/configure  --build=x86_64-linux 		  --host=aarch64-xilinx-linux 		  --target=aarch64-xilinx-linux 		  --prefix=/usr 		  --exec_prefix=/usr 		  --bindir=/usr/bin 		  --sbindir=/usr/sbin 		  --libexecdir=/usr/libexec 		  --datadir=/usr/share 		  --sysconfdir=/etc 		  --sharedstatedir=/com 		  --localstatedir=/var 		  --libdir=/usr/lib 		  --includedir=/usr/include 		  --oldincludedir=/usr/include 		  --infodir=/usr/share/info 		  --mandir=/usr/share/man 		  --disable-silent-rules 		  --disable-dependency-tracking 		  --with-libtool-sysroot=/home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/recipe-sysroot --enable-kernel=3.14                 --disable-profile                 --disable-debug --without-gd                 --enable-clocale=gnu                 --with-headers=/home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/recipe-sysroot/usr/include                 --without-selinux                 --enable-tunables                 --enable-bind-now                 --enable-stack-protector=strong                 --enable-stackguard-randomization                 --disable-crypt                 --with-default-link                                                     --disable-static  --enable-nscd 

../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git/configure: line 1323: cd: ../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git: No such file or directory


configure: error: sources are in ../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git, but `cd ../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git' does not work
checking build system type... x86_64-pc-linux-gnu
checking host system type... aarch64-xilinx-linux-gnu
checking for aarch64-xilinx-linux-gcc... aarch64-xilinx-linux-gcc  -mcpu=cortex-a72.cortex-a53 -march=armv8-a+crc  --sysroot=/home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/recipe-sysroot
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether aarch64-xilinx-linux-gcc  -mcpu=cortex-a72.cortex-a53 -march=armv8-a+crc  --sysroot=/home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/recipe-sysroot accepts -g... yes
checking for gcc... gcc 
checking for aarch64-xilinx-linux-readelf... aarch64-xilinx-linux-readelf
checking whether we are using the GNU C++ compiler... yes
checking whether aarch64-xilinx-linux-g++  -mcpu=cortex-a72.cortex-a53 -march=armv8-a+crc  --sysroot=/home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/recipe-sysroot accepts -g... yes
checking whether aarch64-xilinx-linux-g++  -mcpu=cortex-a72.cortex-a53 -march=armv8-a+crc  --sysroot=/home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/recipe-sysroot can link programs... no
../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git/configure: line 3253: cd: ../../../../../../../../../../../home/hankf/proj/vck190/vck190-0316-peta/build/tmp/work/cortexa72-cortexa53-xilinx-linux/glibc/2.32-r0/git: No such file or directory
configure: error: you must configure in a separate build directory

修改文件變化通知機制Inotify的限制

編譯PetaLinux 2021.2工程,遇到錯誤“Too many open files”。編譯的命令行錯誤如下:

[hankf@localhost vck190-0316-peta]$ petalinux-build
[INFO] Sourcing buildtools
[INFO] Building project
[INFO] Sourcing build environment
[INFO] Adding user layers
ERROR: Failed to add user layer: /home/hankf/proj/vck190/vck190-0316-peta/project-spec/meta-user
ERROR: Failed to build project. Check the /home/hankf/proj/vck190/vck190-0316-peta/build/build.log file for more details...

build.log的內容如下:

NOTE: Starting bitbake server...
ERROR: Unable to start bitbake server (None)
ERROR: Server log for this session (/proj/hankf/vck190/vck190-0316-peta/build/bitbake-cookerdaemon.log):
3577 03:25:27.646174 --- Starting bitbake server pid 3577 at 2022-03-16 03:25:27.646160 ---
Traceback (most recent call last):
  File "/proj/hankf/vck190/vck190-0316-peta/components/yocto/layers/core/bitbake/bin/bitbake-server", line 53, in <module>
    bb.server.process.execServer(lockfd, readypipeinfd, lockname, sockname, timeout, xmlrpcinterface)
  File "/proj/hankf/vck190/vck190-0316-peta/components/yocto/layers/core/bitbake/lib/bb/server/process.py", line 542, in execServer
    cooker = bb.cooker.BBCooker(featureset, server.register_idle_function)
  File "/proj/hankf/vck190/vck190-0316-peta/components/yocto/layers/core/bitbake/lib/bb/cooker.py", line 169, in __init__
    self.configwatcher = pyinotify.WatchManager()
  File "/proj/hankf/vck190/vck190-0316-peta/components/yocto/layers/core/bitbake/lib/pyinotify.py", line 1748, in __init__
    raise OSError(err % self._inotify_wrapper.str_errno())
OSError: Cannot initialize new instance of inotify, Errno=Too many open files (EMFILE)

修改max_user_instances,可以修正錯誤,成功編譯。

[hankf@localhost vck190-0316-peta]$ cat /proc/sys/fs/inotify/max_user_instances
128
[hankf@localhost vck190-0316-peta]$ sudo echo 99999999 > /proc/sys/fs/inotify/max_user_instances
bash: /proc/sys/fs/inotify/max_user_instances: Permission denied
[hankf@localhost vck190-0316-peta]$ ls -l -h /proc/sys/fs/inotify/max_user_instances
-rw-r--r--. 1 root root 0 Mar 15 23:31 /proc/sys/fs/inotify/max_user_instances
[hankf@localhost vck190-0316-peta]$ sudo su
[sudo] password for hankf:
[root@localhost vck190-0316-peta]# echo 99999999 > /proc/sys/fs/inotify/max_user_instances
[root@localhost vck190-0316-peta]# cat /proc/sys/fs/inotify/max_user_instances
99999999
[root@localhost vck190-0316-peta]# exit
exit
[hankf@localhost vck190-0316-peta]$ petalinux-build
[INFO] Sourcing buildtools
[INFO] Building project
[INFO] Sourcing build environment
[INFO] Adding user layers
[INFO] Generating workspace directory
..........

為了永久生效,需要在文件/etc/sysctl.conf里增加下列行。

fs.inotify.max_user_instances = 256

petalinuxbsp.conf里的RM_WORK_EXCLUDE行后不能加注釋

在petalinuxbsp.conf的RM_WORK_EXCLUDE加注釋,引起錯誤“unparsed line: 'RM_WORK_EXCLUDE += "linux-xlnx" # good'”。 去掉后面的注釋,錯誤消失。錯誤信息如下。

NOTE: Starting bitbake server...
NOTE: No reply from server in 30s
ERROR: ParseError at /home/hankf/proj/vck190/vck190-0316-peta/project-spec/meta-user/conf/petalinuxbsp.conf:20: unparsed line: 'RM_WORK_EXCLUDE += "linux-xlnx"  # good'
ERROR: ParseError at /home/hankf/proj/vck190/vck190-0316-peta/project-spec/meta-user/conf/petalinuxbsp.conf:20: unparsed line: 'RM_WORK_EXCLUDE += "linux-xlnx"  # good'
ERROR: Exception in server main event loop running command [] ()
Traceback (most recent call last):
..........

使用gFTP更新單板系統映像

調試時,修改Linux代碼、Linux驅動代碼、Devicetree后,需要重新生成V單板系統映像的boot.bin, image.ub等文件。
如果單板從TF卡啟動,一般需要把上面的文件復制到TF卡上。傳統做法,是拔插TF卡到PC機,復制后再插TF卡到單板。

更方便的辦法,是使用網絡傳輸到單板的TF卡。Windows的winscp可以用來完成這個工作。但是Linux上流行的軟件FileZilla 3.7.4.1, 與單板使用的Dropbear不能完成密鑰交換,不能建立SFTP連接。下面是FileZilla報告的消息。

10:11:07	Trace:	Couldn't agree a key exchange algorithm (available: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group14-sha256,kexguess2@matt.ucc.asn.au)
10:11:07	Error:	Couldn't agree a key exchange algorithm (available: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group14-sha256,kexguess2@matt.ucc.asn.au)

經過嘗試,在Linux上使用gFTP,能建立SFTP連接。另外,默認的PetaLinux工程生成的Linux,每次啟動時會重新生成新的密鑰。gFTP第二次連接時,會報告密鑰錯誤,也不能建立連接。建議刪除文件“~/.ssh/known_hosts”中的單板對應的條目,gFTP就能建立連接。如果沒有其它應用程序使用這個文件,可以刪除整個文件。

rm ~/.ssh/known_hosts
gftp


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM