-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example toolchain and target to utilize tarfs
- Loading branch information
Showing
2 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Create executable with built in tarfs | ||
|
||
# In theory could just set up an executable with the extra steps to create the tarred object | ||
# Setting up to easily run from prep, might work from install but would need to sort out directories | ||
|
||
set(TARFS_DEV_DIR ${MISSION_BINARY_DIR}${CMAKE_INSTALL_PREFIX}/tarfs_dev) | ||
set(DEV_DIR ${MISSION_BINARY_DIR}${CMAKE_INSTALL_PREFIX}/devboard) | ||
|
||
file(MAKE_DIRECTORY ${TARFS_DEV_DIR}) | ||
|
||
# Create the nonvol tar file | ||
execute_process( | ||
COMMAND tar cf ${TARFS_DEV_DIR}/tarfile nonvol | ||
WORKING_DIRECTORY ${DEV_DIR}) | ||
|
||
# Create the tar file object | ||
execute_process( | ||
COMMAND ${CMAKE_LINKER} -r --noinhibit-exe -o tarfile.o -b binary tarfile | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR}) | ||
|
||
# Force symbol inclusion as needed for modules | ||
set(INCLUDE_SYMBOLS "-u strncat -u fgetc -u fputc -u fprintf -u fwrite") | ||
|
||
# Convert since execute command needs list not string with spaces | ||
string(REPLACE " " ";" TARFS_FLAGS_LIST ${RTEMS_SYS_SPECS_FLAGS} " " ${RTEMS_BSP_C_FLAGS} " " ${INCLUDE_SYMBOLS}) | ||
|
||
file(GLOB devboard_exe "${MISSION_BINARY_DIR}${CMAKE_INSTALL_PREFIX}/devboard/*.exe") | ||
foreach(executable ${devboard_exe}) | ||
message("Processing executable: ${executable}") | ||
get_filename_component(BASE_NAME ${executable} NAME_WE) | ||
|
||
#### LINKS | ||
#### Does not work to replace -Wl,--export-dynamic with -rdynamic | ||
#### Does need -lrtemscpu | ||
# set(TARFS_PRELINK ${CMAKE_C_COMPILER} -B/opt/rcc-1.3.1-gcc/sparc-gaisler-rtems5/sparc-rtems5/leon3/lib -qbsp=leon3 -qrtems -mcpu=leon3 -fno-common -u Init -o ${BASE_NAME}.prelink -Wl,--export-dynamic -Wl,--whole-archive ${executable} tarfile.o -Wl,--no-whole-archive -lrtemscpu) | ||
|
||
#### BEST SO FAR | ||
# set(TARFS_PRELINK ${CMAKE_C_COMPILER} ${TARFS_FLAGS_LIST} -u Init -o ${BASE_NAME}.prelink -Wl,--export-dynamic -Wl,--whole-archive ${executable} tarfile.o -Wl,--no-whole-archive -lrtemscpu) | ||
|
||
# rtemscpu adds ~8MB of debug info, need to strip even if cFS release build | ||
# -Wl,--export-dynamic doesn't seem to do anything (same exact size either way), needs 2 step link | ||
# -Wl,--whole-archive and -Wl,--no-whole-archive have no impact either | ||
# -u Init has no impact | ||
# TODO investigate adding: -ffunction-sections -fdata-sections -Wl,--gc-sections | ||
set(TARFS_LINK ${CMAKE_C_COMPILER} ${TARFS_FLAGS_LIST} ${executable} tarfile.o -lrtemscpu) | ||
|
||
#### LINKS | ||
#### First shot at rcc style prelink | ||
# set(TARFS_PRELINK ${CMAKE_C_COMPILER} -mcpu=leon3 -ffunction-sections -fdata-sections -Wl,--gc-sections -B/opt/rcc-1.3.1-gcc/sparc-gaisler-rtems5/leon3/lib -qrtems -specs bsp_specs -o rki.elf.pre ${executable} tarfile.o --start-group -lrtemsbsp -lrtemscpu -latomic -lc -lm -lgcc --end-group) | ||
|
||
#### LINKS | ||
# set(TARFS_PRELINK ${CMAKE_C_COMPILER} -mcpu=leon3 -ffunction-sections -fdata-sections -Wl,--gc-sections -B/opt/rcc-1.3.1-gcc/sparc-gaisler-rtems5/leon3/lib -qrtems -o ${BASE_NAME}.prelink ${executable} tarfile.o -lrtemsbsp -lrtemscpu -latomic -lc -lm -lgcc) | ||
|
||
#### BROKEN - Note this fails since it includes crt0.c, and can't find _start ?!? | ||
# set(TARFS_PRELINK ${CMAKE_C_COMPILER} -mcpu=leon3 -ffunction-sections -fdata-sections -Wl,--gc-sections ${RTEMS_SYS_SPECS_FLAGS} -o ${BASE_NAME}.prelink ${executable} tarfile.o -latomic -lc -lm -lgcc) | ||
|
||
message("") | ||
message("Prelink execution:") | ||
execute_process( | ||
COMMAND ${TARFS_LINK} -o ${BASE_NAME}.prelink | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE TARFS_PRELINK_OUT | ||
ERROR_VARIABLE TARFS_PRELINK_ERR) | ||
message("Output:\n${TARFS_PRELINK_OUT}Error:\n${TARFS_PRELINK_ERR}") | ||
|
||
message("Get dl symbols") | ||
execute_process( | ||
COMMAND ${RTEMS_TOOLS_PREFIX}/bin/rtems-syms -v -e -c ${RTEMS_BSP_C_FLAGS} -C ${CMAKE_C_COMPILER} -o ${BASE_NAME}-dl-sym.o ${BASE_NAME}.prelink | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE TARFS_PRELINK_OUT | ||
ERROR_VARIABLE TARFS_PRELINK_ERR) | ||
message("Output:\n${TARFS_PRELINK_OUT}Error:\n${TARFS_PRELINK_ERR}") | ||
|
||
message("Final link:") | ||
execute_process( | ||
COMMAND ${TARFS_LINK} ${BASE_NAME}-dl-sym.o -o ${BASE_NAME}.elf | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE TARFS_PRELINK_OUT | ||
ERROR_VARIABLE TARFS_PRELINK_ERR) | ||
message("Output:\n${TARFS_PRELINK_OUT}Error:\n${TARFS_PRELINK_ERR}") | ||
|
||
message("Strip binary:") | ||
execute_process( | ||
COMMAND ${CMAKE_OBJCOPY} -O binary --strip-all ${BASE_NAME}.elf ${BASE_NAME}.bin | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE TARFS_PRELINK_OUT | ||
ERROR_VARIABLE TARFS_PRELINK_ERR) | ||
message("Output:\n${TARFS_PRELINK_OUT}Error:\n${TARFS_PRELINK_ERR}") | ||
|
||
message("Strip elf:") | ||
execute_process( | ||
COMMAND ${CMAKE_OBJCOPY} --strip-all ${BASE_NAME}.elf ${BASE_NAME}-strip.elf | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE TARFS_PRELINK_OUT | ||
ERROR_VARIABLE TARFS_PRELINK_ERR) | ||
message("Output:\n${TARFS_PRELINK_OUT}Error:\n${TARFS_PRELINK_ERR}") | ||
|
||
message("Report sizes:") | ||
execute_process( | ||
COMMAND ${CMAKE_SIZE} ${BASE_NAME}.elf | ||
WORKING_DIRECTORY ${TARFS_DEV_DIR} | ||
COMMAND_ECHO STDOUT | ||
OUTPUT_VARIABLE TARFS_PRELINK_OUT | ||
ERROR_VARIABLE TARFS_PRELINK_ERR) | ||
message("Output:\n${TARFS_PRELINK_OUT}Error:\n${TARFS_PRELINK_ERR}") | ||
|
||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# This example toolchain file describes the cross compiler to use for | ||
# the target architecture indicated in the configuration file. | ||
|
||
# In this sample application, the cross toolchain is configured to | ||
# use a compiler for the RTEMS operating system targeting the "pc686" BSP | ||
|
||
# Note that to use this, the "RTEMS" platform module may need to be added | ||
# to the system-wide CMake installation as a default CMake does not yet | ||
# recognize RTEMS as a system name. An example of this is distributed with | ||
# the pc-rtems PSP. | ||
|
||
# Basic cross system configuration | ||
set(CMAKE_SYSTEM_NAME RTEMS) | ||
set(CMAKE_SYSTEM_PROCESSOR sparc) | ||
set(CMAKE_SYSTEM_VERSION 5) | ||
|
||
# The BSP that will be used for this build | ||
set(RTEMS_BSP "leon3") | ||
|
||
# these settings are specific to cFE/OSAL and determines which | ||
# abstraction layers are built when using this toolchain | ||
SET(CFE_SYSTEM_PSPNAME pc-rtems) | ||
SET(OSAL_SYSTEM_BSPTYPE generic-rtems) | ||
SET(OSAL_SYSTEM_OSTYPE rtems) | ||
|
||
# This is for version specific RTEMS ifdefs needed by the OSAL and PSP | ||
ADD_DEFINITIONS(-DOS_RTEMS_5) | ||
|
||
# RTEMS_DYNAMIC_LOAD definition: | ||
# - Set to FALSE for platforms that create a RTEMS executable and link it | ||
# to the cFE core. | ||
# - Set to TRUE for platforms that expect the cFE core to to be dynamically | ||
# loaded into an existing runtime image. | ||
# This is tied to the OSAL-BSP and PSP implementation so generally cannot | ||
# be switched on a specific OSAL/PSP platform without modifications. | ||
set(RTEMS_DYNAMIC_LOAD TRUE) | ||
set(RTEMS_INCLUDE_TARFS TRUE) | ||
set(RTEMS_NO_CMDLINE TRUE) | ||
|
||
# Default to no shell (flight like and batch testing) but allow override from make line | ||
# Example: make TARGET=devboard RTEMS_NO_SHELL=FALSE install | ||
if (NOT DEFINED ENV{RTEMS_NO_SHELL}) | ||
set(RTEMS_NO_SHELL TRUE) | ||
else () | ||
set(RTEMS_NO_SHELL $ENV{RTEMS_NO_SHELL}) | ||
endif () | ||
|
||
# TODO Only remaining dependency is for network setup, switch to osal network config and remove | ||
if (RTEMS_INCLUDE_TARFS) | ||
ADD_DEFINITIONS(-DRTEMS_INCLUDE_TARFS) | ||
endif () | ||
|
||
set(RTEMS_BSP_C_FLAGS "-mcpu=leon3 -fno-common") | ||
set(RTEMS_BSP_CXX_FLAGS ${RTEMS_BSP_C_FLAGS}) | ||
set(RTEMS_BSP_SPECS_FLAGS "-qbsp=leon3") | ||
|
||
# Exception handling is very iffy. These two options disable eh_frame creation. | ||
set(CMAKE_C_COMPILE_OPTIONS_PIC -fno-exceptions -fno-asynchronous-unwind-tables) | ||
|
||
# The TOOLS and BSP are allowed to be installed in different locations. | ||
# If the README was followed they will both be installed under $HOME | ||
# By default it is assumed the BSP is installed to the same directory as the tools | ||
SET(RTEMS_TOOLS_PREFIX "/opt/rcc-1.3.1-gcc" CACHE PATH | ||
"RTEMS tools install directory") | ||
SET(RTEMS_BSP_PREFIX "/opt/rcc-1.3.1-gcc/sparc-gaisler-rtems${CMAKE_SYSTEM_VERSION}" CACHE PATH | ||
"RTEMS BSP install directory") | ||
|
||
#+---------------------------------------------------------------------------+ | ||
#| Common RTEMS toolchain statements | ||
#+---------------------------------------------------------------------------+ | ||
|
||
# specify the cross compiler - adjust accord to compiler installation | ||
# This uses the compiler-wrapper toolchain that buildroot produces | ||
SET(SDKHOSTBINDIR "${RTEMS_TOOLS_PREFIX}/bin") | ||
set(TARGETPREFIX "${CMAKE_SYSTEM_PROCESSOR}-gaisler-rtems${CMAKE_SYSTEM_VERSION}-") | ||
|
||
SET(CMAKE_C_COMPILER "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}gcc") | ||
SET(CMAKE_CXX_COMPILER "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}g++") | ||
SET(CMAKE_LINKER "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}ld") | ||
SET(CMAKE_ASM_COMPILER "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}as") | ||
SET(CMAKE_STRIP "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}strip") | ||
SET(CMAKE_NM "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}nm") | ||
SET(CMAKE_AR "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}ar") | ||
SET(CMAKE_OBJDUMP "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}objdump") | ||
SET(CMAKE_OBJCOPY "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}objcopy") | ||
SET(CMAKE_SIZE "${RTEMS_TOOLS_PREFIX}/bin/${TARGETPREFIX}size") | ||
|
||
# search for programs in the build host directories | ||
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | ||
|
||
# for libraries and headers in the target directories | ||
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | ||
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | ||
|
||
SET(CMAKE_PREFIX_PATH /) |