From patchwork Sat Jun 24 15:39:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 780360 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wvzzm0wK6z9s4q for ; Sun, 25 Jun 2017 01:40:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 834BBC21D61; Sat, 24 Jun 2017 15:40:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D6FB8C21C54; Sat, 24 Jun 2017 15:40:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E003FC21C54; Sat, 24 Jun 2017 15:40:24 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lists.denx.de (Postfix) with ESMTPS id 958A1C21C2B for ; Sat, 24 Jun 2017 15:40:24 +0000 (UTC) Received: from localhost.localdomain ([88.152.145.149]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MFLhE-1dawFz2guC-00EOP8; Sat, 24 Jun 2017 17:39:47 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Sat, 24 Jun 2017 17:39:30 +0200 Message-Id: <20170624153930.3546-1-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.11.0 X-Provags-ID: V03:K0:gNJVrHiMhNgzHySFlKKzWDrLeUrXRPXJCHD9l0VWUkJ54UiTRS1 toOZrVCtME7cqj+d7HthwtpMgsZxfUVHO40qUA1bGthtTpNXnaGSmT8igSBtgniLevMlxs7 Nlkczd1LN9wutUIQ+426VoiL4B+TWDaJDzNeasxAtEyuWKqRQ5jInOyTLZpVqN6QJivghkq qREu6I1zSKRzHy2gmIAzg== X-UI-Out-Filterresults: notjunk:1; V01:K0:hd4VU36lOK8=:QBZYOjrJoTxXfD5PAmwHUg sn75EgKSbC2mVYMVzHoQiVb6s9kVI2QR6+OJmPeW85ka+FpvNum90kEJIYXofN4SJvwNt839c B8k3L0q11gAl01wAKucZCItDTWBXD8lGnnrpr6nCiQN19rthwtpYWGC7yxyeOhshGyzXBN2A5 ncHORYTz4ebHJef9AWcAfM6FvmK25TCDbSV3IXyNvjVODQqLGwAO7L16vsA7tbRjCNkUoGmkW oBATSkBVES2tL7pSfAGjS3qbDIsjYwVhE/fYgJRf2/t397phns90qVjFl+lT1GurM0vcoSVFB s9ISt+HnNhZQMSAaUWoDH24vg1ThD/f9KbqZzwjrRhIhUvBHLMUh5LSGj1d2jmkK28IS+as/Y gS434jrHONVuE5DbysCo48EDZrUVC3H89bJdRpp25E2im+vv5ZjOm77FCxztM7PGWnbNoFFjx hBE23RpudS1ZvHCdtQgf7JGfY0iaGfTBjI9kh0x6FbYKl/922vtKsrA5J917UDQLIUXdAf3FA wfTa11gssqaYF9KXZ34szYu31WR5ack14uQi5dHFYfRTcnPFte6OC85YVqi2ylVVakQmg8GmG /XcWCpWk3fVw49TB4MuMNVpmDxELyDieXA3pcpDMLv89Q5W7qZy/PyOdQJ2RV9nRxUFRnRoww VvZHGnLgO5i8I+Bb1nUlRAoxI2sPFzSXkOZdfhHXBENky6TAa3zDCrKNN1ApVjsU6t46GekKF LuX8SCzk6th/hcdPI3H9aA13IHbR1bnIpSHfQDu0jj3sfwdDkUCe2bB+UrA= Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH 1/1] bootefi: allow return without EFI_BOOT_SERVICES.Exit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The Unified Extensible Firmware Interface Specification, version 2.7, defines in chapter 2.1.2 - UEFI Application that an EFI application may either directly return or call EFI_BOOT_SERVICES.Exit(). Unfortunately U-Boot makes the incorrect assumption that EFI_BOOT_SERVICES.Exit() is always called. So the following application leads to a memory exception on the aarch64 architecture when returning: EFI_STATUS efi_main( EFI_HANDLE handle, EFI_SYSTEM_TABlE systable) { return EFI_SUCCESS; } With this patch the entry point is stored in the image handle. The new wrapper function do_enter is used to call the EFI entry point. Signed-off-by: Heinrich Schuchardt --- cmd/bootefi.c | 18 ++++++++++++++++-- include/efi_api.h | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index a0a5434967..fcb223e999 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -141,6 +142,18 @@ static void *copy_fdt(void *fdt) return new_fdt; } +static asmlinkage ulong do_enter(void *image_handle, + struct efi_system_table *st) +{ + struct efi_loaded_image *handle = image_handle; + efi_status_t ret = EFI_LOAD_ERROR; + + if (handle->entry) + ret = handle->entry(image_handle, st); + st->boottime->exit(image_handle, ret, 0 , NULL); + return ret; +} + #ifdef CONFIG_ARM64 static unsigned long efi_run_in_el2(ulong (*entry)(void *image_handle, struct efi_system_table *st), void *image_handle, @@ -149,7 +162,7 @@ static unsigned long efi_run_in_el2(ulong (*entry)(void *image_handle, /* Enable caches again */ dcache_enable(); - return entry(image_handle, st); + return do_enter(image_handle, st); } #endif @@ -237,6 +250,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) efi_status_t status = loaded_image_info.exit_status; return status == EFI_SUCCESS ? 0 : -EINVAL; } + loaded_image_info.entry = entry; #ifdef CONFIG_ARM64 /* On AArch64 we need to make sure we call our payload in < EL3 */ @@ -254,7 +268,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt) } #endif - return entry(&loaded_image_info, &systab); + return do_enter(&loaded_image_info, &systab); } diff --git a/include/efi_api.h b/include/efi_api.h index 5c3836a51b..611c35c422 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -253,6 +253,10 @@ struct efi_loaded_image { efi_status_t exit_status; struct jmp_buf_data exit_jmp; #endif +#ifdef CONFIG_CMD_BOOTEFI + ulong (*entry)(void *image_handle, struct efi_system_table *st) + asmlinkage; +#endif }; #define DEVICE_PATH_GUID \