Skip to content

Commit

Permalink
xtensa: don't build and run the reset handler twice
Browse files Browse the repository at this point in the history
Currently Zephyr links reset-vector.S twice in xtensa builds:
into the bootloader and the main image. It is run at the end
of the boot loader execution and immediately after that again
in the beginning of the main code. This patch adds a
configuration option to select whether to link the file to the
bootloader or to the application. The default is to the
application, as needed e.g. for QEMU, SOF links it to the
bootloader like in native builds.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh authored and nashif committed Jan 13, 2021
1 parent ca94040 commit ca0e5df
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
9 changes: 9 additions & 0 deletions arch/xtensa/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ config XTENSA_RESET_VECTOR
This is always needed for the simulator. Real boards may already
implement this in boot ROM.

if XTENSA_RESET_VECTOR
config RESET_VECTOR_IN_BOOTLOADER
bool "Link reset vector into bootloader"
default n
help
Reset vector code can be either linked in the bootloader or the
application binary. Select "y" to link it into the bootloader.
endif

config XTENSA_USE_CORE_CRT1
bool "Use crt1.S from core"
default y
Expand Down
5 changes: 4 additions & 1 deletion arch/xtensa/core/startup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ if(CONFIG_XTENSA_RESET_VECTOR)
-mlongcalls
)

zephyr_library_sources(
zephyr_library_sources_ifndef(CONFIG_RESET_VECTOR_IN_BOOTLOADER
reset-vector.S
)

zephyr_library_sources(
memerror-vector.S
memctl_default.S
)
Expand Down
1 change: 1 addition & 0 deletions samples/audio/sof/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CONFIG_SMP=n
CONFIG_LOG=y
CONFIG_MP_NUM_CPUS=1
CONFIG_BUILD_OUTPUT_BIN=n
CONFIG_RESET_VECTOR_IN_BOOTLOADER=y

# Requires heap_info() be implemented, but no Zephyr wrapper
CONFIG_DEBUG_MEMORY_USAGE_SCAN=n
9 changes: 7 additions & 2 deletions soc/xtensa/intel_adsp/common/bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ add_executable(bootloader
boot_entry.S
${ARCH_DIR}/${ARCH}/core/startup/memctl_default.S
${ARCH_DIR}/${ARCH}/core/startup/memerror-vector.S
${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S
boot_loader.c
start_address.S
)

target_sources_ifdef(CONFIG_RESET_VECTOR_IN_BOOTLOADER bootloader PRIVATE
${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S
)

add_dependencies(bootloader ${SYSCALL_LIST_H_TARGET})

set(zephyr_sdk $ENV{ZEPHYR_SDK_INSTALL_DIR})
Expand Down Expand Up @@ -69,7 +72,9 @@ add_custom_command(TARGET bootloader
)

set_source_files_properties(boot_entry.S PROPERTIES COMPILE_FLAGS -DASSEMBLY)
set_source_files_properties(${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S PROPERTIES COMPILE_FLAGS -DBOOTLOADER)
if(CONFIG_RESET_VECTOR_IN_BOOTLOADER)
set_source_files_properties(${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S PROPERTIES COMPILE_FLAGS -DBOOTLOADER)
endif()

target_compile_options(bootloader PUBLIC -fno-inline-functions -mlongcalls -mtext-section-literals -imacros${CMAKE_BINARY_DIR}/zephyr/include/generated/autoconf.h)

Expand Down
13 changes: 13 additions & 0 deletions soc/xtensa/intel_adsp/common/bootloader/start_address.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@
.global _start
.equ _start, SOF_TEXT_BASE

#ifndef CONFIG_RESET_VECTOR_IN_BOOTLOADER
.begin literal_prefix .ResetVector
.section .ResetVector.text, "ax"

.literal_position

.align 4
.global __start

__start:
movi a0, 0
call0 _start /* jump to _start (in crt1-*.S) */
#endif
4 changes: 4 additions & 0 deletions soc/xtensa/intel_adsp/common/main_entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

_MainEntry:

#ifdef CONFIG_RESET_VECTOR_IN_BOOTLOADER
j _start
#else
j __start
#endif

.size _MainEntry, . - _MainEntry

Expand Down

0 comments on commit ca0e5df

Please sign in to comment.