Compiling for Zynq
Compiling for the Zynq requires the use of the Vivado compiler toolchain and the headers and libraries corresponding to your Zynq firmware image. The following sections describe how to build applications for the Zynq.
An example Makefile is provided with this documentation demonstrating the use of this build configuration. Note that you must still perform the steps in the Setup section of this document in order to use it.
Setup
In order to compile an application to run on the Zynq, you must first source the
Vivado settings environment script to put the arm-xilinx-linux-gnueabi
toolchain in your path.
. /opt/Xilinx/Vivado/2014.4/settings64.sh
You will also need to procure a copy of the PetaLinux stage directory matching your CTP7 Zynq firmware image.
Compiling
Applications may now be built normally in the same way as non-Zynq C/C++
applications, however, instead of using gcc
or g++
you should use
arm-xilinx-linux-gnueabi-gcc
or arm-xilinx-linux-gnueabi-g++
. There is a
similar set of tools available under the arm-xilinx-linux-gnueabi-
tool
prefix. You should also take note of the CFLAGS used by the petalinux build
system, and use a similar set of your own.
CFLAGS
The following combination of CFLAGS has been taken from the PetaLinux build system, and should be used when compiling applications for the Zynq. Other flags may be added as usual at your discretion.
CFLAGS= -fomit-frame-pointer -pipe -fno-common -fno-builtin \
-Wall \
-march=armv7-a -mfpu=neon -mfloat-abi=softfp \
-mthumb-interwork -mtune=cortex-a9 \
-DEMBED -Dlinux -D__linux__ -Dunix -fPIC \
-I$(PETA_STAGE)/usr/include \
-I$(PETA_STAGE)/include
LDLIBS= -L$(PETA_STAGE)/stage/lib \
-L$(PETA_STAGE)/stage/usr/lib
Note that you must replace $(PETA_STAGE)
with the path to the PetaLinux stage
directory corresponding to your Zynq firwmare image.
Hardware Memory Access
The CTP7 firmware provides a library and service, libmemsvc to allow applications to safely access the Virtex 7 hardware registers over the AXI Chip-2-Chip link. This library also permits the standard user accounts to perform direct memory accesses such as those required to access registers.
The header files for this library are in this documentation package as well as properly installed in the stage directory provided with your firmware.
In order to use the library, you can open a handle to the service with memsvc_open
,
and read and write data words to permitted memory locations with memsvc_read
and memsvc_write
.
The library will gracefully handle SIGBUS errors related to the Chip-2-Chip
memory areas being inaccesible for you. Always check the return status of the
memory access functions in case the access did not succeed. See libmemsvc.h
for more information, as well as information on requirements for use with
threads or a SIGBUS handler.
The Zynq Chip-2-Chip link is mapped as a 256 MB region at 0x60000000-0x6fffffff.