diff --git a/cmake-tool/helpers/application_settings.cmake b/cmake-tool/helpers/application_settings.cmake index eaac50ccc..4706537d4 100644 --- a/cmake-tool/helpers/application_settings.cmake +++ b/cmake-tool/helpers/application_settings.cmake @@ -49,9 +49,6 @@ function(ApplyData61ElfLoaderSettings kernel_platform kernel_sel4_arch) if(KernelPlatformZynqmp AND KernelSel4ArchAarch32) set(IMAGE_START_ADDR 0x8000000 CACHE INTERNAL "" FORCE) endif() - if(KernelPlatformSpike AND KernelSel4ArchRiscV32) - set(IMAGE_START_ADDR 0x80400000 CACHE INTERNAL "" FORCE) - endif() endfunction() function(ApplyCommonSimulationSettings kernel_sel4_arch) diff --git a/elfloader-tool/src/arch-riscv/crt0.S b/elfloader-tool/src/arch-riscv/crt0.S index 6a9633b13..98ed60bbe 100644 --- a/elfloader-tool/src/arch-riscv/crt0.S +++ b/elfloader-tool/src/arch-riscv/crt0.S @@ -58,10 +58,23 @@ _start: /* Attach the stack to sp before calling any C functions */ la sp, (elfloader_stack_alloc + BIT(12)) -#ifdef CONFIG_IMAGE_BINARY + /* + * Binary images may not be loaded in the correct location. + * Try and move ourselves so we're in the right place. + */ + jal fixup_image_base + /* fixup_image_base returns 0 if no need to move */ + beqz a0, 1f + + /* otherwise, restore args and jump to the start of the new elfloader */ + mv a2, a0 + mv a0, s0 + mv a1, s2 + jr a2 + /* Clear the BSS before we get to do anything more specific */ +1: jal clear_bss -#endif /* Check if the Heart State Management (HSM) extension exists, so it can be * used to switch harts if we are not running on hart CONFIG_FIRST_HART_ID.