Pull request efi-2025-04-rc1

Documentation:
 
 * Correct the defconfig name in the coolpi documentation
 
 UEFI:
 
 * Carve out the biggest part of the RISC-V and ARM linker scripts for EFI
   binary into a common include.
 * Correct the values of SizeOfCode and SizeOfInitializedData in generated
   EFI binaries for RISC-V and ARM.
 * Avoid gaps between sections in EFI binaries causing a failure in secure
   boot.
 * Makefile: let clean remove capsule_in.capsule*.efi-capsule
 * Refactor some of the code used for launching EFI binaries.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEK7wKXt3/btL6/yA+hO4vgnE3U0sFAmeLyu8ACgkQhO4vgnE3
 U0tLDA//TSLPk2ovu8bibonuptFZs/fB8/X7ZyIy154L65cNpyk69ZiR+1R77FRG
 9C8YhiF+XSABgckpGHTVqH8vPHZLRKawKgVhSi8CU31OrT9ahjfcDujvGuO8ZlsD
 LxrVL2T55711buRDX1kw6VzEqtSGvQxI2IDoNnkeoiBZ29D8lptHvmvzD3G8CCPC
 Z75Xxd4ly8euT3jDNznp10IoAu5eEp+rcmEEFC7UYJnDpFencuSWZjYcv3N1nKD6
 nTVQPqkWvx6jOA/tcNgK3ERrSD2Zhmc1TZrvfDxg/ecynho9DZrMyq/MINpHo4Fk
 OcDMZXG9C820qSYTkVdmaMnxklH4Sr+D6jyZDl523+GqCLiDD/lUOGt3qRAxhfwB
 j6IdFynB3djE2Mlu0ep9MQ556gvqJPUaXeR/K8dQ/rOXmNpwOMmerqy0eqK1mrxO
 IKXuyBVZWlRyMonnxQmDQAL4wXqlzhmSXevipaOupahHB0hSZKFT6z9mo6zKG7UH
 g2fDMGMpOZfvfmxV4EoD59mDHJESSY5Aorm/vfpLqYJsDsPfu3v9+tHKOEfm5rOS
 b0ykBQjhfVwda7JNpbwW+w1xVEpBEuWT41HbI6lijeGeFocJ8T6m7/eHlEYUvtmv
 1rQ2DhVwvoVha0YW8rNa+stLqpWjjiqLI5DaUhsexoaGmReaZ3o=
 =7RxC
 -----END PGP SIGNATURE-----

Merge tag 'efi-2025-04-rc1' of https://source.denx.de/u-boot/custodians/u-boot-efi

Pull request efi-2025-04-rc1

Documentation:

* Correct the defconfig name in the coolpi documentation

UEFI:

* Carve out the biggest part of the RISC-V and ARM linker scripts for EFI
  binary into a common include.
* Correct the values of SizeOfCode and SizeOfInitializedData in generated
  EFI binaries for RISC-V and ARM.
* Avoid gaps between sections in EFI binaries causing a failure in secure
  boot.
* Makefile: let clean remove capsule_in.capsule*.efi-capsule
* Refactor some of the code used for launching EFI binaries.
This commit is contained in:
Tom Rini 2025-01-18 10:46:23 -06:00
commit a1e7dd7e14
12 changed files with 150 additions and 313 deletions

View file

@ -2230,7 +2230,7 @@ CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h include/bmp_logo_data.h \
itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
Test* capsule.*.efi-capsule capsule*.map
Test* capsule*.*.efi-capsule capsule*.map
# Directories & files removed with 'make mrproper'
MRPROPER_DIRS += include/config include/generated spl tpl vpl \

View file

@ -41,7 +41,7 @@ optional_header:
.byte 0x02 /* MajorLinkerVersion */
.byte 0x14 /* MinorLinkerVersion */
.long _etext - _start /* SizeOfCode */
.long 0 /* SizeOfInitializedData */
.long _data_size /* SizeOfInitializedData */
.long 0 /* SizeOfUninitializedData */
.long _start - ImageBase /* AddressOfEntryPoint */
.long _start - ImageBase /* BaseOfCode */

View file

@ -38,16 +38,16 @@ optional_header:
.short IMAGE_NT_OPTIONAL_HDR32_MAGIC /* PE32 format */
.byte 0x02 /* MajorLinkerVersion */
.byte 0x14 /* MinorLinkerVersion */
.long _edata - _start /* SizeOfCode */
.long 0 /* SizeOfInitializedData */
.long _etext - _start /* SizeOfCode */
.long _data_size /* SizeOfInitializedData */
.long 0 /* SizeOfUninitializedData */
.long _start - image_base /* AddressOfEntryPoint */
.long _start - image_base /* BaseOfCode */
.long 0 /* BaseOfData */
extra_header_fields:
.long 0 /* image_base */
.long 0x200 /* SectionAlignment */
.long 0 /* ImageBase */
.long 0x1000 /* SectionAlignment */
.long 0x200 /* FileAlignment */
.short 0 /* MajorOperatingSystemVersion */
.short 0 /* MinorOperatingSystemVersion */
@ -84,6 +84,7 @@ extra_header_fields:
.quad 0 /* CertificationTable */
.quad 0 /* BaseRelocationTable */
/* Section table */
section_table:
/*
@ -111,9 +112,9 @@ section_table:
.byte 0
.byte 0
.byte 0 /* end of 0 padding of section name */
.long _text_size /* VirtualSize */
.long _etext - _start /* VirtualSize */
.long _start - image_base /* VirtualAddress */
.long _text_size /* SizeOfRawData */
.long _etext - _start /* SizeOfRawData */
.long _start - image_base /* PointerToRawData */
.long 0 /* PointerToRelocations */
.long 0 /* PointerToLineNumbers */

View file

@ -8,70 +8,4 @@
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
PHDRS
{
data PT_LOAD FLAGS(3); /* SHF_WRITE | SHF_ALLOC */
}
ENTRY(_start)
SECTIONS
{
.text 0x0 : {
_text = .;
*(.text.head)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
. = ALIGN(16);
*(.dynamic);
. = ALIGN(512);
}
.rela.dyn : { *(.rela.dyn) }
.rela.plt : { *(.rela.plt) }
.rela.got : { *(.rela.got) }
.rela.data : { *(.rela.data) *(.rela.data*) }
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.data : {
_data = .;
*(.sdata)
*(.data)
*(.data1)
*(.data.*)
*(.got.plt)
*(.got)
/*
* The EFI loader doesn't seem to like a .bss section, so we
* stick it all into .data:
*/
. = ALIGN(16);
_bss = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(512);
_bss_end = .;
_edata = .;
} :data
_data_size = _edata - _data;
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
.note.gnu.build-id : { *(.note.gnu.build-id) }
/DISCARD/ : {
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 : { *(.comment) }
}
INCLUDE lib/efi_loader/elf_efi.ldsi

View file

@ -8,73 +8,4 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
PHDRS
{
data PT_LOAD FLAGS(3); /* PF_W | PF_X */
}
ENTRY(_start)
SECTIONS
{
.text 0x0 : {
_text = .;
*(.text.head)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
. = ALIGN(16);
*(.dynamic);
. = ALIGN(512);
}
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.data : {
_data = .;
*(.sdata)
*(.data)
*(.data1)
*(.data.*)
*(.got.plt)
*(.got)
/*
* The EFI loader doesn't seem to like a .bss section, so we
* stick it all into .data:
*/
. = ALIGN(16);
_bss = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(512);
_bss_end = .;
_edata = .;
} :data
_data_size = . - _data;
/DISCARD/ : {
/*
* We don't support relocations. These would have to be
* translated from ELF to PE format and added to the .reloc
* section.
*/
*(.rel.dyn)
*(.rel.plt)
*(.rel.got)
*(.rel.data)
*(.rel.data*)
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
*(.dynsym)
*(.dynstr)
*(.note.gnu.build-id)
*(.comment)
}
}
INCLUDE lib/efi_loader/elf_efi.ldsi

View file

@ -63,8 +63,8 @@ optional_header:
.short PE_MAGIC /* PE32(+) format */
.byte 0x02 /* MajorLinkerVersion */
.byte 0x14 /* MinorLinkerVersion */
.long _edata - _start /* SizeOfCode */
.long 0 /* SizeOfInitializedData */
.long _etext - _start /* SizeOfCode */
.long _data_size /* SizeOfInitializedData */
.long 0 /* SizeOfUninitializedData */
.long _start - ImageBase /* AddressOfEntryPoint */
.long _start - ImageBase /* BaseOfCode */

View file

@ -8,70 +8,4 @@
OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv", "elf32-littleriscv")
OUTPUT_ARCH(riscv)
PHDRS
{
data PT_LOAD FLAGS(3); /* SHF_WRITE | SHF_ALLOC */
}
ENTRY(_start)
SECTIONS
{
.text 0x0 : {
_text = .;
*(.text.head)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
. = ALIGN(16);
*(.dynamic);
. = ALIGN(512);
}
.rela.dyn : { *(.rela.dyn) }
.rela.plt : { *(.rela.plt) }
.rela.got : { *(.rela.got) }
.rela.data : { *(.rela.data) *(.rela.data*) }
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.data : {
_data = .;
*(.sdata)
*(.data)
*(.data1)
*(.data.*)
*(.got.plt)
*(.got)
/*
* The EFI loader doesn't seem to like a .bss section, so we
* stick it all into .data:
*/
. = ALIGN(16);
_bss = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(512);
_bss_end = .;
_edata = .;
} :data
_data_size = _edata - _data;
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
.note.gnu.build-id : { *(.note.gnu.build-id) }
/DISCARD/ : {
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 : { *(.comment) }
}
INCLUDE lib/efi_loader/elf_efi.ldsi

View file

@ -8,70 +8,4 @@
OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv")
OUTPUT_ARCH(riscv)
PHDRS
{
data PT_LOAD FLAGS(3); /* SHF_WRITE | SHF_ALLOC */
}
ENTRY(_start)
SECTIONS
{
.text 0x0 : {
_text = .;
*(.text.head)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
. = ALIGN(16);
*(.dynamic);
. = ALIGN(512);
}
.rela.dyn : { *(.rela.dyn) }
.rela.plt : { *(.rela.plt) }
.rela.got : { *(.rela.got) }
.rela.data : { *(.rela.data) *(.rela.data*) }
_etext = .;
_text_size = . - _text;
. = ALIGN(4096);
.data : {
_data = .;
*(.sdata)
*(.data)
*(.data1)
*(.data.*)
*(.got.plt)
*(.got)
/*
* The EFI loader doesn't seem to like a .bss section, so we
* stick it all into .data:
*/
. = ALIGN(16);
_bss = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(512);
_bss_end = .;
_edata = .;
} :data
_data_size = _edata - _data;
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
.note.gnu.build-id : { *(.note.gnu.build-id) }
/DISCARD/ : {
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 : { *(.comment) }
}
INCLUDE lib/efi_loader/elf_efi.ldsi

View file

@ -28,7 +28,7 @@ Get the TF-A and DDR init (TPL) binaries
cd u-boot
export ROCKCHIP_TPL=../rkbin/bin/rk35/rk3588_ddr_lp4_2112MHz_lp5_2400MHz_v1.17.bin
export BL31=../rkbin/bin/rk35/rk3588_bl31_v1.46.elf
make coolpi-genbook-cm5-rk3588_defconfig
make coolpi-cm5-genbook-rk3588_defconfig
make CROSS_COMPILE=aarch64-linux-gnu-
This will build ``u-boot-rockchip.bin`` for eMMC and ``u-boot-rockchip-spi.bin`` for SPI Nor.

View file

@ -44,12 +44,64 @@ void efi_clear_bootdev(void)
image_size = 0;
}
/**
* calculate_paths() - Calculate the device and image patch from strings
*
* @dev: device, e.g. "MMC"
* @devnr: number of the device, e.g. "1:2"
* @path: path to file loaded
* @device_pathp: returns EFI device path
* @image_pathp: returns EFI image path
* Return: EFI_SUCCESS on success, else error code
*/
static efi_status_t calculate_paths(const char *dev, const char *devnr,
const char *path,
struct efi_device_path **device_pathp,
struct efi_device_path **image_pathp)
{
struct efi_device_path *image, *device;
efi_status_t ret;
#if IS_ENABLED(CONFIG_NETDEVICES)
if (!strcmp(dev, "Net") || !strcmp(dev, "Http")) {
ret = efi_net_set_dp(dev, devnr);
if (ret != EFI_SUCCESS)
return ret;
}
#endif
ret = efi_dp_from_name(dev, devnr, path, &device, &image);
if (ret != EFI_SUCCESS)
return ret;
*device_pathp = device;
if (image) {
/* FIXME: image should not contain device */
struct efi_device_path *image_tmp = image;
efi_dp_split_file_path(image, &device, &image);
efi_free_pool(image_tmp);
}
*image_pathp = image;
log_debug("- boot device %pD\n", device);
if (image)
log_debug("- image %pD\n", image);
return EFI_SUCCESS;
}
/**
* efi_set_bootdev() - set boot device
*
* This function is called when a file is loaded, e.g. via the 'load' command.
* We use the path to this file to inform the UEFI binary about the boot device.
*
* For a valid image, it sets:
* - image_addr to the provided buffer
* - image_size to the provided buffer_size
* - bootefi_device_path to the EFI device-path
* - bootefi_image_path to the EFI image-path
*
* @dev: device, e.g. "MMC"
* @devnr: number of the device, e.g. "1:2"
* @path: path to file loaded
@ -59,7 +111,6 @@ void efi_clear_bootdev(void)
void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
void *buffer, size_t buffer_size)
{
struct efi_device_path *device, *image;
efi_status_t ret;
log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev,
@ -93,34 +144,12 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
image_addr = buffer;
image_size = buffer_size;
#if IS_ENABLED(CONFIG_NETDEVICES)
if (!strcmp(dev, "Net") || !strcmp(dev, "Http")) {
ret = efi_net_set_dp(dev, devnr);
if (ret != EFI_SUCCESS)
goto error;
ret = calculate_paths(dev, devnr, path, &bootefi_device_path,
&bootefi_image_path);
if (ret) {
log_debug("- efi_dp_from_name() failed, err=%lx\n", ret);
efi_clear_bootdev();
}
#endif
ret = efi_dp_from_name(dev, devnr, path, &device, &image);
if (ret != EFI_SUCCESS)
goto error;
bootefi_device_path = device;
if (image) {
/* FIXME: image should not contain device */
struct efi_device_path *image_tmp = image;
efi_dp_split_file_path(image, &device, &image);
efi_free_pool(image_tmp);
}
bootefi_image_path = image;
log_debug("- boot device %pD\n", device);
if (image)
log_debug("- image %pD\n", image);
return;
error:
log_debug("- efi_dp_from_name() failed, err=%lx\n", ret);
efi_clear_bootdev();
}
/**
@ -130,7 +159,7 @@ error:
* @source_size: size of the UEFI image
* Return: status code
*/
efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
{
efi_handle_t mem_handle = NULL, handle;
struct efi_device_path *file_path = NULL;

View file

@ -0,0 +1,74 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* U-Boot EFI linker script include
*
* Modified from elf_aarch64_efi.lds in gnu-efi
*/
PHDRS
{
data PT_LOAD FLAGS(3); /* SHF_WRITE | SHF_ALLOC */
}
ENTRY(_start)
SECTIONS
{
.text 0x0 : {
_text = .;
*(.text.head)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.srodata)
*(.rodata*)
. = ALIGN(16);
*(.dynamic);
. = ALIGN(512);
}
.rela.dyn : { *(.rela.dyn) }
.rela.plt : { *(.rela.plt) }
.rela.got : { *(.rela.got) }
.rela.data : { *(.rela.data) *(.rela.data*) }
. = ALIGN(4096);
_etext = .;
_text_size = . - _text;
.data : {
_data = .;
*(.sdata)
*(.data)
*(.data1)
*(.data.*)
*(.got.plt)
*(.got)
/*
* The EFI loader doesn't seem to like a .bss section, so we
* stick it all into .data:
*/
. = ALIGN(16);
_bss = .;
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(.bss.*)
*(COMMON)
. = ALIGN(512);
_bss_end = .;
_edata = .;
} :data
_data_size = _edata - _data;
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
. = ALIGN(4096);
.note.gnu.build-id : { *(.note.gnu.build-id) }
/DISCARD/ : {
*(.rel.reloc)
*(.eh_frame)
*(.note.GNU-stack)
}
.comment 0 : { *(.comment) }
}

View file

@ -523,10 +523,10 @@ $(obj)/%.efi: $(obj)/%_efi.so
KBUILD_EFILDFLAGS = -nostdlib -zexecstack -znocombreloc -znorelro
KBUILD_EFILDFLAGS += $(call ld-option,--no-warn-rwx-segments)
quiet_cmd_efi_ld = LD $@
cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -T $(EFI_LDS_PATH) \
cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -L $(srctree) -T $(EFI_LDS_PATH) \
-shared -Bsymbolic -s $^ -o $@
EFI_LDS_PATH = $(srctree)/arch/$(ARCH)/lib/$(EFI_LDS)
EFI_LDS_PATH = arch/$(ARCH)/lib/$(EFI_LDS)
$(obj)/efi_crt0.o: $(srctree)/arch/$(ARCH)/lib/$(EFI_CRT0:.o=.S) FORCE
$(call if_changed_dep,as_o_S)