Building a Bare-Metal System - 2022.2 English

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2022-10-19
Version
2022.2 English
Building a bare-metal system requires a few additional steps from the standard application flow previously described. The specific steps required are described here.
  1. Build the bare-metal platform.

    Building bare-metal applications requires a bare-metal domain in the platform. The base platform xilinx_vck190_base_202220_1 does not have a bare-metal domain, which mean you must create a platform with one. Starting from the v++ linking process as described in Linking the System, you must create a custom platform because the PS application needs drivers for the PL kernels in the design.

    Use the XSA generated during the link process to create a new platform using the following command:

    generate-platform.sh -name vck190_baremetal -hw <filename>.xsa \
    							-domain psv_cortexa72_0:standalone

    where:

    • -name vck190_baremetal: Specifies a name for the platform that will be created. The platform will be created according to the specified name. In this example it will be written to: ./vck190_baremetal/export/vck190_baremetal
    • -hw <filename>.xsa: Specifies the name of the input XSA file generated during the v++ --link command. The <filename> will be the same as the file name specified for the .xclbin output.
    • -domain psv_cortexa72_0:standalone: Specifies the processor domain and operating system to apply to the new platform.

    You can add the new platform to your platform repository by adding the file location to your $PLATFORM_REPO_PATHS environment variable. This makes it accessible to the Vitis IDE for instance, or allows you to specify the platform in command-lines by simply referring to the name rather than the whole path.

    Note: The generated platform will be used only for building the bare-metal PS application and is not used any other places across the flow.
  2. Compile and link the PS application.

    To build the PS application for the bare-metal flow, use the platform generated in the prior step. You need the PS application (main.cpp), and the bare-metal AI Engine control file (aie_control.cpp), which is created by the aiecompiler command and can be found in the ./Work/ps/c_rts folder.

    Compile the main.cpp file using the following command:

    aarch64-none-elf-gcc -I.. -I. -I../src \
    -I./vck190_baremetal/export/vck190_baremetal/sw/vck190_baremetal/standalone_domain/bspinclude/include \
    -g -c -std=c++17 -o main.o main.cpp
    Note: You must include the BSP include files for the generated platform, located at: ./vck190_baremetal/export/vck190_baremetal/sw/vck190_baremetal/standalone_domain/bspinclude/include

    Compile the aie_control.cpp file using the following command:

    aarch64-none-elf-gcc -I.. -I. -I../src \
    -I./vck190_baremetal/export/vck190_baremetal/sw/vck190_baremetal/standalone_domain/bspinclude/include \
    -g -c -std=c++17 -o aie_control.o ../Work/ps/c_rts/aie_control.cpp

    Link the PS application using the two compiled object files:

    aarch64-none-elf-gcc main.o aie_control.o -g -mcpu=cortex-a72 -Wl,-T -Wl,./lscript.ld \
    
    -L./vck190_baremetal/export/vck190_baremetal/sw/vck190_baremetal/standalone_domain/bsplib/lib  \
    -ladf_api -Wl,--start-group,-lxil,-lgcc,-lc,-lstdc++,--end-group -o main.elf
    Note: You also need the BSP libxil.a located at ./vck190_baremetal/export/vck190_baremetal/standalone_domain/bsplib/lib during linking. Here the assumption is the AI Engine are enabled during the platform management controller (PMC) boot.
  3. Package the System

    Finally, you must run the package process to generate the final boot-able image (PDI) for running the design on the bare-metal platform. This command produces the SD card content for booting the device and running the application. Refer to Packaging for more information. This requires the use of the v++ --package command as follows:

    v++ -p -t hw \
        -f xilinx_vck190_base_202220_1 \
        libadf.a project.xsa \
        --package.out_dir ./sd_card \
        --package.domain aiengine \
        --package.defer_aie_run \
        --package.boot_mode sd \
        --package.ps_elf main.elf,a72-0 \
        -o aie_graph.xclbin
    Tip: For bare-metal ELF files running on PS cores, you should also add the package.ps_elf option to the --package command.

    The use of --package.defer_aie_run is related to the way the AI Engine graph is run. If the application is loaded and launched at boot time, these options are not required. If your host application launches and controls the graph, then you need to use these options when compiling and packaging your system as described in Deploying the System.

    The ./sd_card folder, specified by the --out_dir option, contains the following files produced for the hardware build:

    |-- BOOT.BIN	//BOOT.BIN file containing PDI and the application ELF
    |-- boot_image.bif	  //bootgen input file used to create BOOT.BIN
    `-- sd_card              //SD card folder
        |-- aie_graph.xclbin     //xclbin output file (not used)
        `-- BOOT.BIN         //BOOT.BIN file containing PDI and the application ELF

    Copy the contents of the sd_card folder to an SD card to create a boot device for your system.

Now you have built the bare-metal system, you can run it or debug it.