public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: marek.vasut@gmail.com
To: u-boot@lists.denx.de
Cc: Marek Vasut <marek.vasut+renesas@gmail.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>
Subject: [PATCH] efi_loader: Handle GD_FLG_SKIP_RELOC
Date: Sun, 10 Oct 2021 23:48:57 +0200	[thread overview]
Message-ID: <20211010214857.871670-1-marek.vasut@gmail.com> (raw)

From: Marek Vasut <marek.vasut+renesas@gmail.com>

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 <marek.vasut+renesas@gmail.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
 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 <asm/global_data.h>
 #include <u-boot/crc.h>
 
+#include <asm/sections.h>
+
 /* 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


             reply	other threads:[~2021-10-10 21:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-10 21:48 marek.vasut [this message]
2021-10-11 11:36 ` [PATCH] efi_loader: Handle GD_FLG_SKIP_RELOC Heinrich Schuchardt
2021-10-23 23:03   ` Marek Vasut
2021-10-25 18:46     ` Heinrich Schuchardt
2021-10-25 18:52       ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211010214857.871670-1-marek.vasut@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox