From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B2CC433F5 for ; Sun, 10 Oct 2021 21:49:38 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A517A60F46 for ; Sun, 10 Oct 2021 21:49:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A517A60F46 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8842A8354E; Sun, 10 Oct 2021 23:49:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id B59FA83475; Sun, 10 Oct 2021 23:49:33 +0200 (CEST) From: marek.vasut@gmail.com To: u-boot@lists.denx.de Cc: Marek Vasut , Heinrich Schuchardt , Simon Glass , Tom Rini Subject: [PATCH] efi_loader: Handle GD_FLG_SKIP_RELOC Date: Sun, 10 Oct 2021 23:48:57 +0200 Message-Id: <20211010214857.871670-1-marek.vasut@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean From: Marek Vasut In case U-Boot starts with GD_FLG_SKIP_RELOC, the efi loader relocation code breaks down because it assumes gd->relocaddr points to relocated U-Boot code, which is not the case. Add special case for handling GD_FLG_SKIP_RELOC, which uses the __image_copy_start instead of gd->relocaddr for efi loader code relocation source address. Signed-off-by: Marek Vasut Cc: Heinrich Schuchardt Cc: Simon Glass Cc: Tom Rini --- common/board_r.c | 7 ++++++- lib/efi_loader/efi_runtime.c | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common/board_r.c b/common/board_r.c index 31a59c585a..3e95123f95 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -178,7 +178,12 @@ static int initr_reloc_global_data(void) */ efi_save_gd(); - efi_runtime_relocate(gd->relocaddr, NULL); +#ifdef CONFIG_ARM + if (gd->flags & GD_FLG_SKIP_RELOC) + efi_runtime_relocate((ulong)__image_copy_start, NULL); + else +#endif + efi_runtime_relocate(gd->relocaddr, NULL); #endif return 0; diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 93a695fc27..876ca09106 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -17,6 +17,8 @@ #include #include +#include + /* For manual relocation support */ DECLARE_GLOBAL_DATA_PTR; @@ -629,13 +631,23 @@ out: return ret; } +static unsigned long efi_get_reloc_start(void) +{ +#ifdef CONFIG_ARM + if (gd->flags & GD_FLG_SKIP_RELOC) + return (unsigned long)__image_copy_start; + else +#endif + return gd->relocaddr; +} + static __efi_runtime void efi_relocate_runtime_table(ulong offset) { ulong patchoff; void **pos; /* Relocate the runtime services pointers */ - patchoff = offset - gd->relocaddr; + patchoff = offset - efi_get_reloc_start(); for (pos = (void **)&efi_runtime_services.get_time; pos <= (void **)&efi_runtime_services.query_variable_info; ++pos) { if (*pos) @@ -681,7 +693,7 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map) ulong *p; ulong newaddr; - p = (void*)((ulong)rel->offset - base) + gd->relocaddr; + p = (void*)((ulong)rel->offset - base) + efi_get_reloc_start(); /* * The runtime services table is updated in @@ -852,7 +864,8 @@ static efi_status_t EFIAPI efi_set_virtual_address_map( map = (void*)virtmap + (descriptor_size * i); if (map->type == EFI_RUNTIME_SERVICES_CODE) { ulong new_offset = map->virtual_start - - map->physical_start + gd->relocaddr; + map->physical_start + + efi_get_reloc_start(); efi_relocate_runtime_table(new_offset); efi_runtime_relocate(new_offset, map); -- 2.33.0