Using PetaLinux to Create Linux Boot Files

PetaLinux can generate the Linux boot files for an SDSoC platform using the process documented in PetaLinux 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 and cd into 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 <path_to_project> -s <path_to_base_BSP>
  • 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 <install>/SDx/2017.1/platforms/<platform name>/hw/vivado for 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 the petalinux-config command, 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, the petalinx-config –c kernel step 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 PetaLinux settings.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 <platform name> -s <petalinux_install>/<base BSP name>
  3. Configure PetaLinux with the HDF derived earlier for the associated platform (the production of which is described in the introduction):
    petalinux-config -p <platform name> --get-hw-description=<HDF path>
    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 <platform name> -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 <platform name> -c rootfs
    Add stdc++ libs:
    • Filesystem Packages → misc → gcc-runtime → libstdc++ (ON)
  6. Add device tree fragment for APF driver. At the bottom of <platform name>/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 <petalinux project>/images/linux/ there are a number of important files that are partitioned into two categories:
    1. Files that end up compiled into BOOT.BIN, referred to collectively as ‘boot files’, that should be copied into a boot folder. Boot files include the following: u-boot.elf, zynq-fsbl.elf or zynqmp-fsbl.elf, along with bl31.elf and pmufw.elf for Zynq UltraScale+ devices.
    2. Files that must reside on the SD card but are not compiled into BOOT.BIN, referred to as ‘image files’, that should be copied into an image folder. The only image file from a PetaLinux build is image.ub, but you can add other files to the image folder that you want to make available to users of the platform.
    From within the <petalinux project>/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 the boot folder into a BOOT.BIN file.

    An SDSoC boot image file looks similar to a standard BIF, with symbolic constants instead of paths specified. SDSoC typically relies on a .bif file 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]<boot/fsbl.elf>
      [pmufw_image]<boot/pmufw.elf>
      [destination_device=pl] <bitstream>
      [destination_cpu=a53-0, exception_level=el-3, trustzone] <boot/bl31.elf>
      [destination_cpu=a53-0, exception_level=el-2] <boot/u-boot.elf>
    }
    

Taken together, the boot directory, the image directory, and the .bif file, constitute the software artifacts that the SDSoC Platform Utility needs as input for the Linux OS:

Figure: Linux Boot Information