cmake: add metaware toolchain support in build system

* add metaware toolchain support in build system:
   * compiler
   * linker
   * binutils
     * gcc objcopy is used because it can't be replaced
       with mwdt's binutils currently
* To use ARC metaware toolchain, you'd better:
   * in Linux/Unix environment
   * install arc gcc/zephyr toolchain to use gnu's objcopy
     tool
   * set ZEPHYR_TOOLCHAIN_VARIANT=arcmwdt

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
This commit is contained in:
Wayne Ren 2020-07-03 18:13:49 +08:00 committed by Maureen Helm
parent 2167ffbe45
commit b868018b51
6 changed files with 902 additions and 0 deletions

View file

@ -0,0 +1,371 @@
# SPDX-License-Identifier: Apache-2.0
# Configures binary tools as mwdt binutils
find_program(CMAKE_ELF2BIN ${CROSS_COMPILE}elf2bin PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}elfdumpac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AS ${CROSS_COMPILE}ccac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AR ${CROSS_COMPILE}arac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_RANLIB ${CROSS_COMPILE}arac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${CROSS_COMPILE}elfdumpac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_NM ${CROSS_COMPILE}nmac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_STRIP ${CROSS_COMPILE}stripac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_SIZE ${CROSS_COMPILE}sizeac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_ELF2HEX ${CROSS_COMPILE}elf2hex PATH ${TOOLCHAIN_HOME} 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)
# MWDT binutils don't support required features like section renameing, so we
# temporarily had to use GNU objcopy instead
find_program(CMAKE_OBJCOPY arc-elf32-objcopy)
if (NOT CMAKE_OBJCOPY)
find_program(CMAKE_OBJCOPY arc-linux-objcopy)
endif()
if (NOT CMAKE_OBJCOPY)
find_program(CMAKE_OBJCOPY objcopy)
endif()
if(NOT CMAKE_OBJCOPY)
message(FATAL_ERROR "Zephyr unable to find any GNU objcopy (ARC or host one)")
endif()
# Add and/or prepare print of memory usage report
#
# Usage:
# bintools_print_mem_usage(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
# )
#
function(bintools_print_mem_usage)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_MEMUSAGE
""
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST"
""
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_MEMUSAGE_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_MEMUSAGE_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
endif()
# no copy right msg + gnu format
set(memusage_args "-gq")
# Construct the command
set(memusage_cmd
# Base command
COMMAND ${CMAKE_SIZE} ${memusage_args}
${KERNEL_ELF_NAME}
)
# Place command in the parent provided variable
set(${BINTOOLS_MEMUSAGE_RESULT_CMD_LIST} ${memusage_cmd} PARENT_SCOPE)
endfunction()
# Construct a commandline suitable for calling the toolchain binary tools
# version of objcopy.
#
# Usage:
# bintools_objcopy(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# STRIP_ALL <When present, remove relocation and symbol info>
# STRIP_DEBUG <When present, remove debugging symbols and sections>
#
# TARGET_INPUT <Input file format type>
# TARGET_OUTPUT <Output file format type>
#
# GAP_FILL <Value used for gap fill, empty or not set, no gap fill>
# SREC_LEN <For srec format only, max length of the records>
#
# SECTION_ONLY <One or more section names to be included>
# SECTION_REMOVE <One or more section names to be excluded>
# SECTION_RENAME <One or more section names to be renamed 'from=to'>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_objcopy)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_OBJCOPY
# List of argument names without values, hence boolean
"STRIP_ALL;STRIP_DEBUG"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;TARGET_INPUT;TARGET_OUTPUT;GAP_FILL;SREC_LEN;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
"SECTION_ONLY;SECTION_RENAME;SECTION_REMOVE"
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_OBJCOPY_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_OBJCOPY_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_OBJCOPY_FILE_INPUT OR NOT DEFINED BINTOOLS_OBJCOPY_FILE_OUTPUT)
message(FATAL_ERROR "Both FILE_INPUT and FILE_OUTPUT is required.")
endif()
# Handle stripping
if (DEFINED BINTOOLS_OBJCOPY_STRIP OR DEFINED BINTOOLS_OBJCOPY_STRIP_ALL)
if(${BINTOOLS_OBJCOPY_STRIP_ALL})
set(obj_copy_strip "-qs")
elseif(${BINTOOLS_OBJCOPY_STRIP_DEBUG})
set(obj_copy_strip "-ql")
endif()
set(obj_copy_cmd
COMMAND ${CMAKE_STRIP} ${obj_copy_strip}
${BINTOOLS_OBJCOPY_FILE_INPUT} ${BINTOOLS_OBJCOPY_FILE_OUTPUT})
endif()
# no support of --srec-len in mwdt
# Handle Input and Output target types
if(DEFINED BINTOOLS_OBJCOPY_TARGET_OUTPUT)
set(obj_copy_target_output "")
set(obj_copy_gap_fill "")
if(DEFINED BINTOOLS_OBJCOPY_GAP_FILL)
set(obj_copy_gap_fill "-f;${BINTOOLS_OBJCOPY_GAP_FILL}")
endif()
# only mwdt's elf2hex supports gap fill
if(${BINTOOLS_OBJCOPY_TARGET_OUTPUT} STREQUAL "srec")
set(obj_copy_target_output "-m")
elseif(${BINTOOLS_OBJCOPY_TARGET_OUTPUT} STREQUAL "ihex")
set(obj_copy_target_output "-I")
elseif(${BINTOOLS_OBJCOPY_TARGET_OUTPUT} STREQUAL "binary")
set(obj_copy_target_output "-B")
endif()
set(obj_copy_cmd
COMMAND ${CMAKE_ELF2HEX} ${obj_copy_gap_fill} ${obj_copy_target_output}
-o ${BINTOOLS_OBJCOPY_FILE_OUTPUT} ${BINTOOLS_OBJCOPY_FILE_INPUT})
endif()
# Handle sections, if any
# 1. Section only selection(s)
set(obj_copy_sections_only "")
if(DEFINED BINTOOLS_OBJCOPY_SECTION_ONLY)
foreach(section_only ${BINTOOLS_OBJCOPY_SECTION_ONLY})
list(APPEND obj_copy_sections_only "-sn;${section_only}")
endforeach()
set(obj_copy_cmd
COMMAND ${CMAKE_ELF2BIN} -q ${obj_copy_sections_only}
${BINTOOLS_OBJCOPY_FILE_INPUT} ${BINTOOLS_OBJCOPY_FILE_OUTPUT})
endif()
set(obj_copy_sections_rename "")
if(DEFINED BINTOOLS_OBJCOPY_SECTION_RENAME)
foreach(section_rename ${BINTOOLS_OBJCOPY_SECTION_RENAME})
if(NOT ${section_rename} MATCHES "^.*=.*$")
message(FATAL_ERROR "Malformed section renaming. Must be from=to, have ${section_rename}")
else()
list(APPEND obj_copy_sections_rename "--rename-section;${section_rename}")
endif()
endforeach()
set(obj_copy_cmd
COMMAND ${CMAKE_OBJCOPY} ${obj_copy_sections_rename}
${BINTOOLS_OBJCOPY_FILE_INPUT} ${BINTOOLS_OBJCOPY_FILE_OUTPUT})
endif()
# no support of remove sections
# Place command in the parent provided variable
set(${BINTOOLS_OBJCOPY_RESULT_CMD_LIST} ${obj_copy_cmd} PARENT_SCOPE)
endfunction(bintools_objcopy)
# Construct a commandline suitable for calling the toolchain binary tools
# version of objdump.
#
# Usage:
# bintools_objdump(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# DISASSEMBLE <Display the assembler mnemonics for the machine instructions from input>
# DISASSEMBLE_SOURCE < Display source code intermixed with disassembly, if possible>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_objdump)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_OBJDUMP
# List of argument names without values, hence boolean
"DISASSEMBLE;DISASSEMBLE_SOURCE"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
""
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_OBJDUMP_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_OBJDUMP_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_OBJDUMP_FILE_INPUT)
message(FATAL_ERROR "FILE_INPUT is required.")
endif()
# Handle disassembly
set(obj_dump_disassemble "")
if(${BINTOOLS_OBJDUMP_DISASSEMBLE_SOURCE})
set(obj_dump_disassemble "-S") # --source
elseif(${BINTOOLS_OBJDUMP_DISASSEMBLE})
set(obj_dump_disassemble "-T") # --disassemble
endif()
# Handle output
set(obj_dump_output "")
if(DEFINED BINTOOLS_OBJDUMP_FILE_OUTPUT)
set(obj_dump_output > ${BINTOOLS_OBJDUMP_FILE_OUTPUT})
endif()
# Construct the command
set(obj_dump_cmd
# Base command
COMMAND ${CMAKE_OBJDUMP} ${obj_dump_disassemble}
# Input and Output
${BINTOOLS_OBJDUMP_FILE_INPUT} ${obj_dump_output}
)
# Place command in the parent provided variable
set(${BINTOOLS_OBJDUMP_RESULT_CMD_LIST} ${obj_dump_cmd} PARENT_SCOPE)
endfunction(bintools_objdump)
# Construct a commandline suitable for calling the toolchain binary tools
# version of readelf.
#
# Usage:
# bintools_readelf(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# HEADERS <Display all the headers in the input file>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_readelf)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_READELF
# List of argument names without values, hence boolean
"HEADERS"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
""
# Parser input
${ARGN}
)
# Verify arguments
if(NOT DEFINED BINTOOLS_READELF_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_READELF_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_READELF_FILE_INPUT)
message(FATAL_ERROR "FILE_INPUT is required.")
endif()
# Handle headers
set(readelf_headers "")
if(${BINTOOLS_READELF_HEADERS})
set(readelf_headers "-qshp") # --headers
endif()
# Handle output
set(readelf_output "")
if(DEFINED BINTOOLS_READELF_FILE_OUTPUT)
set(readelf_output > ${BINTOOLS_READELF_FILE_OUTPUT})
endif()
# Construct the command
set(readelf_cmd
# Base command
COMMAND ${CMAKE_READELF} ${readelf_headers}
# Input and Output
${BINTOOLS_READELF_FILE_INPUT} ${readelf_output}
)
# Place command in the parent provided variable
set(${BINTOOLS_READELF_RESULT_CMD_LIST} ${readelf_cmd} PARENT_SCOPE)
endfunction(bintools_readelf)
# Construct a commandline suitable for calling the toolchain binary tools
# version of strip.
#
# Usage:
# bintools_strip(
# RESULT_CMD_LIST <List of commands to be executed, usually after build>
# RESULT_BYPROD_LIST <List of command output byproducts>
#
# STRIP_ALL <When present, remove relocation and symbol info>
# STRIP_DEBUG <When present, remove debugging symbols and sections>
#
# FILE_INPUT <The input file>
# FILE_OUTPUT <The output file>
# )
function(bintools_strip)
cmake_parse_arguments(
# Prefix of output variables
BINTOOLS_STRIP
# List of argument names without values, hence boolean
"STRIP_ALL;STRIP_DEBUG"
# List of argument names with one value
"RESULT_CMD_LIST;RESULT_BYPROD_LIST;FILE_INPUT;FILE_OUTPUT"
# List of argument names with multible values
""
# Parser input
${ARGN}
)
if(NOT DEFINED BINTOOLS_STRIP_RESULT_CMD_LIST OR NOT DEFINED ${BINTOOLS_STRIP_RESULT_CMD_LIST})
message(FATAL_ERROR "RESULT_CMD_LIST is required.")
elseif(NOT DEFINED BINTOOLS_STRIP_FILE_INPUT OR NOT DEFINED BINTOOLS_STRIP_FILE_OUTPUT)
message(FATAL_ERROR "Both FILE_INPUT and FILE_OUTPUT are required.")
endif()
# Handle stripping
set(strip_what "")
if(${BINTOOLS_STRIP_STRIP_ALL})
set(strip_what "-qls")
elseif(${BINTOOLS_STRIP_STRIP_DEBUG})
set(strip_what "-ql")
endif()
# Handle output
set(strip_output -o ${BINTOOLS_STRIP_FILE_OUTPUT})
# Construct the command
set(strip_cmd
# Base command
COMMAND ${CMAKE_STRIP} ${strip_what}
# Input and Output
${BINTOOLS_STRIP_FILE_INPUT} ${strip_output}
)
# Place command in the parent provided variable
set(${BINTOOLS_STRIP_RESULT_CMD_LIST} ${strip_cmd} PARENT_SCOPE)
endfunction(bintools_strip)

View file

@ -0,0 +1,22 @@
# SPDX-License-Identifier: Apache-2.0
# Configures CMake for using ccac
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}ccac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
if(CMAKE_C_COMPILER STREQUAL CMAKE_C_COMPILER-NOTFOUND)
message(FATAL_ERROR "Zephyr was unable to find the Metaware compiler")
endif()
execute_process(
COMMAND ${CMAKE_C_COMPILER} --version
RESULT_VARIABLE ret
OUTPUT_QUIET
ERROR_QUIET
)
if(ret)
message(FATAL_ERROR "Executing the below command failed. Are permissions set correctly?
'${CMAKE_C_COMPILER} --version'"
)
endif()

View file

@ -0,0 +1,273 @@
# find the compilers for C, CPP, assembly
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}ccac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER ${CROSS_COMPILE}ccac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_ASM_COMPILER ${CROSS_COMPILE}ccac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
# The CMAKE_REQUIRED_FLAGS variable is used by check_c_compiler_flag()
# (and other commands which end up calling check_c_source_compiles())
# to add additional compiler flags used during checking. These flags
# are unused during "real" builds of Zephyr source files linked into
# the final executable.
#
# Appending onto any existing values lets users specify
# toolchain-specific flags at generation time.
list(APPEND CMAKE_REQUIRED_FLAGS
-c
-HL
-Hnosdata
-Hnolib
-Hnocrt
-Hnoentry
-Hldopt=-Bbase=0x0 # Set an entry point to avoid a warning
-Werror
)
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(NOSTDINC "")
list(APPEND NOSTDINC ${TOOLCHAIN_HOME}/arc/inc)
# For CMake to be able to test if a compiler flag is supported by the
# toolchain we need to give CMake the necessary flags to compile and
# link a dummy C file.
#
# CMake checks compiler flags with check_c_compiler_flag() (Which we
# wrap with target_cc_option() in extentions.cmake)
foreach(isystem_include_dir ${NOSTDINC})
list(APPEND isystem_include_flags -isystem "\"${isystem_include_dir}\"")
endforeach()
# common compile options, no copyright msg, little-endian, no small data
list(APPEND TOOLCHAIN_C_FLAGS -Hnocopyr -HL -Hnosdata)
# based flags for assembly
macro(toolchain_cc_asm_base_flags dest_var_name)
# Specify assembly as the source language for the preprocessor to expect
set_ifndef(${dest_var_name} "-Hasmcpp")
endmacro()
# options to not include default library
macro(toolchain_cc_nostdinc)
if (NOT CONFIG_NEWLIB_LIBC AND
NOT CONFIG_NATIVE_APPLICATION)
zephyr_compile_options( -Hno_default_include -Hnoarcexlib)
zephyr_system_include_directories(${NOSTDINC})
endif()
endmacro()
# do not link in supplied run-time startup files
macro(toolchain_cc_freestanding)
zephyr_compile_options(-Hnocrt)
endmacro()
# options to generate debug information
macro(toolchain_cc_produce_debug_info)
zephyr_compile_options(-g)
endmacro()
# compile common globals like normal definitions
macro(toolchain_cc_nocommon)
zephyr_compile_options(-fno-common)
endmacro()
# c std options
macro(toolchain_cc_cstd_flag dest_var_name c_std)
# mwdt supports: c89, c99, gnu89, gnu99, c++11. c++98
if (${c_std} STREQUAL "c99")
set_ifndef(${dest_var_name} "-std=gnu99")
elseif(${c_std} STREQUAL "c89")
set_ifndef(${dest_var_name} "-std=gnu89")
endif()
endmacro()
# coverage options
macro(toolchain_cc_coverage)
# mwdt's coverage mechanism is different with gnu
# at present, zephyr only support gnu coverage
endmacro()
# base options for cpp
macro(toolchain_cc_cpp_base_flags dest_list_name)
endmacro()
# C++ std options
# The "register" keyword was deprecated since C++11, but not for C++98
macro(toolchain_cc_cpp_dialect_std_98_flags dest_list_name)
list(APPEND ${dest_list_name} "-std=c++98")
endmacro()
macro(toolchain_cc_cpp_dialect_std_11_flags dest_list_name)
list(APPEND ${dest_list_name} "-std=c++11")
endmacro()
macro(toolchain_cc_cpp_dialect_std_14_flags dest_list_name)
#no support of C++14
endmacro()
macro(toolchain_cc_cpp_dialect_std_17_flags dest_list_name)
#no support of C++17"
endmacro()
macro(toolchain_cc_cpp_dialect_std_2a_flags dest_list_name)
#no support of C++2a"
endmacro()
# no exceptions for C++
macro(toolchain_cc_cpp_no_exceptions_flag dest_var_name)
set_ifndef(${dest_var_name} "-fno-exceptions")
endmacro()
# no rtti for c++
macro(toolchain_cc_cpp_no_rtti_flag dest_var_name)
set_ifndef(${dest_var_name} "-fno-rtti")
endmacro()
# include only macros defined in a file
macro(toolchain_cc_imacros header_file)
zephyr_compile_options(-imacros${header_file})
endmacro()
# optimizaiton options
macro(toolchain_cc_optimize_for_no_optimizations_flag dest_var_name)
set_ifndef(${dest_var_name} "-O0")
endmacro()
# optimizaiton for debug
macro(toolchain_cc_optimize_for_debug_flag dest_var_name)
set_ifndef(${dest_var_name} "-O0")
endmacro()
macro(toolchain_cc_optimize_for_speed_flag dest_var_name)
set_ifndef(${dest_var_name} "-O2")
endmacro()
macro(toolchain_cc_optimize_for_size_flag dest_var_name)
set_ifndef(${dest_var_name} "-Os")
endmacro()
macro(toolchain_cc_asan)
#no support of -fsanitize=address and -lasan
endmacro()
macro(toolchain_cc_ubsan)
#no support of -fsanitize=undefined"
endmacro()
macro(toolchain_cc_security_canaries)
zephyr_compile_options(-fstack-protector-all)
#no support of -mstack-protector-guard=global"
endmacro()
macro(toolchain_cc_security_fortify)
#no support of _FORTIFY_SOURCE"
endmacro()
# options for warnings
# base options
macro(toolchain_cc_warning_base)
zephyr_compile_options(
-Wformat
-Wformat-security
-Wno-format-zero-length
-Wno-main-return-type
-Wno-unaligned-pointer-conversion
-Wno-incompatible-pointer-types-discards-qualifiers
)
zephyr_cc_option(-Wno-pointer-sign)
# Prohibit void pointer arithmetic. Illegal in C99
zephyr_cc_option(-Wpointer-arith)
endmacro()
# level 1 warning options
macro(toolchain_cc_warning_dw_1)
zephyr_compile_options(
-Wextra
-Wunused
-Wno-unused-parameter
-Wmissing-declarations
-Wmissing-format-attribute
)
zephyr_cc_option(
-Wold-style-definition
-Wmissing-prototypes
-Wmissing-include-dirs
-Wunused-but-set-variable
-Wno-missing-field-initializers
)
endmacro()
# level 2 warning options
macro(toolchain_cc_warning_dw_2)
zephyr_compile_options(
-Waggregate-return
-Wcast-align
-Wdisabled-optimization
-Wnested-externs
-Wshadow
)
zephyr_cc_option(
-Wlogical-op
-Wmissing-field-initializers
)
endmacro()
# level 3 warning options
macro(toolchain_cc_warning_dw_3)
zephyr_compile_options(
-Wbad-function-cast
-Wcast-qual
-Wconversion
-Wpacked
-Wpadded
-Wpointer-arith
-Wredundant-decls
-Wswitch-default
)
zephyr_cc_option(
-Wpacked-bitfield-compat
-Wvla
)
endmacro()
# extended warning options
macro(toolchain_cc_warning_extended)
zephyr_cc_option(
-Wno-sometimes-uninitialized
-Wno-shift-overflow
-Wno-missing-braces
-Wno-self-assign
-Wno-address-of-packed-member
-Wno-unused-function
-Wno-initializer-overrides
-Wno-section
-Wno-unknown-warning-option
-Wno-unused-variable
-Wno-format-invalid-specifier
-Wno-gnu
# comparison of unsigned expression < 0 is always false
-Wno-tautological-compare
)
endmacro()
macro(toolchain_cc_warning_error_implicit_int)
zephyr_cc_option(-Werror=implicit-int)
endmacro()
#
# The following macros leaves it up to the root CMakeLists.txt to choose
# the variables in which to put the requested flags, and whether or not
# to call the macros
#
macro(toolchain_cc_warning_error_misra_sane dest_var_name)
set_ifndef(${dest_var_name} "-Werror=vla")
endmacro()
macro(toolchain_cc_cpp_warning_error_misra_sane dest_var_name)
set_ifndef(${dest_var_name} "-Werror=vla")
endmacro()
# List the warnings that are not supported for C++ compilations
list(APPEND CXX_EXCLUDED_OPTIONS
-Werror=implicit-int
-Wold-style-definition
)

View file

@ -0,0 +1,211 @@
# SPDX-License-Identifier: Apache-2.0
find_program(CMAKE_LINKER ${CROSS_COMPILE}lldac PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
# the prefix to transfer linker options from compiler
set_ifndef(LINKERFLAGPREFIX -Wl,)
# Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen}
# NOTE: ${linker_script_gen} will be produced at build-time; not at configure-time
macro(configure_linker_script linker_script_gen linker_pass_define)
set(extra_dependencies ${ARGN})
# Different generators deal with depfiles differently.
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
# Note that the IMPLICIT_DEPENDS option is currently supported only
# for Makefile generators and will be ignored by other generators.
set(linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT})
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
# Using DEPFILE with other generators than Ninja is an error.
set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${linker_script_gen}.dep)
else()
# TODO: How would the linker script dependencies work for non-linker
# script generators.
message(STATUS "Warning; this generator is not well supported. The
Linker script may not be regenerated when it should.")
set(linker_script_dep "")
endif()
zephyr_get_include_directories_for_lang(C current_includes)
get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME)
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
# the command to generate linker file from template
add_custom_command(
OUTPUT ${linker_script_gen}
DEPENDS
${LINKER_SCRIPT}
${extra_dependencies}
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
${linker_script_dep}
COMMAND ${CMAKE_C_COMPILER}
-x c
${NOSYSDEF_CFLAG}
-Hnocopyr
-MD -MF ${linker_script_gen}.dep -MT ${base_name}/${linker_script_gen}
-D_LINKER
-D_ASMLANGUAGE
${current_includes}
${current_defines}
${linker_pass_define}
${LINKER_SCRIPT}
-P
-o ${linker_script_gen}
VERBATIM
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endmacro()
# Force symbols to be entered in the output file as undefined symbols
function(toolchain_ld_force_undefined_symbols)
foreach(symbol ${ARGN})
zephyr_link_libraries(${LINKERFLAGPREFIX}-u${symbol})
endforeach()
endfunction()
# Link a target to given libraries with toolchain-specific argument order
#
# Usage:
# toolchain_ld_link_elf(
# TARGET_ELF <target_elf>
# OUTPUT_MAP <output_map_file_of_target>
# LIBRARIES_PRE_SCRIPT [libraries_pre_script]
# LINKER_SCRIPT <linker_script>
# LIBRARIES_POST_SCRIPT [libraries_post_script]
# DEPENDENCIES [dependencies]
# )
function(toolchain_ld_link_elf)
cmake_parse_arguments(
TOOLCHAIN_LD_LINK_ELF # prefix of output variables
"" # list of names of the boolean arguments
"TARGET_ELF;OUTPUT_MAP;LINKER_SCRIPT" # list of names of scalar arguments
"LIBRARIES_PRE_SCRIPT;LIBRARIES_POST_SCRIPT;DEPENDENCIES" # list of names of list arguments
${ARGN} # input args to parse
)
target_link_libraries(
${TOOLCHAIN_LD_LINK_ELF_TARGET_ELF}
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_PRE_SCRIPT}
${LINKERFLAGPREFIX}-T${TOOLCHAIN_LD_LINK_ELF_LINKER_SCRIPT}
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_POST_SCRIPT}
${LINKERFLAGPREFIX}--gc-sections
${LINKERFLAGPREFIX}--entry=__start
${LINKERFLAGPREFIX}--Map=${TOOLCHAIN_LD_LINK_ELF_OUTPUT_MAP}
${LINKERFLAGPREFIX}--whole-archive
${ZEPHYR_LIBS_PROPERTY}
${LINKERFLAGPREFIX}--no-whole-archive
kernel
$<TARGET_OBJECTS:${OFFSETS_LIB}>
${LIB_INCLUDE_DIR}
-L${PROJECT_BINARY_DIR}
${TOOLCHAIN_LIBS}
${TOOLCHAIN_LD_LINK_ELF_DEPENDENCIES}
)
endfunction(toolchain_ld_link_elf)
# linker options of temporary linkage for code generation
macro(toolchain_ld_baremetal)
zephyr_ld_options(
-Hlld
-Hnocopyr
-Hnosdata
-Hnocrt
-Xtimer0 # to suppress the warning message
-Hnoxcheck
-Hnocplus
-Hcl
-Hheap=0
-Hnoivt
)
# Funny thing is if this is set to =error, some architectures will
# skip this flag even though the compiler flag check passes
# (e.g. ARC and Xtensa). So warning should be the default for now.
#
# Skip this for native application as Zephyr only provides
# additions to the host toolchain linker script. The relocation
# sections (.rel*) requires us to override those provided
# by host toolchain. As we can't account for all possible
# combination of compiler and linker on all machines used
# for development, it is better to turn this off.
#
# CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections
# without any warnings or errors, which is the default behavior.
# So there is no need to explicitly set a linker flag.
if(CONFIG_LINKER_ORPHAN_SECTION_WARN)
message(WARNING "MWDT toolchain does not support
CONFIG_LINKER_ORPHAN_SECTION_WARN")
elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR)
zephyr_ld_options(
${LINKERFLAGPREFIX}--orphan-handling=error)
endif()
endmacro()
# base linker options
macro(toolchain_ld_base)
if(NOT PROPERTY_LINKER_SCRIPT_DEFINES)
set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__MWDT_LINKER_CMD__)
endif()
# Sort the common symbols and each input section by alignment
# in descending order to minimize padding between these symbols.
zephyr_ld_option_ifdef(
CONFIG_LINKER_SORT_BY_ALIGNMENT
${LINKERFLAGPREFIX}--sort-section=alignment
)
endmacro()
# generate linker script snippts from configure files
macro(toolchain_ld_configure_files)
configure_file(
$ENV{ZEPHYR_BASE}/include/arch/common/app_data_alignment.ld
${PROJECT_BINARY_DIR}/include/generated/app_data_alignment.ld)
configure_file(
$ENV{ZEPHYR_BASE}/include/linker/app_smem.ld
${PROJECT_BINARY_DIR}/include/generated/app_smem.ld)
configure_file(
$ENV{ZEPHYR_BASE}/include/linker/app_smem_aligned.ld
${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld)
configure_file(
$ENV{ZEPHYR_BASE}/include/linker/app_smem_unaligned.ld
${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld)
endmacro()
# link C++ libraries
macro(toolchain_ld_cpp)
zephyr_link_libraries(
-Hcppmw -Hcplus
)
endmacro()
# use linker for relocation
macro(toolchain_ld_relocation)
set(MEM_RELOCATION_LD "${PROJECT_BINARY_DIR}/include/generated/linker_relocate.ld")
set(MEM_RELOCATION_SRAM_DATA_LD
"${PROJECT_BINARY_DIR}/include/generated/linker_sram_data_relocate.ld")
set(MEM_RELOCATION_SRAM_BSS_LD
"${PROJECT_BINARY_DIR}/include/generated/linker_sram_bss_relocate.ld")
set(MEM_RELOCATION_CODE "${PROJECT_BINARY_DIR}/code_relocation.c")
add_custom_command(
OUTPUT ${MEM_RELOCATION_CODE} ${MEM_RELOCATION_LD}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/gen_relocate_app.py
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
-d ${APPLICATION_BINARY_DIR}
-i '$<TARGET_PROPERTY:code_data_relocation_target,COMPILE_DEFINITIONS>'
-o ${MEM_RELOCATION_LD}
-s ${MEM_RELOCATION_SRAM_DATA_LD}
-b ${MEM_RELOCATION_SRAM_BSS_LD}
-c ${MEM_RELOCATION_CODE}
DEPENDS app kernel ${ZEPHYR_LIBS_PROPERTY}
)
add_library(code_relocation_source_lib STATIC ${MEM_RELOCATION_CODE})
target_link_libraries(code_relocation_source_lib zephyr_interface)
endmacro()

View file

@ -0,0 +1,22 @@
# SPDX-License-Identifier: Apache-2.0
set_ifndef(ARCMWDT_TOOLCHAIN_PATH "$ENV{ARCMWDT_TOOLCHAIN_PATH}")
set(ARCMWDT_TOOLCHAIN_PATH ${ARCMWDT_TOOLCHAIN_PATH} CACHE PATH "mwdt tools install directory")
assert(ARCMWDT_TOOLCHAIN_PATH "ARCMWDT_TOOLCHAIN_PATH is not set")
if(NOT EXISTS ${ARCMWDT_TOOLCHAIN_PATH})
message(FATAL_ERROR "Nothing found at ARCMWDT_TOOLCHAIN_PATH: '${ARCMWDT_TOOLCHAIN_PATH}'")
endif()
set(TOOLCHAIN_HOME ${ARCMWDT_TOOLCHAIN_PATH}/MetaWare)
set(COMPILER arcmwdt)
set(LINKER arcmwdt)
set(BINTOOLS arcmwdt)
set(SYSROOT_TARGET arc)
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/arc/bin/)
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")

View file

@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
# This file intentionally left blank.