From ca0e5df219a1309d74c801be2b64e28eba2d0c29 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Wed, 6 Jan 2021 12:55:12 +0100 Subject: [PATCH] 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 --- arch/xtensa/Kconfig | 9 +++++++++ arch/xtensa/core/startup/CMakeLists.txt | 5 ++++- samples/audio/sof/prj.conf | 1 + .../intel_adsp/common/bootloader/CMakeLists.txt | 9 +++++++-- .../intel_adsp/common/bootloader/start_address.S | 13 +++++++++++++ soc/xtensa/intel_adsp/common/main_entry.S | 4 ++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index ba1678dd5a6..436ecf5c285 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -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 diff --git a/arch/xtensa/core/startup/CMakeLists.txt b/arch/xtensa/core/startup/CMakeLists.txt index 1c21781ca72..29859e755ac 100644 --- a/arch/xtensa/core/startup/CMakeLists.txt +++ b/arch/xtensa/core/startup/CMakeLists.txt @@ -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 ) diff --git a/samples/audio/sof/prj.conf b/samples/audio/sof/prj.conf index 2be9a027b56..41bfe78400a 100644 --- a/samples/audio/sof/prj.conf +++ b/samples/audio/sof/prj.conf @@ -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 diff --git a/soc/xtensa/intel_adsp/common/bootloader/CMakeLists.txt b/soc/xtensa/intel_adsp/common/bootloader/CMakeLists.txt index 50e939f120d..81f96729a74 100644 --- a/soc/xtensa/intel_adsp/common/bootloader/CMakeLists.txt +++ b/soc/xtensa/intel_adsp/common/bootloader/CMakeLists.txt @@ -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}) @@ -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) diff --git a/soc/xtensa/intel_adsp/common/bootloader/start_address.S b/soc/xtensa/intel_adsp/common/bootloader/start_address.S index fa33ba48641..fae7e3a85a8 100644 --- a/soc/xtensa/intel_adsp/common/bootloader/start_address.S +++ b/soc/xtensa/intel_adsp/common/bootloader/start_address.S @@ -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 diff --git a/soc/xtensa/intel_adsp/common/main_entry.S b/soc/xtensa/intel_adsp/common/main_entry.S index efcebf91ac2..10614aa0b07 100644 --- a/soc/xtensa/intel_adsp/common/main_entry.S +++ b/soc/xtensa/intel_adsp/common/main_entry.S @@ -27,7 +27,11 @@ _MainEntry: +#ifdef CONFIG_RESET_VECTOR_IN_BOOTLOADER + j _start +#else j __start +#endif .size _MainEntry, . - _MainEntry