From: Chao Peng <chao.p.peng@linux.intel.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
gor Mammedov <imammedo@redhat.com>,
Xiao Guangrong <guangrong.xiao@linux.intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>,
Eduardo Habkost <ehabkost@redhat.com>,
Haozhong Zhang <haozhong.zhang@intel.com>
Subject: [Qemu-devel] [RFC PATCH v2 12/12] pc: skip firmware
Date: Thu, 25 Aug 2016 06:15:05 -0400 [thread overview]
Message-ID: <1472120105-29235-13-git-send-email-chao.p.peng@linux.intel.com> (raw)
In-Reply-To: <1472120105-29235-1-git-send-email-chao.p.peng@linux.intel.com>
An ELF format kernel must be specified. Only linux is supported.
Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
---
hw/i386/pc.c | 92 ++++++++++++++++++++++++++++++++++++++--------------
include/hw/i386/pc.h | 2 ++
2 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4a368de..1362810 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -974,8 +974,43 @@ struct setup_data {
uint8_t data[0];
} __attribute__((packed));
-static void load_linux(PCMachineState *pcms,
- FWCfgState *fw_cfg)
+static void load_linux_efi(PCMachineState *pcms)
+{
+ unsigned char class;
+ MachineState *machine = MACHINE(pcms);
+ FILE *file = fopen(machine->kernel_filename, "rb");
+
+ if (!file) {
+ goto err;
+ }
+
+ if (fseek(file, EI_CLASS, 0) || fread(&class, 1, 1, file) != 1) {
+ fclose(file);
+ goto err;
+ }
+ fclose(file);
+
+ if (load_elf(machine->kernel_filename, NULL, NULL, &boot_info.entry,
+ NULL, NULL, 0, EM_X86_64, 0, 0) < 0) {
+ goto err;
+ }
+
+ if (class == ELFCLASS64) {
+ boot_info.long_mode = true;
+ } else if (class != ELFCLASS32) {
+ goto err;
+ }
+
+ boot_info.protected_mode = true;
+ return;
+
+err:
+ fprintf(stderr, "qemu: could not load kernel '%s'\n",
+ machine->kernel_filename);
+ exit(1);
+}
+
+static void load_linux_bzimage(PCMachineState *pcms, FWCfgState *fw_cfg)
{
uint16_t protocol;
int setup_size, kernel_size, initrd_size = 0, cmdline_size;
@@ -1488,7 +1523,7 @@ void xen_load_linux(PCMachineState *pcms)
fw_cfg = fw_cfg_init_io(FW_CFG_IO_BASE);
rom_set_fw(fw_cfg);
- load_linux(pcms, fw_cfg);
+ load_linux_bzimage(pcms, fw_cfg);
for (i = 0; i < nb_option_roms; i++) {
assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
!strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -1506,7 +1541,7 @@ void pc_memory_init(PCMachineState *pcms,
int linux_boot, i;
MemoryRegion *ram, *option_rom_mr;
MemoryRegion *ram_below_4g, *ram_above_4g;
- FWCfgState *fw_cfg;
+ FWCfgState *fw_cfg = NULL;
MachineState *machine = MACHINE(pcms);
PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
@@ -1588,36 +1623,42 @@ void pc_memory_init(PCMachineState *pcms,
&pcms->hotplug_memory.mr);
}
- /* Initialize PC system firmware */
- pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
+ if (pcms->fw) {
+ /* Initialize PC system firmware */
+ pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
- option_rom_mr = g_malloc(sizeof(*option_rom_mr));
- memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
- &error_fatal);
- vmstate_register_ram_global(option_rom_mr);
- memory_region_add_subregion_overlap(rom_memory,
- PC_ROM_MIN_VGA,
- option_rom_mr,
- 1);
+ option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+ memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+ &error_fatal);
+ vmstate_register_ram_global(option_rom_mr);
+ memory_region_add_subregion_overlap(rom_memory,
+ PC_ROM_MIN_VGA,
+ option_rom_mr,
+ 1);
- fw_cfg = bochs_bios_init(&address_space_memory, pcms);
+ fw_cfg = bochs_bios_init(&address_space_memory, pcms);
- rom_set_fw(fw_cfg);
+ rom_set_fw(fw_cfg);
- if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) {
- uint64_t *val = g_malloc(sizeof(*val));
- PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
- uint64_t res_mem_end = pcms->hotplug_memory.base;
+ if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) {
+ uint64_t *val = g_malloc(sizeof(*val));
+ PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
+ uint64_t res_mem_end = pcms->hotplug_memory.base;
- if (!pcmc->broken_reserved_end) {
- res_mem_end += memory_region_size(&pcms->hotplug_memory.mr);
+ if (!pcmc->broken_reserved_end) {
+ res_mem_end += memory_region_size(&pcms->hotplug_memory.mr);
+ }
+ *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
+ fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
}
- *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30));
- fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val));
}
if (linux_boot) {
- load_linux(pcms, fw_cfg);
+ if (pcms->fw) {
+ load_linux_bzimage(pcms, fw_cfg);
+ } else {
+ load_linux_efi(pcms);
+ }
}
for (i = 0; i < nb_option_roms; i++) {
@@ -2347,6 +2388,7 @@ static void pc_machine_initfn(Object *obj)
PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIC, pic, true);
PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_PIT, pit, true);
PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_STATIC_PRT, static_prt, false);
+ PC_MACHINE_DEFINE_PROP_BOOL(pcms, PC_MACHINE_FW, fw, true);
}
static void pc_machine_reset(void)
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 55ab09a..f5e01e1 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -82,6 +82,7 @@ struct PCMachineState {
bool pic;
bool pit;
bool static_prt;
+ bool fw;
};
#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
@@ -95,6 +96,7 @@ struct PCMachineState {
#define PC_MACHINE_PIC "pic"
#define PC_MACHINE_PIT "pit"
#define PC_MACHINE_STATIC_PRT "static-prt"
+#define PC_MACHINE_FW "fw"
/**
* PCMachineClass:
--
1.8.3.1
next prev parent reply other threads:[~2016-08-25 10:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-25 10:14 [Qemu-devel] [RFC PATCH v2 00/12] Guest startup time optimization Chao Peng
2016-08-25 10:14 ` [Qemu-devel] [RFC PATCH v2 01/12] pc: make smbus configurable Chao Peng
2016-09-06 20:18 ` Eduardo Habkost
2016-08-25 10:14 ` [Qemu-devel] [RFC PATCH v2 02/12] pc: make sata configurable Chao Peng
2016-08-25 10:14 ` [Qemu-devel] [RFC PATCH v2 03/12] pc: make pic configurable Chao Peng
2016-08-25 10:14 ` [Qemu-devel] [RFC PATCH v2 04/12] pc: make pit configurable Chao Peng
2016-08-25 10:14 ` [Qemu-devel] [RFC PATCH v2 05/12] acpi: build static _PRT Chao Peng
2016-08-29 17:06 ` Paolo Bonzini
2016-08-25 10:14 ` [Qemu-devel] [RFC PATCH v2 06/12] acpi: expose data structurs and functions of BIOS linker loader Chao Peng
2016-08-25 10:15 ` [Qemu-devel] [RFC PATCH v2 07/12] acpi: expose acpi_checksum() Chao Peng
2016-08-25 10:15 ` [Qemu-devel] [RFC PATCH v2 08/12] acpi: patch guest ACPI when there is no firmware Chao Peng
2016-08-25 10:15 ` [Qemu-devel] [RFC PATCH v2 09/12] ich9: enable pm registers " Chao Peng
2016-08-25 10:15 ` [Qemu-devel] [RFC PATCH v2 10/12] q35: initialize MMCFG base " Chao Peng
2016-08-25 10:15 ` [Qemu-devel] [RFC PATCH v2 11/12] pc: support direct loading protected/long mode kernel Chao Peng
2016-08-25 10:15 ` Chao Peng [this message]
2016-08-29 17:08 ` [Qemu-devel] [RFC PATCH v2 12/12] pc: skip firmware Paolo Bonzini
2016-09-02 11:08 ` [Qemu-devel] [RFC PATCH v2 00/12] Guest startup time optimization Paolo Bonzini
2016-09-05 2:37 ` Michael S. Tsirkin
2016-09-06 10:48 ` Chao Peng
2016-09-06 11:53 ` Michael S. Tsirkin
2016-09-06 14:28 ` Chao Peng
2016-09-12 15:15 ` Gerd Hoffmann
2016-09-12 17:57 ` [Qemu-devel] [SeaBIOS] " Peter Stuge
2016-09-06 14:21 ` [Qemu-devel] " Paolo Bonzini
2016-09-06 14:31 ` Chao Peng
2016-09-06 14:45 ` Michael S. Tsirkin
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=1472120105-29235-13-git-send-email-chao.p.peng@linux.intel.com \
--to=chao.p.peng@linux.intel.com \
--cc=ehabkost@redhat.com \
--cc=guangrong.xiao@linux.intel.com \
--cc=haozhong.zhang@intel.com \
--cc=imammedo@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).