From: Anthony PERARD <anthony.perard@citrix.com>
To: xen-devel@lists.xen.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v5 08/14] hvmloader: Locate the BIOS blob
Date: Wed, 22 Jun 2016 18:15:39 +0100 [thread overview]
Message-ID: <20160622171545.5304-9-anthony.perard@citrix.com> (raw)
In-Reply-To: <20160622171545.5304-1-anthony.perard@citrix.com>
The BIOS blob can be found an entry called "firmware" of the modlist of
the hvm_start_info struct.
The found BIOS blob is not loaded by this patch, but only passed as
argument to bios_load() function.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Changes in V5:
- don't BUG() on module's paddr having value 0, and just skip.
- fix some coding style
- rename module name to "firmware" (was "bios")
- less use of BUG_ON in get_module_entry() and skip entries instead.
Only BUG() if the module which match name is not accessible.
Changes in V4:
- add more BUG_ON into get_module_entry(). Check that modules paddr and
size are 32bits.
Changes in V3:
- fix some codying style
- use module.cmdline to look for a module name instead of the main cmdline
from hvm_start_info.
---
tools/firmware/hvmloader/config.h | 2 +-
tools/firmware/hvmloader/hvmloader.c | 54 ++++++++++++++++++++++++++++++++++--
tools/firmware/hvmloader/ovmf.c | 3 +-
tools/firmware/hvmloader/rombios.c | 3 +-
tools/firmware/hvmloader/util.h | 2 ++
5 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h
index b838cf9..4c6d8ad 100644
--- a/tools/firmware/hvmloader/config.h
+++ b/tools/firmware/hvmloader/config.h
@@ -22,7 +22,7 @@ struct bios_config {
/* ROMS */
void (*load_roms)(void);
- void (*bios_load)(const struct bios_config *config);
+ void (*bios_load)(const struct bios_config *config, void *addr, uint32_t size);
void (*bios_info_setup)(void);
void (*bios_info_finish)(void);
diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index c45f367..7fdc847 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -253,10 +253,51 @@ static void acpi_enable_sci(void)
BUG_ON(!(pm1a_cnt_val & ACPI_PM1C_SCI_EN));
}
+const struct hvm_modlist_entry *get_module_entry(
+ const struct hvm_start_info *info,
+ const char *name)
+{
+ const struct hvm_modlist_entry *modlist =
+ (struct hvm_modlist_entry *)(uint32_t)info->modlist_paddr;
+ unsigned int i;
+
+ if ( !modlist || info->modlist_paddr > UINT_MAX)
+ return NULL;
+
+ for ( i = 0; i < info->nr_modules; i++ )
+ {
+ uint32_t module_name = modlist[i].cmdline_paddr;
+
+ /* Skip if the module or its cmdline is missing. */
+ if ( !module_name || !modlist[i].paddr )
+ continue;
+
+ /* Skip if the cmdline can not be read. */
+ if ( modlist[i].cmdline_paddr > UINT_MAX )
+ continue;
+
+ if ( !strcmp(name, (char*)module_name) )
+ {
+ if ( modlist[i].paddr > UINT_MAX || modlist[i].size > UINT_MAX ||
+ (modlist[i].paddr + modlist[i].size) > UINT_MAX )
+ {
+ printf("Can not load \"%s\" from 0x"PRIllx" (0x"PRIllx")\n",
+ name, PRIllx_arg(modlist[i].paddr),
+ PRIllx_arg(modlist[i].size));
+ BUG();
+ }
+ return &modlist[i];
+ }
+ }
+
+ return NULL;
+}
+
int main(void)
{
const struct bios_config *bios;
int acpi_enabled;
+ const struct hvm_modlist_entry *bios_module;
/* Initialise hypercall stubs with RET, rendering them no-ops. */
memset((void *)HYPERCALL_PHYSICAL_ADDRESS, 0xc3 /* RET */, PAGE_SIZE);
@@ -292,8 +333,17 @@ int main(void)
}
printf("Loading %s ...\n", bios->name);
- if ( bios->bios_load )
- bios->bios_load(bios);
+ bios_module = get_module_entry(hvm_start_info, "firmware");
+ if ( bios_module && bios->bios_load )
+ {
+ uint32_t paddr = bios_module->paddr;
+
+ bios->bios_load(bios, (void*)paddr, bios_module->size);
+ }
+ else if ( bios->bios_load )
+ {
+ bios->bios_load(bios, NULL, 0);
+ }
else
{
BUG_ON(bios->bios_address + bios->image_size >
diff --git a/tools/firmware/hvmloader/ovmf.c b/tools/firmware/hvmloader/ovmf.c
index db9fa7a..858a2d4 100644
--- a/tools/firmware/hvmloader/ovmf.c
+++ b/tools/firmware/hvmloader/ovmf.c
@@ -93,7 +93,8 @@ static void ovmf_finish_bios_info(void)
info->checksum = -checksum;
}
-static void ovmf_load(const struct bios_config *config)
+static void ovmf_load(const struct bios_config *config,
+ void *bios_addr, uint32_t bios_length)
{
xen_pfn_t mfn;
uint64_t addr = OVMF_BEGIN;
diff --git a/tools/firmware/hvmloader/rombios.c b/tools/firmware/hvmloader/rombios.c
index 1f15b94..2ded844 100644
--- a/tools/firmware/hvmloader/rombios.c
+++ b/tools/firmware/hvmloader/rombios.c
@@ -121,7 +121,8 @@ static void rombios_load_roms(void)
option_rom_phys_addr + option_rom_sz - 1);
}
-static void rombios_load(const struct bios_config *config)
+static void rombios_load(const struct bios_config *config,
+ void *unused_addr, uint32_t unused_size)
{
uint32_t bioshigh;
struct rombios_info *info;
diff --git a/tools/firmware/hvmloader/util.h b/tools/firmware/hvmloader/util.h
index 9808016..003dc71 100644
--- a/tools/firmware/hvmloader/util.h
+++ b/tools/firmware/hvmloader/util.h
@@ -34,6 +34,8 @@ enum {
#undef NULL
#define NULL ((void*)0)
+#define UINT_MAX (~0U)
+
void __assert_failed(char *assertion, char *file, int line)
__attribute__((noreturn));
#define ASSERT(p) \
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-06-22 17:15 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-22 17:15 [PATCH v5 00/14] Load BIOS via toolstack instead of been embedded in hvmloader Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 01/14] libxc: Rework extra module initialisation Anthony PERARD
2016-07-07 14:55 ` Wei Liu
2016-07-08 10:52 ` Anthony PERARD
2016-07-08 11:29 ` Wei Liu
2016-07-08 13:26 ` Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 02/14] libxc: Prepare a start info structure for hvmloader Anthony PERARD
2016-06-23 14:44 ` Boris Ostrovsky
2016-06-23 16:52 ` Anthony PERARD
2016-07-07 14:55 ` Wei Liu
2016-07-08 10:55 ` Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 03/14] configure: #define SEABIOS_PATH and OVMF_PATH Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 04/14] firmware/makefile: install BIOS blob Anthony PERARD
2016-07-07 14:55 ` Wei Liu
2016-06-22 17:15 ` [PATCH v5 05/14] libxl: Load guest BIOS from file Anthony PERARD
2016-06-24 7:23 ` Jan Beulich
2016-06-24 14:20 ` Anthony PERARD
2016-07-07 14:55 ` Wei Liu
2016-06-22 17:15 ` [PATCH v5 06/14] xen: Move the hvm_start_info C representation from libxc to public/xen.h Anthony PERARD
2016-07-07 14:55 ` Wei Liu
2016-07-07 15:07 ` Jan Beulich
2016-07-07 15:28 ` Wei Liu
2016-07-08 9:53 ` Julien Grall
2016-07-07 15:02 ` Andrew Cooper
2016-07-07 15:09 ` Jan Beulich
2016-07-07 15:12 ` Andrew Cooper
2016-06-22 17:15 ` [PATCH v5 07/14] hvmloader: Grab the hvm_start_info pointer Anthony PERARD
2016-06-22 17:15 ` Anthony PERARD [this message]
2016-06-24 7:33 ` [PATCH v5 08/14] hvmloader: Locate the BIOS blob Jan Beulich
2016-06-24 17:02 ` Anthony PERARD
2016-06-27 7:13 ` Jan Beulich
2016-06-30 15:04 ` Anthony PERARD
2016-07-01 6:40 ` Jan Beulich
2016-06-22 17:15 ` [PATCH v5 09/14] hvmloader: Check modules whereabouts in perform_tests Anthony PERARD
2016-06-24 7:44 ` Jan Beulich
2016-06-24 17:14 ` Anthony PERARD
2016-06-27 7:20 ` Jan Beulich
2016-06-22 17:15 ` [PATCH v5 10/14] hvmloader: Load SeaBIOS from hvm_start_info modules Anthony PERARD
2016-06-24 7:46 ` Jan Beulich
2016-06-22 17:15 ` [PATCH v5 11/14] hvmloader: Load OVMF from modules Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 12/14] hvmloader: bios->bios_load() now needs to be defined Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 13/14] hvmloader: Always build-in SeaBIOS and OVMF loader Anthony PERARD
2016-06-22 17:15 ` [PATCH v5 14/14] configure: do not depend on SEABIOS_PATH or OVMF_PATH 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=20160622171545.5304-9-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.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 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).