From patchwork Mon Apr 23 05:59:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 133952 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp616089lji; Sun, 22 Apr 2018 23:01:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx49c+wjNcZLDSq7oGtOTt9RUvdfHPjhLZDPxKxOgw9icOSLevDE/FPRVd+cVbeQj5SKjUvAb X-Received: by 10.80.175.134 with SMTP id h6mr27025847edd.258.1524463314806; Sun, 22 Apr 2018 23:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524463314; cv=none; d=google.com; s=arc-20160816; b=N2ZmU8lpgB/y2dHj41ANh94zzbs1t2t36x4VRajbYgPiAuL9zbWAW6GyqwsnXVQdeP 8SSwPQl+Qy41/97YLZnfnlmQt0A1eH00pdzk3EVKmY1V/V++28ratldKQyj4k8u+/JVs AonqmPEMyz41lUojR7X1pz+COG+ecUAmGCeYv5IA2vWfoEZov0XrkqdEySzOE+ZKGyGI Hmi4BcPA4pOYYFGxcjrtwC3d1mqyiuq5RMfzJpFnRsiQnZaCD6/99KXeLDOsa35m8oLy xxEOEjm7MXNYbKNXrh9imcZ9GZD83mQZwj07qwDUnsnGVzhCmvOHiZoO0QQsvxkgNVhh FfNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:arc-authentication-results; bh=Sr6xbxBtDFG6vlhapqm0oQ/FzDT/Mx40yshrchE2Sxs=; b=T22NPOBtz0LUYvThJD5DGgR+4bBuddrtRkSi/lKTTVWS4verWO0ylqPwSfYfELU6do QlN9SDauoF0MQoBMS/j+WYfvzoejFs0BhchtkJKE48FlMENP93lJ/r4u2xm/DzZWlKvI qnlgdvL7of6XNz75r7Wf8lt6kUwfkAYOgK9BTa/v1dTeUBK2jlMumwJh+fb3iqE2QKIt DlU9dE/m+41IbjErxHwfJbfDJX15jOvTBOJA3DLJha7S4vs55/7Fol+xdum/8pD7+jaA wxKuCMIqY1imkE+nNkMosBO3P6Zfg/SXlWj5nqc6WMBff3PjnJWJO5nAc0KQi+u3DMG3 RDIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id h48si399832edh.427.2018.04.22.23.01.54; Sun, 22 Apr 2018 23:01:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 4C995C21D74; Mon, 23 Apr 2018 06:00:20 +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=RCVD_IN_DNSWL_BLOCKED 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 0A4F7C21DD7; Mon, 23 Apr 2018 06:00:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 11832C21D8E; Mon, 23 Apr 2018 05:59:52 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id D9FDCC21DAF for ; Mon, 23 Apr 2018 05:59:51 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A233AAE9F; Mon, 23 Apr 2018 05:59:51 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Mon, 23 Apr 2018 07:59:50 +0200 Message-Id: <20180423055950.78818-9-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180423055950.78818-1-agraf@suse.de> References: <20180423055950.78818-1-agraf@suse.de> Cc: Heinrich Schuchardt , schwab@suse.de, Greentime Hu Subject: [U-Boot] [PATCH v3 8/8] efi_loader: Enable RISC-V support 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" 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 --- v1 -> v2: - Enable hello world binary --- arch/riscv/cpu/nx25/u-boot.lds | 16 ++++++++++++++++ cmd/Kconfig | 2 +- lib/efi_loader/Kconfig | 2 +- lib/efi_loader/efi_runtime.c | 41 ++++++++++++++++++++++++++++++++++++----- 4 files changed, 54 insertions(+), 7 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/cmd/Kconfig b/cmd/Kconfig index bc1d2f31c0..c9883a40e7 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -228,7 +228,7 @@ config CMD_BOOTEFI config CMD_BOOTEFI_HELLO_COMPILE bool "Compile a standard EFI hello world binary for testing" - depends on CMD_BOOTEFI && (ARM || X86) + depends on CMD_BOOTEFI && (ARM || X86 || RISCV) default y help This compiles a standard EFI hello world application with U-Boot so 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 #define R_RELATIVE R_386_RELATIVE #define R_MASK 0xffULL +#elif defined(CONFIG_RISCV) +#include +#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) ||