用户工具

站点工具


fpga:petalinux

这是本文档旧的修订版!


petalinux

1. create project

source /xilinx/settings.sh
 
petalinux-create -t project --template zynq -n xxx_name
petalinux-config --get-hw-description .

2. create modules

相当于创建linux模块驱动

petalinux-create -t modules -n xxx_module --enable

3. create app

创建一个linux平台下的app可执行程序

petalinux-create -t apps -n xxx_app  --enable

然后进入recipes-apps/xxx_app目录,修改files/xxx_app.c文件,默认是一个hello world!打印程序。

4. build

petalinux-build -c rootfs
petalinux-build -c xxx_module
petalinux-build -c xxx_app -x do_install
 
 
 
petalinux-build

5. app单独编译&调试

petalinux-build -c xxx_app -x do_compile   # 对指定app进行编译, 编译后生成的app可执行文件在以下位置
ls build/tmp/work/cortexa9hf-neon-xilinx-linux-gnueabi/myapp3/1.0-r0/myapp3
 
# 然后可以将此文件通过scp的方式,copy到zynq设备,修改权限chmod 777 ./myapp3, 执行程序./myapp3
# 这样的方式不用每次app修改后都烧写到flash, 通过scp的方式加快app开发调试速度。

6. package to BOOT.BIN

petalinux-package --boot --fsbl zynq_fsbl.elf --u-boot --kernel --fpga system.bit --force
# --boot, 打包成BOOT.BIN文件
# -- 输入fsdb文件
# --u-boot, 输入默认u-boot文件, 一般是指u-boot.elf
# --kernel ,输入petalinux内核, 默认是指image.ub
# --fpga, 指定FPGA bits文件。
#一般是建议先不用--kernel选项生成BOOT.BIN文件,然后将BOOT.BIN文件和image.ub一起copy到SD卡,从SD卡启动看看程序效果,程序稳定后可以再考虑弄成为flash启动,这样调试速度会快一些。

7. 一个简单的驱动开发例程——GPIO流水灯(Petalinux部分)

8. 实现app开机启动

参考ug1144, Ch.7: Customizing the Rootfs

参考: https://blog.csdn.net/qq_37775990/article/details/126951572

 
实现开机启动
本章节内容参考UG1144。
(1)创建myapp-init应用
 
cd <plnx-proj-proot>
petalinux-create -t apps --template install -n myapp-init --enable
 
(2)修改myapp-init.bb配置文件
配置文件的位置在:
 
project-spec/meta-user/recipes-apps/myapp-init/myapp-init.bb
修改文件内容为:
 
#
# This file is the myapp-init recipe.
#
SUMMARY = "Simple myapp-init application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM ="file://${COMMON_LICENSE_DIR}/
MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://myapp-init \
 "
S = "${WORKDIR}"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
inherit update-rc.d
INITSCRIPT_NAME = "myapp-init"
INITSCRIPT_PARAMS = "start 99 S ."
do_install() {
 install -d ${D}${sysconfdir}/init.d
 install -m 0755 ${S}/myapp-init ${D}${sysconfdir}/init.d/myapp-init
}
FILES_${PN} += "${sysconfdir}/*"3)修改myapp-init脚本文件内容
脚本文件的位置在:
 
project-spec/meta-user/recipes-apps/
myapp-init/files/myapp-init
 
本文修改的内容为加载xilinx-axidma.ko module和在后台启动程序xxx_app
 
#!/bin/sh
 
cd /lib/modules/5.4.0-xilinx-v2020.1/extra
insmod xxx_module.ko
 
cd /usr/bin
./xxx_app &   
## 注意,最好在此加上&,让其后台执行,不然系统会把当前命令执行完之后再进行下面的任务,
##  比如下面的任务是配置网络, 这对于需要网络的开机启动尤其重要
 
完成后进行petalinux-build,使用新生成的镜像,下次就可以开机自启动了。

开机启动执行log example:

Hello PetaLinux World, startup test....
blink: loading out-of-tree module taints kernel.
<1>Hello module world.
<1>Module parameters were (0xdeadbeef) and "default"
blink_init: Registers mapped to mmio = 0xf09d0000  
Registeration is a success the major device number is 245.
If you want to talk to the device driver,
create a device file by following command. 
 
mknod /dev/blink_Dev c 245 0
 
The device file name is important, because
the ioctl program assumes that's the file you'll use
################################ 
      Blink LED Application device_open(c7e4c6c0)
 
################################ 
************************************************ 
start LED sparkle...
************************************************ 
app led on
KERNEL PRINT : set_blink_ctrl 
 
app led off
KERNEL PRINT : reset_blink_ctrl 
 
app led on
KERNEL PRINT : set_blink_ctrl 
 
app led off
KERNEL PRINT : reset_blink_ctrl 
 
device_release(ef1d9370,c7e4c6c0)
################################ 
INIT: Entering runlevel: 5ation  
Configuring network interfaces... IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.24.1) started
Sending discover...
Sending discover...
macb e000b000.ethernet eth0: link up (1000/Full)
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
Sending discover...
Sending select for 192.168.0.166...
Lease of 192.168.0.166 obtained, lease time 268435455
/etc/udhcpc.d/50default: Adding DNS 192.168.0.1
done.
Starting Dropbear SSH server: Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCh7/mYSvw3pyvt0K//+5A2N2sIGUoo7ZXjChqDaBD/iV8MDrVQiGiyyXmxkUlcrgKVeWzP
NQ0Q4i58cvtTIIJmeEQI3rM9WD7V+o/HcDRr8TlyIbK0SOKHCcHpglKwm54e01evpmX2tt4cdXfxdnaRhcONjPMJq4cAutFu0yO85QGwsVQ1
OFJYrdmt4Rc5T0BZdF3LtuXaVOF7mJ7aavI7vpsme1JIvzAOkGMSXH+HqY2wG4Ak6D07WdH78AaQsI86vDLA1WLaPP4oCMjiLjeFKIuAbnhl
d+HuJtwvj5fx4GZcRyQ5VrwVE7anQmAu4Olw/O9dwQQTAJ0LX1u6Ui0V root@petalinux_boot_from_flash
Fingerprint: md5 61:94:fc:ff:b1:94:85:d7:fa:19:26:a9:a4:92:df:7f
dropbear.
hwclock: can't open '/dev/misc/rtc': No such file or directory
Starting syslogd/klogd: done
Starting tcf-agent: OK
 
PetaLinux 2018.3 petalinux_boot_from_flash /dev/ttyPS0
 
petalinux_boot_from_flash login: random: crng init done
 
PetaLinux 2018.3 petalinux_boot_from_flash /dev/ttyPS0
 
petalinux_boot_from_flash login:

从上面的执行log看出来,很明显获取IP地址是在开机启动执行程序完成之后才开始的,所以一定要注意这一点。

9. zynq设备上运行指定驱动的app程序

在zynq fpga运行过程。

root@petalinux_boot_from_flash:/lib/modules/4.14.0-xilinx-v2018.3/extra# pwd
/lib/modules/4.14.0-xilinx-v2018.3/extra
root@petalinux_boot_from_flash:/lib/modules/4.14.0-xilinx-v2018.3/extra# ls
blink.ko

modprobe blink.ko     #  加载驱动
mknod /dev/blink_Dev c 245 0   # 标 dev, 这个信息根据modprobe的提示信息输入
ls /dev/blink_Dev    #  已经有dev
blinkapp    # 运用app程序

10. linux 加载module

insmod blink.ko
# 如果有同名文件module已经加载,可以先lsmode查看
 
lsmod   # 列出已经加载的module
 
rmmod blink.ko  # 删除已加载的module, 可以在后面两次加载新的module.
fpga/petalinux.1675909303.txt.gz · 最后更改: 2023/03/17 10:12 (外部编辑)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki