Skip to content

Commit 4de0d55

Browse files
tejlmandnashif
authored andcommitted
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 <[email protected]>
1 parent ce8f8c9 commit 4de0d55

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# For armclang the elfconvert command is made into a script.
2+
# Reason for that is because not a single command covers all use cases,
3+
# and it must therefore be possible to call individual commands, depending
4+
# on the arguments used.
5+
cmake_minimum_required(VERSION 3.13)
6+
7+
# Handle stripping
8+
if (STRIP_DEBUG OR STRIP_ALL)
9+
set(obj_copy_target_output "--elf")
10+
if(STRIP_ALL)
11+
set(obj_copy_strip "--strip=all")
12+
elseif(STRIP_DEBUG)
13+
set(obj_copy_strip "--strip=debug")
14+
endif()
15+
endif()
16+
17+
# Unknown support of --srec-len in arm-ds
18+
19+
# Handle Input and Output target types
20+
if(DEFINED OUTTARGET)
21+
if(${OUTTARGET} STREQUAL "srec")
22+
set(obj_copy_target_output "--m32")
23+
elseif(${OUTTARGET} STREQUAL "ihex")
24+
set(obj_copy_target_output "--i32combined")
25+
elseif(${OUTTARGET} STREQUAL "binary")
26+
set(obj_copy_target_output "--bincombined")
27+
if(GAP_FILL)
28+
set(obj_copy_gap_fill "--bincombined_padding=1,${GAP_FILL}")
29+
endif()
30+
endif()
31+
endif()
32+
33+
if(DEFINED ONLY_SECTION AND "${OUTTARGET}" STREQUAL "binary")
34+
set(obj_copy_target_output "--bin")
35+
set(outfile_dir .dir)
36+
string(REGEX REPLACE "^[\.]" "" only_section_clean "${ONLY_SECTION}")
37+
endif()
38+
39+
# Note: fromelf is a little special regarding bin output, as each section gets
40+
# its own file. This means that when only a specific section is required
41+
# then that section must be moved to correct location.
42+
execute_process(
43+
COMMAND ${FROMELF}
44+
${obj_copy_strip}
45+
${obj_copy_gap_fill} ${obj_copy_target_output}
46+
--output ${OUTFILE}${outfile_dir} ${INFILE}
47+
)
48+
49+
if(DEFINED ONLY_SECTION AND "${OUTTARGET}" STREQUAL "binary")
50+
execute_process(
51+
COMMAND ${CMAKE_COMMAND} -E copy
52+
${OUTFILE}${outfile_dir}/${only_section_clean} ${OUTFILE}
53+
)
54+
endif()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# Configures binary tools as mwdt binutils
4+
5+
find_program(CMAKE_FROMELF fromelf PATH ${TOOLCHAIN_HOME}/bin NO_DEFAULT_PATH)
6+
find_program(CMAKE_AS armasm PATH ${TOOLCHAIN_HOME}/bin NO_DEFAULT_PATH)
7+
find_program(CMAKE_AR armar PATH ${TOOLCHAIN_HOME}/bin NO_DEFAULT_PATH)
8+
9+
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -rq <TARGET> <LINK_FLAGS> <OBJECTS>")
10+
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -rq <TARGET> <LINK_FLAGS> <OBJECTS>")
11+
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_AR> -sq <TARGET>")
12+
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_AR> -sq <TARGET>")
13+
14+
find_program(CMAKE_GDB ${CROSS_COMPILE}mdb PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
15+
16+
include(${CMAKE_CURRENT_LIST_DIR}/target_bintools.cmake)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# List of format the tool supports for converting, for example,
2+
# GNU tools uses objectcopyy, which supports the following: ihex, srec, binary
3+
set_property(TARGET bintools PROPERTY elfconvert_formats ihex binary)
4+
5+
# armclang toolchain does not support all options in a single command
6+
# Therefore a CMake script is used, so that multiple commands can be executed
7+
# successively.
8+
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_COMMAND})
9+
10+
set_property(TARGET bintools PROPERTY elfconvert_flag
11+
-DFROMELF=${CMAKE_FROMELF}
12+
)
13+
14+
set_property(TARGET bintools PROPERTY elfconvert_flag_final
15+
-P ${CMAKE_CURRENT_LIST_DIR}/elfconvert_command.cmake)
16+
17+
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-DSTRIP_ALL=True")
18+
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-DSTRIP_DEBUG=True")
19+
20+
set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "-DINTARGET=")
21+
set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "-DOUTTARGET=")
22+
23+
set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "-DREMOVE_SECTION=")
24+
set_property(TARGET bintools PROPERTY elfconvert_flag_section_only "-DONLY_SECTION=")
25+
26+
# mwdt doesn't handle rename, consider adjusting abstraction.
27+
set_property(TARGET bintools PROPERTY elfconvert_flag_section_rename "-DRENAME_SECTION=")
28+
29+
set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "-DGAP_FILL=")
30+
set_property(TARGET bintools PROPERTY elfconvert_flag_srec_len "-DSREC_LEN=")
31+
32+
set_property(TARGET bintools PROPERTY elfconvert_flag_infile "-DINFILE=")
33+
set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "-DOUTFILE=")
34+
35+
#
36+
# - disassembly : Name of command for disassembly of files
37+
# In this implementation `fromelf` is used
38+
# disassembly_flag : --disassemble
39+
# disassembly_flag_final : empty
40+
# disassembly_flag_inline_source : --interleave=source
41+
# disassembly_flag_all : empty, fromelf does not differentiate on this.
42+
# disassembly_flag_infile : empty, fromelf doesn't take arguments for filenames
43+
# disassembly_flag_outfile : --output
44+
45+
set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_FROMELF})
46+
set_property(TARGET bintools PROPERTY disassembly_flag --disassemble)
47+
set_property(TARGET bintools PROPERTY disassembly_flag_final "")
48+
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source --interleave=source)
49+
set_property(TARGET bintools PROPERTY disassembly_flag_all "")
50+
51+
set_property(TARGET bintools PROPERTY disassembly_flag_infile "")
52+
set_property(TARGET bintools PROPERTY disassembly_flag_outfile "--output=" )
53+
54+
#
55+
# - readelf : Name of command for reading elf files.
56+
# In this implementation `fromelf` is used
57+
# readelf_flag : empty
58+
# readelf_flag_final : empty
59+
# readelf_flag_headers : --text
60+
# readelf_flag_infile : empty, fromelf doesn't take arguments for filenames
61+
# readelf_flag_outfile : --output
62+
63+
# This is using fromelf from arm-ds / Keil.
64+
set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_FROMELF})
65+
66+
set_property(TARGET bintools PROPERTY readelf_flag "")
67+
set_property(TARGET bintools PROPERTY readelf_flag_final "")
68+
set_property(TARGET bintools PROPERTY readelf_flag_headers --text)
69+
70+
set_property(TARGET bintools PROPERTY readelf_flag_infile "")
71+
set_property(TARGET bintools PROPERTY readelf_flag_outfile "--output=")

0 commit comments

Comments
 (0)