xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Kiper <daniel.kiper@oracle.com>
To: xen-devel@lists.xenproject.org
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: [PATCH v7 06/14] efi: build xen.gz with EFI code
Date: Fri, 23 Sep 2016 23:47:31 +0200	[thread overview]
Message-ID: <1474667259-27290-7-git-send-email-daniel.kiper@oracle.com> (raw)
In-Reply-To: <1474667259-27290-1-git-send-email-daniel.kiper@oracle.com>

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 <daniel.kiper@oracle.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
---
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 c3a8920..49d7e59 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -223,7 +223,7 @@ 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
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
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 9adb2f3..38baea3 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -267,8 +267,6 @@ SECTIONS
     *(.reloc)
   } :text
   . = ALIGN(__section_alignment__);
-#else
-  efi = .;
 #endif
 
   /* Trick the linker into setting the image size to exactly 16Mb. */
@@ -277,6 +275,8 @@ SECTIONS
     __end_of_image__ = .;
   } :text
 
+  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:
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-09-23 21:48 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-23 21:47 [PATCH v7 00/14] x86: multiboot2 protocol support Daniel Kiper
2016-09-23 21:47 ` [PATCH v7 01/14] x86: move xen ELF end of image to 16 MiB Daniel Kiper
2016-09-26 10:39   ` Jan Beulich
2016-09-26 11:34     ` Daniel Kiper
2016-09-26 12:32       ` Jan Beulich
2016-09-27 17:42         ` Daniel Kiper
2016-09-23 21:47 ` [PATCH v7 02/14] x86: properly calculate xen ELF end of image address Daniel Kiper
2016-09-26 10:45   ` Jan Beulich
2016-09-26 12:06     ` Daniel Kiper
2016-09-26 12:34       ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 03/14] x86: add multiboot2 protocol support Daniel Kiper
2016-09-26 13:18   ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 04/14] efi: create efi_enabled() Daniel Kiper
2016-09-23 21:47 ` [PATCH v7 05/14] x86: allow EFI reboot method neither on EFI platforms Daniel Kiper
2016-09-23 21:47 ` Daniel Kiper [this message]
2016-09-23 21:47 ` [PATCH RFC v7 07/14] efi: create new early memory allocator Daniel Kiper
2016-09-23 23:35   ` Julien Grall
2016-09-26  6:53     ` Jan Beulich
2016-09-26 20:01       ` Julien Grall
2016-09-27  8:06         ` Jan Beulich
2016-09-27 23:23           ` Julien Grall
2016-09-26 13:37   ` Jan Beulich
2016-09-27 17:49     ` Daniel Kiper
2016-09-28  8:48       ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 08/14] x86: add multiboot2 protocol support for EFI platforms Daniel Kiper
2016-09-26 13:47   ` Jan Beulich
2016-09-27 18:11     ` Daniel Kiper
2016-09-28  8:57       ` Jan Beulich
2016-09-28  9:39         ` Daniel Kiper
2016-09-28 10:16           ` Jan Beulich
2016-09-26 14:19   ` Andrew Cooper
2016-09-26 14:33     ` Jan Beulich
2016-09-26 14:40       ` Andrew Cooper
2016-09-26 15:12         ` Jan Beulich
2016-09-27 18:21           ` Daniel Kiper
2016-09-28  8:58             ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 09/14] x86/boot: implement early command line parser in C Daniel Kiper
2016-09-26 13:49   ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 10/14] x86: change default load address from 1 MiB to 2 MiB Daniel Kiper
2016-09-23 21:47 ` [PATCH v7 11/14] x86/setup: use XEN_IMG_OFFSET instead of Daniel Kiper
2016-09-23 21:47 ` [PATCH v7 12/14] x86: make Xen early boot code relocatable Daniel Kiper
2016-09-26 15:03   ` Jan Beulich
2016-09-27 19:55     ` Daniel Kiper
2016-09-28  9:06       ` Jan Beulich
2016-09-28  9:56         ` Daniel Kiper
2016-09-28 10:19           ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 13/14] x86/boot: rename sym_phys() to sym_offs() Daniel Kiper
2016-09-26 15:47   ` Jan Beulich
2016-09-23 21:47 ` [PATCH v7 14/14] x86: add multiboot2 protocol support for relocatable images Daniel Kiper
2016-09-26 15:53   ` Jan Beulich
2016-09-27 20:07     ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474667259-27290-7-git-send-email-daniel.kiper@oracle.com \
    --to=daniel.kiper@oracle.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=cardoe@cardoe.com \
    --cc=david.vrabel@citrix.com \
    --cc=fu.wei@linaro.org \
    --cc=gang.wei@intel.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=julien.grall@arm.com \
    --cc=ning.sun@intel.com \
    --cc=pgnet.dev@gmail.com \
    --cc=qiaowei.ren@intel.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).