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.
Working with a User Space Yocto Layer
This tip has been adapted to PetaLinux using the meta-example layer available here
meta-example Code Block |
---|
|
$ git clone https://github.com/DynamicDevices/meta-example |
This example layer is providing 3 build recipes, bbexample, bbexample-rt and bbexample-lt respectively fetching the source code from a git tree, a remote tar file and a local tar file
Code Block |
---|
|
$ petalinux-build -c bbexample
$ petalinux-build -c bbexample-rt
$ petalinux-build -c bbexample-lt |
Configuring the layer path in the PetaLinux build system
Move to your
PetaLinux Petalinux project
build directory,
edit the conf/bblayers.conf file and add your layer path to BBLAYERS Code Block |
---|
|
BBLAYERS := " \
${SDKBASEMETAPATH}/layers/poky/meta \
${SDKBASEMETAPATH}/layers/poky/meta-poky \
add the layer path in below config option.
Code Block |
---|
cd <plnx-proj-root>
petalinux-config --> Yocto Settings --> User Layers --> (/absolute_path_to_meta_layer/meta-example) \user layer " |
Building the meta-layer
Move to your Yocto project build directory, edit the conf/bblayers.conf file and add your layer path to BBLAYERS Code Block |
---|
|
BBLAYERS := " \
${SDKBASEMETAPATH}/layers/poky/meta \
${SDKBASEMETAPATH}/layers/poky/meta-poky \
/absolute_path_to_meta_layer/meta-example \
" |
The recipe we are going to build is
https://github.com/DynamicDevices/meta-example/blob/master/recipes-example/bbexample/bbexample-lt_1.0.bbThe recipe bbexample-lt is using some variables
1.
SRC_URI Space-delimited list of URIs to download source code, patches, and other files from git, local absolute path, https, ftp etc.
2.
PN is the Package Name. The value of this variable is derived by BitBake from the base name of the recipe file.
3.
PV is the Package Version. which is derived by BitBake from the base name of the recipe file
Code Block |
---|
|
# Use local tarball
SRC_URI = "file://bbexample-${PV}.tar.gz" |
The recipe
bbexample-lt can invoked using the following command
Code Block |
---|
|
$ petalinux-build -c bbexample-lt |
here is the command output
Code Block |
---|
|
$ petalinux-build -c bbexample-lt
[INFO] building bbexample-lt
[INFO] sourcing bitbake
INFO: bitbake bbexample-lt
Loading cache: 100% |###############################################################################################################################################################################| ETA: 00:00:00
Loaded 2941 entries from dependency cache.
Parsing recipes: 100% |#############################################################################################################################################################################| Time: 00:00:01
Parsing of 2328 .bb files complete (2294 cached, 34 parsed). 2943 targets, 196 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
NOTE: Preparing RunQueue
NOTE: Checking sstate mirror object availability (for 38 objects)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 872 tasks of which 857 didn't need to be rerun and all succeeded.
INFO: Copying Images from deploy to images
[INFO] successfully built bbexample-lt |
You have now successfully built the layer but you still need to include the binary produced into the kernel root file system
There are two options in order to
do so1. Edit your project conf/local.conf do so1. Edit your project <BUILD_DIR>/conf/local.conf file for YOCTO project <plnx-proj-root>/meta-user/conf/petalinuxbsp.conf file for PETALINUX project and add
Code Block |
---|
|
IMAGE_INSTALL_append = " bbexample-lt" |
2. Adding a package to an image via a
.bbappendYou may wish to add specific packages to specific images, which is generally viewed as better practice. We are using
core-image-minimal bitbake recipe for this tip by creating file
core-image-minimal.bbappend. This .bbappend file is extending the original core-image-minimal recipe in order to include the layer build output into the Linux root file system.
Code Block |
---|
|
recipes-core/images/core-image-minimal.bbappend |
core-image-minimal.bbappend file content
Code Block |
---|
|
IMAGE_INSTALL += " bbexample-lt" |
1. Rebuild your layer
Code Block |
---|
|
$ petalinux-build -c bbexample_lt -x cleansstate |
2. Rebuild your kernel
Code Block |
---|
|
$ petalinux-build -c kernel |
3. Start qemu
Code Block |
---|
|
$ petalinux-boot --qemu --kernel |
4. Log on qemu and start the application
Code Block |
---|
|
root@plnx_arm:/# /usr/bin/bbexample
Hello Yocto World...
Hello World (from a shared library!) |
Patching the Linux Kernel of a PetaLinux Project
1. Copy the patch to project file
<plnx-proj-root>/project-spec/meta-user/recipes-kernel/linux/linux-xlnx directory.
2. Modify project file
<plnx-proj-root>/project-spec/meta-user/recipes-kernel/linux/linux-xlnx_%.bbappend to use the patch file by adding the patch file name to the SRC_URI_append variable. If the variable does not exist in the file then add a new line with
Code Block |
---|
|
SRC_URI_append = " file://0001-linux-driver-fix.patch"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
3. Make sure the priority for the meta-user layer is 7 in the project file
<plnx-proj-root>/project-spec/meta-user/conf/layer.conf .
Note: Any patches in the project will not be applied to an external source tree for the Linux kernel or u-boot. The user should apply patches to the external source tree.
How to Modify inittab or getty in a PetaLinux Project
1. Create a sysvinit directory in meta-user layer as
Code Block |
---|
|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-core/sysvinit/sysvinit-inittab |
2. Create a
sysvinit-inittab_%.bbappend file and your own inittab file or your inittab patch
Code Block |
---|
|
$ vim <plnx-proj-root>/project-spec/meta-user/recipes-core/sysvinit/sysvinit-inittab_%.bbappend |
Code Block |
---|
|
SRC_URI_append = " file://inittab"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
Or
Code Block |
---|
|
SRC_URI_append = " file://inittab.patch"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
How to Patch the FSBL in a PetaLinux Project
Note: This method can't be used for v2016.4 PetaLinux Projects. PetaLinux tools use externalsrc methodology to fetch the source code from XSDK. Yocto does not allow patching in this externalsrc mechanism. Hence this method can't be used in Yocto.1. Create a fsbl and files directory in meta-user layer as
Code Block |
---|
|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsbl/files
## From 2021.1 onwards
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-bsp/embeddedsw/ |
2. Copy patch files to
<plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsbl/files as Code Block |
---|
|
as Code Block |
---|
|
$ cp 0001-FSBL.patch <plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsbl/files
## From 2021.1 onwards
$ cp 0001-FSBL.patch <plnx-proj-root>/project-spec/meta-user/recipes-bsp/fsblembeddedsw/files |
Note that patches should be generated based on the embeddedsw GIT repo which contains FSBL as the patches require the path into the repo to apply correctly.
3. 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 |
Code Block |
---|
|
# Patch for FSBL
# Note: do_configure_prepend task section is required only for 2017.1 release
# Refer https://github.com/Xilinx/meta-xilinx-tools/blob/rel-v2017.2/classes/xsctbase.bbclass#L29-L35
do_configure_prepend() {
if [ -d "${S}/patches" ]; then
rm -rf ${S}/patches
fi
if [ -d "${S}/.pc" ]; then
rm -rf ${S}/.pc
fi
}
SRC_URI_append = " \
file://0001-FSBL.patch \
"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
#Add debug for FSBL(optional)
XSCTH_BUILD_DEBUG = "1"
#Enable appropriate FSBL debug or compiler flags
YAML_COMPILER_FLAGS_append = " -DXPS_BOARD_ZCU102"
# Note: This is not required if you are using Yocto
# CAUTION!: EXTERNALXSCTSRC and EXTERNALXSCTSRC_BUILD is required only for 2018.2 and below petalinux releases
EXTERNALXSCTSRC = ""
EXTERNALXSCTSRC_BUILD = "" |
4. Remove the
<plnx-proj-root>/components/plnx_workspace and clean your project workspace before rebuilding FSBL components
Code Block |
---|
|
$ petalinux-build -x mrproper
#Note: In v2018.1 PetaLinux release onwards "petalinux-build -x mrproper" command will remove <plnx-proj-root>/components/plnx_workspace directory
$ rm -rf <plnx-proj-root>/components/plnx_workspace |
5. Rebuilding FSBL components
Code Block |
---|
|
$ petalinux-build -c bootloader |
How to Patch the PMU Firmware in a PetaLinux Project
Note: This method can't be used for v2016.4 PetaLinux Projects. PetaLinux tools use externalsrc methodology to fetch the source code from XSDK. Yocto does not allow patching in this externalsrc mechanism. Hence this method can't be used in Yocto.1. Create a pmu/pmu-firmware and files directory in meta-user layer as
Code Block |
---|
|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu/files
#For v2018.1 release onwards
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu-firmware/files |
2. Copy patch files to
<plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu/files as
Code Block |
---|
|
$ cp 0001-PMUFW.patch <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu/files
#For v2018.1 release onwards
$ cp 0001-PMUFW.patch <plnx-proj-root>/project-spec/meta-user/recipes-bsp/pmu-firmware/files |
3. 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 |
Code Block |
---|
|
# Patch for PMUFW
# Note: do_configure_prepend task section is required only for 2017.1 release
# Refer https://github.com/Xilinx/meta-xilinx-tools/blob/rel-v2017.2/classes/xsctbase.bbclass#L29-L35
do_configure_prepend() {
if [ -d "${S}/patches" ]; then
rm -rf ${S}/patches
fi
if [ -d "${S}/.pc" ]; then
rm -rf ${S}/.pc
fi
}
SRC_URI_append = " \
file://0001-PMUFW.patch \
"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
# Enable appropriate PMUFW debug or compiler flags
YAML_COMPILER_FLAGS_append = " -DENABLE_EM"
# Note: This is not required if you are using Yocto
# CAUTION!: EXTERNALXSCTSRC and EXTERNALXSCTSRC_BUILD is required only for 2018.2 and below petalinux releases
EXTERNALXSCTSRC = ""
EXTERNALXSCTSRC_BUILD = "" |
4. Remove the
<plnx-proj-root>/components/plnx_workspace and clean your project workspace before rebuilding PMUFW components
Code Block |
---|
|
$ petalinux-build -x mrproper
#Note: In v2018.1 or later PetaLinux release "petalinux-build -x mrproper" command will remove <plnx-proj-root>/components/plnx_workspace directory
$ rm -rf <plnx-proj-root>/components/plnx_workspace |
5. Rebuilding PMUFW components
Code Block |
---|
|
$ petalinux-build -c pmufw |
Configuring the FSBL and PMUFW Debugs in a PetaLinux Project
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" |
By pass PMUFW debug logs on different UART console:
Code Block |
---|
|
YAML_SERIAL_CONSOLE_STDIN_forcevariable = "psu_uart_1"
YAML_SERIAL_CONSOLE_STDOUT_forcevariable = "psu_uart_1" |
Remove the
<plnx-proj-root>/components/plnx_workspace and clean you project workspace before rebuilding FSBL or PMUFW components
Code Block |
---|
|
$ petalinux-build -x mrproper
#Note: In v2018.1 or later PetaLinux release "petalinux-build -x mrproper" command will remove <plnx-proj-root>/components/plnx_workspace directory
$ rm -rf <plnx-proj-root>/components/plnx_workspace
$ petalinux-build |
How to Update psu_init Files in PetaLinux Project
Info |
---|
Note: PSU_INIT files are generated based on HDF or XSA parsing, Hence these files can't be patched on top of embedded_sw repo using Yocto SRC_URI variable. Alternatively we can update these files by editing <plnx-proj-root>/project-spec/hw-description/psu_init.c and copy to FSBL build workspace during do_compile_prepend bitbake task. |
1. Modify <plnx-proj-root>/project-spec/hw-description/psu_init.c file as per your requirement
2. Create a FSBL bbappend file under <plnx-proj-root>/project-spec/meta-user/recipes-bsp-spec/meta-user/recipes-bsp/embeddedsw/fsbl-firmware_%.bbappend and add below content to update psu_init.c changes to FSBL
Code Block |
---|
|
# For 2018.2 and below versions
do_compile_prepend(){
install -m 0644 ${TOPDIR}/../project-spec/hw-description/psu_init.c ${TOPDIR}/../components/plnx_workspace/fsbl/fsbl_ |
%.bbappend and add below content to update changes to FSBL Code Block |
---|
|
# For 2018.2 and below versions
}
# For 2018.3 and later versions we removed FSBL and PMUFW external workspace from <plnx-proj-root>/components/plnx_workspace directory
# to align Yocto patching mechanism. Hence we are copying the files to build workspace(${B})
# https://github.com/Xilinx/meta-xilinx-tools/blob/rel-v2018.3/classes/xsctbase.bbclass#L14
do_compile_prepend(){
install -m 0644 ${TOPDIR}/../project-spec/hw-description/psu_init.c ${TOPDIRB}/fsbl/psu_init.c
} |
How to Add Pre-built Libraries in PetaLinux or Yocto Projects
1./components/plnx_workspace/fsbl/fsbl_hwproj/psu_init.c
}
# For 2018.3 and later versions we removed FSBL and PMUFW external workspace from <plnx-proj-root>/components/plnx_workspace directory
# to align Yocto patching mechanism. Hence we are copying the files to build workspace(${B})
# https://github.com/Xilinx/meta-xilinx-tools/blob/rel-v2018.3/classes/xsctbase.bbclass#L14
do_compile_prepend(){
install -m 0644 ${TOPDIR}/../project-spec/hw-description/psu_init.c ${B}/fsbl/psu_init.c
}How to Add Pre-built Libraries in PetaLinux or Yocto Recipes
1. Create a new recipe or in existing recipe in meta-user layer as shown Code Block |
---|
theme | Midnight Create an application/recipe and copy prebuilt library and header files with the following commands. Assuming prebuilt library name is libcpsample.so.1.0.1. In Petalinux Flow:
Code Block |
---|
|
$ petalinux-create -t apps --template install --name libcpsample --enable
$ cp libcpsample.so.1.0.1 <plnx-proj-root>/project-spec/meta-user/recipes-apps/libcpsample/files
$ cp cpsample.h <plnx-proj-root>/project-spec/meta-user/recipes-apps/libcpsample/files |
(or) You can use the below single command to achieve the above functionality. Code Block |
---|
|
$ petalinux-create -t apps --template install --name libcpsample --enable --srcuri "<path-to-dir>/libcpsample.so.1.0.1 <path-to-dir>/cpsample.h>" |
In Yocto Flow:
Code Block |
---|
$ mkdir -p <plnx-proj-root>/project-spec/meta-user/<layer-path>/recipes-apps/libcpsample/files |
2. Copy pre-built libraries files and header file required for libraries to <plnx-proj-root>/project-spec/meta-user/
$ touch <layer-path>/recipes-apps/libcpsample/ |
files as Code Block |
---|
|
libcpsample.bb
$ cp libcpsample.so.1.0.1 <plnx<layer-proj-root>/project-spec/meta-user/path>/recipes-apps/libcpsample/files
$ cp cpsample.h <plnx-proj-root>/project-spec/meta-user/<layer-path>/recipes-apps/libcpsample/files |
32. Add the below content to recipe
(bb) file
Code Block |
---|
|
#
# This file is the libcpsample recipe.
#
SUMMARY = "Sample pre-built library copy to rootfs"
SECTION = "libs"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = " \
file://libcpsample.so.1.0.1 \
file://cpsample.h \
"
S = "${WORKDIR}"
# Add dependency libraireslibraries if any
# for example DEPENDS = "libpcap"
# If you need to create a symbolic link using the pre-built libraries you should use oe_soinstall.
# This copies libraries to "{TARGET_ROOTFS}/usr/lib" directory and create a symlink as
# lrwxrwxrwx libcpsample.so.1.0 -> libcpsample.so.1.0.1
# -rwxr-xr-x libcpsample.so.1.0.1
do_install() {
install -d ${D}${libdir}
oe_soinstall ${S}/libcpsample.so.1.0.1 ${D}${libdir}
install -d -m 0655 ${D}${includedir}/CPSAMPLE
install -m 0644 ${S}/*.h ${D}${includedir}/CPSAMPLE/
}
# Inhibit warnings about files being stripped
INSANE_SKIP_${PN} = "ldflags"
INSANE_SKIP_${PN} = "already-stripped"
# If you don't have .h file to copy to /usr/include add something like below
# FILES_${PN} = "${libdir}/*.so.*"
FILES_${PN} = "${libdir}/*.so.* ${includedir}/*"
FILES_${PN}-dev = "${libdir}/*.so" |
4. Build the pre-built library recipe
Code Block |
---|
|
$ petalinux-build -c libcpsamplerootfs |
Creating Libraries in a PetaLinux Project
...