Skip to content

Commit 4bdabbb

Browse files
bentheredonethatarnopo
authored andcommitted
examples: legacy_apps: vendor: Add initial vendor port for AMD-Xilinx platforms
Add CMake logic to build AMD-xilinx classic OpenAMP RPU Firmware demos using Software Hardware Exchange Loop (SHEL) Flow to generate linker script. This can be done with Lopper to generate the device tree and native CMake, Yocto AMD-Xilinx Embedded Development Framework (EDF) or Vitis Unified IDE Workflows. As part of this add options for vendor specific build. By default all tests and examples will still build but add options to make each mutable. Signed-off-by: Ben Levinsky <ben.levinsky@amd.com>
1 parent a591224 commit 4bdabbb

30 files changed

Lines changed: 900 additions & 6 deletions

examples/legacy_apps/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ collector_create (APP_LIB_DEPS "")
2626
collector_create (APP_EXTRA_C_FLAGS "")
2727
collect (APP_INC_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
2828

29-
add_subdirectory (machine)
3029
add_subdirectory (system)
31-
add_subdirectory (tests)
30+
add_subdirectory (machine)
31+
32+
if (WITH_TESTS)
33+
add_subdirectory (tests)
34+
endif(WITH_TESTS)
35+
if (WITH_EXAMPLES)
3236
add_subdirectory (examples)
37+
endif (WITH_EXAMPLES)

examples/legacy_apps/cmake/options.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,7 @@ if (DEFINED RPMSG_BUFFER_SIZE)
120120
endif (DEFINED RPMSG_BUFFER_SIZE)
121121

122122
option (WITH_DOC "Build with documentation" OFF)
123+
option (WITH_TESTS "Build tests" OFF)
124+
option (WITH_EXAMPLES "Build all examples" OFF)
123125

124126
message ("-- C_FLAGS : ${CMAKE_C_FLAGS}")
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt")
1+
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_VENDOR}/CMakeLists.txt")
2+
add_subdirectory (${PROJECT_VENDOR})
3+
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt")
24
add_subdirectory (${PROJECT_MACHINE})
3-
endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}/CMakeLists.txt")
5+
endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_VENDOR}/CMakeLists.txt")
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
# For AMD-Xilinx tooling enable control flow path whereby only target app
5+
# is configured to build. In the future we can add options for each
6+
# app but for now enable as a one-shot flow switch
7+
8+
message("Building for AMD-Xilinx Demos")
9+
10+
cmake_minimum_required(VERSION 3.24)
11+
12+
enable_language(C ASM )
13+
14+
set_property (GLOBAL PROPERTY OPENAMP_APP_NAME "${OPENAMP_APP_NAME}")
15+
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/")
16+
17+
include(CheckSymbolExists)
18+
19+
# Demos currently target R5 and R52.
20+
# If the target is not one of these target cores, then surrounding
21+
# tooling (Yocto or Vitis) will report error.
22+
#set (MACHINE "zynqmp_r5")
23+
#set_property (GLOBAL PROPERTY MACHINE ${MACHINE})
24+
#set (PROJECT_MACHINE ${MACHINE})
25+
26+
get_property (OPENAMP_APP_NAME GLOBAL PROPERTY OPENAMP_APP_NAME)
27+
if(OPENAMP_APP_NAME STREQUAL "rpc_demo")
28+
set(_app rpc_demo)
29+
elseif(OPENAMP_APP_NAME STREQUAL "echo")
30+
set (_app rpmsg-echo)
31+
elseif(OPENAMP_APP_NAME STREQUAL "matrix_multiply")
32+
set (_app matrix_multiplyd)
33+
else()
34+
message(FATAL_ERROR "OPENAMP_APP_NAME not picked up")
35+
endif()
36+
message("OpenAMP: OPENAMP_APP_NAME: ${OPENAMP_APP_NAME}")
37+
38+
# Ensure that for Compile step that the _AMD_GENERATED_ symbol is present
39+
# for app build if it was provided in CMake configure tooling
40+
if (_AMD_GENERATED_)
41+
add_definitions(-D_AMD_GENERATED_)
42+
endif()
43+
44+
string(TOUPPER "${CMAKE_MACHINE}" _soc)
45+
46+
if(_soc STREQUAL "ZYNQMP" OR _soc STREQUAL "VERSAL")
47+
set_property(GLOBAL PROPERTY SOC "${_soc}")
48+
else()
49+
message(FATAL_ERROR "Unsupported CMAKE_MACHINE: ${CMAKE_MACHINE}")
50+
endif()
51+
52+
get_property (SOC GLOBAL PROPERTY SOC)
53+
message("OpenAMP: SOC in build is: ${SOC}")
54+
55+
# Lopper plugin can generate linker meta data in below file
56+
# This can define RSC_TABLE so include before
57+
message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
58+
file (GLOB LINKER_METADATA_FILE "${CMAKE_SOURCE_DIR}/*Example.cmake")
59+
if (EXISTS ${LINKER_METADATA_FILE})
60+
set_property(GLOBAL PROPERTY LINKER_METADATA_FILE ${LINKER_METADATA_FILE})
61+
message("OpenAMP: Linker will be configured using file: ${LINKER_METADATA_FILE}")
62+
else()
63+
message("OpenAMP: Linker will be configured using static linker script for ${SOC}")
64+
endif()
65+
66+
get_property (OPENAMP_APP_NAME GLOBAL PROPERTY OPENAMP_APP_NAME)
67+
if (OPENAMP_APP_NAME STREQUAL "")
68+
message(FATAL_ERROR "AMD-Xilinx: Demos: missing property OPENAMP_APP_NAME.")
69+
return()
70+
#else()
71+
#add_subdirectory (${APPS_ROOT_DIR}/machine ${CMAKE_CURRENT_BINARY_DIR}/machine_build)
72+
#add_subdirectory (${APPS_ROOT_DIR}/system ${CMAKE_CURRENT_BINARY_DIR}/system_build)
73+
endif (OPENAMP_APP_NAME STREQUAL "")
74+
75+
add_subdirectory(${PROJECT_MACHINE})
76+
77+
# pull in original legacy app demo logic here
78+
set (_cflags "${CMAKE_C_FLAGS} ${APP_EXTRA_C_FLAGS} -fdata-sections -ffunction-sections")
79+
set (_fw_dir "${APPS_SHARE_DIR}")
80+
81+
collect(APP_INC_DIRS ${APPS_ROOT_DIR}/examples/${OPENAMP_APP_NAME})
82+
collect(APP_INC_DIRS ${APPS_ROOT_DIR}/machine/${MACHINE})
83+
84+
collector_list (_list PROJECT_INC_DIRS)
85+
collector_list (_app_list APP_INC_DIRS)
86+
87+
include_directories (${_list} ${_app_list})
88+
include_directories (${APPS_ROOT_DIR}/examples/legacy_apps/include)
89+
link_directories (${_list} ${_app_list})
90+
91+
get_property (_linker_opt GLOBAL PROPERTY APP_LINKER_OPT)
92+
93+
# below is where demo config and compilation occurs
94+
collect(PROJECT_LIB_DEPS c)
95+
collect(PROJECT_LIB_DEPS m)
96+
collect(PROJECT_LIB_DEPS metal)
97+
collect(PROJECT_LIB_DEPS open_amp)
98+
99+
collect (APP_COMMON_SOURCES "${APPS_ROOT_DIR}/examples/${OPENAMP_APP_NAME}/${_app}.c")
100+
collect (APP_COMMON_SOURCES "${APPS_ROOT_DIR}/examples/${OPENAMP_APP_NAME}/${PROJECT_SYSTEM}/main.c")
101+
collector_list (_sources APP_COMMON_SOURCES)
102+
103+
collector_list (_app_list APP_INC_DIRS)
104+
collector_list (_list PROJECT_INC_DIRS)
105+
include_directories (${_list} ${_app_list} ${APPS_ROOT_DIR} ${APPS_ROOT_DIR}/system/${PROJECT_SYSTEM}/machine/${PROJECT_MACHINE}/)
106+
collector_list (_list PROJECT_LIB_DIRS)
107+
collector_list (_app_list APP_LIB_DIRS)
108+
link_directories (${_list} ${_app_list} ${APPS_ROOT_DIR}/system/${PROJECT_SYSTEM}/machine/${PROJECT_MACHINE}/)
109+
# UserConfig.cmake is file generated by Vitis-Unified workspace for applications.
110+
include(${CMAKE_SOURCE_DIR}/UserConfig.cmake)
111+
set (executable_name ${CMAKE_PROJECT_NAME})
112+
add_executable (${executable_name}.elf ${_sources})
113+
set_source_files_properties(${_sources} PROPERTIES COMPILE_FLAGS "${_cflags}")
114+
115+
get_property (LINKER_METADATA_FILE GLOBAL PROPERTY LINKER_METADATA_FILE)
116+
get_property (SOC GLOBAL PROPERTY SOC)
117+
set (SOCS ZYNQMP VERSAL)
118+
set (LOPPER_CFG_LINKERS lscript_r5.ld.in lscript_versal_r5.ld.in)
119+
120+
list(FIND SOCS "${SOC}" soc_index)
121+
122+
# AMD-Xilinx SDT workflow has split up libxil. Below are required libs
123+
# That were previously in libxil.
124+
collect(PROJECT_LIB_DEPS xil)
125+
collect(PROJECT_LIB_DEPS xiltimer)
126+
collect(PROJECT_LIB_DEPS xilstandalone)
127+
128+
if (EXISTS ${LINKER_METADATA_FILE})
129+
include(${LINKER_METADATA_FILE})
130+
list (GET LOPPER_CFG_LINKERS ${soc_index} linker_in)
131+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/linker_files/${linker_in} "${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld")
132+
list(APPEND LINKER_FILE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${linker_in})
133+
list(APPEND LINKER_FILE ${linker_in})
134+
set (_linker_script "${CMAKE_CURRENT_SOURCE_DIR}/lscript.ld")
135+
message("Using LINKER_METADATA_FILE: ${LINKER_METADATA_FILE}")
136+
set (_linker_opt "-Wl,--defsym,_rsc_table=${RSC_TABLE} -T\"${_linker_script}\"")
137+
else()
138+
message(FATAL_ERROR "Could not find linker meta data file")
139+
endif(EXISTS ${LINKER_METADATA_FILE})
140+
141+
collector_list (_deps PROJECT_LIB_DEPS)
142+
143+
# Enable user to pass in extra linker flags
144+
if (DEFINED DEMO_LINK_FLAGS)
145+
set (_deps "${_deps} ${DEMO_LINK_FLAGS}")
146+
endif(DEFINED DEMO_LINK_FLAGS)
147+
148+
target_link_libraries(${executable_name}.elf -Wl,-Map=${executable_name}.map -L${CMAKE_LIBRARY_PATH} -L${USER_LINK_DIRECTORIES} -Wl,--gc-sections ${_linker_opt} -Wl,--start-group ${OPENAMP_LIB} ${_deps} -Wl,--end-group)
149+
target_compile_definitions(${executable_name}.elf PUBLIC ${USER_COMPILE_DEFINITIONS})
150+
install (TARGETS ${executable_name}.elf RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Steps to generate inputs for AMD-Xilinx RPU Firmware Demos
2+
3+
Dependencies:
4+
1. Lopper : https://github.com/devicetree-org/lopper.git
5+
2. System Device Tree generated from design : https://docs.amd.com/r/en-US/ug1647-porting-embeddedsw-components/Generating-a-System-Device-Tree-Using-SDTGen
6+
7+
Below is sample run for Versal Gen 1 platform
8+
### Generate OpenAMP RPU Device Tree
9+
10+
SDT is the System Device Tree generated from design
11+
```sh
12+
export LOPPER_DTC_FLAGS="-b 0 -@"
13+
14+
python3 lopper.py -f --enhanced \
15+
-x '*.yaml' \
16+
-i $YAML $SDT yaml_applied.dts
17+
18+
python3 lopper.py -f --enhanced \
19+
yaml_applied.dts rpu.dts \
20+
-- gen_domain_dts psu_cortexr5_0 --openamp_no_header
21+
```
22+
The above Device Tree "rpu.dts" will be used for configuration of the app's interrupts, shared memory and linker script.
23+
24+
### Generate OpenAMP App config header
25+
26+
```sh
27+
export LOPPER_DTC_FLAGS="-b 0 -@"
28+
export CONFIG_DTFILE=rpu.dts
29+
30+
cd openamp-system-reference/examples/legacy_apps/machine/zynqmp_r5
31+
python3 lopper.py -O -f -v --enhanced --permissive \
32+
-O . ${CONFIG_DTFILE} -- openamp --openamp_header_only \
33+
--openamp_output_filename=amd_platform_info.h \
34+
--openamp_remote=psv_cortexr5_0
35+
cd -
36+
```
37+
The output amd_platform_info.h needs to be in the location denoted above of "openamp-system-reference/examples/legacy_apps/machine/zynqmp_r5" BEFORE
38+
cmake configure step.
39+
40+
### Generate RPU Application Linker config object
41+
42+
```sh
43+
export LOPPER_DTC_FLAGS="-b 0 -@"
44+
export CONFIG_DTFILE=rpu.dts
45+
python3 lopper.py -O ${S} rpu.dts \
46+
-- baremetallinker_xlnx psv_cortexr5_0 <output location> openamp
47+
```
48+
The RPU Application Linker config object needs to be pointed to with cmake variable LINKER_METADATA_FILE at cmake configure step.

0 commit comments

Comments
 (0)