From patchwork Tue Jun 5 17:20:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 137790 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp1222390lji; Tue, 5 Jun 2018 10:20:41 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIbShBTB1LWmxEcW9fAX1e3s/j9F8rY0/p7m0W/VG05V/Tny9jFDfcBz6PR/TYeWIrec0e8 X-Received: by 2002:a50:9606:: with SMTP id y6-v6mr92983eda.114.1528219240991; Tue, 05 Jun 2018 10:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528219240; cv=none; d=google.com; s=arc-20160816; b=fElFdYOkH0N3VhtIi3La1E+TLEREpDgZq/4PaC9vkLYwjra5pd6tDQv54VKHf2IMQ4 Y2SnDTOiiOkILJy2GTMBhYxtt5gJ1IrfE2u7xGul+VCnJtyqbHxSKbQCwE01ysklUa4k JJdTZq4YU8emwv+h7UHGols/xdru0sBdvH8s9XAVaznbfurnUClvzOeeHZYlwFIgKHo3 ANgZ26lwFcWokilmSA4lcVk7kxs+m4VKjWpdKNRTKhxaeVQzZgHMyKh0RMv4u0H3UfuR mtAVZK7VzqM+mHqUimb7RsA2qbHEAUuzmsYkAX41/X8NOMHF2oa7fzIN7Y9s1af88FAe sXxA== 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:message-id:date:to:from :arc-authentication-results; bh=KZXW79Cv7Bc6BvX8E+giL8mKBkMg6avXFU7b8xMRUBw=; b=JSurp9u4bGADd73Pk56gr4tIA1/PONEl7xKvwoo/If0FQ7duNp43/h2h1XpHzwVhiI zRLa6be+PFFlozIXDzEL+Rvg8uyG1/bGy/XGDfvtIitOWaGvkdU2tnloPN61BMljFhSM Gdlp8xjkBnrYmes1Efb9npkw/lkQ2UVYUBI1HXbD+B5Yepr9paSDf8E/RmbPle2bnLT1 LHdg6KpeP72LsFm2riXu1AuNca4k54U+fp6OCZi0WCRYeLgGXzEXToi3yO6XigGIH15R YDcDJoEvoU/P+KdZFvAKPfA/7jMmhzL9e5Dl+aysWSublwDCxuejSFSP1RUukHls91OW gSRw== 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 21-v6si770418edw.36.2018.06.05.10.20.40; Tue, 05 Jun 2018 10:20:40 -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 3DFAFC21F99; Tue, 5 Jun 2018 17:20:39 +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=none 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 4B68AC21F6E; Tue, 5 Jun 2018 17:20:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7FEE7C21F6E; Tue, 5 Jun 2018 17:20:35 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 1E0B8C21C2C for ; Tue, 5 Jun 2018 17:20:35 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9E7D3AC0D; Tue, 5 Jun 2018 17:20:34 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Tue, 5 Jun 2018 19:20:32 +0200 Message-Id: <20180605172032.2150-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Subject: [U-Boot] [PATCH] riscv: Add support for HI20 PE relocations 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 PE standard allows for HI20/LOW12 relocations. Within the efi_loader target we always know that our relocation target is 4k aligned, so we don't need to worry about the LOW12 part. This patch adds support for the respective relocations. With this and a few grub patches I have cooking in parallel I'm able to run grub on RISC-V. Signed-off-by: Alexander Graf --- include/pe.h | 3 +++ lib/efi_loader/efi_image_loader.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/pe.h b/include/pe.h index d73eb142cb..36e1908b7e 100644 --- a/include/pe.h +++ b/include/pe.h @@ -201,10 +201,13 @@ typedef struct _IMAGE_RELOCATION #define IMAGE_REL_BASED_MIPS_JMPADDR 5 #define IMAGE_REL_BASED_ARM_MOV32A 5 /* yes, 5 too */ #define IMAGE_REL_BASED_ARM_MOV32 5 /* yes, 5 too */ +#define IMAGE_REL_BASED_RISCV_HI20 5 /* yes, 5 too */ #define IMAGE_REL_BASED_SECTION 6 #define IMAGE_REL_BASED_REL 7 #define IMAGE_REL_BASED_ARM_MOV32T 7 /* yes, 7 too */ #define IMAGE_REL_BASED_THUMB_MOV32 7 /* yes, 7 too */ +#define IMAGE_REL_BASED_RISCV_LOW12I 7 /* yes, 7 too */ +#define IMAGE_REL_BASED_RISCV_LOW12S 8 #define IMAGE_REL_BASED_MIPS_JMPADDR16 9 #define IMAGE_REL_BASED_IA64_IMM64 9 /* yes, 9 too */ #define IMAGE_REL_BASED_DIR64 10 diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index 3cffe9ef46..6892171ccd 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -126,6 +126,20 @@ static efi_status_t efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel, case IMAGE_REL_BASED_DIR64: *x64 += (uint64_t)delta; break; +#ifdef __riscv + case IMAGE_REL_BASED_RISCV_HI20: + *x32 = ((*x32 & 0xfffff000) + (uint32_t)delta) | + (*x32 & 0x00000fff); + break; + case IMAGE_REL_BASED_RISCV_LOW12I: + case IMAGE_REL_BASED_RISCV_LOW12S: + /* We know that we're 4k aligned */ + if (delta & 0xfff) { + printf("Unsupported reloc offset\n"); + return EFI_LOAD_ERROR; + } + break; +#endif default: printf("Unknown Relocation off %x type %x\n", offset, type);