Skip to content

Commit

Permalink
elfloader, RISC-V: Move the elfloader during boot
Browse files Browse the repository at this point in the history
The SBI implementation usually loads the elfloader where the kernel
would prefer to also be loaded. Allow the elfloader to move itself to a
higher address before loading the kernel and user images.

Signed-off-by: Kent McLeod <[email protected]>
  • Loading branch information
kent-mcleod committed Feb 1, 2022
1 parent 3a3c02f commit 52f3510
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 0 additions & 3 deletions cmake-tool/helpers/application_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 17 additions & 2 deletions elfloader-tool/src/arch-riscv/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,25 @@ _start:
mv s0, a0 /* preserve a0 (hart id) in s0 */
mv s2, a1 /* preserve a1 (dtb) in s2 */

#ifdef CONFIG_IMAGE_BINARY
/* Set a stack so that we can call into C functions */
la sp, (elfloader_stack_alloc + BIT(12))
/*
* 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.
Expand Down

0 comments on commit 52f3510

Please sign in to comment.