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/boot.c b/elfloader-tool/src/arch-riscv/boot.c index 003aab00c..b5fa66639 100644 --- a/elfloader-tool/src/arch-riscv/boot.c +++ b/elfloader-tool/src/arch-riscv/boot.c @@ -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; diff --git a/elfloader-tool/src/arch-riscv/crt0.S b/elfloader-tool/src/arch-riscv/crt0.S index 343e4643f..223fb1a12 100644 --- a/elfloader-tool/src/arch-riscv/crt0.S +++ b/elfloader-tool/src/arch-riscv/crt0.S @@ -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 diff --git a/elfloader-tool/src/arch-riscv/linker.lds b/elfloader-tool/src/arch-riscv/linker.lds index 0c5eeba97..e02758b18 100644 --- a/elfloader-tool/src/arch-riscv/linker.lds +++ b/elfloader-tool/src/arch-riscv/linker.lds @@ -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 : @@ -46,6 +42,12 @@ SECTIONS *(.data.*) } . = ALIGN(16); + ._archive_cpio : { + _archive_start = .; + *(._archive_cpio) + _archive_end = .; + } + . = ALIGN(16); .bss : { _bss = .;