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.
This requires ensuring that the stacks are not overwritten during the
merge, and so must be placed before the _archive_cpio section in the
linker script.

Signed-off-by: Kent McLeod <[email protected]>
  • Loading branch information
kent-mcleod committed Feb 4, 2022
1 parent d8a36b3 commit 6bb649a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 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
2 changes: 1 addition & 1 deletion elfloader-tool/src/arch-riscv/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ unsigned long l2pt[PTES_PER_PT] __attribute__((aligned(4096)));
unsigned long l2pt_elf[PTES_PER_PT] __attribute__((aligned(4096)));
#endif

char elfloader_stack_alloc[BIT(CONFIG_KERNEL_STACK_BITS)];
char elfloader_stack_alloc[BIT(CONFIG_KERNEL_STACK_BITS)] __attribute__((section(".data"))) ;

/* first HART will initialise these */
void const *dtb = NULL;
Expand Down
15 changes: 15 additions & 0 deletions elfloader-tool/src/arch-riscv/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ _start:
/* Attach the stack to sp before calling any 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

/* Check if the Heart State Management (HSM) extension exists, so it can be
Expand Down
10 changes: 6 additions & 4 deletions elfloader-tool/src/arch-riscv/linker.lds
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ SECTIONS
/*
* ld crashes when we add this here: *(_driver_list)
*/
. = ALIGN(16);
_archive_start = .;
*(._archive_cpio)
_archive_end = .;
}
. = ALIGN(16);
.data :
Expand All @@ -46,6 +42,12 @@ SECTIONS
*(.data.*)
}
. = ALIGN(16);
._archive_cpio : {
_archive_start = .;
*(._archive_cpio)
_archive_end = .;
}
. = ALIGN(16);
.bss :
{
_bss = .;
Expand Down

0 comments on commit 6bb649a

Please sign in to comment.