Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #265, implement cmake name based targets #776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions cmake/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ function(add_cfe_tables APP_NAME TBL_SRC_FILES)
# current content of a dependency (rightfully so).
add_custom_command(
OUTPUT "${TABLE_DESTDIR}/${TBLWE}.tbl"
COMMAND ${CMAKE_C_COMPILER} ${TBL_CFLAGS} -c -o ${TBLWE}.o ${TBL_SRC}
COMMAND ${CMAKE_C_COMPILER} ${TBL_CFLAGS}
-DCFE_PLATFORM_CPU_ID=${${TGT}_PROCESSORID}
-DCFE_PLATFORM_CPU_NAME="${TGT}"
-c -o ${TBLWE}.o ${TBL_SRC}
COMMAND ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TBLWE}.o
DEPENDS ${MISSION_BINARY_DIR}/tools/elf2cfetbl/elf2cfetbl ${TBL_SRC}
WORKING_DIRECTORY ${TABLE_DESTDIR}
Expand Down Expand Up @@ -326,14 +329,7 @@ function(process_arch SYSVAR)
endif()

# Generate a list of targets that share this system architecture
set(INSTALL_TARGET_LIST)
foreach(TGTID ${TGTSYS_${SYSVAR}})
set(TGTNAME ${TGT${TGTID}_NAME})
if(NOT TGTNAME)
set(TGTNAME "cpu${TGTID}")
endif(NOT TGTNAME)
list(APPEND INSTALL_TARGET_LIST ${TGTNAME})
endforeach()
set(INSTALL_TARGET_LIST ${TGTSYS_${SYSVAR}})

# Assume use of an OSAL BSP of the same name as the CFE PSP
# This can be overridden by the PSP-specific build_options but normally this is expected.
Expand Down Expand Up @@ -454,20 +450,14 @@ function(process_arch SYSVAR)
set(TGTLIST_${APP})
endforeach()

foreach(TGTID ${TGTSYS_${SYSVAR}})
foreach(TGTNAME ${TGTSYS_${SYSVAR}})

set(TGTNAME ${TGT${TGTID}_NAME})
if(NOT TGTNAME)
set(TGTNAME "cpu${TGTID}")
set(TGT${TGTID}_NAME "${TGTNAME}")
endif(NOT TGTNAME)

# Append to the app install list for this CPU
foreach(APP ${TGT${TGTID}_APPLIST})
set(TGTLIST_${APP} ${TGTLIST_${APP}} ${TGTNAME})
endforeach(APP ${TGT${TGTID}_APPLIST})
foreach(APP ${${TGTNAME}_APPLIST})
list(APPEND TGTLIST_${APP} ${TGTNAME})
endforeach(APP ${${TGTNAME}_APPLIST})

endforeach(TGTID ${TGTSYS_${SYSVAR}})
endforeach(TGTNAME ${TGTSYS_${SYSVAR}})

# Process each app that is used on this system architecture
foreach(APP ${TGTSYS_${SYSVAR}_APPS})
Expand All @@ -478,14 +468,12 @@ function(process_arch SYSVAR)

# Process each target that shares this system architecture
# Second Pass: Build and link final target executable
foreach(TGTID ${TGTSYS_${SYSVAR}})
foreach(TGTNAME ${TGTSYS_${SYSVAR}})

set(TGTNAME ${TGT${TGTID}_NAME})

# Target to generate the actual executable file
add_subdirectory(cmake/target ${TGTNAME})

foreach(INSTFILE ${TGT${TGTID}_FILELIST})
foreach(INSTFILE ${${TGTNAME}_FILELIST})
if(EXISTS ${MISSION_DEFS}/${TGTNAME}_${INSTFILE})
set(FILESRC ${MISSION_DEFS}/${TGTNAME}_${INSTFILE})
elseif(EXISTS ${MISSION_DEFS}/${INSTFILE})
Expand All @@ -498,9 +486,8 @@ function(process_arch SYSVAR)
else(FILESRC)
message("WARNING: Install file ${INSTFILE} for ${TGTNAME} not found")
endif (FILESRC)
endforeach(INSTFILE ${TGT${TGTID}_FILELIST})
endforeach(TGTID ${TGTSYS_${SYSVAR}})

endforeach(INSTFILE ${${TGTNAME}_FILELIST})
endforeach(TGTNAME ${TGTSYS_${SYSVAR}})

endfunction(process_arch SYSVAR)

82 changes: 57 additions & 25 deletions cmake/global_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,61 @@ function(read_targetconfig)
set(TGTSYS_LIST)
set(MISSION_APPS)
set(MISSION_PSPMODULES)

# This while loop checks for a sequential set of variables prefixed with TGT<x>_
# where <x> is a sequence number starting with 1. The first "gap" (undefined name)
# is treated as the end of list.
# This is the historical way of specifying CPU configs. New/future development should
# prefer the name-based specification. This translates the sequential TGT<x> variable
# to a name-based variable.
set(TGTID 0)
while(1)
math(EXPR TGTID "${TGTID} + 1")
if (NOT DEFINED TGT${TGTID}_NAME)
break()
endif()
if (NOT DEFINED TGT${TGTID}_SYSTEM)
set(TGT${TGTID}_SYSTEM "cpu${TGTID}")
set(TGT${TGTID}_SYSTEM "${TGT${TGTID}_SYSTEM}" PARENT_SCOPE)
endif()
if (NOT DEFINED TGT${TGTID}_PLATFORM)
set(TGT${TGTID}_PLATFORM "default" "${TGT${TGTID}_NAME}")
set(TGT${TGTID}_PLATFORM "${TGT${TGTID}_PLATFORM}" PARENT_SCOPE)
endif()
set(CPUNAME ${TGT${TGTID}_NAME})
# by default if PROCESSORID isn't specified, then use TGTID number.
if(NOT DEFINED TGT${TGTID}_PROCESSORID)
set(TGT${TGTID}_PROCESSORID ${TGTID})
endif()

if (SIMULATION)
# Translate the TGT<x> prefix to the CPU name prefix
# also propagate the value to parent scope
foreach(PROP PROCESSORID
APPLIST
STATIC_APPLIST
STATIC_SYMLIST
PSP_MODULELIST
FILELIST
EMBED_FILELIST
SYSTEM
PLATFORM)
set(${CPUNAME}_${PROP} ${TGT${TGTID}_${PROP}})
set(${CPUNAME}_${PROP} ${${CPUNAME}_${PROP}} PARENT_SCOPE)
endforeach()
list(APPEND MISSION_CPUNAMES ${CPUNAME})
endwhile()

foreach(CPUNAME ${MISSION_CPUNAMES})
if (DEFINED SIMULATION)
# if simulation use simulation system architecture for all targets
set(TOOLCHAIN_NAME "${SIMULATION}")
else (SIMULATION)
elseif (DEFINED ${CPUNAME}_SYSTEM)
# get the target system arch identifier string
set(TOOLCHAIN_NAME "${TGT${TGTID}_SYSTEM}")
endif (SIMULATION)
set(TOOLCHAIN_NAME "${${CPUNAME}_SYSTEM}")
else()
# assume a toolchain name matching the CPU name
set(TOOLCHAIN_NAME "${CPUNAME}")
set(${CPUNAME}_SYSTEM ${TOOLCHAIN_NAME} PARENT_SCOPE)
endif ()

if (NOT DEFINED ${CPUNAME}_PLATFORM)
set(${CPUNAME}_PLATFORM "default" "${CPUNAME}")
set(${CPUNAME}_PLATFORM "${${CPUNAME}_PLATFORM}" PARENT_SCOPE)
endif()

set(BUILD_CONFIG ${TOOLCHAIN_NAME} ${TGT${TGTID}_PLATFORM})
set(BUILD_CONFIG ${TOOLCHAIN_NAME} ${${CPUNAME}_PLATFORM})

# convert to a the string which is safe for a variable name
string(REGEX REPLACE "[^A-Za-z0-9]" "_" SYSVAR "${BUILD_CONFIG}")
Expand All @@ -181,25 +212,25 @@ function(read_targetconfig)

# if the "global" applist is not empty, append to every CPU applist
if (MISSION_GLOBAL_APPLIST)
list(APPEND TGT${TGTID}_APPLIST ${MISSION_GLOBAL_APPLIST})
set(TGT${TGTID}_APPLIST ${TGT${TGTID}_APPLIST} PARENT_SCOPE)
list(APPEND ${CPUNAME}_APPLIST ${MISSION_GLOBAL_APPLIST})
set(${CPUNAME}_APPLIST ${${CPUNAME}_APPLIST} PARENT_SCOPE)
endif (MISSION_GLOBAL_APPLIST)

if (MISSION_GLOBAL_STATIC_APPLIST)
list(APPEND TGT${TGTID}_STATIC_APPLIST ${MISSION_GLOBAL_STATIC_APPLIST})
set(TGT${TGTID}_STATIC_APPLIST ${TGT${TGTID}_STATIC_APPLIST} PARENT_SCOPE)
list(APPEND ${CPUNAME}_STATIC_APPLIST ${MISSION_GLOBAL_STATIC_APPLIST})
set(${CPUNAME}_STATIC_APPLIST ${${CPUNAME}_STATIC_APPLIST} PARENT_SCOPE)
endif (MISSION_GLOBAL_STATIC_APPLIST)

# Append to global lists
list(APPEND TGTSYS_LIST "${SYSVAR}")
list(APPEND TGTSYS_${SYSVAR} "${TGTID}")
list(APPEND TGTSYS_${SYSVAR}_APPS ${TGT${TGTID}_APPLIST})
list(APPEND TGTSYS_${SYSVAR}_STATICAPPS ${TGT${TGTID}_STATIC_APPLIST})
list(APPEND TGTSYS_${SYSVAR}_PSPMODULES ${TGT${TGTID}_PSP_MODULELIST})
list(APPEND MISSION_APPS ${TGT${TGTID}_APPLIST} ${TGT${TGTID}_STATIC_APPLIST})
list(APPEND MISSION_PSPMODULES ${TGT${TGTID}_PSP_MODULELIST})
list(APPEND TGTSYS_${SYSVAR} "${CPUNAME}")
list(APPEND TGTSYS_${SYSVAR}_APPS ${${CPUNAME}_APPLIST})
list(APPEND TGTSYS_${SYSVAR}_STATICAPPS ${${CPUNAME}_STATIC_APPLIST})
list(APPEND TGTSYS_${SYSVAR}_PSPMODULES ${${CPUNAME}_PSP_MODULELIST})
list(APPEND MISSION_APPS ${${CPUNAME}_APPLIST} ${${CPUNAME}_STATIC_APPLIST})
list(APPEND MISSION_PSPMODULES ${${CPUNAME}_PSP_MODULELIST})

endwhile()
endforeach()

# Remove duplicate entries in the generated lists
list(REMOVE_DUPLICATES TGTSYS_LIST)
Expand All @@ -214,6 +245,7 @@ function(read_targetconfig)
set(TGTSYS_LIST ${TGTSYS_LIST} PARENT_SCOPE)
set(MISSION_APPS ${MISSION_APPS} PARENT_SCOPE)
set(MISSION_PSPMODULES ${MISSION_PSPMODULES} PARENT_SCOPE)
set(MISSION_CPUNAMES ${MISSION_CPUNAMES} PARENT_SCOPE)

foreach(SYSVAR ${TGTSYS_LIST})
set(TGTSYS_${SYSVAR} ${TGTSYS_${SYSVAR}} PARENT_SCOPE)
Expand All @@ -229,7 +261,7 @@ function(read_targetconfig)
list(REMOVE_DUPLICATES TGTSYS_${SYSVAR}_PSPMODULES)
set(TGTSYS_${SYSVAR}_PSPMODULES ${TGTSYS_${SYSVAR}_PSPMODULES} PARENT_SCOPE)
endif(TGTSYS_${SYSVAR}_PSPMODULES)
endforeach(SYSVAR IN LISTS TGTSYS_LIST)
endforeach(SYSVAR ${TGTSYS_LIST})

endfunction(read_targetconfig)

Expand Down
12 changes: 1 addition & 11 deletions cmake/sample_defs/cpu1_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@
*/
#include "cfe_mission_cfg.h"

/*
** CPU Id for target Processor
*/
#define CFE_PLATFORM_CPU_ID 1

/*
** CPU Name for target Processor
*/
#define CFE_PLATFORM_CPU_NAME "CPU1"

/**
** \cfesbcfg Maximum Number of Unique Message IDs SB Routing Table can hold
**
Expand Down Expand Up @@ -1786,7 +1776,7 @@
** \par Limits
** This value can be any 32 bit unsigned integer.
*/
#define CFE_PLATFORM_TBL_VALID_PRID_1 (CFE_PLATFORM_CPU_ID)
#define CFE_PLATFORM_TBL_VALID_PRID_1 (10)
astrogeco marked this conversation as resolved.
Show resolved Hide resolved
#define CFE_PLATFORM_TBL_VALID_PRID_2 (CFE_PLATFORM_TBL_U32FROM4CHARS('a', 'b', 'c', 'd'))
#define CFE_PLATFORM_TBL_VALID_PRID_3 0
#define CFE_PLATFORM_TBL_VALID_PRID_4 0
Expand Down
68 changes: 31 additions & 37 deletions cmake/sample_defs/targets.cmake
Original file line number Diff line number Diff line change
@@ -1,74 +1,70 @@
######################################################################
#
#
# Master config file for cFS target boards
#
# This file indicates the architecture and configuration of the
# target boards that will run core flight software.
#
# The following variables are defined per board, where <x> is a
# sequential index number starting with 1:
# The following variables are defined per board, where <x> is the
# CPU number starting with 1:
#
# TGT<x>_NAME : the user-friendly name of the cpu. Should be simple
# <cpuname>_NAME : the user-friendly name of the cpu. Should be simple
# word with no punctuation. This MUST be specified.
# TGT<x>_PROCESSORID : the default numeric ID for this processor at
# runtime. If not specified, then the sequential index number is
# used. This translates to the numeric value returned by
# CFE_PSP_GetProcessorId() at runtime.
# TGT<x>_APPLIST : list of applications to build and install on the CPU.
# <cpuname>_APPLIST : list of applications to build and install on the CPU.
# These are built as dynamically-loaded applications and installed
# as files in the non-volatile storage of the target, and loaded
# at runtime via the startup script or commands.
# TGT<x>_STATIC_APPLIST : list of applications to build and statically
# <cpuname>_STATIC_APPLIST : list of applications to build and statically
# link with the CFE executable. This is similar to the "APPLIST"
# except the application is built with STATIC linkage, and it is
# included directly when linking the CFE core executable itself.
# No separate application file is generated for these apps.
# TGT<x>_STATIC_SYMLIST : list of symbols to include in the OSAL static
# No separate application file is generated for these apps.
# <cpuname>_STATIC_SYMLIST : list of symbols to include in the OSAL static
# symbol lookup table. Each entry is a comma-separated pair containing
# the symbol name and virtual module/app name, such as
# the symbol name and virtual module/app name, such as
# My_C_Function_Name,MY_APP
# The first item must be a publicly-exposed C symbol name available to
# the linker at static link time, generally the entry point/main function
# of the a module or library (see STATIC_APPLIST). The second item is the
# module name that should match the name used in the CFE startup script
# module name that should match the name used in the CFE startup script
# (4th parameter).
# IMPORTANT: For this to work, the OS_STATIC_LOADER configuration option
# IMPORTANT: For this to work, the OS_STATIC_LOADER configuration option
# must be specified in the osconfig.h for that CPU.
# TGT<x>_PSP_MODULELIST : additional PSP "modules" to link into the
# <cpuname>_PSP_MODULELIST : additional PSP "modules" to link into the
# CFE executable for this target. These can be device drivers or
# other bits of modular PSP functionality that provide I/O or other
# low level functions.
# TGT<x>_FILELIST : list of extra files to copy onto the target. No
# <cpuname>_FILELIST : list of extra files to copy onto the target. No
# modifications of the file will be made. In order to differentiate
# between different versions of files with the same name, priority
# will be given to a file named <cpuname>_<filename> to be installed
# as simply <filename> on that cpu (prefix will be removed). These
# files are intended to be copied to the non-volatile storage on the
# target for use during runtime.
# TGT<x>_EMBED_FILELIST : list of extra files which are to be converted
# into data arrays and linked with/embedded into the CFE executable,
# <cpuname>_EMBED_FILELIST : list of extra files which are to be converted
# into data arrays and linked with/embedded into the CFE executable,
# so the content of the files can be available at runtime on systems
# that do not have run time non-volatile storage. The format of each
# list entry is a comma-separated pair of variable and file name:
# VARIABLE_NAME,FILE_NAME
# The binary contents of the file will subsequently be available as:
# extern const char VARIABLE_NAME_DATA[] and
# extern const char VARIABLE_NAME_DATA[] and
# extern const unsigned long VARIABLE_NAME_SIZE
# The same prefix-based filename mapping as used on FILELIST is also
# employed here, allowing CPU-specific data files to be used.
# TGT<x>_SYSTEM : the toolchain to use for building all code. This
# employed here, allowing CPU-specific data files to be used.
# <cpuname>_SYSTEM : the toolchain to use for building all code. This
# will map to a CMake toolchain file called "toolchain-<ZZZ>"
# If not specified then it will default to "cpu<x>" so that
# each CPU will have a dedicated toolchain file and no objects
# will be shared across CPUs.
# Otherwise any code built using the same toolchain may be
# will be shared across CPUs.
# Otherwise any code built using the same toolchain may be
# copied to multiple CPUs for more efficient builds.
# TGT<x>_PLATFORM : configuration for the CFE core to use for this
# <cpuname>_PLATFORM : configuration for the CFE core to use for this
# cpu. This determines the cfe_platform_cfg.h to use during the
# build. Multiple files/components may be concatenated together
# allowing the config to be generated in a modular fashion. If
# allowing the config to be generated in a modular fashion. If
# not specified then it will be assumed as "default <cpuname>".
#
#

# The MISSION_NAME will be compiled into the target build data structure
# as well as being passed to "git describe" to filter the tags when building
Expand Down Expand Up @@ -102,17 +98,15 @@ list(APPEND MISSION_GLOBAL_APPLIST sample_app sample_lib)
SET(FT_INSTALL_SUBDIR "host/functional-test")

# Each target board can have its own HW arch selection and set of included apps
SET(TGT1_NAME cpu1)
SET(TGT1_APPLIST ci_lab to_lab sch_lab)
SET(TGT1_FILELIST cfe_es_startup.scr)
SET(MISSION_CPUNAMES cpu1)

SET(cpu1_PROCESSORID 10)
SET(cpu1_APPLIST ci_lab to_lab sch_lab)
SET(cpu1_FILELIST cfe_es_startup.scr)

# CPU2/3 are duplicates of CPU1. These are not built by default anymore but are
# commented out to serve as an example of how one would configure multiple cpus.
#SET(TGT2_NAME cpu2)
#SET(TGT2_APPLIST ci_lab to_lab sch_lab)
#SET(TGT2_FILELIST cfe_es_startup.scr)

#SET(TGT3_NAME cpu3)
#SET(TGT3_APPLIST ci_lab to_lab sch_lab)
#SET(TGT3_FILELIST cfe_es_startup.scr)
SET(cpu2_PROCESSORID 11)
SET(cpu2_APPLIST ci_lab to_lab sch_lab)
SET(cpu2_FILELIST cfe_es_startup.scr)

Loading