From patchwork Tue Jul 8 12:50:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33203 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1FF7F20969 for ; Tue, 8 Jul 2014 12:52:14 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id il7sf20083114vcb.8 for ; Tue, 08 Jul 2014 05:52:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=ux7dOsBaPnsAdj8Jq5lVjDW46ZhhkRin/4P6/sgqF5Q=; b=aur7fKtVLri2lykPkoOSFEYr5Ocwd+3/yDPZw5I8UnKy+llxkkSAhdDuGmXpvaWbR7 OhJHjeJyWS8XKIWsHILAn8KOpeBQR+5FodsY5NY4YUfng2/awhgDcBt9SoF2fRkJnY+S Jd0lRSvap6rYlhnnWoKbuNw5fsCSglvwiknCrIsc0QiSIlyz7cpkwgFgrvd2AO4imf4i FyhlETM2MQVMq9tqI2Uwdc+ZDWraq1COeY+DK+wQQqWL/BwxbK+IthrKt8yLGn4yh/24 g+Y8szkEtjvPZWDKh87cgTSbszu13wKUDEy3IKsnCEJW0jHh0q50M3jS3s4itnZwyzv0 on5A== X-Gm-Message-State: ALoCoQmtRtILfopU51IpTRJx6BYBEfyyTLfDyTFC17P84U66GSuJtKvh1Y3tiOg7qKHD05U4Rs4w X-Received: by 10.224.41.74 with SMTP id n10mr16969981qae.1.1404823933924; Tue, 08 Jul 2014 05:52:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.112 with SMTP id n103ls2161498qga.86.gmail; Tue, 08 Jul 2014 05:52:13 -0700 (PDT) X-Received: by 10.53.7.204 with SMTP id de12mr1200446vdd.41.1404823933816; Tue, 08 Jul 2014 05:52:13 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id cl2si20074831vcb.98.2014.07.08.05.52.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Jul 2014 05:52:13 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id la4so5501135vcb.28 for ; Tue, 08 Jul 2014 05:52:13 -0700 (PDT) X-Received: by 10.53.1.231 with SMTP id bj7mr328998vdd.49.1404823933748; Tue, 08 Jul 2014 05:52:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp767626vcb; Tue, 8 Jul 2014 05:52:13 -0700 (PDT) X-Received: by 10.68.97.37 with SMTP id dx5mr9166469pbb.119.1404823932939; Tue, 08 Jul 2014 05:52:12 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id kb2si43402362pbc.123.2014.07.08.05.52.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jul 2014 05:52:12 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X4UrK-0001CQ-J5; Tue, 08 Jul 2014 12:50:58 +0000 Received: from mail-wg0-f48.google.com ([74.125.82.48]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X4Ur9-0000rz-Rv for linux-arm-kernel@lists.infradead.org; Tue, 08 Jul 2014 12:50:49 +0000 Received: by mail-wg0-f48.google.com with SMTP id x12so977166wgg.19 for ; Tue, 08 Jul 2014 05:50:25 -0700 (PDT) X-Received: by 10.194.61.47 with SMTP id m15mr40665154wjr.63.1404823825356; Tue, 08 Jul 2014 05:50:25 -0700 (PDT) Received: from ards-macbook-pro.local (225-131.dsl.iskon.hr. [89.164.225.131]) by mx.google.com with ESMTPSA id 10sm84508382wjx.26.2014.07.08.05.50.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Jul 2014 05:50:24 -0700 (PDT) From: Ard Biesheuvel To: will.deacon@arm.com, mark.rutland@arm.com Subject: [RFC PATCH 3/3] arm64/efi: efistub: get TEXT_OFFSET from the Image header at runtime Date: Tue, 8 Jul 2014 14:50:03 +0200 Message-Id: <1404823803-7317-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404823803-7317-1-git-send-email-ard.biesheuvel@linaro.org> References: <1404823803-7317-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140708_055048_082232_9BE4B509 X-CRM114-Status: GOOD ( 15.26 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.48 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.48 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: roy.franz@linaro.org, Ard Biesheuvel , leif.lindholm@linaro.org, linux-arm-kernel@lists.infradead.org, msalter@redhat.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The EFI stub for arm64 needs to behave like an ordinary bootloader in the sense that it needs to inspect the Image header at runtime and not rely on the linker or preprocessor to produce a value for TEXT_OFFSET. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/Makefile | 2 -- arch/arm64/kernel/efi-stub.c | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index cdaedad3afe5..99b676eeeb0f 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -4,8 +4,6 @@ CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) -CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) \ - -I$(src)/../../../scripts/dtc/libfdt CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_insn.o = -pg diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index 12456a7d3fa2..01581d332858 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -11,6 +11,7 @@ */ #include #include +#include #include @@ -24,20 +25,30 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, { efi_status_t status; unsigned long kernel_size, kernel_memsize = 0; + struct image_hdr *hdr = (struct image_hdr *)*image_addr; + unsigned long image_base; + + /* make sure image_addr points to an arm64 kernel Image */ + if (!image_hdr_check(hdr)) { + pr_efi_err(sys_table, "Kernel Image header corrupt\n"); + return EFI_LOAD_ERROR; + } + + /* put the image at the offset specified in the Image header */ + image_base = dram_base + image_hdr_text_offset(hdr); /* Relocate the image, if required. */ kernel_size = _edata - _text; - if (*image_addr != (dram_base + TEXT_OFFSET)) { + if (*image_addr != image_base) { kernel_memsize = kernel_size + (_end - _edata); status = efi_relocate_kernel(sys_table, image_addr, kernel_size, kernel_memsize, - dram_base + TEXT_OFFSET, - PAGE_SIZE); + image_base, PAGE_SIZE); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Failed to relocate kernel\n"); return status; } - if (*image_addr != (dram_base + TEXT_OFFSET)) { + if (*image_addr != image_base) { pr_efi_err(sys_table, "Failed to alloc kernel memory\n"); efi_free(sys_table, kernel_memsize, *image_addr); return EFI_LOAD_ERROR;