From patchwork Wed Jan 18 14:16:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Goldstein X-Patchwork-Id: 9523969 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 278446020A for ; Wed, 18 Jan 2017 14:19:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A4228553 for ; Wed, 18 Jan 2017 14:19:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AB6D285F5; Wed, 18 Jan 2017 14:19:45 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 7468E28553 for ; Wed, 18 Jan 2017 14:19:44 +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 1cTr3D-00070K-Fp; Wed, 18 Jan 2017 14:17:23 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cTr3B-000702-IA for xen-devel@lists.xen.org; Wed, 18 Jan 2017 14:17:21 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 95/A5-25337-0F87F785; Wed, 18 Jan 2017 14:17:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRWlGSWpSXmKPExsVyMXThEd0PFfU RBl9Oc1ss+biYxYHR4+ju30wBjFGsmXlJ+RUJrBlPV05iK1isU9Gz+wJbA+NClS5GLg4hgQmM EovPPmHuYuTkYBHYzywxd38mSEJCYBmrxJ1bB9hBEhICMRJt534yQdhVEs+6f7KB2EICChK/J xxigpi0jEli+6RjYAk2AQ2JJ79mgNkiAtIS1z5fZgQpYhZ4wiSxYt97sKnCAuYST7bsZIFYrS rRcOMDI4jNKxAnserhdhaIbfISC88fAdvMKZAq8fkQRFxIIEXiYs97nOITGIUWMDKsYtQoTi0 qSy3SNbTQSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87P3cQIDEYGINjBeHNjwCFGSQ4m JVHe5Vb1EUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeNeXA+UEi1LTUyvSMnOAcQGTluDgURLhn QuS5i0uSMwtzkyHSJ1iNObo6Tr9koljz67LL5mEWPLy81KlxHlPgpQKgJRmlObBDYLF6yVGWS lhXkag04R4ClKLcjNLUOVfMYpzMCoJ824AmcKTmVcCt+8V0ClMQKdYKYOdUpKIkJJqYHQ0iVn /Yz9Tb8nhWQbHJbd1eNo2+C1eynr0Q5Txj9kzXt/+/fcz/4aQ1TpfN5VJnjsY0Nmrbflr5okZ 4mFBNpNKbmzPLW5dcHDp/p5evewdu6+GCzsp7ugU2/orzyaM6YDWVNWTX4UsLI9fXHA8Y9E2z 3mT5O1cMxIiTte/OcLlbHRdQ9bC5a0SS3FGoqEWc1FxIgDWaM790gIAAA== X-Env-Sender: cardoe@cardoe.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1484749039!77033634!1 X-Originating-IP: [209.85.161.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58653 invoked from network); 18 Jan 2017 14:17:20 -0000 Received: from mail-yw0-f196.google.com (HELO mail-yw0-f196.google.com) (209.85.161.196) by server-5.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Jan 2017 14:17:20 -0000 Received: by mail-yw0-f196.google.com with SMTP id 17so1090394ywk.2 for ; Wed, 18 Jan 2017 06:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cardoe.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=RRKOV3xd8sKPOJq/Co9jRv9M6sNvoAGuUTdRMoSXIKk=; b=ThIIeNJHugkNA2neyQITRh40WDsHDXvNN9RvTYROFXa5Cu3KR6UAoEfJ+RktFkNXf3 66kqbPzuTy/2xHfMoCpiSzLfd/N4Rj0Zof5LjgLaGq97MHvecco/KUss5ho901bqZHAN be0FD5WVLwnkykbCWi01cxeVJMi2sZ2UivkTo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=RRKOV3xd8sKPOJq/Co9jRv9M6sNvoAGuUTdRMoSXIKk=; b=M1Piryrw/C+v1aYQNwKDWiLmQEjQEunf9Hj2b0hOb8To0qbaJYfdmBsG8XPGWvsSux BpoTR8KiU6QRl/5iZX/O9ED2IeC7L9fwMJPhFsfd+wW7n4gkZZ0QFLwI4F6txTm3KznA acM2I58D3Sb8R7p/9/pPEpHKejzM0n4lBj/HGK1GV5MYzKm5gHaSeZi+hTUGN6ITsdPB ZiqjhKc1p8X9IiBfXw4yo9LU9McFkhWWC9cR56vBSy/LWw/VZh15CmJeNiN3zmCK12lm 5Xm4RTyuAGfXT+UykcLnkTIBX0m5VDrIH4RxOkE62AWdFXaS20+APg38dIAJsrEXFIbK Bo+g== X-Gm-Message-State: AIkVDXKtp6W5bGZQEY29i6MiqY3mTaO7BDgTV3EPmdjDQBIhbnzGRoHY6cjSnQUftC8efA== X-Received: by 10.13.229.133 with SMTP id o127mr2683544ywe.36.1484749038780; Wed, 18 Jan 2017 06:17:18 -0800 (PST) Received: from swanson.attlocal.net (104-179-196-18.lightspeed.brhmal.sbcglobal.net. [104.179.196.18]) by smtp.gmail.com with ESMTPSA id d4sm177888ywg.38.2017.01.18.06.17.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 06:17:18 -0800 (PST) From: Doug Goldstein To: xen-devel@lists.xen.org Date: Wed, 18 Jan 2017 08:16:59 -0600 Message-Id: <6d0733a6d4e6e5663945c9b001405fe9a06c106f.1484748781.git-series.cardoe@cardoe.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: References: In-Reply-To: References: Cc: jgross@suse.com, sstabellini@kernel.org, konrad.wilk@oracle.com, Andrew Cooper , Daniel Kiper , Doug Goldstein , pgnet.dev@gmail.com, ning.sun@intel.com, julien.grall@arm.com, Jan Beulich , qiaowei.ren@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v4 2/5] 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 From: Daniel Kiper 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 Reviewed-by: Doug Goldstein --- 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 7f6b5d7..2e22cdf 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 3e5e4ab..df8c702 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 8c44835..25323de 100644 --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -196,6 +196,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: @@ -331,6 +334,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: