From 71f0587f2049397d86e9eee7983bce623de5fb5e Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Mon, 23 Jan 2017 18:02:17 +0100 Subject: efi: include and execute exit calls Signed-off-by: Michael Olbrich Signed-off-by: Sascha Hauer --- arch/efi/Makefile | 4 ++-- arch/efi/efi/efi-image.c | 2 ++ arch/efi/lib/elf_x86_64_efi.lds.S | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'arch') diff --git a/arch/efi/Makefile b/arch/efi/Makefile index b078bd0e35..32a1c152b7 100644 --- a/arch/efi/Makefile +++ b/arch/efi/Makefile @@ -28,8 +28,8 @@ cmd_barebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_barebox) -o $@ \ quiet_cmd_efi_image = EFI-IMG $@ cmd_efi_image = $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \ -j .dynsym -j .rel -j .rela -j .reloc -j __barebox_initcalls \ - -j __barebox_cmd -j .barebox_magicvar -j .bbenv.* \ - --target=$(TARGET) $< $@ + -j __barebox_exitcalls -j __barebox_cmd -j .barebox_magicvar \ + -j .bbenv.* --target=$(TARGET) $< $@ KBUILD_BINARY := barebox diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c index 32e060886a..c780cad6d4 100644 --- a/arch/efi/efi/efi-image.c +++ b/arch/efi/efi/efi-image.c @@ -145,6 +145,7 @@ static int efi_execute_image(const char *file) loaded_image->load_options = xstrdup_char_to_wchar(options); loaded_image->load_options_size = (strlen(options) + 1) * sizeof(wchar_t); + shutdown_barebox(); } efiret = BS->start_image(handle, NULL, NULL); @@ -255,6 +256,7 @@ static int do_bootm_efi(struct image_data *data) efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid, get_time_ns()/1000); + shutdown_barebox(); linux_efi_handover(handle, boot_header); return 0; diff --git a/arch/efi/lib/elf_x86_64_efi.lds.S b/arch/efi/lib/elf_x86_64_efi.lds.S index e1bc2120fa..93d34d17ab 100644 --- a/arch/efi/lib/elf_x86_64_efi.lds.S +++ b/arch/efi/lib/elf_x86_64_efi.lds.S @@ -80,6 +80,7 @@ SECTIONS *(.rela.data*) *(.rela.barebox*) *(.rela.initcall*) + *(.rela.exitcall*) *(.rela.got) *(.rela.stab) } -- cgit v1.2.3 From aa6f3cc4b46c90c485aed7e183199871348c4821 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Mon, 23 Jan 2017 18:02:18 +0100 Subject: efi: don't unload drivers EFI applications should be unloaded to avoid leaking memory. However, boot or runtime services continue in the background. So they must not be unloaded. Signed-off-by: Michael Olbrich Signed-off-by: Sascha Hauer --- arch/efi/efi/efi-image.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/efi/efi/efi-image.c b/arch/efi/efi/efi-image.c index c780cad6d4..27f3c1b39c 100644 --- a/arch/efi/efi/efi-image.c +++ b/arch/efi/efi/efi-image.c @@ -130,12 +130,16 @@ static int efi_execute_image(const char *file) efi_status_t efiret; struct linux_kernel_header *image_header; const char *options; + bool is_driver; int ret; ret = efi_load_image(file, &loaded_image, &handle); if (ret) return ret; + is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) || + (loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE); + image_header = (struct linux_kernel_header *)loaded_image->image_base; if (image_header->boot_flag == 0xAA55 && image_header->header == 0x53726448) { @@ -152,7 +156,8 @@ static int efi_execute_image(const char *file) if (EFI_ERROR(efiret)) pr_err("failed to StartImage: %s\n", efi_strerror(efiret)); - BS->unload_image(handle); + if (!is_driver) + BS->unload_image(handle); efi_connect_all(); efi_register_devices(); -- cgit v1.2.3