Using PetaLinux to Create Linux Boot Files

PetaLinux can generate the Linux boot files for an SDSoC platform using the process documented inPetaLinux Tools Documentation: Workflow Tutorial(UG1156). The overall workflow for SDSoC platforms is the same, and the basic steps are outlined below. If you are familiar with the PetaLinux tools, you should be able to complete these steps for Zynq-UltraScale+ MPSoC or Zynq-7000 All Programmable (AP) SoC designs.

Before starting, you should complete the following:

  • Set up your shell environment with PetaLinux tools in your PATH environment variable.
  • Create andcdinto a working directory.
  • Create a new PetaLinux project targeting a BSP that corresponds to the type of board you are targetting:
    petalinux-create –t project-s
  • Obtain a copy of the hardware handoff file (.hdf) from the Vivado project for your hardware platform.
Important:This guide assumes the existence of a valid hardware description file, HDF, for the platform, which can be produced with the use of the Vivado Design Suite project included in /SDx/2017.1/platforms//hw/vivadofor a specific platform. Implement the Vivado project to generate the bitstream, and export the HDF with the bitstream included.

The steps below include basic setup, loading the hardware handoff file, kernel configuration, root file system configuration, and building the Linux image, fsbl, pmufw, and atf. The steps include the actions to perform, or the PetaLinux command to run, with arguments. Once the build completes, your working directory contains a unified boot image file (image.ub) that includes the devicetree, kernel and ramdisk. The basic setup is the procedure used to configure the linux images packaged in all base platforms shipped with SDSoC platforms.

When using thepetalinux-configcommand, a text-based user interface appears with a hierarchical menu system. The steps present a hierarchy of commands and the settings to use. Selections with the same indentation are at the same level of hierarchy. For example, thepetalinx-config –c kernelstep asks you to select Device Drivers from the top-level menu, select Generic Driver Options, go down one level to apply settings, go back up to Staging drivers, and apply settings to its sub-menu items.

To build the PetaLinux image, use the following steps:

  1. Source PetaLinuxsettings.sh
  2. Create a PetaLinux project against base BSP corresponding to the selected board (for example, for zc702: xilinx-zc702-v2017.1-final.bsp)
    petalinux-create -t project -n-s/
  3. Configure PetaLinux with the HDF derived earlier for the associated platform (the production of which is described in the introduction):
    petalinux-config -p--get-hw-description=
    Change boot args to include "quiet" at the end of whatever is the default:
    • Kernel Bootargs→generate boot args automatically (OFF)
    • for Zynq MPSoC: Kernel Bootargs→ user set kernel bootargs (earlycon clk_ignore_unused quiet)
    • for Zynq-7000: Kernel Bootargs→ user set kernel bootargs (console=ttyPS0,115200 earlyprintk quiet)
  4. Configure PetaLinux kernel:
    petalinux-config -p-c kernel
    Set CMA size to be larger, for SDS-alloc buffers:
    • for Zynq MPSoC: Device Drivers→ Generic Driver Options → Size in Mega Bytes(1024)
    • for Zynq-7000: Device Drivers→ Generic Driver Options → Size in Mega Bytes(256)
    Enable staging drivers:
    • Device Drivers → Staging drivers (ON)
    Enable APF management driver:
    • Device Drivers → Staging drivers → Xilinx APF Accelerator driver (ON)
    Enable APF DMA driver:
    • Device Drivers → Staging drivers → Xilinx APF Accelerator driver → Xilinx APF DMA engines support (ON)
    Note:For Zynq MPSoC, you must turn off CPU idle and frequency scaling. To do so, mark the following options:
    • CPU Power Management->CPU idle->CPU idle PM support (OFF)
    • CPU Power Management->CPU Frequency scaling->CPU Frequency scaling (OFF)
  5. Configure petalinux rootfs:
    petalinux-config -p-c rootfs
    Add stdc++ libs:
    • Filesystem Packages → misc → gcc-runtime → libstdc++ (ON)
  6. Add device tree fragment for APF driver. At the bottom of/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi, add the following entry:
    /{ xlnk { compatible = "xlnx,xlnk-1.0"; }; };
  7. Build the PetaLinux image:
    • petalinux-build
  8. In the directory/images/linux/there are a number of important files that are partitioned into two categories:
    1. Files that end up compiled intoBOOT.BIN, referred to collectively as ‘boot files’, that should be copied into abootfolder. Boot files include the following:u-boot.elf,zynq-fsbl.elforzynqmp-fsbl.elf, along withbl31.elfandpmufw.elffor Zynq UltraScale+ devices.
    2. Files that must reside on the SD card but are not compiled intoBOOT.BIN, referred to as ‘image files’, that should be copied into animagefolder. The only image file from a PetaLinux build isimage.ub, but you can add other files to theimagefolder that you want to make available to users of the platform.
    From within the /images/linux/folder run the following commands:
    $ mkdir ./boot $ mkdir ./image $ cp u-boot.elf ./boot/u-boot.elf $ cp *fslb.elf ./boot/fsbl.elf $ cp bl31.elf ./boot/bl31.elf $ cp linux/pmufw.elf ./boot/pmufw.elf $ cp image.ub ./image/image.ub
  9. Finally, create a boot image file, or BIF, that is used to compile the contents of thebootfolder into aBOOT.BINfile.

    An SDSoC boot image file looks similar to a standard BIF, with symbolic constants instead of paths specified. SDSoC typically relies on a.biffile that is written using patterns that are replaced with generated content, rather than direct paths to boot files. This is because the bitstream file will be procedurally generated, and some of the elements do not have known file names at the time the BIF file is being created.

    The following is an example BIF for a Zynq-UltraScale+ MPSoC device:
    the_ROM_image: { [fsbl_config] a53_x64 [bootloader] [pmufw_image] [destination_device=pl]  [destination_cpu=a53-0, exception_level=el-3, trustzone]  [destination_cpu=a53-0, exception_level=el-2]  }

Taken together, thebootdirectory, theimagedirectory, and the.biffile, constitute the software artifacts that the SDSoC Platform Utility needs as input for the Linux OS:

Figure:Linux Boot Information