petalinux 并不是一个特殊 Linux 内核,而是一套开发环境配置的工具,降低 uboot、内核、 根文件系统的配置的工作量,可以从 Vivado 的导出硬件信息自动完成相关软件的配置。
petalinux 是赛灵思基于 buildroot 工具链为自家处理器方便适配 Linux 定制的工具集。
在 Xilinx 官方文档 UG1144 中有详细安装方法,如果本教程安装失败,请参考 Xilinx 的 ug1144 文档
进行安装。(https://www.xilinx.com/support/documentation/sw_manuals/xilinx2020_1/ug1144-petalinux-tool s-reference-guide.pdf)
准备 Linux 操作系统环境
这里使用 PVE 下的 Ubuntu18.04 虚拟机做运行系统环境。
注意:petalinux 对系统版本和设置有严格要求,一定要选择对应版本推荐的系统版本安装。不对应的系统版本可能会出现各种问题。
配置网络可连接外网,安装 ssh 服务端,可 ssh 登录,后面基本在命令行下进行操作。
更新软件列表
sudo apt-get update
#使用本地代理方式
sudo apt -o Acquire::http::proxy="http://192.168.196.112:3142" update
安装基础软件,这里写成了脚本。
#!/bin/bash
set -x
script_dir=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
# This script sets up a Ubuntu host to be able to create the image by
# installing all of the necessary files. It assumes a host with
# passwordless sudo
# Install a bunch of packages we need
read -d '' PACKAGES <<EOT
iproute2
gcc
g++
net-tools
libncurses5-dev
zlib1g:i386
libssl-dev
flex
bison
libselinux1
xterm
autoconf
libtool
texinfo
zlib1g-dev
gcc-multilib
build-essential
screen
pax
gawk
python3
python3-pexpect
python3-pip
python3-git
python3-jinja2
xz-utils
debianutils
iputils-ping
libegl1-mesa
libsdl1.2-dev
pylint3
cpio
EOT
set -e
sudo apt-get update
if [[ $(lsb_release -rs) == "16.04" ]]; then
echo "Install packages on Ubuntu 16.04..."
sudo apt purge -y libgnutls-dev
elif [[ $(lsb_release -rs) == "18.04" ]]; then
echo "Install packages on Ubuntu 18.04..."
else
echo "Error: current OS not supported."
exit 1
fi
sudo dpkg --add-architecture i386 #开启i386体系支持
sudo apt-get update
sudo apt-get install -y $PACKAGES
echo "Now install Vivado, SDK, and Petalinux."
echo "Re-login to ensure the enviroment is properly set up."
为了加快下载包可以使用代理,另一种脚本如下:
#!/bin/bash
sudo apt-get -o Acquire::http::proxy="http://192.168.196.112:3142" update
sudo dpkg --add-architecture i386 #开启i386体系支持
sudo apt-get -o Acquire::http::proxy="http://192.168.196.112:3142" update
sudo apt-get -o Acquire::http::proxy="http://192.168.196.112:3142" install -y iproute2 gcc g++ net-tools libncurses5-dev zlib1g:i386 libssl-dev flex bison libselinux1 xterm autoconf libtool texinfo zlib1g-dev gcc-multilib build-essential screen pax gawk python3 python3-pexpect python3-pip python3-git python3-jinja2 xz-utils debianutils iputils-ping libegl1-mesa libsdl1.2-dev pylint3 cpio
安装 Petalinux
创建安装目录并设置
sudo -s
mkdir -p /opt/pkg/petalinux
chgrp scilogyhunter /opt/pkg/petalinux
chown scilogyhunter /opt/pkg/petalinux
exit
设置petalinux-v2020.1-final-installer.run 文件可执行权限
scilogyhunter@ubuntu1804:~/petalinux$
scilogyhunter@ubuntu1804:~/petalinux$ ls -al
total 48758708
drwxrwxr-x 2 scilogyhunter scilogyhunter 4096 5月 20 17:48 .
drwxr-xr-x 16 scilogyhunter scilogyhunter 4096 5月 20 16:28 ..
-rw-rw-r-- 1 scilogyhunter scilogyhunter 35509900839 5月 20 16:35 downloads_2020.1.tar.gz
-rwxrwxrwx 1 scilogyhunter scilogyhunter 1123 5月 20 16:29 host_env_setup.sh
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1207 5月 20 17:38 host_env_setup.shes
-rw-rw-r-- 1 scilogyhunter scilogyhunter 213906986 5月 20 16:39 linux-xlnx-xilinx-v2020.1.zip
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1315548907 5月 20 16:29 petalinux-v2020.1-final-installer.run
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1237 5月 20 17:48 setup_proxy.sh
-rw-rw-r-- 1 scilogyhunter scilogyhunter 12870640734 5月 20 16:38 sstate_aarch64_2020.1.tar.gz
-rw-rw-r-- 1 scilogyhunter scilogyhunter 598 5月 20 16:39 sstate_rel_2020.1_README.tar.gz
-rw-rw-r-- 1 scilogyhunter scilogyhunter 18868392 5月 20 16:39 u-boot-xlnx-xilinx-v2020.1.tar.gz
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1231 5月 20 17:42 yes
scilogyhunter@ubuntu1804:~/petalinux$ chmod +x petalinux-v2020.1-final-installer.run
scilogyhunter@ubuntu1804:~/petalinux$ ls -al
total 48758708
drwxrwxr-x 2 scilogyhunter scilogyhunter 4096 5月 20 17:48 .
drwxr-xr-x 16 scilogyhunter scilogyhunter 4096 5月 20 16:28 ..
-rw-rw-r-- 1 scilogyhunter scilogyhunter 35509900839 5月 20 16:35 downloads_2020.1.tar.gz
-rwxrwxrwx 1 scilogyhunter scilogyhunter 1123 5月 20 16:29 host_env_setup.sh
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1207 5月 20 17:38 host_env_setup.shes
-rw-rw-r-- 1 scilogyhunter scilogyhunter 213906986 5月 20 16:39 linux-xlnx-xilinx-v2020.1.zip
-rwxrwxr-x 1 scilogyhunter scilogyhunter 1315548907 5月 20 16:29 petalinux-v2020.1-final-installer.run
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1237 5月 20 17:48 setup_proxy.sh
-rw-rw-r-- 1 scilogyhunter scilogyhunter 12870640734 5月 20 16:38 sstate_aarch64_2020.1.tar.gz
-rw-rw-r-- 1 scilogyhunter scilogyhunter 598 5月 20 16:39 sstate_rel_2020.1_README.tar.gz
-rw-rw-r-- 1 scilogyhunter scilogyhunter 18868392 5月 20 16:39 u-boot-xlnx-xilinx-v2020.1.tar.gz
-rw-rw-r-- 1 scilogyhunter scilogyhunter 1231 5月 20 17:42 yes
scilogyhunter@ubuntu1804:~/petalinux$
scilogyhunter@ubuntu1804:~/petalinux$./petalinux-v2020.1-final-installer.run -d /opt/pkg/petalinux
开始安装
scilogyhunter@ubuntu1804:~/petalinux$ ./petalinux-v2020.1-final-installer.run -d /opt/pkg/petalinux
INFO: Checking installation environment requirements...
INFO: Checking free disk space
INFO: Checking installed tools
INFO: Checking installed development libraries
INFO: Checking network and other services
WARNING: No tftp server found - please refer to "UG1144 PetaLinux Tools Documentation Reference Guide" for its impact and solution
INFO: Checking installer checksum...
INFO: Extracting PetaLinux installer...
LICENSE AGREEMENTS
PetaLinux SDK contains software from a number of sources. Please review
the following licenses and indicate your acceptance of each to continue.
You do not have to accept the licenses, however if you do not then you may
not use PetaLinux SDK.
Use PgUp/PgDn to navigate the license viewer, and press 'q' to close
Press Enter to display the license agreements
Do you accept Xilinx End User License Agreement? [y/N] > Do you accept Xilinx End User License Agreement? [y/N] >
Do you accept Xilinx End User License Agreement? [y/N] > y
Do you accept Webtalk Terms and Conditions? [y/N] > Do you accept Webtalk Terms and Conditions? [y/N] > y
Do you accept Third Party End User License Agreement? [y/N] > Do you accept Third Party End User License Agreement? [y/N] >
Do you accept Third Party End User License Agreement? [y/N] > y
INFO: Installing PetaLinux...
INFO: Checking PetaLinux installer integrity...
INFO: Installing PetaLinux SDK to "/opt/pkg/petalinux/."
INFO: Installing buildtools in /opt/pkg/petalinux/./components/yocto/buildtools
INFO: PetaLinux SDK has been installed to /opt/pkg/petalinux/.
scilogyhunter@ubuntu1804:~/petalinux$
安装过程中需要回车查看授权协议,按 q 退出。后面还有多次需要同意协议内容,按 y 同意。
安装目录生成内容
scilogyhunter@ubuntu1804:~/petalinux$ ls /opt/pkg/petalinux/
components doc etc settings.csh settings.sh tools
scilogyhunter@ubuntu1804:~/petalinux$
安装过程的当前目录下还会生成petalinux_installation_log 文件,记录安装日志。
scilogyhunter@ubuntu1804:~/petalinux$ ls
downloads_2020.1.tar.gz linux-xlnx-xilinx-v2020.1.zip setup_proxy.sh u-boot-xlnx-xilinx-v2020.1.tar.gz
host_env_setup.sh petalinux_installation_log sstate_aarch64_2020.1.tar.gz
host_env_setup.shes petalinux-v2020.1-final-installer.run sstate_rel_2020.1_README.tar.gz
scilogyhunter@ubuntu1804:~/petalinux$ rm setup_proxy.sh
scilogyhunter@ubuntu1804:~/petalinux$ cat petalinux_installation_log
INFO: Checking installation environment requirements...
INFO: Checking installer checksum...
INFO: Extracting PetaLinux installer...
INFO: Installing PetaLinux...
INFO: Checking PetaLinux installer integrity...
INFO: Installing PetaLinux SDK to "/opt/pkg/petalinux/."
.......................................................INFO: Installing buildtools in /opt/pkg/petalinux/./components/yocto/buildtools
Build tools installer version 2020.1
====================================
You are about to install the SDK to "/opt/pkg/petalinux/components/yocto/buildtools". Proceed [Y/n]? Y
Extracting SDK..........................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
$ . /opt/pkg/petalinux/components/yocto/buildtools/environment-setup-x86_64-petalinux-linux
INFO: PetaLinux SDK has been installed to /opt/pkg/petalinux/.
scilogyhunter@ubuntu1804:~/petalinux$
设置环境变量
设置 petalinux 环境变量,运行下面命令 (环境变量只在当前打开的终端中有效,后面和
petalinux 相关的命令都要在当前终端中输入,如果关闭了当前终端则需要重新运行这条命
令) 。
scilogyhunter@ubuntu1804:~/petalinux$ source /opt/pkg/petalinux/settings.sh
PetaLinux environment set to '/opt/pkg/petalinux'
WARNING: /bin/sh is not bash!
bash is PetaLinux recommended shell. Please set your default shell to bash.
INFO: Checking free disk space
INFO: Checking installed tools
INFO: Checking installed development libraries
INFO: Checking network and other services
WARNING: No tftp server found - please refer to "UG1144 2020.1 PetaLinux Tools Documentation Reference Guide" for its impact and solution
scilogyhunter@ubuntu1804:~/petalinux$
验证petalinux
使用 petalinux-create -h 命令验证 petalinux 安装可用。
scilogyhunter@ubuntu1804:~/petalinux$ petalinux-create -h
petalinux-create (c) 2005-2020 Xilinx, Inc.
This command creates a new PetaLinux Project or component
Usage:
petalinux-create [options] <-t|--type <TYPE> <-n|--name <COMPONENT_NAME>
Required:
-t, --type <TYPE> Available type:
* project : PetaLinux project
* apps : Linux user application
* modules : Linux user module
-n, --name <COMPONENT_NAME> specify a name for the component or
project. It is OPTIONAL to create a
PROJECT. If you specify source BSP when
you create a project, you are not
required to specify the name.
Options:
-p, --project <PROJECT> specify full path to a PetaLinux project
this option is NOT USED for PROJECT CREATION.
default is the working project.
--force force overwriting an existing component
directory.
-h, --help show function usage
--enable this option applies to all types except
project.
enable the created component
--srcuri this option is to specify the source files
from outside project.This will copy specified
files into recipe files directory and add to
SRC_URI variable in .bb file.
Specify the multiple files with space.
Options for project:
--template <TEMPLATE> versal|zynqMP|zynq|microblaze
user needs specify which template to use.
-s|--source <SOURCE> specify a PetaLinux BSP as a project
source.
Options for apps:
--template <TEMPLATE> <c|c++|autoconf|install>
c : c user application(default)
c++ : c++ user application
autoconf: autoconf user application
install: install data only
fpgamanager: autoload .dtbo and .bin files
Enable 'FPGA Manager' to build the fpgamanager apps.
-s, --source <SOURCE> valid source name format:
*.tar.gz, *.tgz, *.tar.bz2, *.tar,
*.zip, app source directory
Options for modules: (No specific options for modules)
EXAMPLES:
Create project from PetaLinux Project BSP:
$ petalinux-create -t project -s <PATH_TO_PETALINUX_PROJECT_BSP>
Create project from template:
For microblaze project,
$ petalinux-create -t project -n <PROJECT> --template microblaze
For zynq project,
$ petalinux-create -t project -n <PROJECT> --template zynq
For zynqMP project,
$ petalinux-create -t project -n <PROJECT> --template zynqMP
For versal project,
$ petalinux-create -t project -n <PROJECT> --template versal
Create an app and enable it:
$ petalinux-create -t apps -n myapp --enable
The application "myapp" will be created with c template in:
<PROJECT>/project-spec/meta-user/recipes-apps/myapp
Create an app with remote sources:
$ petalinux-create -t apps -n myapp --enable --srcuri http://example.tar.gz
$ petalinux-create -t apps -n myapp --enable --srcuri git://example.git\;protocol=https
$ petalinux-create -t apps -n myapp --enable --srcuri https://example.tar.gz
Create a FPGAmanager application to load .dtsi and .bit/.pdi
$ petalinux-create -t apps --template fpgamanager -n gpio --enable
The application "gpio" will be created with the fpgamanager class
include to build .dtbo and .bin files which will load on target
boot time(default).
NOTE: Make sure you have enabled the 'FPGA manager' in petalinux-config
Create an app with local source files:
$ petalinux-create -t apps --template fpgamanager -n gpio --enable --srcuri \
"<path>/pl.dtsi <path>/system.bit"
This will create "gpio" application with pl.dtsi and system.bit added
to SRC_URI and copied to files directory.
Create an module and enable it:
$ petalinux-create -t modules -n mymodule --enable
The module "mymodule" will be created with template in:
<PROJECT>/project-spec/meta-user/recipes-modules/mymodule
Create an module with source files:
$ petalinux-create -t modules -n mymodule --enable --srcuri "<path>/mymoudle.c <path>/Makefile"
scilogyhunter@ubuntu1804:~/petalinux$