From patchwork Wed Sep 28 22:51:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9355103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CFA1F6086A for ; Wed, 28 Sep 2016 22:54:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C206D29529 for ; Wed, 28 Sep 2016 22:54:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6C8F2964E; Wed, 28 Sep 2016 22:54:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3BD15295AA for ; Wed, 28 Sep 2016 22:54:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpNi8-0004Kq-VT; Wed, 28 Sep 2016 22:52:20 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpNi8-0004K9-8O for xen-devel@lists.xenproject.org; Wed, 28 Sep 2016 22:52:20 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id C5/3E-13924-3A94CE75; Wed, 28 Sep 2016 22:52:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXSO6nOVXeh55t wg8mzzC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxH87gKjmhXvLhynK2B8ZByFyMXh5BAB5PE oskvWCGcb4wSR6/3MkI4GxklNix4AeVMYJT49PAtUBknB5uAjsTFLw/ZQWwRASWJe6smM4EUM QvsYpI4dXkjI0hCWMBS4v6CXUBFHBwsAqoS93b5g4R5Bdwl1s18xgJiSwgoSnQ/m8AGYnMKeE j8ePgBrFUIqOb2ou+MEDXGEn2z+lgmMPItYGRYxahenFpUllqka6SXVJSZnlGSm5iZo2toYKq Xm1pcnJiempOYVKyXnJ+7iREYKAxAsIPx+x+nQ4ySHExKorxTjd+EC/El5adUZiQWZ8QXleak Fh9ilOHgUJLgvewBlBMsSk1PrUjLzAGGLExagoNHSYR3Dkiat7ggMbc4Mx0idYpRUUqcdwFIQ gAkkVGaB9cGi5NLjLJSwryMQIcI8RSkFuVmlqDKv2IU52BUEoYYz5OZVwI3/RXQYiagxUtPvA BZXJKIkJJqYGwwqSs9KVY8nTNOaLPi26h3PtcaJ1Ylncu7OuOMdOqLy909f8+JTwhXfpvf837 KdsaoXDdJ04NzbiQuevtT6JBnUbV+z36d6yxGsw7cFPzdxvV+S8+tBTNC7SwunLyy9bjKOUEe xZNnqvs4Qi9ILVZefGV92dHyxSqcobZ/OfyuSl7y22+SpqnEUpyRaKjFXFScCAC++XhNjgIAA A== X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1475103136!44925106!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41198 invoked from network); 28 Sep 2016 22:52:17 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-10.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 28 Sep 2016 22:52:17 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8SMq6uC011717 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Sep 2016 22:52:06 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u8SMq6jK030530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Sep 2016 22:52:06 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u8SMq3Wr012076; Wed, 28 Sep 2016 22:52:05 GMT Received: from olila.local.net-space.pl (/10.175.227.27) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 28 Sep 2016 15:52:03 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Thu, 29 Sep 2016 00:51:24 +0200 Message-Id: <1475103092-27893-6-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1475103092-27893-1-git-send-email-daniel.kiper@oracle.com> References: <1475103092-27893-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: jgross@suse.com, sstabellini@kernel.org, andrew.cooper3@citrix.com, cardoe@cardoe.com, pgnet.dev@gmail.com, ning.sun@intel.com, julien.grall@arm.com, david.vrabel@citrix.com, jbeulich@suse.com, qiaowei.ren@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v8 05/13] efi: build xen.gz with EFI code X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Build xen.gz with EFI code. We need this to support multiboot2 protocol on EFI platforms. If we wish to load non-ELF file using multiboot (v1) or multiboot2 then it must contain "linear" (or "flat") representation of code and data. This is requirement of both boot protocols. Currently, PE file contains many sections which are not "linear" (one after another without any holes) or even do not have representation in a file (e.g. BSS). From EFI point of view everything is OK and works. However, this file layout cannot be properly interpreted by multiboot protocols family. In theory there is a chance that we could build proper PE file (from multiboot protocols POV) using current build system. However, it means that xen.efi further diverge from Xen ELF file (in terms of contents and build method). On the other hand ELF has all needed properties. So, it means that this is good starting point for further development. Additionally, I think that this is also good starting point for further xen.efi code and build optimizations. It looks that there is a chance that finally we can generate xen.efi directly from Xen ELF using just simple objcopy or other tool. This way we will have one Xen binary which can be loaded by three boot protocols: EFI native loader, multiboot (v1) and multiboot2. Signed-off-by: Daniel Kiper Acked-by: Jan Beulich --- v6 - suggestions/fixes: - improve efi_enabled() checks in efi_runtime_call() (suggested by Jan Beulich). v5 - suggestions/fixes: - properly calculate efi symbol address in xen/arch/x86/xen.lds.S (I hope that this change does not invalidate Jan's ACK). v4 - suggestions/fixes: - functions should return -ENOSYS instead of -EOPNOTSUPP if EFI runtime services are not available (suggested by Jan Beulich), - remove stale bits from xen/arch/x86/Makefile (suggested by Jan Beulich). v3 - suggestions/fixes: - check for EFI platform in EFI code (suggested by Jan Beulich), - fix Makefiles (suggested by Jan Beulich), - improve commit message (suggested by Jan Beulich). v2 - suggestions/fixes: - build EFI code only if it is supported in a given build environment (suggested by Jan Beulich). --- xen/arch/x86/Makefile | 2 +- xen/arch/x86/efi/Makefile | 12 ++++-------- xen/arch/x86/xen.lds.S | 4 ++-- xen/common/efi/boot.c | 3 +++ xen/common/efi/runtime.c | 9 +++++++++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 8e003ff..3972dd5 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -219,6 +219,6 @@ efi/mkreloc: efi/mkreloc.c clean:: rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32 rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d - rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.o efi/.*.d efi/*.efi efi/disabled efi/mkreloc + rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/disabled efi/mkreloc rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin rm -f note.o diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile index ad3fdf7..442f3fc 100644 --- a/xen/arch/x86/efi/Makefile +++ b/xen/arch/x86/efi/Makefile @@ -1,18 +1,14 @@ CFLAGS += -fshort-wchar -obj-y += stub.o - -create = test -e $(1) || touch -t 199901010000 $(1) - efi := y$(shell rm -f disabled) efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y)) efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y)) -efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o))) - -extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o buildid.o +efi := $(if $(efi),$(shell rm disabled)y) %.o: %.ihex $(OBJCOPY) -I ihex -O binary $< $@ -stub.o: $(extra-y) +obj-y := stub.o +obj-$(efi) := boot.init.o compat.o relocs-dummy.o runtime.o +extra-$(efi) += buildid.o nogcov-$(efi) += stub.o diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 7676de9..b0b1c9b 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -270,10 +270,10 @@ SECTIONS .pad : { . = ALIGN(MB(16)); } :text -#else - efi = .; #endif + efi = DEFINED(efi) ? efi : .; + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 56544dc..1ef5d0b 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1251,6 +1251,9 @@ void __init efi_init_memory(void) } *extra, *extra_head = NULL; #endif + if ( !efi_enabled(EFI_BOOT) ) + return; + printk(XENLOG_INFO "EFI memory map:%s\n", map_bs ? " (mapping BootServices)" : ""); for ( i = 0; i < efi_memmap_size; i += efi_mdesc_size ) diff --git a/xen/common/efi/runtime.c b/xen/common/efi/runtime.c index 5f2de80..41f49f7 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -174,6 +174,9 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info) { unsigned int i, n; + if ( !efi_enabled(EFI_BOOT) ) + return -ENOSYS; + switch ( idx ) { case XEN_FW_EFI_VERSION: @@ -308,6 +311,12 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op) EFI_STATUS status = EFI_NOT_STARTED; int rc = 0; + if ( !efi_enabled(EFI_BOOT) ) + return -ENOSYS; + + if ( !efi_enabled(EFI_RS) ) + return -EOPNOTSUPP; + switch ( op->function ) { case XEN_EFI_get_time: