Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
This document describes the process to build linux application using PetaLinux. This also covers booting up your board as well as how to run demo test applications. There is a faster way to test your hardware by using prebuilt images from PetaLinux BSP which is also covered in this document.
PetaLinux - Overview
PetaLinux is an embedded Linux Software Development Kit (SDK) targeting FPGA-based system on a chip (SoC) designs. PetaLinux SDK is a Xilinx development tool that contains everything necessary to build, develop, test, and deploy embedded Linux systems.
The PetaLinux tool contains:
Yocto Extensible SDK (eSDK)
XSCT (Xilinx Software Command-Line Tool), including XSDB and toolchains
PetaLinux CLI tools
PetaLinux needs to be installed first before use - refer to UG1144 - PetaLinux Tools Documentation for the Installation steps and setting up PetaLinux Environment
Building Linux Distribution using PetaLinux including OpenAMP demos
This section covers steps to be followed in order to modify created PetaLinux BSP as per user requirements.
Creating PetaLinux BSP
Create the PetaLinux master project in a suitable directory without any spaces.
This will create directory named default project name same as BSP, indicating here as <plnx-user-proj-root>, in the current directory.
Navigate to the directory:
$ cd <plnx-user-proj-root>
PetaLinux Images Quick Try: Prebuilt images are present at <plnx-user-proj-root>/pre-built/linux/images which can directly be used to boot up hardware without doing any further steps. This can be helpful to verify hardware. You can also run demo tests with this prebuilt image.
Include a remote application in the PetaLinux project (Optional)
This step is needed only if you want to add your developed Firmware separately into PetaLinux BSP. Refer to section Building Firmware using PetaLinux.
Enable all of the modules and applications in the RootFS
Open the RootFS configuration menu:
petalinux-config -c rootfs
Select below to ensure OpenAMP applications and RPMsg modules are included
Filesystem Packages --->
-> Petalinux Package Groups
-> packagegroup-petalinux-openamp
Select below to include default demo test firmware files
The openamp.dtb and openamp.dtsi files are provided for reference only. You can refer to the contents from these files to edit the system-user.dtsi file to include the content from openamp.dtsi for your project. Either you can copy paste the contents of openamp.dtsi in the system-user.dtsi or you can update system-user.dtsi to include openamp.dtsi (or any other reference dtsi file) as follows:
Append below line in system-user.dtsi:
/include/ "openamp.dtsi" or /include/ "<your-updated-dtsi-filename>.dtsi"
If you do above “include file step” then you will also have to give reference to this file to append device tree recipe as follows:
This step is needed while Building Linux Application if you have developed and built a remote application (for example, with Xilinx SDK) or you want to add any user application. It must be included in the PetaLinux project so that it is available from the Linux filesystem for remoteproc.
Create a PetaLinux application inside the components/apps/ directory, using the following command:
The resource table is defined in rsc_table.c and rsc_table.h files that are built into the remote binary and is then parsed by the host application during Remoteproc ELF Load to establish RPMsg IPC. The platform_info.c and platform_info.h files which define platform specific data and implement API’s to set platform specific information for OpenAMP.
If you want to do any modifications in demo tests firmware code, then to get the source code from git url specified in meta-layers (as given above), run below command to create firmware specific workspace at <plnx-proj-root>/components/yocto :
You can find source code files (rsc_table.c, rsc_table.h, platform_info.c, platform_info.h) at <plnx-proj-root>/components/yocto/workspace/sources/<recipe-name>/lib/sw_apps/<demo-test-name>/src/machine/<machine-name>/<filename>
For example, <plnx-proj-root>/components/yocto/workspace/sources/openamp-fw-echo-testd/lib/sw_apps/openamp_echo_test/src/machine/zynqmp_r5/rsc_table.c
In case of any changes in files, build Firmware with: petalinux-build -c openamp-fw-echo-testd
Verify firmware file is generated at <plnx-proj-root>/components/yocto/workspace/sources/<recipe-name>/<recipe-name>/<rpu-firmware>
For example, <plnx-proj-root>/components/yocto/workspace/sources/openamp-fw-echo-testd/openamp-fw-echo-testd/executable.elf
Booting the PetaLinux Project
You can boot up built-up image virtually from QEMU (Quick Emulator) or from hardware that is either SD card or through JTAG. You can use images from your built images directory i.e. <plnx-user-proj-root>/images/linux or you can also use prebuilt images from <plnx-user-proj-root>/pre-built/linux/images for quick try instead of building whole project.
Booting on QEMU
Ensure that you are in the PetaLinux project root directory: <plnx-user-proj-root>
For further explanation on PetaLinux boot you can run: petalinux-boot --help
Booting on Hardware with SD card
To boot up board from SD card copy the generated BOOT.BIN file (also copy BOOT.BIN, Image, boot.scr, rootfs.cpio.gz.u-boot files from <plnx-proj-root>/images/linux or <plnx-proj-root>/pre-built/linux/images/ ) into the boot directory in SD card and power ON board with that SD card.
After the system is up and running, log in with the username and password.
Username is “petalinux” from 2022.1 onwards and verison previous to that it is “root”. Keep simple password for example, “root”. In order to run demo applications you need to be root.
xilinx-zcu102-20221 login: petalinux
You are required to change your password immediately (administrator enforced).
New password:
Retype new password:
[ 37.029943] audit: type=1006 audit(1659496543.347:2): pid=573 uid=0 old-auid=4294967295 auid=1000 tty=(none) old-ses=4294967295 ses=1 res=1
[ 37.031000] audit: type=1300 audit(1659496543.347:2): arch=c00000b7 syscall=64 success=yes exit=4 a0=8 a1=ffffcb6856b0 a2=4 a3=ffff807616b0 items=0 ppid=1 pid=573 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=1 comm="(systemd)" exe="/lib/systemd/systemd" key=(null)
[ 37.032490] audit: type=1327 audit(1659496543.347:2): proctitle="(systemd)"
xilinx-zcu102-20221:~$ sudo -s
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
Password:
xilinx-zcu102-20221:/home/petalinux#
Make sure you have remoteproc driver loaded. If you have unloaded the remoteproc driver, you can load it as follows:
For the Zynq UltraScale+ MPSoC device: modprobe zynqmp_r5_remoteproc
For the Zynq-7000 SoC device: modprobe zynq_remoteproc
xilinx-zcu102-20221:/home/petalinux# lsmod
Module Size Used by
zynqmp_r5_remoteproc 20480 0
uio_pdrv_genirq 16384 0
zocl 167936 0
xilinx-zcu102-20221:/home/petalinux#
xilinx-zcu102-20221:/home/petalinux# echo image_echo_test > /sys/class/remoteproc/remoteproc0/firmware
xilinx-zcu102-20221:/home/petalinux# echo start > /sys/class/remoteproc/remoteproc0/state
[ 324.510671] remoteproc remoteproc0: powering up ff9a0000.rf5ss:r5f_0
[ 324.514926] remoteproc remoteproc0: Booting fw image image_echo_test, size 615944
[ 324.574954] remoteproc0#vdev0buffer: registered virtio0 (type 7)
[ 324.576755] remoteproc remoteproc0: remote processor ff9a0000.rf5ss:r5f_0 is now up
main():98 openamp lib version: 1.1.0 (main():99 Major: 1, main():100 Minor: 1, main():101 Patch: 0)
main():103 libmetal lib version: 1.1.0 (main():104 Major: 1, main():105 Minor: 1, main():106 Patch: 0)
main():108 Starting application...
xilinx-zcu102-20221:/home/petalinux# 0 L7 registered generic bus
1 L7 init_system():160 c_buf,c_len = 0x3ed201c0,4096
2 L6 platform_init():176 platform_create_proc()
3 L6 platform_create_proc():109 rsc_table, rsc_size = 0x3ed20000, 0x100
4 L7 zynqmp_r5_a53_proc_init():73 metal_device_open(generic, poll_dev, 0x2770)
5 L7 platform_create_proc():119 poll{name,bus,chn_mask} = poll_dev,generic,0x1000000
6 L7 zynqmp_r5_a53_proc_mmap():138 lpa,lda= 0x3ed20000,0xffffffff
7 L7 zynqmp_r5_a53_proc_mmap():150 mem= 0x3a28
8 L7 zynqmp_r5_a53_proc_mmap():154 tmpio= 0x3a68
9 L7 zynqmp_r5_a53_proc_mmap():138 lpa,lda= 0x3ed40000,0xffffffff
10 L7 zynqmp_r5_a53_proc_mmap():150 mem= 0x3ab0
11 L7 zynqmp_r5_a53_proc_mmap():154 tmpio= 0x3af0
12 L6 platform_create_proc():148 Initialize remoteproc successfully.
13 L6 platform_create_rpmsg_vdev():208 creating remoteproc virtio rproc 0x3ed20138
14 L6 platform_create_rpmsg_vdev():216 initializing rpmsg shared buffer pool
[ 324.649797] virtio_rpmsg_bus virtio0: rpmsg host is online
15 L6 platform_create_rpmsg_vdev():221 initializing rpmsg vdev
16 L6 app():63 Try to create rpmsg endpoint.
17 L6 app():74 Successfully created rpmsg endpoint.
[ 324.655948] virtio_rpmsg_bus virtio0: creating channel rpmsg-openamp-demo-channel addr 0x400
xilinx-zcu102-20221:/home/petalinux# echo_test
Echo test start
Master>probe rpmsg_char
+ lsmod
Module Size Used by
rpmsg_char 16384 0
virtio_rpmsg_bus 20480 0
rpmsg_ns 16384 1 virtio_rpmsg_bus
rpmsg_core 16384 3 virtio_rpmsg_bus,rpmsg_char,rpmsg_ns
zynqmp_r5_remoteproc 20480 0
uio_pdrv_genirq 16384 0
zocl 167936 0
+ modprobe rpmsg_char
lookup_channel():231 using dev file: virtio0.rpmsg-openamp-demo-channel.-1.1024
bind_rpmsg_chrdev():127 open /sys/bus/rpmsg/devices/virtio0.rpmsg-openamp-demo-channel.-1.1024/driver_override
bind_rpmsg_chrdev():150 write virtio0.rpmsg-openamp-demo-channel.-1.1024 to /sys/bus/rpmsg/drivers/rpmsg_chrdev/bind
get_rpmsg_chrdev_fd():170 opendir /sys/bus/rpmsg/devices/virtio0.rpmsg-openamp-demo-channel.-1.1024/rpmsg
get_rpmsg_chrdev_fd():180 open /dev/rpmsg_ctrl1
main():300 rpmsg_create_ept: rpmsg-openamp-demo-channel[src=0,dst=0x400]
checking /sys/class/rpmsg/rpmsg_ctrl1/rpmsg0/name
svc_name: rpmsg-openamp-demo-channel
.
open /dev/rpmsg0
**************************************
Echo Test Round 0
**************************************
sending payload number 0 of size 17
echo test: sent : 17
received payload number 0 of size 17
sending payload number 1 of size 18
echo test: sent : 18
received payload number 1 of size 18
:
:
:
sending payload number 470 of size 487
echo test: sent : 487
received payload number 470 of size 487
sending payload number 471 of size 488
echo test: sent : 488
received payload number 471 of size 488
**************************************
Echo Test Round 0 Test Results: Error count = 0
**************************************
18 L6 rpmsg_endpoint_cb():36 shutdown message is received.
19 L7 app():82 done
[ 403.172430] virtio_rpmsg_bus virtio0: destroying channel rpmsg-openamp-demo-channel addr 0x400
20 L6 main():129 Stopping application...
21 L7 unregistered generic bus
xilinx-zcu102-20221:/home/petalinux# echo stop > /sys/class/remoteproc/remoteproc0/state
[ 495.603000] remoteproc remoteproc0: stopped remote processor ff9a0000.rf5ss:r5f_0
xilinx-zcu102-20221:/home/petalinux#
For RPMsg in Userspace
Load Firmware and module, run the test, unload application - all is taken care of by running this application: rpmsg-echo-ping-shared
xilinx-zcu102-20221:/home/petalinux# rpmsg-echo-ping-shared
metal: info: metal_linux_dev_open: checking driver vfio-platform,3ed20000.shm,(null)
metal: info: metal_uio_dev_open: No IRQ for device 3ed20000.shm.
Successfully14 L6 platform_create_rpmsg_vdev():216 initializing rpmsg shared buffer pool
15 L6 platform_create_rpmsg_vdev():221 initializing rpmsg vdev
16 L6 app():63 Try to create rpmsg endpoint.
17 L6 app():74 Successfully created rpmsg endpoint.
open shm device.
Successfully added shared memory
metal: info: metal_linux_dev_open: checking driver vfio-platform,ff340000.ipi,(null)
Successfully probed IPI device
Successfully initialized Linux r5 remoteproc.
Successfully initialized remoteproc
Calling mmap resource table.
Successfully mmap resource table.
Successfully set resource table to remoteproc.
Creating virtio...
Successfully created virtio device.
initializing rpmsg vdev
1 - Send data to remote core, retrieve the echo and validate its integrity ..
RPMSG endpoint is binded with remote.
sending payload number 0 of size 17
echo test: sent : 17
received payload number 0 of size 17
sending payload number 1 of size 18
echo test: sent : 18
received payload number 1 of size 18
:
:
:
sending payload number 477 of size 494
echo test: sent : 494
received payload number 477 of size 494
sending payload number 478 of size 495
echo test: sent : 495
received payload number 478 of size 495
sending payload number 479 of size 496
echo test: sent : 496
received payload number 479 of size 496
**********************************
Test Results: Error count = 0
**********************************
Quitting application .. Echo test end
Stopping application...
xilinx-zcu102-20221:/home/petalinux#
Running the Matrix Multiplication Test
For RPMsg in Kernel space
Load the Matrix Multiply test firmware and RPMsg module, Run the test and unload the application after test is done
xilinx-zcu102-20221:/home/petalinux# echo image_rpc_demo > /sys/class/remoteproc/remoteproc0/firmware
xilinx-zcu102-20221:/home/petalinux# echo start > /sys/class/remoteproc/remoteproc0/state
[ 145.782852] remoteproc remoteproc0: powering up ff9a0000.rf5ss:r5f_0
[ 145.785939] remoteproc remoteproc0: Booting fw image image_rpc_demo, size 624084
Starting application...
[ 145.841165] virtio_rpmsg_bus virtio0: rpmsg host is online
[ 145.842383] remoteproc0#vdev0buffer: registered virtio0 (type 7)
[ 145.843265] remoteproc remoteproc0: remote processor ff9a0000.rf5ss:r5f_0 is now up
xilinx-zcu102-20221:/home/petalinux# 0 L7 registered generic bus
1 L7 init_system():160 c_buf,c_len = 0x3ed2017c,4096
2 L6 platform_init():176 platform_create_proc()
3 L6 platform_create_proc():109 rsc_table, rsc_size = 0x3ed20000, 0x100
4 L7 zynqmp_r5_a53_proc_init():73 metal_device_open(generic, poll_dev, 0x2bd8)
5 L7 platform_create_proc():119 poll{name,bus,chn_mask} = poll_dev,generic,0x1000000
6 L7 zynqmp_r5_a53_proc_mmap():138 lpa,lda= 0x3ed20000,0xffffffff
7 L7 zynqmp_r5_a53_proc_mmap():150 mem= 0x3e98
8 L7 zynqmp_r5_a53_proc_mmap():154 tmpio= 0x3ed8
9 L7 zynqmp_r5_a53_proc_mmap():138 lpa,lda= 0x3ed40000,0xffffffff
10 L7 zynqmp_r5_a53_proc_mmap():150 mem= 0x3f20
11 L7 zynqmp_r5_a53_proc_mmap():154 tmpio= 0x3f60
12 L6 platform_create_proc():148 Initialize remoteproc successfully.
13 L6 platform_create_rpmsg_vdev():208 creating remoteproc virtio rproc 0x3ed20138
14 L6 platform_create_rpmsg_vdev():216 initializing rpmsg shared buffer pool
15 L6 platform_create_rpmsg_vdev():221 initializing rpmsg vdev
Initializating I/Os redirection...
[ 145.879312] virtio_rpmsg_bus virtio0: creating channel rpmsg-openamp-demo-channel addr 0x400
xilinx-zcu102-20221:/home/petalinux# proxy_app
Master>Loading remote firmware
Master>probe rpmsg_char
using dev file: virtio0.rpmsg-openamp-demo-channel.-1.1024
open /sys/bus/rpmsg/devices/virtio0.rpmsg-openamp-demo-channel.-1.1024/driver_override
write virtio0.rpmsg-openamp-demo-channel.-1.1024 to /sys/bus/rpmsg/drivers/rpmsg_chrdev/bind
opendir /sys/bus/rpmsg/devices/virtio0.rpmsg-openamp-demo-channel.-1.1024/rpmsg
open /dev/rpmsg_ctrl1
rpmsg_create_ept: rpmsg-openamp-demo-channel[src=0,dst=0x400]
checking /sys/class/rpmsg/rpmsg_ctrl1/rpmsg0/name
svc_name: rpmsg-openamp-demo-channel
.
Master>RPC service started !!
Remote>Baremetal Remote Procedure Call (RPC) Demonstration
Remote>***************************************************
Remote>Rpmsg based retargetting to proxy initialized..
Remote>FileIO demo ..
Remote>Creating a file on master and writing to it..
Remote>Opened file 'remote.file' with fd = 6
Remote>Wrote to fd = 6, size = 45, content = This is a test string being written to file..
Remote>Closed fd = 6
Remote>Reading a file on master and displaying its contents..
Remote>Opened file 'remote.file' with fd = 6
handle_read: 4, 45
Remote>Read from fd = 6, size = 45, printing contents below .. This is a test string being written to file..
Remote>Closed fd = 6
Remote>Remote firmware using scanf and printf ..
Remote>Scanning user input from master..
Remote>Enter name
zynq
handle_read: 4, 5
Remote>Enter age
10
handle_read: 4, 3
Remote>Enter value for pi
3.14159265358979
handle_read: 4, 17
Remote>User name = 'zynq'
Remote>User age = '10'
Remote>User entered value of pi = '3.141593'
Remote>Repeat demo ? (enter yes or no)
no
handle_read: 4, 3
Remote>RPC retargetting quitting ...
Remote> Firmware's rpmsg-rpc-channel going down!
Release remoteproc procedure call
[ 738.862033] virtio_rpmsg_bus virtio0: destroying channel rpmsg-openamp-demo-channel addr 0x400
Stopping application...
16 L7 unregistered generic bus
xilinx-zcu102-20221:/home/petalinux# echo stop > /sys/class/remoteproc/remoteproc0/state
[ 291.874626] remoteproc remoteproc0: stopped remote processor ff9a0000.rf5ss:r5f_0
xilinx-zcu102-20221:/home/petalinux#
For RPMsg in Userspace
Load Firmware and module, run the test, unload application - all is taken care of by running this application: rpc_demod-shared
xilinx-zcu102-20221:/home/petalinux# rpc_demod-shared
Master> Starting application...
metal: info: metal_linux_dev_open: checking driver vfio-platform,3ed20000.shm,(null)
metal: info: metal_uio_dev_open: No IRQ for device 3ed20000.shm.
Successfully open shm device.
Successfully added shared memory
metal: info: metal_linux_dev_open: checking driver vfio-platform,ff340000.ipi,(null)
Successfully probed IPI device
Successfully initialized Linux r5 remoteproc.
Successfully initialized remoteproc
Calling mmap resource table.
Successfully mmap resource table.
Successfully set resource table to remoteproc.
Creating virtio...
Successfully created virtio device.
initializing rpmsg vdev
Master> Try to create rpmsg endpoint.
14 L6 platform_create_rpmsg_vdev():216 initializing rpmsg shared buffer pool
15 L6 platform_create_rpmsg_vdev():221 initializing rpmsg vdev
Master> Successfully created rpmsg endpoint.
Initializating I/Os redirection...
Remote>Baremetal Remote Procedure Call (RPC) Demonstration
Remote>***************************************************
Remote>Rpmsg based retargetting to proxy initialized..
Remote>FileIO demo ..
Remote>Creating a file on master and writing to it..
Remote>Opened file 'remote.file' with fd = 7
Remote>Wrote to fd = 7, size = 45, content = This is a test string being written to file..
Remote>Closed fd = 7
Remote>Reading a file on master and displaying its contents..
Remote>Opened file 'remote.file' with fd = 7
Remote>Read from fd = 7, size = 45, printing contents below .. This is a test string being written to file..
Remote>Closed fd = 7
Remote>Remote firmware using scanf and printf ..
Remote>Scanning user input from master..
Remote>Enter name
zynq
Remote>Enter age
10
Remote>Enter value for pi
3.1415
Remote>User name = 'zynq'
Remote>User age = '10'
Remote>User entered value of pi = '3.141500'
Remote>Repeat demo ? (enter yes or no)
no
Remote>RPC retargetting quitting ...
Remote> Firmware's rpmsg-rpc-channel going down!
Release remoteproc procedure call
Master> Received termination request
Stopping application...
Master> Endpoint is destroyed
Master>
16 L7 unregistered generic bus
RPC service exiting !!
Master> Destroying endpoint.
Master> Stopping application...
xilinx-zcu102-20221:/home/petalinux#