Rate This Document
Findability
Accuracy
Completeness
Readability

CMake Script Configuration Description

Top-level CMake Configurations

The top-level CMake configurations are as follows:

cmake_minimum_required(VERSION 3.14.1)
project(fullnat_ovs LANGUAGES C ASM)

# Set the path to the SDK package directory.
set(SDK_DIR {flexda_sdk installation path}/flexda_sdk CACHE STRING "the path of FlexDA_SDK" FORCE)
# Set the user code path, that is, the path to the current top-level CMake configuration file.
set(GUEST_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "the path of customer code" FORCE)

# Set the board type (eth_2x100ge_dpu).
set(BOARD_TYPE "eth_2x100ge_dpu" CACHE STRING "BOARD_TYPE" FORCE)

# Set the user firmware version (format: X.Y.Z.N, where each character represents a number ranging from 0 to 255).
set(VERSION "17.6.3.3" CACHE STRING "VERSION" FORCE)

# Set the user firmware integrity signature switch (on/off).
set(KEY_SWITCH "off" CACHE STRING "KEY_SWITCH" FORCE)

# Set the user private key file path.
set(PRIVATE_KEY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../build/cs_keys_and_pubkey_hash/private_key.pem CACHE STRING "the path of private key" FORCE)

# Set the user public key file path.
set(PUBLIC_KEY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../build/cs_keys_and_pubkey_hash/public_key_ne.bin CACHE STRING "the path of public key" FORCE)

# Set the solver switch (Res_Planning, on/off).
set(RES_PLAN_ENABLE "on" CACHE STRING "RES_PLAN_ENABLE" FORCE)
# Set the resource file path.
# set(RES_XML ${SDK_DIR}/tools/res_planning/configs/dpu3.1/eth_2x100G_dpu/resource_eth_2x100G_dpu_bms_blk.xml CACHE STRING "RES_XML" FORCE)

# Set the compilation options and tools.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTACK_CONTROL=n -DINLINE_LEVEL=1 -DDBG_PRINT=y -DCMAKE_EXPORT_COMPILE_COMMAND=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_MODE_ASIC -DDBG_PRINT_TO_HOST -D__INLINE_DEBUG__")
# Set the log print level (error/info/debug/warning).
set(DBG_PRINT_LEVEL error)
if(DBG_PRINT_LEVEL STREQUAL "debug")
    set(PRINT_FLAGS "${PRINT_FLAGS} -DDBG_PRINT_LV_ERROR -DDBG_PRINT_LV_WARN -DDBG_PRINT_LV_INFO -DDBG_PRINT_LV_DEBUG")
elseif(DBG_PRINT_LEVEL STREQUAL "info")
    set(PRINT_FLAGS "${PRINT_FLAGS} -DDBG_PRINT_LV_ERROR -DDBG_PRINT_LV_WARN -DDBG_PRINT_LV_INFO")
elseif(DBG_PRINT_LEVEL STREQUAL "warning")
    set(PRINT_FLAGS "${PRINT_FLAGS} -DDBG_PRINT_LV_ERROR -DDBG_PRINT_LV_WARN")
elseif(DBG_PRINT_LEVEL STREQUAL "error")
    set(PRINT_FLAGS "${PRINT_FLAGS} -DDBG_PRINT_LV_ERROR")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PRINT_FLAGS}")
set(FLASH_BIN "flash_bin")
set(NPU_DEP "" CACHE INTERNAL "Global variable")
set(NPU_DEP_SRC "" CACHE INTERNAL "Global variable")
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(FlexDACC_TOOLCHAIN ${SDK_DIR}/tools/compiler/flexdacc)

# Run the flexdacc environment check function to check whether the dependencies in the environment meet the requirements.
execute_process(
    COMMAND ${FlexDACC_TOOLCHAIN} --check
    RESULT_VARIABLE FlexDAACC_CHECK_RESULT
)
if(NOT "${FlexDACC_CHECK_RESULT}" STREQUAL "0")
    message(FATAL_ERROR 
    "$Error: Environment check failed. \n"
    "{FlexDAACC_TOOLCHAIN} check failed with exit code: ${FlexDACC_CHECK_RESULT}")
endif()

set(CMAKE_LINKER ${FlexDACC_TOOLCHAIN})
set(CMAKE_CXX_COMPILER ${FlexDACC_TOOLCHAIN})
set(CMAKE_C_COMPILER ${FlexDACC_TOOLCHAIN})   # Use flexdacc as the C compiler
set(CMAKE_C_COMPILER_ARG1 "--compile")
set(LD_ENDIAN "-EB")
set(LDFLAGS "${LD_ENDIAN}")
set(LD_SCRIPT ${SDK_DIR}/build/sim_all.ld)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -c -O2 -flto -flto-partition=none -fgnu89-inline -fno-gcse -fno-ipa-ra -fno-optimize-sibling-calls --param=max-inline-insns-single=400")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a -Wall -ffunction-sections -fno-builtin -ffreestanding -fno-jump-tables -fno-ipa-sra -std=gnu89")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mgeneral-regs-only")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x27\" -ffixed-\"x27\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x26\" -ffixed-\"x26\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x21\" -ffixed-\"x21\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x20\" -ffixed-\"x20\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x19\" -ffixed-\"x19\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x28\" -ffixed-\"x28\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x23\" -ffixed-\"x23\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x24\" -ffixed-\"x24\" -fno-strict-aliasing")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcall-used-\"x22\" -ffixed-\"x22\" -fno-strict-aliasing")

# Set library files.
set(LIB_DIR ${SDK_DIR}/lib)
set(LIB_FILES
        "${LIB_DIR}/libbase.a"
        "${LIB_DIR}/libroce.a"
        "${LIB_DIR}/libtoe.a"
        "${LIB_DIR}/libovs.a"
        "${LIB_DIR}/libpubservice.a"
        "${LIB_DIR}/libnic.a"
        "${LIB_DIR}/libvirtio.a"
        "${LIB_DIR}/libnal.a"
        "${LIB_DIR}/libhal.a"
        "${LIB_DIR}/libvroce.a"
        "${LIB_DIR}/libdsl.a"
)

set(NPU_DEP_SRC ${NPU_DEP_SRC} ${LIB_FILES} CACHE INTERNAL "Global variable")
add_compile_options(-mbig-endian)
add_definitions(-DSML_TBL_DEFINE_COMPUTE_DPU)
add_definitions(-DHYDRA_LOG)

# Set header file paths.
set(INCLUDE_PATH ${SDK_DIR}/include)
include_directories(${INCLUDE_PATH})
include_directories(${INCLUDE_PATH}/common)
include_directories(${INCLUDE_PATH}/dfx)
include_directories(${INCLUDE_PATH}/nal)
include_directories(${INCLUDE_PATH}/dsl)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
include_directories(${CMAKE_BINARY_DIR})

# Configure a firmware compilation task.
add_subdirectory(${GUEST_SRCDIR}/src_dsl)
add_custom_target(${FLASH_BIN} ALL
        COMMAND ${CMAKE_LINKER} --link -flto -flto-partition=none -fgnu89-inline -mbig-endian -mgeneral-regs-only -fcall-used-\"x27\" -ffixed-\"x27\" -fno-strict-aliasing -fcall-used-\"x26\" -ffixed-\"x26\" -fno-strict-aliasing -fcall-used-\"x23\" -ffixed-\"x23\" -fno-strict-aliasing -fcall-used-\"x21\" -ffixed-\"x21\" -fno-strict-aliasing -fcall-used-\"x20\" -ffixed-\"x20\" -fno-strict-aliasing -fcall-used-\"x19\" -ffixed-\"x19\" -fno-strict-aliasing -fcall-used-\"x28\" -ffixed-\"x28\" -fno-strict-aliasing -fcall-used-\"x24\" -ffixed-\"x24\" -fno-strict-aliasing -fcall-used-\"x22\" -ffixed-\"x22\" -fno-strict-aliasing -march=armv8-a -Wall -nostdlib -Wfatal-errors -ffunction-sections -fno-builtin -ffreestanding -fno-jump-tables -fno-ipa-sra -std=gnu89 -t -Wl,-Map,sim.map -O2 -T ${LD_SCRIPT} -Wl,-EB -Wl,--whole-archive -Wl,--start-group ${NPU_DEP_SRC} -Wl,--end-group -o ${CMAKE_BINARY_DIR}/sim.elf
        COMMAND_EXPAND_LISTS
)
add_dependencies(${FLASH_BIN} ${NPU_DEP})

You can modify the following configurations as required. Retain other configurations.

Table 1 Configuration description

Configuration Content

Mandatory (Yes/No)

Configuration Item

Set SDK_DIR to the path to the flexda_sdk directory after the installation.

The user code project (for example, ovs_project) can be placed in any directory. However, you need to modify this configuration and enter the path to flexda_sdk.

Yes

set(SDK_DIR {Custom programming framework installation path}/flexda_sdk CACHE STRING "the path of FlexDA_SDK" FORCE)

For example, if the user code project is stored in the {Custom programming framework installation path}/flexda_sdk/example directory, change the configuration as follows:

set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../.. CACHE STRING "the path of FlexDA_SDK" FORCE)

Set GUEST_SRCDIR to the path to the top-level CMakeLists.txt file of the user code.

Yes

set(GUEST_SRCDIR {Path to the top-level CMakeLists.txt file} CACHE STRING "the path of customer code" FORCE)

Set RES_XML to the resource file path.

No

set(RES_XML {Resource file path} CACHE STRING "RES_XML" FORCE)

Optional. If this item is not set, the default configuration file in flexda_sdk is used.

Set the log print level, which can be info, debug, warning, or error.

Yes

set(DBG_PRINT_LEVEL={Log level})

Set the board type, which can be eth_2x100ge_dpu.

Yes

set(BOARD_TYPE {Board type} CACHE STRING "BOARD_TYPE" FORCE)

Set the user firmware version (format: X.Y.Z.N, where each character represents a number ranging from 0 to 255). The default version is 0.0.0.0.

For details, see Managing Versions.

No

set(VERSION "17.6.3.3" CACHE STRING "VERSION" FORCE)

Set the user firmware integrity signature switch. If the switch is turned on, the user firmware is signed. The default value is off.

If this item is set to on, you can enable the firmware integrity protection function based on Enabling User Firmware Integrity Protection.

No

set(KEY_SWITCH "off" CACHE STRING "KEY_SWITCH" FORCE)

Set the user private key file path.

No

  • If KEY_SWITCH is set to off, you do not need to set this item.
  • If KEY_SWITCH is set to on: set(PRIVATE_KEY_PATH {Path to the user private key file} CACHE STRING "the path of private key" FORCE). If KEY_SWITCH is not set, the default path {Project path}/build/cs_keys_and_pubkey_hash/private_key.pem is used.

Set the user public key file path.

No

  • If KEY_SWITCH is set to off, you do not need to set this item.
  • If KEY_SWITCH is set to on: set(PUBLIC_KEY_PATH {Path to the user public key file} CACHE STRING "the path of public key" FORCE)
  • If KEY_SWITCH is left blank, the default path {Project path}/build/cs_keys_and_pubkey_hash/public_key_ne.bin is used.

Set the solver switch. If the switch is turned on, the solver is called. The default value is on.

Yes

set(RES_PLAN_ENABLE "on" CACHE STRING "RES_PLAN_ENABLE" FORCE)
NOTICE:

This item is mandatory for the OVS feature and must be set to on. Otherwise, a compilation error is reported.

Set paths to header files of the user code project.

Yes

include_directories({Paths to header files of user code})

Set the path to the user source code subdirectory.

Yes

add_subdirectory({Path to the user source code subdirectory})

CMake Configurations of the Data Plane Subdirectory

The CMake configurations are as follows:

add_library(fullnat "")
set(CUR_TARGET fullnat)
# Set the mode for CMake and Make to process the .hdr file.
set_source_files_properties({User source file}.hdr PROPERTIES LANGUAGE C COMPILE_OPTIONS "-xc")
#======================= Source file ============================#
target_sources(${CUR_TARGET}
        PRIVATE
        {User source file}.hdr
)
set(NPU_DEP_SRC ${NPU_DEP_SRC} ${PROJECT_BINARY_DIR}/lib/libfullnat.a CACHE INTERNAL "Global variable")
set(NPU_DEP ${NPU_DEP} fullnat CACHE INTERNAL "Global variable")

Table 2 describes the configuration items.

Table 2 Configuration description

Configuration Content

Mandatory (Yes/No)

Configuration Item

Set the submodule library file name and project name.

Yes

add_library({Library file name} "")
set(CUR_TARGET {Project name})

Set the submodule source file. Only one .hdr file can be added to target_sources.

Yes

target_sources(${CUR_TARGET}
        PRIVATE
        {User source file}.hdr
)
set(NPU_DEP_SRC ${NPU_DEP_SRC} ${PROJECT_BINARY_DIR}/lib/lib{Library file name}.a CACHE INTERNAL "Global variable")
set(NPU_DEP ${NPU_DEP} {Project name} CACHE INTERNAL "Global variable")
NOTICE:

The suffix of a DSL code file must be .hdr, and the file name can contain only letters, digits, and underscores (a to z, A to Z, 0 to 9, and _).

CMake Configurations of the Control Plane Subdirectory

The CMake configurations are as follows:

add_library(custom_openvswitch_plugin SHARED context.c)
target_include_directories(custom_openvswitch_plugin PUBLIC ./)
target_include_directories(custom_openvswitch_plugin PUBLIC ../../../include/control_plane)

set_target_properties(custom_openvswitch_plugin PROPERTIES
    OUTPUT_NAME "custom_openvswitch_plugin"
    PREFIX ""
)

Table 3 describes the configuration items.

Table 3 Configuration description

Configuration Content

Mandatory (Yes/No)

Configuration Item

Set the source file and header files of the submodule.

Yes

add_library({Project name} {Library file path})
target_include_directories({Project name} {Header file paths})

Set the product name.

Yes

set_target_properties({Project name} PROPERTIES
    OUTPUT_NAME "{Product name}"
    PREFIX ""
)