Ug977 Petalinux Getting Started
Ug977 Petalinux Getting Started
User Guide
© Copyright 2014 Xilinx, Inc. Xilinx, the Xilinx logo, Artix, ISE, Kintex, Spartan, Virtex, Vivado, Zynq, and other designated brands included herein are
trademarks of Xilinx in the United States and other countries. All other trademarks are the property of their respective owners.
Revision History
2011-11-26 1.3 Updated for PetaLinux Tools 1.3 release - PowerPC 440 support
2011-04-01 2.1 Updated for PetaLinux Tools 2.1 release - new procedure for rebuilding
reference designs based on Xilinx 13.1
Online Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Appendix C: How to Work with External Kernel and U-boot With PetaLinux . . . . . . . . . . . . . 22
Additional Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
What is PetaLinux
PetaLinux Tools provide a simple and fast method to build and deploy Linux-based software on Xilinx Zynq-7000
APSoC and MicroBlaze devices. With PetaLinux, you can:
• Build and configure Linux components; Linux kernel, u-boot and file system, for Zynq-7000 APSoC and
MicroBlaze based designs
• Easily synchronize your Linux software platform and hardware platform in a single step
• Easily target and migrate your Linux user application to Zynq-7000 APSoC or MicroBlaze based Linux
platform
• Quickly get started with building Linux-based software on Xilinx and partner development boards using
the pre-built Board Support Packages (BSPs)
• Test your Zynq-7000 APSoC or MicroBlaze Linux system without any hardware in a virtual machine
environment using QEMU
• xilinx-v2014.1 u-boot
The following sections will get you started with building and booting linux using PetaLinux tools.
Prerequisites
This getting started document assumes that the following prerequisites have been satisfied:
• You have PetaLinux Tools installed on your Linux workstation. If you haven’t installed PetaLinux Tools,
please refer to PetaLinux Tools Installation Guide (UG976) to install it.
• A serial communication program such as minicom or kermit has been installed; the baud rate of the
serial communication program has been set to 115200bps.
• If you wish to work on hardware designs, Xilinx tools and JTAG cable drivers must be installed. Please
refer to Xilinx installation documentation and procedures.
• Unless otherwise indicated the PetaLinux tool command must be run from within a project directory
("<project-root>").
• A "/tftpboot" directory on your workstation and all users have read/write permissions to it.
Environment Setup
Setup the PetaLinux working environment by running the PetaLinux setup script as follows:
$ source <path-to-installed-PetaLinux>/settings.sh
or for C shell:
$ source <path-to-installed-PetaLinux>/settings.csh
WARNING:
• Only run one of these scripts - whichever is appropriate for your terminal shell
• You must run the settings script each time you open a new terminal window or shell. The PetaLinux
tools will fail otherwise.
$ echo $PETALINUX
/opt/petalinux-v2014.2-final
Environment variable "$PETALINUX" should point to the path to the installed PetaLinux. Your echo output
may be different from this example, it depends on where you installed PetaLinux.
BSP is not included in the PetaLinux installer, you will need to download the BSP from PetaLinux download
website.
1. Change to the directory under which you want PetaLinux projects to be created. E.g.: I want to create
projects under /home/user:
$ cd /home/user
You will see output similar to the following, according to which BSP you are installing:
INFO: Projects:
INFO: * Xilinx-ZC702-2014.2
INFO: has been successfully installed to /home/user
INFO: New project successfully created in /home/user
In the above example, when the command runs, it tells you what projects has been extracted from the BSP and
installed. If you run ls from "/home/user", you will see the installed projects.
Please refer to section Appendix B: PetaLinux Project Structure for more details on a PetaLinux project.
2. Copy the following files from <plnx-proj-root>/pre-built/linux/images/ into the root directory of the first
partition which is of FAT format of your SD card:
• BOOT.BIN
• image.ub
4. Open a console on your workstation and then start your preferred serial communication program (e.g.
kermit, minicom) with the baud rate set to 115200 on that console.
9. Watch the console. Hit any key to stop autoboot when you see the following message on the console:
10. Type "run sdboot" in the u-boot console to boot Linux from SD card:
11. Watch the serial console, you will see boot messages which is similar to the following:
12. Type user name root and password root on the serial console to log into the PetaLinux system.
2. Connect the JTAG port on the board with the JTAG cable to your workstation.
4. Connect the Ethernet port on the board to the local network via a network switch.
5. For Zynq boards, ensure the mode switches are set to JTAG mode. Refer to the board documentation for
details.
7. Open a console on your workstation and then start your preferred serial communication program (e.g.
kermit, minicom) with the baud rate set to 115200 on that console.
The --jtag option tells petalinux-boot to boot on hardware via JTAG, and the --prebuilt 3 boots
the linux kernel. This command will take some time to finish, please wait until you see the shell prompt
again on the command console.
The figures below are examples of the messages on the workstation command console and on the serial
console:
By default, network settings for PetaLinux reference designs are configured using DHCP. The output you
see may be slightly different from the above example, depending upon which PetaLinux reference design
you test.
9. Type user name root and password root on the serial console to log into the PetaLinux system.
10. Determine the IP address of the PetaLinux by running ifconfig on the system console.
Troubleshooting
If your local network does not have a DHCP server, the system will fail to acquire an IP address. If so, refer to
Apendix A which describes how to manually specify the address.
If the petalinux-boot for jtag command fails, it is typically from a JTAG connectivity failure. Please ensure
the board is powered on and your JTAG cable is properly connected. Please refer to the Xilinx JTAG cable and
tools documentation for more detailed troubleshooting.
1. Change to your project directory and boot the prebuilt linux kernel image:
The --qemu option tells petalinux-boot to boot QEMU, instead of real hardware via JTAG, and the
--prebuilt 3 boots the linux kernel.
• The --prebuilt 1 option performs a Level 1 boot, that is, only configure the FPGA.
• Level 2 is FPGA + u-boot.
• Level 3 is FPGA + pre-built Linux image.
You should see the following kernel boot log on the console:
2. Login to PetaLinux with the default user name root and password root.
TIP: To exit QEMU, press Ctrl+A together, release and then press X
$ petalinux-build
This step will generate DTB, first stage bootloader if select, u-boot if selected, kernel, rootfs, and will
generate boot images.
2. The compilation progress will show on the console. Wait until the compilation finishes.
TIP:
When the build finishes, the generated images will be within the "<project-root>/images" and
"/tftpboot" directories.
The final kernel image is the "zImage" for Zynq or "image.elf" for MicroBlaze, living in the "<project-
root>/images/linux" folder. A copy is also placed in the "/tftpboot" directory or your development
workstation, to support network-based kernel boot.
1. Use petalinux-boot --qemu command to test the newly built software image:
The system boot messages will be shown on the console where QEMU is running.
2. When you see the login prompt on the QEMU console, login as root with password root.
TIP:
1. Use petalinux-boot to program the FPGA with the reference design pre-built bitstream:
This command will take a few moments, please wait until you see the shell prompt shows again on the
command console.
2. Use petalinux-boot to download the built Linux image to the board and boot it:
This command will take a few minutes, downloading the entire kernel image over the JTAG link. Please
wait until the shell prompt displays again on the serial console.
3. Watch the serial console, you should see the Linux booting messages shown on the serial console.
You can now repeat the previous steps for connecting to the board via the serial console and the network demo.
For Zynq, you can follow section Boot Pre-built Images from SD Card for Zynq to SD boot the rebuilt images.
Instead of using the prebuilt image.ub, use the rebuilt one from <plnx-proj-root>/images/linux/image.ub.
• If you are booting on real hardware, and the board is connected to a local network, the IP address
of the system should be in the subnet of the local network.
• If you are booting in QEMU, the IP address of the system should be in the QEMU subnet. Refer to
the PetaLinux Tools QEMU System Emulation Guide (UG982) for more details.
2. Use ifconfig command to set the systems IP address on the login console:
e.g:
3. Use ifconfig on the system login console again to confirm whether the IP address has been successfully
set:
# ifconfig
You should be able to see the IP has been set to the interface eth0.
A PetaLinux project directory contains configuration files of the project, the Linux subsystem, and the
components of the subsystem. petalinux-build builds the project with those configuration files. User
can run petlainux-config to modify them.
Here is an example of a PetaLinux project:
<project-root>
|-.petalinux/
|-hw-description/
|-config.project
|-subsystems/
| |-linux/
| | |-config
| | |-hw-description/
| | |-configs/
| | | |-device-tree/
| | | | |-ps.dtsi
| | | | |-pl.dtsi
| | | | |-system-conf.dtsi
| | | | |-system-top.dts
| | | |-kernel/
| | | | |-config
| | | |-u-boot/
| | | | |-config.mk
| | | | |-platform-auto.h
| | | | |-platform-top.h
| | | |-rootfs/
| | | |-config
|-components/
| |-bootloader/
| | |-fs-boot/ | zynq_fsbl/
| |-apps/
| | |-myapp/
• pl.dtsi
• system-conf.dtsi
system-top.dts will not be modified by any PetaLinux
tools and under full control by user. User can add their
own DTSI files to this directory.
• config.mk
• platform-auto.h
"<project-root>/components/<COMPONENT_
TYPE>/<COMPONENT>"
<project-root>
|-.petalinux/
|-hw-description/
|-config.project
|-subsystems/
| |-linux/
| | |-config
| | |-hw-description/
| | |-configs/
| | | |-device-tree/
| | | |-kernel/
| | | |-u-boot/
| | | |-rootfs/
|-components/
| |-apps/
| | |-myapp/
|-build/
| |-build.log
| |-linux/
| | |-rootfs/
| | | |-targetroot/
| | | |-stage/
| | | |-apps/
| | | | |-myapp/
| | |-kernel/
| | |-u-boot/
| | |-device-tree/
| | |-bootloader/
|-images/
| |-linux/
"<project-root>/images/" is automatically generated. Files in this directory will get updated when
you run petalinux-build.
TIP: You can have version control over your PetaLinux project directory "<project-root>" excluding
the following:
• "<project-root>/.petalinux"
• "<project-root>/.build"
• "<project-root>/.images"
To make PetaLinux tools detect your kernel and u-boot, you can:
• For kernel, create a <plnx-proj-root>/components/linux-kernel/ directory, add your kernel source to the
created directory <plnx-proj-root>/components/linux-kernel/<MY-KERNEL>.
• For u-boot, create a <plnx-proj-root>/components/u-boot/ directory, add your kernel source to the created
directory: <plnx-proj-root>/components/u-boot/<MY-U-BOOT>.
• For kernel, select "kernel () --->", it will list your kernel there. E.g.:
(X) <MY-KERNEL>
( ) xlnx-3.14
( ) remote
• For u-boot, select "u-boot () --->", it will list your u-boot there. E.g.:
(X) <MY-U-BOOT>
( ) u-boot-plnx
( ) remote
( ) none
WARNING: PetaLinux u-boot auto config is just tested with the u-boot shipped with PetaLinux, it is not
guarranted to just work with your own u-boot.
• Sometimes, the default kernel config may not work with your kernel, in this case, you will need to:
◦ you can run "petalinux-config -c kernel" to configure your kernel, or you can use
defconfig of your kernel with the following command:
And then when you run petalinux-config, you can see your kernel and u-boot from the kernel/u-boot
candidate list.
petalinux-create
Usage:
petalinux-create [options] -t|--type <TYPE> -n|--name <COMPONENT_NAME>
Required:
-t, --type <TYPE> Available type:
* project
* apps
* libs
* modules
* generic
-n, --name <COMPONENT_NAME> specify a name for the component or
project. It is OPTIONAL to create a
PROJECT. If you specify source BSP when
you create a project, you are not
required to specify the name.
Options:
-p, --project <PROJECT> specify full path to a PetaLinux project
this option is NOT USED for PROJECT CREATION.
default is the working project.
--force force overwriting an existing component
directory.
-h, --help show function usage
--enable this option applies to all types except
project.
enable the created component
petalinux-config
Usage:
petalinux-config [options] {--component <COMPONENT> |\
--get-hw-description[=SRC] |--searchpath <--ACTION> [VALUE]}
Options:
-h, --help show function usage
-p, --project <PROJECT> path to PetaLinux Tools project.
default is the working project
--oldconfig takes the working configuration
-c, --component <COMPONENT> Specify the component
If no component is specified, it will do
top level subsystem configuration only
all: to configure the whole project
If you specify other component,it will
configure that component
E.g. -c rootfs
--get-hw-description[=SRC] get hardware description.
if [SRC] is specified, look in that
location for an XSDK BSP project.
Otherwise, this MUST be run from
WITHIN an XSDK PetaLinux BSP project.
--searchpath edit project search path
petalinux-build
Usage:
petalinux-build [options]
Required:
Options:
-h, --help show function usage
-p, --project <PROJECT> path to PetaLinux Tools project.
Default is working project.
-c, --component <COMPONENT> Specify the component
all: to build the whole project
If you specify other component,it will
build that component
E.g. -c rootfs
E.g. -c rootfs/myapp
If you use -c with --help option, it will
show you subcomponents.
E.g. -c rootfs --help shows subcomponents
of rootfs.
-x, --execute <GNU_MAKE_TARGET> Specify a GNU make command of the component
--makeenv <MAKE ENV> Pass GNU make environment variables
-v, --verbose Show compile messages verbose mode
Examples:
Build the project:
$ petalinux-build
It is the same as "petalinux-build -c all"
the bootable images are in <PRJOECT>/images/linux/.
Build kernel only:
$ petalinux-build -c kernel
Build kernel and update the bootable images:
$ petalinux-build -c kernel
$ petalinux-build -x package
petalinux-boot
petalinux-boot with –jtag Option
Options:
--prebuilt <BOOT_LEVEL> Boot prebuilt images (override all settings).
supported boot level 1 to 3
1 - download FPGA bitstream (and FSBL for Zynq)
2 - Boot U-Boot only
3 - Boot Linux Kernel only
--boot-addr <BOOT_ADDR> boot address
-i, --image <IMAGE> image to boot
--uboot boot images/linux/u-boot.elf image
if --kernel is specified, --uboot will not take
effect.
--kernel boot images/linux/zImage for Zynq
boot images/linux/image.elf for MicroBlaze
if --kernel is specified, --uboot will not take
effect.
-v, --verbose output debug messages
-h|--help Display help messages
Example to download prebuilt bitstream (and FSBL for zynq) to target board:
$ petalinux-boot --jtag --prebuilt 1
Example to boot prebuilt u-boot on target board:
$ petalinux-boot --jtag --prebuilt 2
It will download the prebuilt bitstream (and FSBL for zynq) to target board,
and then boot prebuilt u-boot on target board.
Options:
--prebuilt <BOOT_LEVEL> Boot prebuilt images (override all settings).
supported boot level 1 to 3
1 - download FPGA bitstream (and FSBL for Zynq)
2 - Boot U-Boot only
3 - Boot Linux Kernel only
--boot-addr <BOOT_ADDR> boot address
-i, --image <IMAGE> image to boot
--uboot boot images/linux/u-boot.elf image
if --kernel is specified, --uboot will not take
effect.
--kernel boot images/linux/zImage for Zynq
boot images/linux/image.elf for MicroBlaze
if --kernel is specified, --uboot will not take
effect.
-v, --verbose output debug messages
-h|--help Display help messages
petalinux-package
Required:
--boot|--bsp|--firmware|--image|--prebuilt
Various package mode.
boot: packages a boot.bin for Zynq
bsp: packages a bsp
firmware: creates a firmware package used
by PetaLinux firmware upgrade demo app to
upgrade firmwares.
image: package various image type
prebuilt: package images to prebuilt
Options:
-h|--help Display help messages
Please specify a package mode option for the detailed options
Show package boot options:
$ petalinux-package --boot --help
Show package bsp options:
$ petalinux-package --bsp --help
Show package firmware options:
$ petalinux-package --firmware --help
Show package image options:
$ petalinux-package --image --help
Show package prebuilt options:
$ petalinux-package --prebuilt --help
The --image, --dtb, --uboot and --jffs2 options allow to override the default
filenames and partitions using the partition:file syntax of the --add option.
For example:
Example to package firmware with BOOT.BIN and kernel image for Zynq:
$ petalinux-package --firmware --bootbin=<BOOT_BIN> --linux
It will create firmware.tar.gz archive in your working directory
including the specified <BOOT_BIN> and <PROJECT>/images/linux/image.ub.
Example to package firmware with bistream, u-boot and kernel image for
microBlaze:
$ petalinux-package --firmware --fpga <BITSTREAM> --uboot --linux
It will create firmware.tar.gz archive in your working directory
including:
* specified <BITSTREAM>
* <PROJECT>/images/linux/u-boot-s.bin
* <PROJECT>/images/linux/iamge.ub
petalinux-util
Required:
--gdb | --jtag-logbuf | --update-sdcard |--webtalk
Various utilities.
gdb: petalinux gdb debug wrapper
jtag-logbuf: prints kernel early printk
with JTAG.
update-sdcard: updates the contents of
SD card.
webtalk: Enable or disable webtalk
Options:
-h|--help Display help messages
Please specify a package mode option for the detailed options
Show gdb util options:
$ petalinux-util --gdb --help
Show jtag-logbuf util options:
$ petalinux-util --jtag-logbuf --help
Show update-sdcard util options:
$ petalinux-util --update-sdcard --help
Show webtalk util options:
$ petalinux-util --webtalk --help