From 58056959d015d8499051d1494d4c13532172de25 Mon Sep 17 00:00:00 2001 From: Viktor Sannum Date: Mon, 28 Jun 2021 18:03:05 +0200 Subject: [PATCH 1/4] elfloader: fixup load from stack on aarch64 It seems that the 'ldp x0, x1, [sp, #-16]!' syntax used to load the registers stored to the stack before calling the fixup_image_base function does not in fact load the registers as expected (at least on my Raspberry Pi 3B). This causes the dtb address supplied by the bootloader to be lost when elfloader loads the dtb image which is an issue if a dtb is not built into the kernel binary image. In the example usage from arm (https://developer.arm.com/documentation/ 102374/0101/Loads-and-stores---load-pair-and-store-pair) the 'ldp x0, x1, [sp], #16' is used for poping the stack. This also seems to also work as expected on my Raspberry Pi 3B resulting in the dtb address to be loaded as expected in sys_boot.c. Signed-off-by: Viktor Sannum --- elfloader-tool/src/arch-arm/64/crt0.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elfloader-tool/src/arch-arm/64/crt0.S b/elfloader-tool/src/arch-arm/64/crt0.S index acd4de92..7d1249be 100644 --- a/elfloader-tool/src/arch-arm/64/crt0.S +++ b/elfloader-tool/src/arch-arm/64/crt0.S @@ -29,7 +29,7 @@ BEGIN_FUNC(_start) bl fixup_image_base mov x2, x0 /* restore original arguments for next step */ - ldp x0, x1, [sp, #-16]! + ldp x0, x1, [sp], #16 /* fixup_image_base returns 1 if no need to move */ cmp x2, #1 beq 1f From b9a96e9d33509afe596fee8ffd46c33874e648c9 Mon Sep 17 00:00:00 2001 From: Viktor Sannum Date: Mon, 28 Jun 2021 18:14:23 +0200 Subject: [PATCH 2/4] elfloader: check for dtb on arm binary images For arm builds, check if the bootloader has passed the dtb image address also for binary image builds, similarly to uimages. The Raspberry Pi bootloader for example, is able to both load binary images directly and passes the dtb address to the loaded image as expected. Signed-off-by: Viktor Sannum --- elfloader-tool/src/arch-arm/sys_boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elfloader-tool/src/arch-arm/sys_boot.c b/elfloader-tool/src/arch-arm/sys_boot.c index 487c744a..aac9510b 100644 --- a/elfloader-tool/src/arch-arm/sys_boot.c +++ b/elfloader-tool/src/arch-arm/sys_boot.c @@ -112,7 +112,7 @@ void main(UNUSED void *arg) print_cpuid(); printf(" paddr=[%p..%p]\n", _text, _end - 1); -#if defined(CONFIG_IMAGE_UIMAGE) +#if defined(CONFIG_IMAGE_UIMAGE) || defined(CONFIG_IMAGE_BINARY) /* U-Boot passes a DTB. Ancient bootloaders may pass atags. When booting via * bootelf argc is NULL. From 75e5c700eaf8b6a3dae370dcdcd69edb765b6388 Mon Sep 17 00:00:00 2001 From: Viktor Sannum Date: Mon, 28 Jun 2021 18:20:26 +0200 Subject: [PATCH 3/4] elfloader: print bootloader_dtb instead of dtb Minor fixup, the dtb variable is always 0 when printed in sys_boot.c as it refers to the the address the dtb is loaded to after load_images has finished loading it from either the bootloader_dtb or cpio archive. Print bootloader_dtb instead, since it contains the address to a valid dtb given by the bootloader or efi. Signed-off-by: Viktor Sannum --- elfloader-tool/src/arch-arm/sys_boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elfloader-tool/src/arch-arm/sys_boot.c b/elfloader-tool/src/arch-arm/sys_boot.c index aac9510b..e02758fd 100644 --- a/elfloader-tool/src/arch-arm/sys_boot.c +++ b/elfloader-tool/src/arch-arm/sys_boot.c @@ -133,7 +133,7 @@ void main(UNUSED void *arg) #endif if (bootloader_dtb) { - printf(" dtb=%p\n", dtb); + printf(" dtb=%p\n", bootloader_dtb); } else { printf("No DTB passed in from boot loader.\n"); } From cdaefa89c7450edde0cb353382f42a98b74f81de Mon Sep 17 00:00:00 2001 From: Viktor Sannum Date: Mon, 28 Jun 2021 18:27:28 +0200 Subject: [PATCH 4/4] cmake-tool: move rpi3 to binary_list The Raspberry Pi3 has its own definition for configuring the setting for binary images builds for aarch64 only, meaning it cannot be part of the more generic binary_list definition. The 32-bit aarch32 rpi3 builds can also boot from a binary image so there is no actual need for this sepcial handling. Remove it and move the bcm2837/rpi3 match to the binary_list definition instead. Signed-off-by: Viktor Sannum --- cmake-tool/helpers/application_settings.cmake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmake-tool/helpers/application_settings.cmake b/cmake-tool/helpers/application_settings.cmake index 6205c40b..4b808817 100644 --- a/cmake-tool/helpers/application_settings.cmake +++ b/cmake-tool/helpers/application_settings.cmake @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.8.2) include_guard(GLOBAL) function(ApplyData61ElfLoaderSettings kernel_platform kernel_sel4_arch) - set(binary_list "tx1;hikey;odroidc2;imx8mq-evk;zynqmp;imx8mm-evk;hifive") + set(binary_list "tx1;hikey;odroidc2;imx8mq-evk;zynqmp;imx8mm-evk;hifive;bcm2837") set(efi_list "tk1;rockpro64") set(uimage_list "tx2;am335x") if( @@ -19,9 +19,6 @@ function(ApplyData61ElfLoaderSettings kernel_platform kernel_sel4_arch) set(ElfloaderImage "efi" CACHE STRING "" FORCE) elseif(${kernel_platform} IN_LIST uimage_list) set(ElfloaderImage "uimage" CACHE STRING "" FORCE) - #rpi3 - elseif(${kernel_platform} STREQUAL "bcm2837" AND ${kernel_sel4_arch} STREQUAL "aarch64") - set(ElfloaderImage "binary" CACHE STRING "" FORCE) #rpi4 elseif(${kernel_platform} STREQUAL "bcm2711" AND ${kernel_sel4_arch} STREQUAL "aarch64") set(ElfloaderImage "efi" CACHE STRING "" FORCE)