This page is intended to be a collection place for tips and tricks related to Yocto layers and how Yocto works under Petalinux.
Table of Contents
Documentation
The first place you should start to better understand many details of the Yocto project is the Yocto project website.
...
Create a
fsbl bbappend file and add below content
Code Block |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsbl/fsbl_%.bbappend
# From 2021.1 onwards
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-bsp/embeddedsw/fsbl-firmware_%.bbappend |
To enable debugs in FSBL:
Code Block |
---|
|
#Add debug for FSBL
XSCTH_BUILD_DEBUG = "1" |
To add compiler flags in FSBL:
Code Block |
---|
|
#Add compiler flags for FSBL
YAML_COMPILER_FLAGS_append = " -DFSBL_PROT_BYPASS" |
To add BSP flags(secure mode) in FSBL:
Code Block |
---|
|
#Add BSP flags for FSBL
YAML_BSP_CONFIG += "secure_mode"
YAML_BSP_CONFIG[secure_mode] = "set,true" |
Create a
pmu-firmware_%.bbappend file and add below content
Code Block |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu/pmu-firmware_%.bbappend
#For v2018.1 or later PetaLinux releases only
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu-firmware/pmu-firmware_%.bbappend |
To enable debugs in PMUFW refer this
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18841724/PMU+Firmware page for DEBUG flags list
Code Block |
---|
|
#Add debug for PMUFW
XSCTH_BUILD_DEBUG = "1" |
To add compiler flags in PMUFW, see
PMU FW Build Flags:
Code Block |
---|
|
#Add compiler flags for PMUFW
YAML_COMPILER_FLAGS_append = " -DDEBUG_MODE -DXPFW_DEBUG_DETAILED" |
To add BSP flags(secure mode) in PMUFW:
Code Block |
---|
|
#Add BSP flags for PMUFW
YAML_BSP_CONFIG += "secure_mode"
YAML_BSP_CONFIG[secure_mode] = "set,true" |
To add BSP flags(debug mode) in PMUFW: For example if you want to enable https://github.com/Xilinx/embeddedsw/blob/release-2018.3/lib/sw_apps/zynqmp_pmufw/misc/xfpga_config.h#L34 debug is Xil BSP libraries
Code Block |
---|
|
#Add BSP flags for PMUFW
YAML_BSP_CONFIG += "debug_mode"
YAML_BSP_CONFIG[debug_mode] = "set,true" |
...
1. Create a library using petalinux tools
Code Block |
---|
|
$ petlainux-create -t apps --template c --name sampleapp --enable |
2. Modify the
sampleapp.bb recipe file
<plnx-proj-root>/project-spec/meta-user/recipes-apps/sampleapp/sampleapp.bb as
Code Block |
---|
|
#
# This file is the sampleapp recipe.
#
SUMMARY = "Simple sampleapp application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI = " \
file://sampleapp.c \
"
S = "${WORKDIR}"
DEPENDS += " libsample"
#This uses libsample.so.1.0.1 (-lsample)
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} -o sampleapp sampleapp.c -lsample
}
do_install() {
install -d ${D}${bindir}
install -d -m 0755 sampleapp ${D}${bindir}
}
FILES_${PN} += "sampleapp" |
3. Modify the
<plnx-proj-root>/project-spec/meta-user/recipes-apps/libsample/files/sampleapp.c generated from petalinux tools as
Code Block |
---|
|
#include <stdio.h>
#include <SAMPLE/sample.h> // From above libs <TARGET_ROOTFS>/usr/lib/SAMPLE/sample.h
int main(int argc, char **argv)
{
printf("Hello World!\n");
sample_hello();
return 0;
} |
4. Build the apps recipe
Code Block |
---|
|
$ petalinux-build -c sampleapp |
How to Auto Run Application at Startup
1. Create a library using petalinux tools
Code Block |
---|
|
$ petalinux-create -t apps --template install -n myapp-init --enable |
2. Edit the file <plnx-proj-root>/project-spec/meta-user/recipes-apps/myapp-init/myappinit.bb. The file should look like the following:
Code Block |
---|
|
#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-init1init ${D}${sysconfdir}/init.d/myapp-init1init
}
FILES_${PN} += "${sysconfdir}/*"
|
3. To run myapp as daemon, edit the file <plnx-proj-root>/project-spec/meta-user/recipes-apps/myapp-init/files/myapp-init.
Code Block |
---|
|
#!/bin/sh
DAEMON=/usr/bin/myapp-init
start ()
{
echo " Starting myapp-init"
start-stop-daemon -S -o --background -x $DAEMON
}
stop ()
{
echo " Stoping myapp-init"
start-stop-daemon -K -x $DAEMON
}
restart()
{
stop
start
}
[ -e $DAEMON ] || exit 1
case "$1" in
start)
start; ;;
stop)
stop; ;;
restart)
restart; ;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $? |
4. Build the project
Code Block |
---|
petalinux-build |
How to Auto Mount SD card in Yocto Recipes
1. Create a base-files directory in meta-user layer as
Code Block |
---|
|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-core/base-files |
2. Create a base-files_%.bbappend file and add below content
Code Block |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-core/base-files/base-files_%.bbappend
#base-files_%.bbappend content
dirs755 += "/media/card"
do_install_append() {
sed -i '/mmcblk0p1/s/^#//g' ${D}${sysconfdir}/fstab
} |
3. Rebuild rootfs
Code Block |
---|
|
$ petalinux-build |
Method 1: Append auto eth1 to existing interfaces file
1. Create a init-ifupdown directory in meta-user layer as
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-core/init-ifupdown/ |
2. Create a
init_ifupdown_%.bbappend file and add below content
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-core/init-ifupdown/init-ifupdown_%.bbappend
# init-ifupdown_%.bbappend content
do_install_append() {
sed -i '/iface eth0 inet dhcp/ a auto eth1' ${D}${sysconfdir}/network/interfaces
} |
3. Rebuild rootfs
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ petalinux-build |
Method 2: Use your own interfaces file
1. Create a init-ifupdown directory in meta-user layer as
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-core/init-ifupdown/files |
2. Create your own network interface file as show below
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-core/init-ifupdown/files/myinterfaces
# myinterfaces content
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# The loopback interface
auto lo
iface lo inet loopback
# Wireless interfaces
iface wlan0 inet dhcp
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf
iface atml0 inet dhcp
# Wired or wireless interfaces
auto eth0
iface eth0 inet dhcp
# Add auto config for eth1
auto eth1
iface eth1 inet dhcp
# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.0
network 192.168.7.0
gateway 192.168.7.1
# Bluetooth networking
iface bnep0 inet dhcp |
3. Create a init_ifupdown_%.bbappend file and add below content
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-core/init-ifupdown/init-ifupdown_%.bbappend
# init-ifupdown_%.bbappend content
SRC_URI += " \
file://myinterfaces \
"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
# Overwrite interface file with myinterface file in rootfs
do_install_append() {
install -m 0644 ${WORKDIR}/myinterfaces ${D}${sysconfdir}/network/interfaces
} |
4. Rebuild rootfs
Code Block |
---|
language | bash |
---|
theme | Midnight |
---|
|
$ petalinux-build |
...