Src Folder in Template Applications - 2024.2 English - UG1647

Porting Guide for embeddedsw Components System Device Tree Based Build Flow (UG1647)

Document ID
UG1647
Release Date
2024-11-27
Version
2024.2 English

A new file called CMakeLists.txt is introduced in this flow. Instead of Makefile, every application should have a CMakeLists.txt file. Following is a sample CMakeLists.txt for the hello_world template.

# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.15)
 
# For more details on <App_name>Example.cmake, please refer Appendix G
include(${CMAKE_CURRENT_SOURCE_DIR}/Hello_worldExample.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/UserConfig.cmake)
set(APP_NAME hello_world)
project(${APP_NAME})
 
enable_language(C ASM CXX)
find_package(common)
 
# Describe the dependency of this application on multiple archivers
collect(PROJECT_LIB_DEPS xilstandalone)
collect(PROJECT_LIB_DEPS xil)
collect(PROJECT_LIB_DEPS xiltimer)
collect(PROJECT_LIB_DEPS gcc)
collect(PROJECT_LIB_DEPS c)
 
collect (PROJECT_LIB_SOURCES platform.c)
collect (PROJECT_LIB_SOURCES helloworld.c)
collector_list (_sources PROJECT_LIB_SOURCES)
foreach (source ${_sources})
    get_filename_component(ext ${source} EXT)
    list(APPEND src_ext ${ext})
endforeach()
 
find_project_type ("${src_ext}" PROJECT_TYPE)
 
if("${PROJECT_TYPE}" STREQUAL "c++")
collect(PROJECT_LIB_DEPS stdc++)
endif()
collector_list (_deps PROJECT_LIB_DEPS)
list (APPEND _deps ${USER_LINK_LIBRARIES})
 
if("${PROJECT_TYPE}" STREQUAL "c++")
string (REPLACE ";" ",-l" _deps "${_deps}")
endif()
if(CMAKE_EXPORT_COMPILE_COMMANDS)
    set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
    set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
linker_gen("${CMAKE_CURRENT_SOURCE_DIR}/linker_files/")
string(APPEND CMAKE_C_FLAGS ${USER_COMPILE_OPTIONS})
string(APPEND CMAKE_CXX_FLAGS ${USER_COMPILE_OPTIONS})
string(APPEND CMAKE_C_LINK_FLAGS ${USER_LINK_OPTIONS})
string(APPEND CMAKE_CXX_LINK_FLAGS ${USER_LINK_OPTIONS})
set_source_files_properties(${_sources} OBJECT_DEPENDS "${CMAKE_LIBRARY_PATH}/*.a")
add_executable(${APP_NAME}.elf ${_sources})
set_target_properties(${APP_NAME}.elf PROPERTIES LINK_DEPENDS ${CMAKE_SOURCE_DIR}/lscript.ld)
target_link_libraries(${APP_NAME}.elf -Wl,-T -Wl,\"${CMAKE_SOURCE_DIR}/lscript.ld\" -L\"${CMAKE_SOURCE_DIR}/\" -L\"${CMAKE_LIBRARY_PATH}/\" -L\"${USER_LINK_DIRECTORIES}/\" -Wl,--start-group,-l${_deps} -Wl,--end-group)
target_compile_definitions(${APP_NAME}.elf PUBLIC ${USER_COMPILE_DEFINITIONS})
target_include_directories(${APP_NAME}.elf PUBLIC ${USER_INCLUDE_DIRECTORIES})
print_elf_size(CMAKE_SIZE ${APP_NAME})

In the existing source files (.c and .h), changes mentioned under the Src Folder in Drivers must be complied to in application sources as well. All the calls of LookupConfig() API of every driver must be updated to use BaseAddress instead of DeviceId. Sample changes are shown in the following code snippet:

--- a/lib/sw_apps/srec_spi_bootloader/src/bootloader.c
+++ b/lib/sw_apps/srec_spi_bootloader/src/bootloader.c
@@ -101,7 +102,11 @@ extern void init_stdout();
 uint8  grab_hex_byte (uint8 *buf);
 int FlashReadID(void);
 
+#if defined (SDT)
+#define SPI_DEVICE_BASEADDR     XPAR_AXI_QUAD_SPI_0_BASEADDR
+#else
 #define SPI_DEVICE_ID          XPAR_SPI_0_DEVICE_ID
+#endif
 
 /*
  * The instances to support the device drivers are global such that they
@@ -172,7 +177,11 @@ int main()
         * Initialize the SPI driver so that it's ready to use,
         * specify the device ID that is generated in xparameters.h.
         */
+#if defined (SDT)
+       Status = XSpi_Initialize(&Spi, SPI_DEVICE_BASEADDR);
+#else
        Status = XSpi_Initialize(&Spi, SPI_DEVICE_ID);
+#endif
        if(Status != XST_SUCCESS) {
                return XST_FAILURE;
        }
 
--- a/lib/sw_apps/srec_spi_bootloader/src/platform.c
+++ b/lib/sw_apps/srec_spi_bootloader/src/platform.c
@@ -1,11 +1,14 @@
 #include "xparameters.h"
+#if !defined (SDT)
 #include "platform_config.h"
+#endif
 
-#ifdef STDOUT_IS_16550
+#if ( defined (STDOUT_IS_16550) || ( defined (SDT) && defined (XPAR_STDIN_IS_UARTNS550)))
 #include "xuartns550_l.h"
 #endif
 
@@ -13,7 +16,7 @@ void
 init_stdout()
 {
        /* if we have a uart 16550, then that needs to be initialized */
-#ifdef STDOUT_IS_16550
+#if ( defined (STDOUT_IS_16550) || ( defined (SDT) && defined (XPAR_STDIN_IS_UARTNS550)))
        XUartNs550_SetBaud(STDOUT_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ, 9600);
        XUartNs550_SetLineControlReg(STDOUT_BASEADDR, XUN_LCR_8_DATA_BITS);
 #endif