armclang: bintools support for armclang (arm-ds/Keil)
Initial bintools support for elfconvert - hex, srec, bin conversion - strip - gap fill Initial bintools support for readelf Initial bintools support for disaasembly Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
ce8f8c9f17
commit
4de0d5511c
3 changed files with 141 additions and 0 deletions
54
cmake/bintools/armclang/elfconvert_command.cmake
Normal file
54
cmake/bintools/armclang/elfconvert_command.cmake
Normal file
|
@ -0,0 +1,54 @@
|
|||
# For armclang the elfconvert command is made into a script.
|
||||
# Reason for that is because not a single command covers all use cases,
|
||||
# and it must therefore be possible to call individual commands, depending
|
||||
# on the arguments used.
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
# Handle stripping
|
||||
if (STRIP_DEBUG OR STRIP_ALL)
|
||||
set(obj_copy_target_output "--elf")
|
||||
if(STRIP_ALL)
|
||||
set(obj_copy_strip "--strip=all")
|
||||
elseif(STRIP_DEBUG)
|
||||
set(obj_copy_strip "--strip=debug")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Unknown support of --srec-len in arm-ds
|
||||
|
||||
# Handle Input and Output target types
|
||||
if(DEFINED OUTTARGET)
|
||||
if(${OUTTARGET} STREQUAL "srec")
|
||||
set(obj_copy_target_output "--m32")
|
||||
elseif(${OUTTARGET} STREQUAL "ihex")
|
||||
set(obj_copy_target_output "--i32combined")
|
||||
elseif(${OUTTARGET} STREQUAL "binary")
|
||||
set(obj_copy_target_output "--bincombined")
|
||||
if(GAP_FILL)
|
||||
set(obj_copy_gap_fill "--bincombined_padding=1,${GAP_FILL}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DEFINED ONLY_SECTION AND "${OUTTARGET}" STREQUAL "binary")
|
||||
set(obj_copy_target_output "--bin")
|
||||
set(outfile_dir .dir)
|
||||
string(REGEX REPLACE "^[\.]" "" only_section_clean "${ONLY_SECTION}")
|
||||
endif()
|
||||
|
||||
# Note: fromelf is a little special regarding bin output, as each section gets
|
||||
# its own file. This means that when only a specific section is required
|
||||
# then that section must be moved to correct location.
|
||||
execute_process(
|
||||
COMMAND ${FROMELF}
|
||||
${obj_copy_strip}
|
||||
${obj_copy_gap_fill} ${obj_copy_target_output}
|
||||
--output ${OUTFILE}${outfile_dir} ${INFILE}
|
||||
)
|
||||
|
||||
if(DEFINED ONLY_SECTION AND "${OUTTARGET}" STREQUAL "binary")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${OUTFILE}${outfile_dir}/${only_section_clean} ${OUTFILE}
|
||||
)
|
||||
endif()
|
16
cmake/bintools/armclang/target.cmake
Normal file
16
cmake/bintools/armclang/target.cmake
Normal file
|
@ -0,0 +1,16 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Configures binary tools as mwdt binutils
|
||||
|
||||
find_program(CMAKE_FROMELF fromelf PATH ${TOOLCHAIN_HOME}/bin NO_DEFAULT_PATH)
|
||||
find_program(CMAKE_AS armasm PATH ${TOOLCHAIN_HOME}/bin NO_DEFAULT_PATH)
|
||||
find_program(CMAKE_AR armar PATH ${TOOLCHAIN_HOME}/bin NO_DEFAULT_PATH)
|
||||
|
||||
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -rq <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -rq <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_AR> -sq <TARGET>")
|
||||
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_AR> -sq <TARGET>")
|
||||
|
||||
find_program(CMAKE_GDB ${CROSS_COMPILE}mdb PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/target_bintools.cmake)
|
71
cmake/bintools/armclang/target_bintools.cmake
Normal file
71
cmake/bintools/armclang/target_bintools.cmake
Normal file
|
@ -0,0 +1,71 @@
|
|||
# List of format the tool supports for converting, for example,
|
||||
# GNU tools uses objectcopyy, which supports the following: ihex, srec, binary
|
||||
set_property(TARGET bintools PROPERTY elfconvert_formats ihex binary)
|
||||
|
||||
# armclang toolchain does not support all options in a single command
|
||||
# Therefore a CMake script is used, so that multiple commands can be executed
|
||||
# successively.
|
||||
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_COMMAND})
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag
|
||||
-DFROMELF=${CMAKE_FROMELF}
|
||||
)
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_final
|
||||
-P ${CMAKE_CURRENT_LIST_DIR}/elfconvert_command.cmake)
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-DSTRIP_ALL=True")
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-DSTRIP_DEBUG=True")
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "-DINTARGET=")
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "-DOUTTARGET=")
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "-DREMOVE_SECTION=")
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_section_only "-DONLY_SECTION=")
|
||||
|
||||
# mwdt doesn't handle rename, consider adjusting abstraction.
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_section_rename "-DRENAME_SECTION=")
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "-DGAP_FILL=")
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_srec_len "-DSREC_LEN=")
|
||||
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_infile "-DINFILE=")
|
||||
set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "-DOUTFILE=")
|
||||
|
||||
#
|
||||
# - disassembly : Name of command for disassembly of files
|
||||
# In this implementation `fromelf` is used
|
||||
# disassembly_flag : --disassemble
|
||||
# disassembly_flag_final : empty
|
||||
# disassembly_flag_inline_source : --interleave=source
|
||||
# disassembly_flag_all : empty, fromelf does not differentiate on this.
|
||||
# disassembly_flag_infile : empty, fromelf doesn't take arguments for filenames
|
||||
# disassembly_flag_outfile : --output
|
||||
|
||||
set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_FROMELF})
|
||||
set_property(TARGET bintools PROPERTY disassembly_flag --disassemble)
|
||||
set_property(TARGET bintools PROPERTY disassembly_flag_final "")
|
||||
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source --interleave=source)
|
||||
set_property(TARGET bintools PROPERTY disassembly_flag_all "")
|
||||
|
||||
set_property(TARGET bintools PROPERTY disassembly_flag_infile "")
|
||||
set_property(TARGET bintools PROPERTY disassembly_flag_outfile "--output=" )
|
||||
|
||||
#
|
||||
# - readelf : Name of command for reading elf files.
|
||||
# In this implementation `fromelf` is used
|
||||
# readelf_flag : empty
|
||||
# readelf_flag_final : empty
|
||||
# readelf_flag_headers : --text
|
||||
# readelf_flag_infile : empty, fromelf doesn't take arguments for filenames
|
||||
# readelf_flag_outfile : --output
|
||||
|
||||
# This is using fromelf from arm-ds / Keil.
|
||||
set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_FROMELF})
|
||||
|
||||
set_property(TARGET bintools PROPERTY readelf_flag "")
|
||||
set_property(TARGET bintools PROPERTY readelf_flag_final "")
|
||||
set_property(TARGET bintools PROPERTY readelf_flag_headers --text)
|
||||
|
||||
set_property(TARGET bintools PROPERTY readelf_flag_infile "")
|
||||
set_property(TARGET bintools PROPERTY readelf_flag_outfile "--output=")
|
Loading…
Add table
Add a link
Reference in a new issue