Skip to contentSkip to conversation

Make OVMF work with Xen

PATCH In review Wei Liu 3 participants 9 messages Dec 5, 2013 – Dec 6, 2013

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v5 cover Make OVMF work with Xen

This is version 5 of Xen side patches. Patches that have been applied are not resent.

Two patches to build system are added to this series.

Still waiting for OVMF side patches to get merged. The main purpose for sending this series is to let people review the newly added build system patches.

Wei.

Changes in V5:
* add patches for build system

Changes in V4:
* go back to dedicated OVMF info structure, 64 bit ready

Changes in V3:
* move seabios_info to common code
* e820 entry number is 16 again, one can bump it when necessary
* reserve low reset vector in E820 map in OVMF

Changes in V2:
* ovmf_info is now almost the same as seabios_info
* bump e820 entry number to 128
* modify build_e820_table to avoid BIOS region reservation if there's none

Wei Liu (4):
hvmloader/ovmf: setup ovmf_info
hvmloader/ovmf: setup E820 map
tools: enable OVMF build for Linux by default tools/ovmf-makefile: only build debug target when specified

 tools/configure                 |   24 ++++++++-------
 tools/configure.ac              |   17 ++++++++++-
 tools/firmware/hvmloader/ovmf.c |   61 +++++++++++++++++++++++++++++++++++++--
 tools/firmware/ovmf-makefile    |   19 ++++++++----
 4 files changed, 101 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH v5 1/4 hvmloader/ovmf: setup ovmf_info

OVMF info contains E820 map allocated by hvmloader. This info is passed to OVMF to help it do proper initialization.

Currently only E820 is necessary, but we reserve spaces for other tables in ovmf_info for later usage.

---
 tools/firmware/hvmloader/ovmf.c |   48 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)
tools/firmware/hvmloader/ovmf.c +46 -2
index a67a2de..d50e2b2 100644
@@ -46,10 +46,54 @@
 #define LOWCHUNK_SIZE           0x00010000
 #define LOWCHUNK_MAXOFFSET      0x0000FFFF
 #define LOWCHUNK_END            (OVMF_BEGIN + OVMF_SIZE)
+#define OVMF_INFO_PHYSICAL_ADDRESS 0x00001000
 
 extern unsigned char dsdt_anycpu[];
 extern int dsdt_anycpu_len;
 
+#define OVMF_INFO_MAX_TABLES 4
+struct ovmf_info {
+    char signature[14]; /* XenHVMOVMF\0\0\0\0 */
+    uint8_t length;     /* Length of this struct */
+    uint8_t checksum;   /* Set such that the sum over bytes 0..length == 0 */
+    /*
+     * Physical address of an array of tables_nr elements.
+     *
+     * Each element is a 64 bit value containing the physical address
+     * of a BIOS table.
+     */
+    uint64_t tables;
+    uint32_t tables_nr;
+    /*
+     * Physical address of the e820 table, contains e820_nr entries.
+     */
+    uint64_t e820;
+    uint32_t e820_nr;
+} __attribute__ ((packed));
+
+static void ovmf_setup_bios_info(void)
+{
+    struct ovmf_info *info = (void *)OVMF_INFO_PHYSICAL_ADDRESS;
+
+    memset(info, 0, sizeof(*info));
+
+    memcpy(info->signature, "XenHVMOVMF", sizeof(info->signature));
+    info->length = sizeof(*info);
+}
+
+static void ovmf_finish_bios_info(void)
+{
+    struct ovmf_info *info = (void *)OVMF_INFO_PHYSICAL_ADDRESS;
+    uint32_t i;
+    uint8_t checksum;
+
+    checksum = 0;
+    for ( i = 0; i < info->length; i++ )
+        checksum += ((uint8_t *)(info))[i];
+
+    info->checksum = -checksum;
+}
+
 static void ovmf_load(const struct bios_config *config)
 {
     xen_pfn_t mfn;
@@ -104,8 +148,8 @@ struct bios_config ovmf_config =  {
 
     .load_roms = 0,
 
-    .bios_info_setup = NULL,
-    .bios_info_finish = NULL,
+    .bios_info_setup = ovmf_setup_bios_info,
+    .bios_info_finish = ovmf_finish_bios_info,
 
     .e820_setup = NULL,
 
Signature · 1 line
1.7.10.4
author
#2 lore raw

PATCH v5 2/4 hvmloader/ovmf: setup E820 map

In reply to Wei Liu

E820 map will be used by OVMF to create memory map.

---
 tools/firmware/hvmloader/ovmf.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/ovmf.c +12 -1
index d50e2b2..28dd7bc 100644
@@ -137,6 +137,17 @@ static void ovmf_create_smbios_tables(void)
         SMBIOS_PHYSICAL_END);
 }
 
+static void ovmf_setup_e820(void)
+{
+    struct ovmf_info *info = (void *)OVMF_INFO_PHYSICAL_ADDRESS;
+    struct e820entry *e820 = scratch_alloc(sizeof(struct e820entry)*16, 0);
+    info->e820 = (uint32_t)e820;
+
+    /* Reserve LOWCHUNK_BEGIN to 0x100000 as well, that's reset vector. */
+    info->e820_nr = build_e820_table(e820, 0, LOWCHUNK_BEGIN);
+    dump_e820_table(e820, info->e820_nr);
+}
+
 struct bios_config ovmf_config =  {
     .name = "OVMF",
 
@@ -151,7 +162,7 @@ struct bios_config ovmf_config =  {
     .bios_info_setup = ovmf_setup_bios_info,
     .bios_info_finish = ovmf_finish_bios_info,
 
-    .e820_setup = NULL,
+    .e820_setup = ovmf_setup_e820,
 
     .acpi_build_tables = ovmf_acpi_build_tables,
     .create_mp_tables = NULL,
Signature · 1 line
1.7.10.4
author
#3 lore raw

PATCH v5 3/4 tools: enable OVMF build for Linux by default

In reply to Wei Liu

Now OVMF can build on Linux, but not NetBSD. I suspect it won't build on FreeBSD either. Even if we fix OVMF build script, it requires upstream QEMU, which to the best of my knowledge is not available in *BSD Xen build at the moment. So the simple thing to do is to only enable OVMF build for Linux.

Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Roger Pau Monne <[email protected]>
---
 tools/configure    |   24 +++++++++++++-----------
 tools/configure.ac |   17 ++++++++++++++++-
 2 files changed, 29 insertions(+), 12 deletions(-)
tools/configure +13 -11
index ff82b32..0bcc922 100755
@@ -1422,7 +1422,8 @@ Optional Features:
   --enable-xenapi         Enable Xen API Bindings (default is DISABLED)
   --disable-ocamltools    Disable Ocaml tools (default is ENABLED)
   --disable-xsmpolicy     Disable XSM policy compilation (default is ENABLED)
-  --enable-ovmf           Enable OVMF (default is DISABLED)
+  --enable-ovmf           Enable OVMF build, (DEFAULT is on for Linux,
+                          otherwise off)
   --disable-rombios       Disable ROM BIOS (default is ENABLED)
   --disable-seabios       Disable SeaBIOS (default is ENABLED)
   --disable-debug         Disable debug build of tools (default is ENABLED)
@@ -3571,23 +3572,24 @@ xsmpolicy=$ax_cv_xsmpolicy
 # Check whether --enable-ovmf was given.
 if test "${enable_ovmf+set}" = set; then :
   enableval=$enable_ovmf;
-fi
-
-
-if test "x$enable_ovmf" = "xno"; then :
+else
 
-    ax_cv_ovmf="n"
+    case $host_os in
+        linux*)
+           enable_ovmf="yes";;
+        *) enable_ovmf="no";;
+    esac
 
-elif test "x$enable_ovmf" = "xyes"; then :
+fi
 
-    ax_cv_ovmf="y"
+if test "x$enable_ovmf" = "xyes"; then :
 
-elif test -z $ax_cv_ovmf; then :
+    ovmf=y
+else
 
-    ax_cv_ovmf="n"
+    ovmf=n
 
 fi
-ovmf=$ax_cv_ovmf
 
 
 
tools/configure.ac +16 -1
index b2941a4..c317932 100644
@@ -53,7 +53,22 @@ AX_ARG_DEFAULT_ENABLE([monitors], [Disable xenstat and xentop monitoring tools])
 AX_ARG_DEFAULT_DISABLE([xenapi], [Enable Xen API Bindings])
 AX_ARG_DEFAULT_ENABLE([ocamltools], [Disable Ocaml tools])
 AX_ARG_DEFAULT_ENABLE([xsmpolicy], [Disable XSM policy compilation])
-AX_ARG_DEFAULT_DISABLE([ovmf], [Enable OVMF])
+
+AC_ARG_ENABLE([ovmf],
+    AS_HELP_STRING([--enable-ovmf],
+                   [Enable OVMF build, (DEFAULT is on for Linux, otherwise off)]),,[
+    case $host_os in
+        linux*)
+           enable_ovmf="yes";;
+        *) enable_ovmf="no";;
+    esac
+])
+AS_IF([test "x$enable_ovmf" = "xyes"], [
+    ovmf=y],[
+    ovmf=n
+])
+AC_SUBST(ovmf)
+
 AX_ARG_DEFAULT_ENABLE([rombios], [Disable ROM BIOS])
 AX_ARG_DEFAULT_ENABLE([seabios], [Disable SeaBIOS])
 AX_ARG_DEFAULT_ENABLE([debug], [Disable debug build of tools])
Signature · 1 line
1.7.10.4
author
#4 lore raw

PATCH v5 4/4 tools/ovmf-makefile: only build debug target when specified

In reply to Wei Liu
---
 tools/firmware/ovmf-makefile |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
tools/firmware/ovmf-makefile +14 -5
index 073ed44..1ad041f 100644
@@ -1,16 +1,25 @@
 # OVMF building system is not ready yet to run in parallel.
 # Force it to be serial in order to exploit parallelism for neighbors.
 
+XEN_ROOT=$(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+ifeq ($(debug),y)
+TARGET=DEBUG
+else
+TARGET=RELEASE
+endif
+
 .NOTPARALLEL:
 MAKEFLAGS  += -j1
 
 .PHONY: all
-all: ovmf.bin
+all: build
 
-.PHONY: ovmf.bin
-ovmf.bin:
-	OvmfPkg/build.sh -a X64
-	cp Build/OvmfX64/DEBUG_GCC*/FV/OVMF.fd ovmf.bin
+.PHONY: build
+build:
+	OvmfPkg/build.sh -a X64 -b $(TARGET)
+	cp Build/OvmfX64/$(TARGET)_GCC*/FV/OVMF.fd ovmf.bin
 
 .PHONY: clean
 clean:
Signature · 1 line
1.7.10.4
Acked-by on the v5 series
#5 lore raw
In reply to Wei Liu
Quoted 7 lines · Wei Liu

This is version 5 of Xen side patches. Patches that have been applied are not resent.

Two patches to build system are added to this series.

Still waiting for OVMF side patches to get merged. The main purpose for sending this series is to let people review the newly added build system patches.

I'd already acked #2, the other 3 are now:

(you forgot to CC the maintainers and George, I've done it here)

Quoted 31 lines

Wei.

Changes in V5:
* add patches for build system

Changes in V4:
* go back to dedicated OVMF info structure, 64 bit ready

Changes in V3:
* move seabios_info to common code
* e820 entry number is 16 again, one can bump it when necessary
* reserve low reset vector in E820 map in OVMF

Changes in V2:
* ovmf_info is now almost the same as seabios_info
* bump e820 entry number to 128
* modify build_e820_table to avoid BIOS region reservation if there's none

Wei Liu (4):
hvmloader/ovmf: setup ovmf_info
hvmloader/ovmf: setup E820 map
tools: enable OVMF build for Linux by default tools/ovmf-makefile: only build debug target when specified

 tools/configure                 |   24 ++++++++-------
 tools/configure.ac              |   17 ++++++++++-
 tools/firmware/hvmloader/ovmf.c |   61 +++++++++++++++++++++++++++++++++++++--
 tools/firmware/ovmf-makefile    |   19 ++++++++----
 4 files changed, 101 insertions(+), 20 deletions(-)
#6 lore raw
In reply to Wei Liu

Il 05/12/2013 18:29, Wei Liu ha scritto:

Quoted 32 lines

This is version 5 of Xen side patches. Patches that have been applied are not resent.

Two patches to build system are added to this series.

Still waiting for OVMF side patches to get merged. The main purpose for sending this series is to let people review the newly added build system patches.

Wei.

Changes in V5:
* add patches for build system

Changes in V4:
* go back to dedicated OVMF info structure, 64 bit ready

Changes in V3:
* move seabios_info to common code
* e820 entry number is 16 again, one can bump it when necessary
* reserve low reset vector in E820 map in OVMF

Changes in V2:
* ovmf_info is now almost the same as seabios_info
* bump e820 entry number to 128
* modify build_e820_table to avoid BIOS region reservation if there's none

Wei Liu (4):
hvmloader/ovmf: setup ovmf_info
hvmloader/ovmf: setup E820 map
tools: enable OVMF build for Linux by default tools/ovmf-makefile: only build debug target when specified

Quoted 6 lines
  tools/configure                 |   24 ++++++++-------
  tools/configure.ac              |   17 ++++++++++-
  tools/firmware/hvmloader/ovmf.c |   61 +++++++++++++++++++++++++++++++++++++--
  tools/firmware/ovmf-makefile    |   19 ++++++++----
  4 files changed, 101 insertions(+), 20 deletions(-)

Is "libxl: bump LIBXL_MAXMEM_CONSTANT to 2048" patch no longer needed?

Thanks for any reply.

author
#7 lore raw
Quoted 33 lines · Fabio Fantoni

Il 05/12/2013 18:29, Wei Liu ha scritto:

Quoted 32 lines

This is version 5 of Xen side patches. Patches that have been applied are not resent.

Two patches to build system are added to this series.

Still waiting for OVMF side patches to get merged. The main purpose for sending this series is to let people review the newly added build system patches.

Wei.

Changes in V5:
* add patches for build system

Changes in V4:
* go back to dedicated OVMF info structure, 64 bit ready

Changes in V3:
* move seabios_info to common code
* e820 entry number is 16 again, one can bump it when necessary
* reserve low reset vector in E820 map in OVMF

Changes in V2:
* ovmf_info is now almost the same as seabios_info
* bump e820 entry number to 128
* modify build_e820_table to avoid BIOS region reservation if there's none

Wei Liu (4):
hvmloader/ovmf: setup ovmf_info
hvmloader/ovmf: setup E820 map
tools: enable OVMF build for Linux by default tools/ovmf-makefile: only build debug target when specified

Quoted 9 lines
Quoted 6 lines
 tools/configure                 |   24 ++++++++-------
 tools/configure.ac              |   17 ++++++++++-
 tools/firmware/hvmloader/ovmf.c |   61 +++++++++++++++++++++++++++++++++++++--
 tools/firmware/ovmf-makefile    |   19 ++++++++----
 4 files changed, 101 insertions(+), 20 deletions(-)

Is "libxl: bump LIBXL_MAXMEM_CONSTANT to 2048" patch no longer needed?

No, it's not necessary anymore.

Wei.

Quoted 1 line

Thanks for any reply.

#8 lore raw
In reply to Wei Liu
Quoted 7 lines · Wei Liu

This is version 5 of Xen side patches. Patches that have been applied are not resent.

Two patches to build system are added to this series.

Still waiting for OVMF side patches to get merged. The main purpose for sending this series is to let people review the newly added build system patches.

As discussed in the 4.4 dev update thread I've applied #1, #2 and #4 leaving #3 (tools: enable OVMF build for Linux by default) until the OVMF side is committed upstream.