Browse Source

iar: toolchain: Implement IAR static init routine

This will implement a way of doing static initialization
the "IAR" way. This is done by calling __iar_data_init3
which handles all static initialization that is mentioned
in the linker file "initialize by copy".

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
pull/89566/head
Robin Kastberg 5 months ago committed by Benjamin Cabé
parent
commit
5a92e46c92
  1. 23
      cmake/linker/iar/config_file_script.cmake
  2. 3
      cmake/linker/iar/linker_flags.cmake
  3. 6
      cmake/linker/iar/target.cmake
  4. 25
      cmake/toolchain/iar/Kconfig
  5. 2
      scripts/ci/check_compliance.py

23
cmake/linker/iar/config_file_script.cmake

@ -333,7 +333,7 @@ function(group_to_string)
endif() endif()
set(${STRING_STRING} "${${STRING_STRING}}\"${name}\": place in ${ILINK_CURRENT_NAME} { block ${name_clean} };\n") set(${STRING_STRING} "${${STRING_STRING}}\"${name}\": place in ${ILINK_CURRENT_NAME} { block ${name_clean} };\n")
if(DEFINED vma AND DEFINED lma AND NOT ${noinit}) if(CONFIG_IAR_ZEPHYR_INIT AND DEFINED vma AND DEFINED lma AND NOT ${noinit})
set(${STRING_STRING} "${${STRING_STRING}}\"${name}_init\": place in ${lma} { block ${name_clean}_init };\n") set(${STRING_STRING} "${${STRING_STRING}}\"${name}_init\": place in ${lma} { block ${name_clean}_init };\n")
endif() endif()
@ -792,6 +792,22 @@ function(section_to_string)
list(JOIN current_sections ", " SELECTORS) list(JOIN current_sections ", " SELECTORS)
set(TEMP "${TEMP}\ndo not initialize {\n${SELECTORS}\n};") set(TEMP "${TEMP}\ndo not initialize {\n${SELECTORS}\n};")
else() else()
if(DEFINED current_sections)
if(CONFIG_IAR_DATA_INIT)
set(TEMP "${TEMP}\ninitialize by copy\n")
set(TEMP "${TEMP}{\n")
foreach(section ${current_sections})
set(TEMP "${TEMP} ${section},\n")
endforeach()
set(TEMP "${TEMP}};")
set(TEMP "${TEMP}\n\"${name}_init\": place in ${group_parent_lma} {\n")
foreach(section ${current_sections})
set(TEMP "${TEMP} ${section}_init,\n")
endforeach()
set(TEMP "${TEMP}};")
elseif(CONFIG_IAR_ZEPHYR_INIT)
# Generate the _init block and the initialize manually statement. # Generate the _init block and the initialize manually statement.
# Note that we need to have the X_init block defined even if we have # Note that we need to have the X_init block defined even if we have
# no sections, since there will come a "place in XXX" statement later. # no sections, since there will come a "place in XXX" statement later.
@ -809,7 +825,6 @@ function(section_to_string)
list(APPEND to_be_kept "block ${name_clean}_init") list(APPEND to_be_kept "block ${name_clean}_init")
endif() endif()
set(TEMP "${TEMP}\n${INIT_TEMP}\n") set(TEMP "${TEMP}\n${INIT_TEMP}\n")
if(DEFINED current_sections)
set(TEMP "${TEMP}\ninitialize manually with copy friendly\n") set(TEMP "${TEMP}\ninitialize manually with copy friendly\n")
set(TEMP "${TEMP}{\n") set(TEMP "${TEMP}{\n")
foreach(section ${current_sections}) foreach(section ${current_sections})
@ -819,6 +834,10 @@ function(section_to_string)
set(current_sections) set(current_sections)
endif() endif()
endif() endif()
set(current_sections)
endif()
endif() endif()
# Finally, add the keeps. # Finally, add the keeps.

3
cmake/linker/iar/linker_flags.cmake

@ -6,6 +6,9 @@
string(APPEND CMAKE_C_LINK_FLAGS --no-wrap-diagnostics) string(APPEND CMAKE_C_LINK_FLAGS --no-wrap-diagnostics)
if(CONFIG_IAR_DATA_INIT)
string(APPEND CMAKE_C_LINK_FLAGS " --redirect z_data_copy=__iar_data_init3")
endif()
foreach(lang C CXX ASM) foreach(lang C CXX ASM)
set(commands "--log modules,libraries,initialization,redirects,sections") set(commands "--log modules,libraries,initialization,redirects,sections")
set(CMAKE_${lang}_LINK_EXECUTABLE set(CMAKE_${lang}_LINK_EXECUTABLE

6
cmake/linker/iar/target.cmake

@ -10,6 +10,10 @@ find_program(CMAKE_LINKER
NO_DEFAULT_PATH NO_DEFAULT_PATH
) )
if(CONFIG_IAR_DATA_INIT)
zephyr_linker_section(NAME .iar.init_table KVMA RAM_REGION GROUP RODATA_REGION)
endif()
add_custom_target(${IAR_LINKER}) add_custom_target(${IAR_LINKER})
set(ILINK_THUMB_CALLS_WARNING_SUPPRESSED) set(ILINK_THUMB_CALLS_WARNING_SUPPRESSED)
set(IAR_LIB_USED) set(IAR_LIB_USED)
@ -61,6 +65,8 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
${STEERING_FILE_ARG} ${STEERING_FILE_ARG}
-DCONFIG_LINKER_LAST_SECTION_ID=${CONFIG_LINKER_LAST_SECTION_ID} -DCONFIG_LINKER_LAST_SECTION_ID=${CONFIG_LINKER_LAST_SECTION_ID}
-DCONFIG_LINKER_LAST_SECTION_ID_PATTERN=${CONFIG_LINKER_LAST_SECTION_ID_PATTERN} -DCONFIG_LINKER_LAST_SECTION_ID_PATTERN=${CONFIG_LINKER_LAST_SECTION_ID_PATTERN}
-DCONFIG_IAR_DATA_INIT=${CONFIG_IAR_DATA_INIT}
-DCONFIG_IAR_ZEPHYR_INIT=${CONFIG_IAR_ZEPHYR_INIT}
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen} -DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen}
${IAR_LIB_USED} ${IAR_LIB_USED}
-P ${ZEPHYR_BASE}/cmake/linker/iar/config_file_script.cmake -P ${ZEPHYR_BASE}/cmake/linker/iar/config_file_script.cmake

25
cmake/toolchain/iar/Kconfig

@ -9,7 +9,30 @@ choice LINKER_SCRIPT
default CMAKE_LINKER_GENERATOR default CMAKE_LINKER_GENERATOR
endchoice endchoice
menu "IAR library options" menu "IAR options"
choice IAR_INIT
bool "Static initialization method"
depends on XIP
default IAR_ZEPHYR_INIT
config IAR_DATA_INIT
bool "IAR"
select SKIP_BSS_CLEAR # IAR handles zeroing.
help
IAR handles initialization of static variables.
Instead of `z_prep_c` calling Zephyrs `z_data_copy`
we call IARs own proprietary initialization method
which can save time and space.
config IAR_ZEPHYR_INIT
bool "Zephyr"
help
Zephyr handles initialization of static variables.
This is the regular `z_data_copy`.
endchoice
config IAR_SEMIHOSTING config IAR_SEMIHOSTING
bool "Use the IAR semihosting implementation." bool "Use the IAR semihosting implementation."

2
scripts/ci/check_compliance.py

@ -1071,8 +1071,10 @@ flagged.
"HEAP_MEM_POOL_ADD_SIZE_", # Used as an option matching prefix "HEAP_MEM_POOL_ADD_SIZE_", # Used as an option matching prefix
"HUGETLBFS", # Linux, in boards/xtensa/intel_adsp_cavs25/doc "HUGETLBFS", # Linux, in boards/xtensa/intel_adsp_cavs25/doc
"IAR_BUFFERED_WRITE", "IAR_BUFFERED_WRITE",
"IAR_DATA_INIT",
"IAR_LIBCPP", "IAR_LIBCPP",
"IAR_SEMIHOSTING", "IAR_SEMIHOSTING",
"IAR_ZEPHYR_INIT",
"IPC_SERVICE_ICMSG_BOND_NOTIFY_REPEAT_TO_MS", # Used in ICMsg tests for intercompatibility "IPC_SERVICE_ICMSG_BOND_NOTIFY_REPEAT_TO_MS", # Used in ICMsg tests for intercompatibility
# with older versions of the ICMsg. # with older versions of the ICMsg.
"LIBGCC_RTLIB", "LIBGCC_RTLIB",

Loading…
Cancel
Save