All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support
Date: Wed, 18 Apr 2018 15:40:30 +0200	[thread overview]
Message-ID: <20180418134030.55127-9-agraf@suse.de> (raw)
In-Reply-To: <20180418134030.55127-1-agraf@suse.de>

We have almost all pieces needed to support RISC-V UEFI binaries in place
already. The only missing piece are ELF relocations for runtime code and
data.

This patch adds respective support in the linker script and the runtime
relocation code. It also allows users to enable the EFI_LOADER configuration
switch on RISC-V platforms.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/riscv/cpu/nx25/u-boot.lds | 16 ++++++++++++++++
 lib/efi_loader/Kconfig         |  2 +-
 lib/efi_loader/efi_runtime.c   | 41 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/arch/riscv/cpu/nx25/u-boot.lds b/arch/riscv/cpu/nx25/u-boot.lds
index 936fd779aa..508fa7e58d 100644
--- a/arch/riscv/cpu/nx25/u-boot.lds
+++ b/arch/riscv/cpu/nx25/u-boot.lds
@@ -38,6 +38,22 @@ SECTIONS
 		KEEP(*(SORT(.u_boot_list*)));
 	}
 
+	. = ALIGN(4);
+
+	.efi_runtime : {
+                __efi_runtime_start = .;
+		*(efi_runtime_text)
+		*(efi_runtime_data)
+                __efi_runtime_stop = .;
+	}
+
+	.efi_runtime_rel : {
+                __efi_runtime_rel_start = .;
+		*(.relaefi_runtime_text)
+		*(.relaefi_runtime_data)
+                __efi_runtime_rel_stop = .;
+	}
+
     . = ALIGN(4);
 
     /DISCARD/ : { *(.rela.plt*) }
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 83d75c4fdc..9de58bb012 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -1,6 +1,6 @@
 config EFI_LOADER
 	bool "Support running EFI Applications in U-Boot"
-	depends on (ARM || X86) && OF_LIBFDT
+	depends on (ARM || X86 || RISCV) && OF_LIBFDT
 	# We need EFI_STUB_64BIT to be set on x86_64 with EFI_STUB
 	depends on !EFI_STUB || !X86_64 || EFI_STUB_64BIT
 	# We need EFI_STUB_32BIT to be set on x86_32 with EFI_STUB
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 573a5d6ac1..33bbc8d6cc 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -41,6 +41,25 @@ static efi_status_t __efi_runtime EFIAPI efi_invalid_parameter(void);
 #include <asm/elf.h>
 #define R_RELATIVE	R_386_RELATIVE
 #define R_MASK		0xffULL
+#elif defined(CONFIG_RISCV)
+#include <elf.h>
+#define R_RELATIVE	R_RISCV_RELATIVE
+#define R_MASK		0xffULL
+#define IS_RELA		1
+
+struct dyn_sym {
+	ulong foo1;
+	ulong addr;
+	u32 foo2;
+	u32 foo3;
+};
+#ifdef CONFIG_CPU_RISCV_32
+#define R_ABSOLUTE	R_RISCV_32
+#define SYM_INDEX	8
+#else
+#define R_ABSOLUTE	R_RISCV_64
+#define SYM_INDEX	32
+#endif
 #else
 #error Need to add relocation awareness
 #endif
@@ -247,15 +266,27 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
 
 		p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
 
-		if ((rel->info & R_MASK) != R_RELATIVE) {
-			continue;
-		}
+		debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__, rel->info, *p, rel->offset);
 
+		switch (rel->info & R_MASK) {
+		case R_RELATIVE:
 #ifdef IS_RELA
-		newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
+			newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
 #else
-		newaddr = *p - lastoff + offset;
+			newaddr = *p - lastoff + offset;
 #endif
+			break;
+#ifdef R_ABSOLUTE
+		case R_ABSOLUTE: {
+			ulong symidx = rel->info >> SYM_INDEX;
+			extern struct dyn_sym __dyn_sym_start[];
+			newaddr = __dyn_sym_start[symidx].addr + offset;
+			break;
+		}
+#endif
+		default:
+			continue;
+		}
 
 		/* Check if the relocation is inside bounds */
 		if (map && ((newaddr < map->virtual_start) ||
-- 
2.12.3

  parent reply	other threads:[~2018-04-18 13:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-18 13:40 [U-Boot] [PATCH 0/8] riscv: Enable efi_loader support Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 1/8] riscv: Add setjmp/longjmp code Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 2/8] riscv: Enable function sections Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 3/8] efi_loader: selftest: Do not build relocation tests for risc-v Alexander Graf
2018-04-18 15:48   ` Heinrich Schuchardt
2018-04-18 16:41     ` Alexander Graf
2018-04-19  5:57   ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 4/8] riscv: Add board_quiesce_devices stub Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 5/8] efi_loader: Use EFI_CACHELINE_SIZE in the image loader too Alexander Graf
2018-04-18 13:40 ` [U-Boot] [PATCH 6/8] distro: Extend with RISC-V defines Alexander Graf
2018-04-18 15:43   ` Heinrich Schuchardt
2018-04-18 13:40 ` [U-Boot] [PATCH 7/8] riscv: nx25: Enable distro boot Alexander Graf
2018-04-18 13:40 ` Alexander Graf [this message]
2018-04-19  5:14   ` [U-Boot] [PATCH 8/8] efi_loader: Enable RISC-V support Heinrich Schuchardt

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=20180418134030.55127-9-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.