Skip to content

Commit ca0e5df

Browse files
lyakhnashif
authored andcommitted
xtensa: don't build and run the reset handler twice
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]>
1 parent ca94040 commit ca0e5df

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

arch/xtensa/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ config XTENSA_RESET_VECTOR
4848
This is always needed for the simulator. Real boards may already
4949
implement this in boot ROM.
5050

51+
if XTENSA_RESET_VECTOR
52+
config RESET_VECTOR_IN_BOOTLOADER
53+
bool "Link reset vector into bootloader"
54+
default n
55+
help
56+
Reset vector code can be either linked in the bootloader or the
57+
application binary. Select "y" to link it into the bootloader.
58+
endif
59+
5160
config XTENSA_USE_CORE_CRT1
5261
bool "Use crt1.S from core"
5362
default y

arch/xtensa/core/startup/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ if(CONFIG_XTENSA_RESET_VECTOR)
99
-mlongcalls
1010
)
1111

12-
zephyr_library_sources(
12+
zephyr_library_sources_ifndef(CONFIG_RESET_VECTOR_IN_BOOTLOADER
1313
reset-vector.S
14+
)
15+
16+
zephyr_library_sources(
1417
memerror-vector.S
1518
memctl_default.S
1619
)

samples/audio/sof/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CONFIG_SMP=n
33
CONFIG_LOG=y
44
CONFIG_MP_NUM_CPUS=1
55
CONFIG_BUILD_OUTPUT_BIN=n
6+
CONFIG_RESET_VECTOR_IN_BOOTLOADER=y
67

78
# Requires heap_info() be implemented, but no Zephyr wrapper
89
CONFIG_DEBUG_MEMORY_USAGE_SCAN=n

soc/xtensa/intel_adsp/common/bootloader/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ add_executable(bootloader
2626
boot_entry.S
2727
${ARCH_DIR}/${ARCH}/core/startup/memctl_default.S
2828
${ARCH_DIR}/${ARCH}/core/startup/memerror-vector.S
29-
${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S
3029
boot_loader.c
3130
start_address.S
3231
)
3332

33+
target_sources_ifdef(CONFIG_RESET_VECTOR_IN_BOOTLOADER bootloader PRIVATE
34+
${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S
35+
)
36+
3437
add_dependencies(bootloader ${SYSCALL_LIST_H_TARGET})
3538

3639
set(zephyr_sdk $ENV{ZEPHYR_SDK_INSTALL_DIR})
@@ -69,7 +72,9 @@ add_custom_command(TARGET bootloader
6972
)
7073

7174
set_source_files_properties(boot_entry.S PROPERTIES COMPILE_FLAGS -DASSEMBLY)
72-
set_source_files_properties(${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S PROPERTIES COMPILE_FLAGS -DBOOTLOADER)
75+
if(CONFIG_RESET_VECTOR_IN_BOOTLOADER)
76+
set_source_files_properties(${ARCH_DIR}/${ARCH}/core/startup/reset-vector.S PROPERTIES COMPILE_FLAGS -DBOOTLOADER)
77+
endif()
7378

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

soc/xtensa/intel_adsp/common/bootloader/start_address.S

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,16 @@
99
.global _start
1010
.equ _start, SOF_TEXT_BASE
1111

12+
#ifndef CONFIG_RESET_VECTOR_IN_BOOTLOADER
13+
.begin literal_prefix .ResetVector
14+
.section .ResetVector.text, "ax"
15+
16+
.literal_position
17+
18+
.align 4
19+
.global __start
20+
21+
__start:
22+
movi a0, 0
23+
call0 _start /* jump to _start (in crt1-*.S) */
24+
#endif

soc/xtensa/intel_adsp/common/main_entry.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727

2828
_MainEntry:
2929

30+
#ifdef CONFIG_RESET_VECTOR_IN_BOOTLOADER
31+
j _start
32+
#else
3033
j __start
34+
#endif
3135

3236
.size _MainEntry, . - _MainEntry
3337

0 commit comments

Comments
 (0)