Compiling and Linking Host Code for Bare-Metal - 2024.2 English - UG1076

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2024-11-28
Version
2024.2 English

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 AI Engine compiler 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 custom base-platform platform, located at: ./vck190_baremetal/export/vck190_baremetal/sw/vck190_baremetal/standalone_domain/bspinclude/include

where, vck190_baremetal is the user-defined platform name.

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. This assumes the AI Engine is enabled during the platform management controller (PMC) boot.
Note: The linker script lscript.ld can be obtained from the Vitis IDE, as described in Creating a Bare-Metal System found in Vitis Reference Guide (UG1702). Additional details can be found in A to Z Bare-metal Flow in the AMD GitHub AI Engine Vitis Tutorials.
Note: If the graph or kernel code is designed for multiple architectures and it must use the __AIE_ARCH__ macro to guard parts of the code specifc to an architecture.You must define the macro in the host compilation. For example, add -D__AIE_ARCH__=10 for host compilation for AI Engine devices, and -D__AIE_ARCH__=20 for AI Engine-ML devices.
Important: The steps to integrate the host code with the AI Engine graph application and the PL kernels into the hardware platform requires running the v++ --package command. Details on building and running the Versal device system using the Vitis tool flow is described in Building and Running the System in the Embedded Design Development Using Vitis (UG1701).