ZCU106 Programmable Logic VCU Demo

This cookbook is written for the ZCU106 board only.

This page describes an AMD EDF demo for the ZCU106 evaluation board. The demo uses dynamically loaded programmable logic firmware together with a containerized VCU application flow on top of the EDF Linux BSP.

Overview

The demo combines two pieces that ship through the meta-amd-edf-demos Yocto layer:

  • A container application that bundles the VCU components and applications (vcu-ctrlsw, vcu-firmware, libvcu-omxil, and kernel-module-vcu). The container also includes dfx-mgr-client support so that it can drive PL firmware that the host loads dynamically.

  • A PL firmware recipe that packages the VCU PL design for the ZCU106. The recipe uses the dfx_user_dts mechanism so that dfx-mgr can discover and load the firmware at runtime through the AMD Dynamic Function eXchange (DFX) manager.

Together, these pieces show how EDF can run a containerized validation application on top of a dynamically loaded PL design on the ZCU106.

The recipes referenced by this page (zcu106-pl-vcu-fw and container-app-zcu106-vcu) live in the meta-amd-edf-demos layer; see References for the upstream recipe URLs.

Demo Components

The following table summarizes the two recipes that make up the demo and the role each one plays.

Recipe

Type

Purpose

zcu106-pl-vcu-fw

PL firmware

Packages the VCU PL design for ZCU106 and installs it under /lib/firmware/xilinx using the dfx_user_dts mechanism so that dfx-mgr-client can load it at runtime.

container-app-zcu106-vcu

Container application

Builds a container image that bundles vcu-ctrlsw, vcu-firmware, libvcu-omxil, and kernel-module-vcu, together with dfx-mgr-client so the container can interact with the loaded PL firmware.

Programmable Logic Firmware Recipe

The PL firmware recipe zcu106-pl-vcu-fw provides the ZCU106 VCU PL design as a loadable firmware package.

The recipe inherits dfx_user_dts, which:

  • compiles the recipe-supplied pl.dtsi into an overlay .dtbo;

  • installs the bitstream and the overlay under /lib/firmware/xilinx/<package-name>/; and

  • registers the package with dfx-mgr so that dfx-mgr-client -listPackage enumerates it on the target.

The recipe is compatible with the ZCU106 EDF target machine. The firmware package contains the required PL artifacts for dynamically loading the VCU design through the AMD dfx-mgr.

For background on the dfx_user_dts flow and how it fits into the EDF segmented build, refer to:

Container Application Recipe

The container application recipe container-app-zcu106-vcu builds a container image on top of the base container image flow. The container rootfs includes:

  • vcu-ctrlsw – standalone command-line executable for enc and dec.

  • vcu-firmware – firmware package loaded onto the VCU hard block.

  • kernel-module-vcu – contains the source code of al5r drivers.

  • libvcu-omxil – contains the AllegroDVT OpenMax Integration Layer (OMXIL) implementation.

  • dfx-mgr-client – so the container can list and load PL firmware packages that the host’s dfx-mgr exposes.

For the general container application packaging pattern, refer to the Application Deployment page.

Building the Demo

BitBake builds the container application from a Yocto build environment. The environment must include the meta-amd-edf-demos layer and target the ZCU106 machine. The firmware is included through CONTAINER_APP.

  1. Clone meta-amd-edf-demos layer:

    $ cd ../sources
    $ git clone https://github.com/Xilinx/meta-amd-edf-demos.git
    
  2. Add meta-amd-edf-demos layer

    $ cd build/
    $ bitbake-layers add-layer ../sources/meta-amd-edf-demos/
    
  3. Build the container application:

    $ MACHINE=amd-cortexa53-mali-common bitbake container-app-zcu106-vcu
    

The generated container rootfs tarball is available under: ${TMPDIR}/deploy/images/amd-cortexa53-mali-common/.... Alternatively, copy the generated container rootfs tarball to the running target.

Reserving Memory for the VCU

The VCU needs a dedicated memory region. Add this region at boot time with a small device tree overlay that U-Boot applies before Linux starts.

Note

Do these steps a single time, the first time you boot the board after flashing the EDF image to the SD card. U-Boot saves the settings and applies them on every later boot.

If you plan to run memory-intensive encoder use cases, read Optional: Reserving Extra Memory for the VCU Encoder before you start.

  1. On your host machine, create a file named vcu-reserved.dtso with the following content:

    /dts-v1/;
    /plugin/;
    
    / {
        fragment@0 {
            target-path = "/reserved-memory";
            __overlay__ {
                #address-cells = <2>;
                #size-cells = <2>;
    
                plmem_vcu_dec: vcu_dma_mem_region@4800000000 {
                    compatible = "shared-dma-pool";
                    reg = <0x48 0x00000000 0x0 0x6a400000>;
                    no-map;
                };
            };
        };
    };
    
  2. Compile the file into an overlay (vcu-reserved.dtbo):

    $ dtc -@ -I dts -O dtb -o vcu-reserved.dtbo vcu-reserved.dtso
    

    If dtc is not installed, install it first, for example with sudo apt install device-tree-compiler on Ubuntu.

  3. Insert the SD card into the host machine and copy the overlay to the first (boot) partition. Replace /dev/sdX1 with the boot partition of your SD card:

    $ sudo mount /dev/sdX1 /mnt
    $ sudo cp vcu-reserved.dtbo /mnt/
    $ sudo umount /mnt
    $ sync
    
  4. Insert the SD card into the ZCU106, power on the board, and press any key on the serial console to stop at the U-Boot prompt.

  5. Enter the following commands at the U-Boot prompt. They tell U-Boot to load and apply vcu-reserved.dtbo automatically on every boot:

    ZynqMP> setenv vcu_fdt 0x40000000
    ZynqMP> setenv vcu_dtbo 0x42000000
    ZynqMP> setenv vcu_fixup 'fdt addr $fdtcontroladdr; fdt move $fdtcontroladdr $vcu_fdt 0x20000; fatload mmc 0 ${vcu_dtbo} vcu-reserved.dtbo; fdt apply $vcu_dtbo; setenv fdtcontroladdr $vcu_fdt'
    ZynqMP> setenv preboot 'run vcu_fixup'
    ZynqMP> saveenv
    ZynqMP> reset
    

    Note

    Enter the setenv vcu_fixup command as a single line. In the PDF version of this guide, the command wraps across several lines. If you copy it from the PDF, join the lines into one before you press Enter. You can also copy the command from the HTML version of this page.

    The board reboots and continues into Linux.

  6. After Linux boots, check that the kernel reserved the memory region:

    $ dmesg | grep reserved
    

    The output includes a line similar to the following:

    OF: reserved mem: 0x0000004800000000..0x000000486a3fffff (1740800 KiB) nomap non-reusable vcu_dma_mem_region@4800000000
    

    If the line is missing, stop at the U-Boot prompt again and run printenv vcu_fixup to check that the command was entered in full.

To undo this change later, stop at the U-Boot prompt again and run:

ZynqMP> setenv vcu_fixup
ZynqMP> setenv vcu_fdt
ZynqMP> setenv vcu_dtbo
ZynqMP> setenv preboot
ZynqMP> saveenv
ZynqMP> reset

Optional: Reserving Extra Memory for the VCU Encoder

This section is optional. You need it only for memory-intensive encoder configurations, for example 4Kp60, AVC, XV20, high bit rate, or Pyramidal B-frames set to 7 or 15. For these configurations the default 750 MB CMA pool is not enough. The encoder needs an extra 1700 MB reserved memory region to run reliably.

The setup has two parts:

  • At boot time, U-Boot applies two overlays: the decoder overlay (vcu-reserved.dtbo) from the previous section and a new encoder overlay (highmem-vcu-enc-reserved.dtbo).

  • At runtime, before you load the PL firmware, you update the firmware’s device tree overlay so that the encoder uses the new region.

Important

U-Boot has only one preboot setting, and each setenv preboot command replaces the previous one. Use the U-Boot commands in this section instead of the U-Boot commands in Reserving Memory for the VCU, not in addition to them.

Set Up the Encoder Memory in U-Boot

  1. Create and compile vcu-reserved.dtso as described in the first two steps of Reserving Memory for the VCU.

  2. On your host machine, create a file named highmem-vcu-enc-reserved.dtso with the following content:

    /dts-v1/;
    /plugin/;
    
    / {
        fragment@0 {
            target-path = "/reserved-memory";
    
            __overlay__ {
                #address-cells = <2>;
                #size-cells = <2>;
    
                highmem_vcu_enc: vcu_encoder_dma_mem_region@800000000 {
                    compatible = "shared-dma-pool";
                    no-map;
                    label = "highmem_vcu_enc";
                    reg = <0x8 0x00000000 0x0 0x6a400000>;
                };
            };
        };
    };
    
  3. Compile the encoder overlay:

    $ dtc -@ -I dts -O dtb \
        -o highmem-vcu-enc-reserved.dtbo \
        highmem-vcu-enc-reserved.dtso
    
  4. Insert the SD card into the host machine and copy both overlays to the first (boot) partition. Replace /dev/sdX1 with the boot partition of your SD card:

    $ sudo mount /dev/sdX1 /mnt
    $ sudo cp vcu-reserved.dtbo highmem-vcu-enc-reserved.dtbo /mnt/
    $ sudo umount /mnt
    $ sync
    
  5. Insert the SD card into the ZCU106, power on the board, and press any key on the serial console to stop at the U-Boot prompt.

  6. Enter the following commands at the U-Boot prompt. They load and apply both overlays automatically on every boot:

    ZynqMP> setenv vcu_fdt 0x40000000
    ZynqMP> setenv vcu_dec_dtbo 0x42000000
    ZynqMP> setenv vcu_enc_dtbo 0x44000000
    ZynqMP> setenv vcu_combined_fixup 'fdt addr $fdtcontroladdr; fdt move $fdtcontroladdr $vcu_fdt 0x40000; fdt addr $vcu_fdt; fatload mmc 0 ${vcu_dec_dtbo} vcu-reserved.dtbo; fdt apply $vcu_dec_dtbo; fatload mmc 0 ${vcu_enc_dtbo} highmem-vcu-enc-reserved.dtbo; fdt apply $vcu_enc_dtbo; setenv fdtcontroladdr $vcu_fdt'
    ZynqMP> setenv preboot 'run vcu_combined_fixup'
    ZynqMP> saveenv
    ZynqMP> reset
    

    Note

    Enter the setenv vcu_combined_fixup command as a single line. In the PDF version of this guide, the command wraps across several lines. If you copy it from the PDF, join the lines into one before you press Enter. You can also copy the command from the HTML version of this page.

  7. After Linux boots, check that the kernel reserved both memory regions:

    $ dmesg | grep reserved
    

    The output includes lines similar to the following:

    OF: reserved mem: 0x0000000800000000..0x000000086a3fffff (1740800 KiB) nomap non-reusable vcu_encoder_dma_mem_region@800000000
    OF: reserved mem: 0x0000004800000000..0x000000486a3fffff (1740800 KiB) nomap non-reusable vcu_dma_mem_region@4800000000
    

Assign the Encoder Memory to the PL Firmware

Do these steps after you start the container in Running the Demo on the Target, and before you load the firmware package with dfx-mgr-client -loadByName. Run them in a terminal on the board, outside the container.

  1. Go to the firmware directory and keep a backup of the original overlay:

    $ cd /lib/firmware/xilinx/zcu106-pl-vcu-fw/
    $ sudo cp zcu106-pl-vcu-fw.dtbo zcu106-pl-vcu-fw.dtbo.orig
    
  2. Convert the overlay into an editable source file:

    $ sudo dtc -I dtb -O dts \
        -o zcu106-pl-vcu-fw.dtso zcu106-pl-vcu-fw.dtbo
    

    This step can print warnings. You can ignore them.

  3. Open zcu106-pl-vcu-fw.dtso in a text editor, find the encoder node (its name starts with al5e@), and add a memory-region line to it:

    al5e@a0100000 {
            ...
            memory-region = <0xffffffff>;
    };
    

    Keep the node name and the other properties that are already in your file. The example shows only the line to add.

  4. In the same file, find the existing __fixups__ node near the end of the file and add a highmem_vcu_enc line to it. The value is the full path to the encoder node, followed by :memory-region:0:

    __fixups__ {
            ...
            highmem_vcu_enc = "/fragment@1/__overlay__/vcu@a0100000/al5e@a0100000:memory-region:0";
    };
    

    Replace the fragment number and node path with the ones from your file. Keep the existing lines in __fixups__, and do not add a second __fixups__ node.

  5. Save the file and compile it back into the overlay:

    $ sudo dtc -@ -I dts -O dtb \
        -o zcu106-pl-vcu-fw.dtbo zcu106-pl-vcu-fw.dtso
    
  6. Load the firmware package from inside the container as usual, then check that the encoder and decoder use their reserved regions:

    $ dmesg | grep al5
    

    The output includes lines similar to the following:

    al5e a0100000.al5e: assigned reserved memory node vcu_encoder_dma_mem_region@800000000
    al5d a0120000.al5d: assigned reserved memory node vcu_dma_mem_region@4800000000
    

    The output can also include messages that say reserved memory is beyond device's set DMA address range. These messages are normal.

Remove the Encoder Memory Configuration

  1. Stop at the U-Boot prompt and clear the combined configuration:

    ZynqMP> setenv vcu_fdt
    ZynqMP> setenv vcu_dec_dtbo
    ZynqMP> setenv vcu_enc_dtbo
    ZynqMP> setenv vcu_combined_fixup
    ZynqMP> setenv preboot
    ZynqMP> saveenv
    ZynqMP> reset
    
  2. Clearing preboot also removes the decoder memory region, which the demo firmware needs. Follow the steps in Reserving Memory for the VCU again to set up the decoder-only configuration. vcu-reserved.dtbo is already on the boot partition, so you can skip the steps that create and copy it.

  3. After Linux boots, restore the original firmware overlay. The edited overlay refers to the encoder memory region, which no longer exists, so it fails to load:

    $ cd /lib/firmware/xilinx/zcu106-pl-vcu-fw/
    $ sudo cp zcu106-pl-vcu-fw.dtbo.orig zcu106-pl-vcu-fw.dtbo
    

Running the Demo on the Target

The following steps assume the ZCU106 has booted an EDF image with dfx-mgr and a container runtime (for example docker or podman) installed. The steps also assume that the preceding container image is present on the target.

Unpack and Import the Container Image

  1. List the available PL firmware packages:

    $ sudo dfx-mgr-client -listPackage
    
  2. Unpack the generated rootfs tarball:

    $ bunzip2 container-app-zcu106-vcu-amd-cortexa53-mali-common.rootfs-<date>.tar.bz2
    
  3. Import the container image into Docker:

    $ sudo docker import \
     container-app-zcu106-vcu-amd-cortexa53-mali-common.rootfs-<date>.tar
    
  4. List the available container images:

    $ sudo docker images
    

Create Docker Volume and Run the Application from the Container Image

  1. Create Firmware directory

    $ sudo mkdir -p /lib/firmware/xilinx/zcu106-pl-vcu-fw
    
  2. Create a Docker volume that bind-mounts the firmware directory.

    $ sudo docker volume create --name producer_consumer \
     --driver local --opt type=none --opt o=bind \
     --opt device=/lib/firmware/xilinx/zcu106-pl-vcu-fw
    
  3. Verify the created volume:

    $ sudo docker volume ls
    
  4. Run the container with the firmware volume and dfx-mgr socket mounted.

    $ sudo docker run -it \
      --privileged \
      -v /dev:/dev \
      -v producer_consumer:/lib/firmware/xilinx/zcu106-pl-vcu-fw \
      -v /var/run/dfx-mgrd.socket:/var/run/dfx-mgrd.socket \
      <image-id> bash
    
  5. From inside the container, load the VCU firmware package. If you set up the optional encoder memory, first complete Assign the Encoder Memory to the PL Firmware.

    $ dfx-mgr-client -loadByName zcu106-pl-vcu-fw
    

    Verify that the firmware package is loaded successfully by re-running dfx-mgr-client -listPackage.

  6. Run the VCU application from inside the container.

    $ ctrlsw_decoder -avc -i AIR_1080p30_nv12.avc --noyuv
    

The container communicates with the host dfx-mgr daemon through the mounted socket and dynamically loads the VCU programmable logic design at runtime.

Unloading the Programmable Logic Firmware

When the demo finishes, unload the firmware from the host:

$ sudo dfx-mgr-client -unloadByName zcu106-pl-vcu-fw

References