ZYNQ:使用 PetaLinux 构建Linux项目

摘要:
-˃YoctoSettings##设置缓存:SStatecache-˃Localsstatefeedssettings-˃localsstatefeedsurl##按Enter/home/xx/sstage_package_for_petalinux/arm-˃YoctoSettings##设置镜像:downloadmirror-˃Addpre-mirrorurl##按Enterfile:///home/xx/sstage_package_for_petalinux/downloads-˃YoctoSettings##设置离线编译[]EnableNetworksstatefeeds##按N[*]EnableBBNONETWORK##按Y启动Linux时自动登录避免输入账号密码。-˃YoctoSettings[*]EnableDebugTweaks##按Y不自动获取IP地址如果网口存在时,可以考虑关闭自动获取IP地址-˃SubsystemAUTOHardwareSettings-˃EthernetSettingsPrimaryEthernet((ps7_ethernet_0)#确认存在此项[]ObtainIPaddressautomatically#按下空格键取消,并设置一个IP(192.168.168.168)StaticIPaddress(255.255.255.0)StaticIPnetmask(NEW)(192.168.168.1)StaticIPgatewayu-bootConfiguration---˃(192.168.168.1)TFTPServerIPaddres#设置TFTP服务器地址修改文件系统类型(可选)默认的文件系统类型会导致文件系统无法保存,一开始的时候可以保持默认,可以在后续修改为以下配置:-˃ImagePackagingConfiguration-˃Rootfilesystemtype-˃Rootfilesystemtype(SDcard)---˃(/dev/mmcblk0p2)DevicenodeofSDdevice(NEW)保存退出,以下是提示信息:INFO:Gettinghardwaredescription...[INFO]generatingKconfigforproject[INFO]menuconfigproject***Endoftheconfiguration.***Execute'make'tostartthebuildortry'makehelp'.[INFO]sourcingbitbake[INFO]generatingplnxtoolconf[INFO]generatingmeta-plnx-generatedlayer[INFO]generatingmachineconfiguration[INFO]generatingbbappendsforproject.Thismaytaketime!

参考文档:ug1144-petalinux-tools-reference-guide.pdf

环境安装

tofrodos iproute2 gawk gcc g++ git make net-tools libncurses5-dev tftpd zlib1g:i386 libssl-dev flex bison libselinux1 gnupg wget diffstat chrpath socat xterm autoconf libtool tar unzip texinfo zlib1g-dev gcc-multilib build-essential libsdl1.2-dev libglib2.0-dev screen pax gzip automake glib2-devel openssl openssl-develxinetd tftp tftp-server redhat-lsb u-boot-tools(或 uboot-tools)

创建目录:

su root
mkdir /opt/env
chown -R huangshuchao:embd /opt/env/
#chown -R huangshuchao:embd /opt/env/

# 2016.4以后的petalinux不能以超级权限去安装,必须在$下安装petalinux。

安装

./petalinux-v2018.3-final-installer.run /opt/env/petalinux/2018.3

Ubuntu bash

dpkg-reconfigure dash
	--> NO

使用

每次都需要:

 source /opt/env/petalinux/2018.3/settings.sh

本文链接https://www.cnblogs.com/schips/p/using-petalinux-build-linux-env.html

导入硬件

拷贝design_1_wrapper_hw_platform_0到Linux

创建项目

petalinux-create --type project --template zynq --name 项目名称(目录)

INFO: Create project: ax_peta
INFO: New project successfully created in /home/huangshuchao/ax_peta

导入硬件信息

输入以下命令:

硬件信息包:design_1_wrapper_hw_platform_0_test.tgz(来自13_vdma_to_qspi_sd

petalinux-config --get-hw-description ~/hw-vivado/design_1_wrapper_hw_platform_0_test

配置优化

我们这里再做一些优化工作,以方便我们的使用:

离线编译

注意,修改镜像时,填入的路径是以file://开头的。

-> Yocto Settings
	## 设置缓存:SState cache
    -> Local sstate feeds settings
       -> local sstate feeds url    ## 按 Enter
	   /home/xx/sstage_package_for_petalinux/arm

-> Yocto Settings
    ## 设置镜像:download mirror
    -> Add pre-mirror url           ## 按 Enter
    file:///home/xx/sstage_package_for_petalinux/downloads
    
-> Yocto Settings    
    ## 设置离线编译
    [ ] Enable Network sstate feeds ## 按 N
    [*] Enable BB NO NETWORK        ## 按 Y

启动Linux时自动登录

避免输入账号密码。

-> Yocto Settings
	[*] Enable Debug Tweaks			## 按 Y

不自动获取IP地址

如果网口存在时,可以考虑关闭自动获取IP地址(会造成开机过慢)

-> Subsystem AUTO Hardware Settings (SUBSYSTEM_HARDWARE_AUTO [=y]) 
	-> Ethernet Settings
		Primary Ethernet ((ps7_ethernet_0)  # 确认 存在此项
		[ ] Obtain IP address automatically # 按下空格键取消,并设置一个IP
		(192.168.168.168) Static IP address
		(255.255.255.0) Static IP netmask (NEW)
		(192.168.168.1) Static IP gateway

u-boot Configuration  --->
		(192.168.168.1) TFTP Server IP addres # 设置TFTP服务器地址

修改文件系统类型(可选)

默认的文件系统类型会导致文件系统无法保存,一开始的时候可以保持默认,可以在后续修改为以下配置:

-> Image Packaging Configuration
  -> Root filesystem type
    -> Root filesystem type (SD card) --->
       (/dev/mmcblk0p2) Device node of SD device (NEW)

保存退出,以下是提示信息:

INFO: Getting hardware description...
[INFO] generating Kconfig for project
[INFO] menuconfig project

*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

[INFO] sourcing bitbake
[INFO] generating plnxtool conf
[INFO] generating meta-plnx-generated layer
[INFO] generating machine configuration
[INFO] generating bbappends for project . This may take time !
[INFO] generating u-boot configuration files
[INFO] generating kernel configuration files
[INFO] generating kconfig for Rootfs
[INFO] oldconfig rootfs
[INFO] generating petalinux-user-image.bb

配置保护

保留Linux和UBoot源代码

echo 'RM_WORK_EXCLUDE += "linux-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf

echo 'RM_WORK_EXCLUDE += "u-boot-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf

echo ''>> project-spec/meta-user/conf/petalinuxbsp.conf

原理:run.do_rm_work中有对关键字进行解析,如果符合条件,那么不执行删除操作。

配置uboot

petalinux-config -c u-boot

进行如下配置:

配置项值与说明
Boot mediaBoot介质,配置从SD卡启动
delay in seconds before automatically bootingBoot自启动时间,默认4s,可修改
Disable support for parallel NOR flashNOR flash支持,无支持
add U-Boot environment variable versU-Boot环境变量添加,无
Display information about the CPU during start up启动阶段显示CPU信息,可选
Display information about the board during start up启动阶段显示板卡信息,可选
Command line interface命令行配置,用户可进一步配置
Device Tree Control设备树控制,保持默认配置(embeded)

配置内核

输入:

petalinux-config -c kernel

以下是提示信息:

[INFO] generating Kconfig for project
[INFO] sourcing bitbake
[INFO] generating plnxtool conf
[INFO] generating meta-plnx-generated layer
[INFO] generating machine configuration
[INFO] configuring: kernel
[INFO] generating kernel configuration files
[INFO] bitbake virtual/kernel -c menuconfig
Parsing recipes:   100% |##########################################| ETA:  0:00:56

Parsing of 2569 .bb files complete (0 cached, 2569 parsed). 3445 targets, 149 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

很快就会弹出Menuconfig菜单,选择

CONFIG_MICREL_PHY:

-> Device Drivers
	-> Network device support (NETDEVICES [=y])
		-> PHY Device support and infrastructure (PHYLIB [=y])
			[y] Micrel PHYs

保存,EXIT。

配置文件系统

petalinux-config -c rootfs

petalinux-config -c rootfs && petalinux-build

无更改,保存退出

编译 uboot、内核、文件系统、设备树

petalinux-build

此后,生成下面的文件

# ls image/linux
rootfs.cpio      rootfs.cpio.gz.u-boot  rootfs.ext4     rootfs.jffs2     rootfs.tar.gz         system.dtb        u-boot.elf  zynq_fsbl.elf      image.ub    rootfs.cpio.bz2  rootfs.ext3            rootfs.ext4.gz  rootfs.manifest  rootfs.testdata.json  System.map.linux  vmlinux    rootfs.bin  rootfs.cpio.gz   rootfs.ext3.bz2        rootfs.its      rootfs.tar.bz2   system.bit            u-boot.bin        zImage

生成BOOT.BIN

执行下面的代码生成BOOT.BIN

petalinux-package --boot --fsbl ./images/linux/zynq_fsbl.elf --fpga ./images/linux/system.bit --u-boot --force

下面的是提示信息:

INFO: Getting system flash information...
INFO: File in BOOT BIN: "/home/huangshuchao/ax_peta2/images/linux/zynq_fsbl.elf"
INFO: File in BOOT BIN: "/home/huangshuchao/ax_peta2/images/linux/system.bit"
INFO: File in BOOT BIN: "/home/huangshuchao/ax_peta2/images/linux/u-boot.elf"
INFO: Generating Zynq binary package BOOT.BIN...


****** Xilinx Bootgen v2018.3
  **** Build date : Nov 15 2018-19:22:29
    ** Copyright 1986-2018 Xilinx, Inc. All Rights Reserved.

INFO: Binary is ready.

生成image.ub

mkimage -f ./images/linux/rootfs.its image.ub 

测试

image/linux中拷贝:BOOT.BINimage.ub,到SD卡即可。

创建项目的脚本

##
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/
#
#    File Name:  copy_petalinux_project_with_hw.sh
#    Created  :  2020-07-25 11:28:24
#
##
#!/bin/sh
# 项目工程常见参数设置
## sstage包下载后设置
SSTATE_LOCAL_PATH="/home/huangshuchao/sstage_package_for_petalinux/"
## IP地址设置
NET=192.168.1
IPADDR=$NET.100


help () {
    echo "Error : need $projectname $hw_bsp"
    echo "  eg :"
    echo "      $0 ax_project ~/hw-vivado-bsp-for-petalinux/some_packakge"
    exit 1
}

if [ -z "$1" ]; then
	help
fi
if [ -z "$2" ]; then
	help
fi

command -v petalinux-create >/dev/null 2>&1 || { echo >&2 "Aborted : Require "petalinux-create" but not found."; exit 1;  }
command -v petalinux-config >/dev/null 2>&1 || { echo >&2 "Aborted : Require "petalinux-config" but not found."; exit 1;  }

## 删除源目录
rm $1 -rf

## 创建项目
petalinux-create --type project --template zynq --name $1
PROJECT=$1
## 导入硬件信息
cd $PROJECT
petalinux-config --get-hw-description $2

## 使PetaLinux不删除源码
echo 'RM_WORK_EXCLUDE += "linux-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf
echo 'RM_WORK_EXCLUDE += "u-boot-xlnx"'>> project-spec/meta-user/conf/petalinuxbsp.conf
echo ''>> project-spec/meta-user/conf/petalinuxbsp.conf


# 删除带有指定关键字的行
delete_line_with_special_word ()
{
    if [[ $# -lt 2 ]]; then
        return
    fi
    FILE=$1
    WORD=$2
    sed -i "/${WORD}/d" ${FILE}
}

# 文件内容追加
append_line_into_file ()
{
    if [[ $# -lt 2 ]]; then
        return
    fi
    FILE=$1
    LINE=$2
    echo $LINE >> $FILE
}
CONFIG=project-spec/configs/config
cp $CONFIG $CONFIG.old

## 网络设置
delete_line_with_special_word   $CONFIG  CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_USE_DHCP
append_line_into_file           $CONFIG  "# CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_USE_DHCP is not set"
append_line_into_file           $CONFIG  "CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_IP_ADDRESS="$IPADDR""
append_line_into_file           $CONFIG  "CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_IP_NETMASK="255.255.255.0""
append_line_into_file           $CONFIG  "CONFIG_SUBSYSTEM_ETHERNET_PS7_ETHERNET_0_IP_GATEWAY="$NET.1""

## 本地包
delete_line_with_special_word   $CONFIG  CONFIG_YOCTO_NETWORK_SSTATE_FEEDS
append_line_into_file           $CONFIG  "# CONFIG_YOCTO_NETWORK_SSTATE_FEEDS is not set"
delete_line_with_special_word   $CONFIG  CONFIG_YOCTO_BB_NO_NETWORK
append_line_into_file           $CONFIG  "CONFIG_YOCTO_BB_NO_NETWORK=y"
delete_line_with_special_word   $CONFIG  CONFIG_PRE_MIRROR_URL
append_line_into_file           $CONFIG  "CONFIG_PRE_MIRROR_URL="file://${SSTATE_LOCAL_PATH}/downloads""
delete_line_with_special_word   $CONFIG  CONFIG_YOCTO_LOCAL_SSTATE_FEEDS_URL
append_line_into_file           $CONFIG  "CONFIG_YOCTO_LOCAL_SSTATE_FEEDS_URL="${SSTATE_LOCAL_PATH}/arm"" #zynq
        ## | 目录      | 平台        |
        ## | --------- | ----------- |
        ## | aarch64   | ZynqMP      |
        ## | arm       | Zynq        |
        ## | mb-full   | MB AXI      |
        ## | mb-lite   | MB AXI lite |
        ## | downloads | 全平台  |

## 免输入密码登陆
delete_line_with_special_word   $CONFIG  CONFIG_YOCTO_ENABLE_DEBUG_TWEAKS
append_line_into_file           $CONFIG  "CONFIG_YOCTO_ENABLE_DEBUG_TWEAKS=y"

附录:PetaLinux注意事项

导入项目创建项目以后,工程项目会确定当前路径,所以需要注意,不要随便改动工程路径。

ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Error, TMPDIR has changed location. You need to either move it back to /home/huangshuchao/ax_1_design1hw0_retry/build/tmp or rebuild

不过可以通过拷贝petalinux工程的配置到另外的目录,再build出那些临时文件。

详情见:加速 PetaLinux 工程编译、复制 PetaLinux 工程

附录: 构建各部分

petalinux-build -c kernel

petalinux-build -c device-tree

petalinux-build -c fsbl

petalinux-build -c u-boot

petalinux-package --boot --fsbl --fpga --u-boot --force

这样在images目录下就会生成我们需要的uImage、system.dtb以及BOOT.BIN,为了确保设备树修改完好,我们这里先反编译一下设备树,生成system.dts,查看里面是否我们要修改的东西都已经修改好了(需要device-tree-compiler)。

在system.dtb文件的目录下运行

dtc -I dtb -O dts -o system.dts system.dtb

打开ststem.dts,我们可以看到已经修改完毕

免责声明:文章转载自《ZYNQ:使用 PetaLinux 构建Linux项目》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Django项目的docker镜像制作Phoenix 使用教程下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux的ftp安装及配置

一、安装ftp服务 1.检查是否已经安装 rpm -qa| grep vsftpd 2.没安装则安装 centos用: yum -y install vsftpd ubuntu用: apt-get install vsftpd 二、启动ftp服务 1.启动ftp服务: service vsftpd start 重启ftp service vsf...

linux简单命令与Shell脚本

说明1、#表示root用户登录,$表示普通用户登录2、|符号是管道符,用于把|前的输出作为后面命令的输入3、>表示追加并覆盖的意思4、>>两个大于符号,表示追加命令1、cd命令:切换目录cd /home 进入/home目录cd ../返回上一级目录cd  ./当前目录2、ls命令:产看文件及目录ls  ./ 查看当前目录所有的文件和目录l...

在debian下安装QT 5.10 32位

  准备工作: 在开始之前最好把GCC升级到5.0以上。 如果升级后出现“libstdc++.so.6: version `CXXABI_1.3.9' not found”错误,可以参考https://blog.csdn.net/zx714311728/article/details/69628836解决。 -----------------------...

转:Linux 编译安装 Mysql5.7

http://broqiang.com/2017/04/18/Mysql-Install-5.7.18-Linux-Compile/ 原文 Linux 编译安装 Mysql5.7 Ubuntu 下快速安装直接 apt 方式即可, 一般的开发环境也足够了 个人比较喜欢新版本,一般有新版本就会尝试一下 此文档适用于 Ubuntu 16.10 和 CentOS...

Linux的PHP开发环境快速搭建

搭建的环境是LNMP: 1、安装MySQL 这个非常简单我用的是Ubuntu那么就用apt源,下载deb文件然后按照全新安装文档按顺序:a.加入apt库  b.更新apt库 c.安装 d.运行MySQL 下载: https://dev.mysql.com/downloads/repo/apt/ 文档: https://dev.mysql.com/doc/m...

蜕变成蝶~Linux设备驱动之异步通知和异步I/O

在设备驱动中使用异步通知可以使得对设备的访问可进行时,由驱动主动通知应用程序进行访问。因此,使用无阻塞I/O的应用程序无需轮询设备是否可访问,而阻塞访问也可以被类似“中断”的异步通知所取代。异步通知类似于硬件上的“中断”概念,比较准确的称谓是“信号驱动的异步I/O"。 1、异步通知的概念和作用 影响:阻塞--应用程序无需轮询设备是否可以访问 非阻塞--中...