All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: xen-devel@lists.xen.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v3 05/16] libxl: Load guest BIOS from file
Date: Thu, 25 Feb 2016 14:56:03 +0000	[thread overview]
Message-ID: <1456412174-20162-6-git-send-email-anthony.perard@citrix.com> (raw)
In-Reply-To: <1456412174-20162-1-git-send-email-anthony.perard@citrix.com>

The path to the BIOS blob can be override by the xl's bios_override option,
or provided by u.hvm.bios_firmware in the domain_build_info struct by other
libxl user.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

---
Change in V3:
- move seabios_path and ovmf_path to libxl_path.c (with renaming)
- fix some coding style
- warn for empty file
- remove rombios stuff (will still be built-in hvmloader)
- rename field bios_filename in domain_build_info to bios_firmware to
  follow naming of acpi and smbios.
- log an error after libxl_read_file_contents() only when it return ENOENT
- return an error on empty file.
- added #define LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE
---
 tools/libxl/libxl.h          |  8 +++++++
 tools/libxl/libxl_dom.c      | 57 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  2 ++
 tools/libxl/libxl_paths.c    | 10 ++++++++
 tools/libxl/libxl_types.idl  |  1 +
 tools/libxl/xl_cmdimpl.c     | 11 ++++++---
 6 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index fa87f53..d223c35 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -876,6 +876,14 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);
  */
 #define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1
 
+/*
+ * LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE
+ *
+ * libxl_domain_build_info has u.hvm.bios_firmware field which can be use
+ * to provide a different bios blob (like SeaBIOS or OVMF).
+ */
+#define LIBXL_HAVE_BUILDINFO_HVM_BIOS_FIRMWARE
+
 typedef char **libxl_string_list;
 void libxl_string_list_dispose(libxl_string_list *sl);
 int libxl_string_list_length(const libxl_string_list *sl);
diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
index 2269998..50abfbc 100644
--- a/tools/libxl/libxl_dom.c
+++ b/tools/libxl/libxl_dom.c
@@ -863,6 +863,38 @@ err:
     return ret;
 }
 
+static int libxl__load_hvm_firmware_module(libxl__gc *gc,
+                                           const char *filename,
+                                           const char *what,
+                                           struct xc_hvm_firmware_module *m)
+{
+    int datalen = 0;
+    void *data = NULL;
+    int e;
+
+    LOG(DEBUG, "Loading %s: %s", what, filename);
+    e = libxl_read_file_contents(CTX, filename, &data, &datalen);
+    if (e) {
+        /*
+         * Print a message only on ENOENT, other error are logged by the
+         * function libxl_read_file_contents().
+         */
+        if (e == ENOENT)
+            LOGEV(ERROR, e, "failed to read %s file", what);
+        return ERROR_FAIL;
+    }
+    libxl__ptr_add(gc, data);
+    if (datalen) {
+        /* Only accept non-empty files */
+        m->data = data;
+        m->length = datalen;
+    } else {
+        LOG(ERROR, "file %s for %s is empty", filename, what);
+        return ERROR_FAIL;
+    }
+    return 0;
+}
+
 static int libxl__domain_firmware(libxl__gc *gc,
                                   libxl_domain_build_info *info,
                                   struct xc_dom_image *dom)
@@ -872,6 +904,7 @@ static int libxl__domain_firmware(libxl__gc *gc,
     int e, rc;
     int datalen = 0;
     void *data;
+    const char *bios_filename = NULL;
 
     if (info->u.hvm.firmware)
         firmware = info->u.hvm.firmware;
@@ -915,6 +948,30 @@ static int libxl__domain_firmware(libxl__gc *gc,
         goto out;
     }
 
+    if (info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
+        if (info->u.hvm.bios_firmware) {
+            bios_filename = info->u.hvm.bios_firmware;
+        } else {
+            switch (info->u.hvm.bios) {
+            case LIBXL_BIOS_TYPE_SEABIOS:
+                bios_filename = libxl__seabios_path();
+                break;
+            case LIBXL_BIOS_TYPE_OVMF:
+                bios_filename = libxl__ovmf_path();
+                break;
+            case LIBXL_BIOS_TYPE_ROMBIOS:
+            default:
+                abort();
+            }
+        }
+    }
+
+    if (bios_filename) {
+        rc = libxl__load_hvm_firmware_module(gc, bios_filename, "BIOS",
+                                             &dom->bios_module);
+        if (rc) goto out;
+    }
+
     if (info->u.hvm.smbios_firmware) {
         data = NULL;
         e = libxl_read_file_contents(ctx, info->u.hvm.smbios_firmware,
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 650a958..0dbff27 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2265,6 +2265,8 @@ _hidden const char *libxl__xen_config_dir_path(void);
 _hidden const char *libxl__xen_script_dir_path(void);
 _hidden const char *libxl__lock_dir_path(void);
 _hidden const char *libxl__run_dir_path(void);
+_hidden const char *libxl__seabios_path(void);
+_hidden const char *libxl__ovmf_path(void);
 
 /*----- subprocess execution with timeout -----*/
 
diff --git a/tools/libxl/libxl_paths.c b/tools/libxl/libxl_paths.c
index 9b7b0d5..6972b90 100644
--- a/tools/libxl/libxl_paths.c
+++ b/tools/libxl/libxl_paths.c
@@ -35,6 +35,16 @@ const char *libxl__run_dir_path(void)
     return XEN_RUN_DIR;
 }
 
+const char *libxl__seabios_path(void)
+{
+    return SEABIOS_PATH;
+}
+
+const char *libxl__ovmf_path(void)
+{
+    return OVMF_PATH;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 9ad7eba..95bacd2 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -487,6 +487,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                        ("timer_mode",       libxl_timer_mode),
                                        ("nested_hvm",       libxl_defbool),
                                        ("altp2m",           libxl_defbool),
+                                       ("bios_firmware",    string),
                                        ("smbios_firmware",  string),
                                        ("acpi_firmware",    string),
                                        ("hdtype",           libxl_hdtype),
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index f40af51..201cff6 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1500,12 +1500,17 @@ static void parse_config_data(const char *config_source,
 
         xlu_cfg_replace_string (config, "firmware_override",
                                 &b_info->u.hvm.firmware, 0);
-        if (!xlu_cfg_get_string(config, "bios", &buf, 0) &&
-            libxl_bios_type_from_string(buf, &b_info->u.hvm.bios)) {
+        xlu_cfg_replace_string (config, "bios_override",
+                                &b_info->u.hvm.bios_firmware, 0);
+        if (!xlu_cfg_get_string(config, "bios", &buf, 0)) {
+            if (libxl_bios_type_from_string(buf, &b_info->u.hvm.bios)) {
                 fprintf(stderr, "ERROR: invalid value \"%s\" for \"bios\"\n",
                     buf);
                 exit (1);
-        }
+            }
+        } else if (b_info->u.hvm.bios_firmware)
+            fprintf(stderr, "WARNING: "
+                    "bios_override given without specific bios name\n");
 
         xlu_cfg_get_defbool(config, "pae", &b_info->u.hvm.pae, 0);
         xlu_cfg_get_defbool(config, "apic", &b_info->u.hvm.apic, 0);
-- 
Anthony PERARD


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

  parent reply	other threads:[~2016-02-25 14:56 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 14:55 [PATCH v3 00/16] Load BIOS via toolstack instead of been embedded in hvmloader Anthony PERARD
2016-02-25 14:55 ` [PATCH v3 01/16] libxc: Rework extra module initialisation Anthony PERARD
2016-03-01 11:51   ` Wei Liu
2016-03-03 16:27     ` Anthony PERARD
2016-02-25 14:56 ` [PATCH v3 02/16] libxc: Load BIOS and ACPI table into guest memory Anthony PERARD
2016-03-01 11:51   ` Wei Liu
2016-03-03 16:57     ` Anthony PERARD
2016-02-25 14:56 ` [PATCH v3 03/16] configure: #define SEABIOS_PATH and OVMF_PATH Anthony PERARD
2016-03-01 11:51   ` Wei Liu
2016-03-03 17:03     ` Anthony PERARD
2016-03-08 15:55       ` Wei Liu
2016-02-25 14:56 ` [PATCH v3 04/16] firmware/makefile: install BIOS and ACPI blob Anthony PERARD
2016-02-29 16:31   ` Jan Beulich
2016-03-03 15:44     ` Anthony PERARD
2016-02-25 14:56 ` Anthony PERARD [this message]
2016-03-01 11:51   ` [PATCH v3 05/16] libxl: Load guest BIOS from file Wei Liu
2016-03-03 17:16     ` Anthony PERARD
2016-02-25 14:56 ` [PATCH v3 06/16] libxl: Load guest ACPI table " Anthony PERARD
2016-03-01 11:51   ` Wei Liu
2016-03-03 17:12     ` Anthony PERARD
2016-03-08 15:55       ` Wei Liu
2016-02-25 14:56 ` [PATCH v3 07/16] hvmloader: Grab the hvm_start_info pointer Anthony PERARD
2016-02-29 16:37   ` Jan Beulich
2016-02-29 16:48     ` Jan Beulich
2016-02-25 14:56 ` [PATCH v3 08/16] hvmloader: Locate the BIOS blob Anthony PERARD
2016-02-29 16:56   ` Jan Beulich
2016-03-03 16:21     ` Anthony PERARD
2016-02-25 14:56 ` [PATCH v3 09/16] hvmloader: Check modules whereabouts Anthony PERARD
2016-02-29 16:58   ` Jan Beulich
2016-03-03 16:00     ` Anthony PERARD
2016-03-03 16:18       ` Jan Beulich
2016-03-03 16:34       ` Andrew Cooper
2016-02-25 14:56 ` [PATCH v3 10/16] hvmloader: Load SeaBIOS from hvm_start_info modules Anthony PERARD
2016-02-29 17:02   ` Jan Beulich
2016-03-03 16:15     ` Anthony PERARD
2016-02-25 14:56 ` [PATCH v3 11/16] hvmloader: Load OVMF from modules Anthony PERARD
2016-03-01 16:03   ` Jan Beulich
2016-03-03 17:39     ` Anthony PERARD
2016-03-05 18:05       ` Wei Liu
2016-02-25 14:56 ` [PATCH v3 12/16] hvmloader: Specific bios_load function required Anthony PERARD
2016-03-01 16:07   ` Jan Beulich
2016-02-25 14:56 ` [PATCH v3 13/16] hvmloader: Load ACPI tables from hvm_start_info module Anthony PERARD
2016-03-01 16:17   ` Jan Beulich
2016-03-03 17:59     ` Anthony PERARD
2016-03-04  8:39       ` Jan Beulich
2016-03-08 11:15         ` Anthony PERARD
2016-02-25 14:56 ` [PATCH v3 14/16] hvmloader: Compile out the qemu-xen ACPI tables Anthony PERARD
2016-03-01 16:19   ` Jan Beulich
2016-02-25 14:56 ` [PATCH v3 15/16] hvmloader: Always build-in SeaBIOS and OVMF loader Anthony PERARD
2016-03-01 16:20   ` Jan Beulich
2016-02-25 14:56 ` [PATCH v3 16/16] hvmloader: do not depend on SEABIOS_PATH or OVMF_PATH Anthony PERARD
2016-03-01 16:24   ` Jan Beulich
2016-03-03 11:38   ` Wei Liu
2016-02-25 16:16 ` [PATCH v3 00/16] Load BIOS via toolstack instead of been embedded in hvmloader Boris Ostrovsky
2016-02-25 16:43   ` Anthony PERARD
2016-03-03 18:03 ` Anthony PERARD
2016-03-04 10:57   ` Andrew Cooper
2016-03-08 11:21     ` Anthony PERARD

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=1456412174-20162-6-git-send-email-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.