From patchwork Thu Jun 26 14:23:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 32561 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 99AE72066E for ; Thu, 26 Jun 2014 14:27:04 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id va2sf19713349obc.10 for ; Thu, 26 Jun 2014 07:27:04 -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=2agB2vUOKXSEoFkpJQ9LEbQ27KH6jqdPuzv8CRKW/H4=; b=CyKfV6VKxJxdRDx1QEaW8fWHhIZO/SNyfRFxa3qOVVqVhCMWCltqJ8mfV7+jEDGYUo apwrbd2/2/38OdqNT1UUiGw+1vniyWb5LWtGLTEB3sT3N+wcnvhW0g8Sl6OE1bbRuPvF QzWK3r1dcgyR5l+k33ms/6T55hv92sbUdn5rVoEDeH0nsQn0kgDPQrCvb36xuqcsySk5 geSWQ2AB97qPTc6GFYGo8kmRPNF8XBvWcX0eVZHtcHaC33JBPj0m6YCt9pksQVq93IoM WdjfVaL4lXXw1OgMPgJdBBh9UlkwnMFCyltK0meWbJ1pX2Q17qapiGOK7o009UcZV8lt 35Vw== X-Gm-Message-State: ALoCoQmz6jImJxJU1xkG3FCpjxPtqiulJvS7++LFZ8lKrMa3O56jCcCmgeSgEvfXJTPLGVpM8kNy X-Received: by 10.182.91.79 with SMTP id cc15mr8751671obb.13.1403792824235; Thu, 26 Jun 2014 07:27:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.245 with SMTP id j108ls228348qgf.51.gmail; Thu, 26 Jun 2014 07:27:04 -0700 (PDT) X-Received: by 10.52.236.163 with SMTP id uv3mr660837vdc.85.1403792824128; Thu, 26 Jun 2014 07:27:04 -0700 (PDT) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id uc3si4461915vec.97.2014.06.26.07.27.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Jun 2014 07:27:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.170 as permitted sender) client-ip=209.85.128.170; Received: by mail-ve0-f170.google.com with SMTP id i13so3778844veh.1 for ; Thu, 26 Jun 2014 07:27:04 -0700 (PDT) X-Received: by 10.53.8.162 with SMTP id dl2mr11505422vdd.24.1403792824033; Thu, 26 Jun 2014 07:27:04 -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 tc5csp34266vcb; Thu, 26 Jun 2014 07:27:03 -0700 (PDT) X-Received: by 10.68.226.197 with SMTP id ru5mr22196830pbc.77.1403792823130; Thu, 26 Jun 2014 07:27:03 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id bm3si10000614pad.232.2014.06.26.07.27.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 07:27:03 -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 1X0AcU-0006dI-J7; Thu, 26 Jun 2014 14:25:46 +0000 Received: from mail-wi0-f170.google.com ([209.85.212.170]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X0Ab1-0003w3-W1 for linux-arm-kernel@lists.infradead.org; Thu, 26 Jun 2014 14:24:20 +0000 Received: by mail-wi0-f170.google.com with SMTP id cc10so1141628wib.5 for ; Thu, 26 Jun 2014 07:23:57 -0700 (PDT) X-Received: by 10.194.92.196 with SMTP id co4mr18684946wjb.4.1403792636640; Thu, 26 Jun 2014 07:23:56 -0700 (PDT) Received: from ards-macbook-pro.local ([109.114.99.252]) by mx.google.com with ESMTPSA id jb16sm25046864wic.10.2014.06.26.07.23.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 26 Jun 2014 07:23:55 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, x86@kernel.org Subject: [PATCH v2 5/5] efi: efistub: convert into static library Date: Thu, 26 Jun 2014 16:23:37 +0200 Message-Id: <1403792617-25792-6-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1403792617-25792-1-git-send-email-ard.biesheuvel@linaro.org> References: <1403792617-25792-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140626_072416_380146_A604B6E7 X-CRM114-Status: GOOD ( 17.41 ) 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 [209.85.212.170 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.170 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: linux-efi@vger.kernel.org, Ard Biesheuvel , catalin.marinas@arm.com, msalter@redhat.com, leif.lindholm@linaro.org, roy.franz@linaro.org, hpa@zytor.com, linux-arm-kernel@lists.infradead.org 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.128.170 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 This patch changes both x86 and arm64 efistub implementations from #including shared .c files under drivers/firmware/efi to building the shared code as a static library. The x86 code uses a stub built into the boot executable which uncompresses the kernel at boot time. In this case, the library is linked into the decompressor. In the arm64 case, the stub is part of the kernel proper so the library is linked into the kernel proper as well. Signed-off-by: Ard Biesheuvel --- arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 1 + arch/arm64/kernel/efi-stub.c | 5 ----- arch/x86/boot/compressed/Makefile | 3 ++- arch/x86/boot/compressed/eboot.c | 2 -- drivers/firmware/efi/Kconfig | 3 +++ drivers/firmware/efi/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile | 26 ++++++++++++++++++++++ drivers/firmware/efi/{ => libstub}/arm-stub.c | 14 ++++++------ .../firmware/efi/{ => libstub}/efi-stub-helper.c | 0 drivers/firmware/efi/{ => libstub}/efistub.h | 0 drivers/firmware/efi/{ => libstub}/fdt.c | 0 12 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 drivers/firmware/efi/libstub/Makefile rename drivers/firmware/efi/{ => libstub}/arm-stub.c (96%) rename drivers/firmware/efi/{ => libstub}/efi-stub-helper.c (100%) rename drivers/firmware/efi/{ => libstub}/efistub.h (100%) rename drivers/firmware/efi/{ => libstub}/fdt.c (100%) diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c similarity index 100% rename from drivers/firmware/efi/efi-stub-helper.c rename to drivers/firmware/efi/libstub/efi-stub-helper.c diff --git a/drivers/firmware/efi/efistub.h b/drivers/firmware/efi/libstub/efistub.h similarity index 100% rename from drivers/firmware/efi/efistub.h rename to drivers/firmware/efi/libstub/efistub.h diff --git a/drivers/firmware/efi/fdt.c b/drivers/firmware/efi/libstub/fdt.c similarity index 100% rename from drivers/firmware/efi/fdt.c rename to drivers/firmware/efi/libstub/fdt.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 93e11f4d9513..f766f346022d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -300,6 +300,7 @@ config EFI select UCS2_STRING select EFI_PARAMS_FROM_FDT select EFI_RUNTIME_WRAPPERS + select EFI_ARMSTUB default y help This option provides support for runtime services provided diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 8185a913c5ed..bb8f21a626c0 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -48,6 +48,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/ core-$(CONFIG_CRYPTO) += arch/arm64/crypto/ libs-y := arch/arm64/lib/ $(libs-y) libs-y += $(LIBGCC) +libs-$(CONFIG_EFI) += drivers/firmware/efi/libstub/ # Default target when executing plain make KBUILD_IMAGE := Image.gz diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index e4999021b07d..12456a7d3fa2 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -13,11 +13,6 @@ #include #include -/* Include shared EFI stub code */ -#include "../../../drivers/firmware/efi/efi-stub-helper.c" -#include "../../../drivers/firmware/efi/fdt.c" -#include "../../../drivers/firmware/efi/arm-stub.c" - efi_status_t handle_kernel_image(efi_system_table_t *sys_table, unsigned long *image_addr, diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 0fcd9133790c..7a801a310e37 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -33,7 +33,8 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \ $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone ifeq ($(CONFIG_EFI_STUB), y) - VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o + VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \ + $(objtree)/drivers/firmware/efi/libstub/lib.a endif $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index d338c134c659..d4d865438a0c 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -280,8 +280,6 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) } } -#include "../../../../drivers/firmware/efi/efi-stub-helper.c" - static void find_bits(unsigned long mask, u8 *pos, u8 *size) { u8 first, len; diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 04a7af46736a..395e76d9a1b5 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -61,6 +61,9 @@ config EFI_RUNTIME_WRAPPERS in which case it needs to provide #definitions of efi_call_virt and __efi_call_virt in +config EFI_ARMSTUB + bool + endmenu config UEFI_CPER diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index e1096539eedb..d9abdbc962f1 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -1,7 +1,7 @@ # # Makefile for linux kernel # -obj-$(CONFIG_EFI) += efi.o vars.o +obj-$(CONFIG_EFI) += efi.o vars.o libstub/ obj-$(CONFIG_EFI_VARS) += efivars.o obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o obj-$(CONFIG_UEFI_CPER) += cper.o diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile new file mode 100644 index 000000000000..b14bc2b9fb4d --- /dev/null +++ b/drivers/firmware/efi/libstub/Makefile @@ -0,0 +1,26 @@ +# +# The stub may be linked into the kernel proper or into a separate boot binary, +# but in either case, it executes before the kernel does (with MMU disabled) so +# things like ftrace and stack-protector are likely to cause trouble if left +# enabled, even if doing so doesn't break the build. +# +cflags-$(CONFIG_X86_32) := -march=i386 +cflags-$(CONFIG_X86_64) := -mcmodel=small +cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 \ + -fPIC -fno-strict-aliasing -mno-red-zone \ + -mno-mmx -mno-sse -DDISABLE_BRANCH_PROFILING + +cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) +cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ + -fno-builtin -fpic -mno-single-pic-base + +KBUILD_CFLAGS := $(cflags-y) \ + $(call cc-option,-ffreestanding) \ + $(call cc-option,-fno-stack-protector) + +GCOV_PROFILE := n + +lib-y := efi-stub-helper.o +lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o + +CFLAGS_fdt.o += -I$(srctree)/scripts/dtc/libfdt/ diff --git a/drivers/firmware/efi/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c similarity index 96% rename from drivers/firmware/efi/arm-stub.c rename to drivers/firmware/efi/libstub/arm-stub.c index 34614d6f9698..480339b6b110 100644 --- a/drivers/firmware/efi/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -151,13 +151,13 @@ void efi_char16_printk(efi_system_table_t *sys_table_arg, * must be reserved. On failure it is required to free all * all allocations it has made. */ -static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, - unsigned long *image_addr, - unsigned long *image_size, - unsigned long *reserve_addr, - unsigned long *reserve_size, - unsigned long dram_base, - efi_loaded_image_t *image); +efi_status_t handle_kernel_image(efi_system_table_t *sys_table, + unsigned long *image_addr, + unsigned long *image_size, + unsigned long *reserve_addr, + unsigned long *reserve_size, + unsigned long dram_base, + efi_loaded_image_t *image); /* * EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint * that is described in the PE/COFF header. Most of the code is the same