diff --git a/hw/pc.c b/hw/pc.c
index a3e8539..cf7257b 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -55,10 +55,6 @@
#define DPRINTF(fmt, ...)
#endif
-#define BIOS_FILENAME "bios.bin"
-
-#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024)
-
/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */
#define ACPI_DATA_SIZE 0x10000
#define BIOS_CFG_IOPORT 0x510
@@ -963,10 +959,8 @@ void pc_memory_init(const char *kernel_filename,
ram_addr_t below_4g_mem_size,
ram_addr_t above_4g_mem_size)
{
- char *filename;
- int ret, linux_boot, i;
- ram_addr_t ram_addr, bios_offset, option_rom_offset;
- int bios_size, isa_bios_size;
+ int linux_boot, i;
+ ram_addr_t ram_addr, option_rom_offset;
void *fw_cfg;
linux_boot = (kernel_filename != NULL);
@@ -983,44 +977,12 @@ void pc_memory_init(const char *kernel_filename,
ram_addr + below_4g_mem_size);
}
- /* BIOS load */
- if (bios_name == NULL)
- bios_name = BIOS_FILENAME;
- filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
- if (filename) {
- bios_size = get_image_size(filename);
- } else {
- bios_size = -1;
- }
- if (bios_size<= 0 ||
- (bios_size % 65536) != 0) {
- goto bios_error;
- }
- bios_offset = qemu_ram_alloc(NULL, "pc.bios", bios_size);
- ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
- if (ret != 0) {
- bios_error:
- fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
- exit(1);
- }
- if (filename) {
- qemu_free(filename);
- }
- /* map the last 128KB of the BIOS in ISA space */
- isa_bios_size = bios_size;
- if (isa_bios_size> (128 * 1024))
- isa_bios_size = 128 * 1024;
- cpu_register_physical_memory(0x100000 - isa_bios_size,
- isa_bios_size,
- (bios_offset + bios_size - isa_bios_size) |
IO_MEM_ROM);
+ /* Initialize ROM or flash ranges for PC firmware */
+ pc_system_firmware_init();
option_rom_offset = qemu_ram_alloc(NULL, "pc.rom", PC_ROM_SIZE);
cpu_register_physical_memory(PC_ROM_MIN_VGA, PC_ROM_SIZE,
option_rom_offset);
- /* map all the bios at the top of memory */
- cpu_register_physical_memory((uint32_t)(-bios_size),
- bios_size, bios_offset | IO_MEM_ROM);
-
fw_cfg = bochs_bios_init();
rom_set_fw(fw_cfg);
diff --git a/hw/pc.h b/hw/pc.h
index 6d5730b..114816d 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -238,4 +238,6 @@ static inline bool isa_ne2000_init(int base, int irq,
NICInfo *nd)
int e820_add_entry(uint64_t, uint64_t, uint32_t);
+void pc_system_firmware_init(void);
+
#endif
diff --git a/hw/pcflash.c b/hw/pcflash.c
new file mode 100644
index 0000000..514b1ed
--- /dev/null
+++ b/hw/pcflash.c
@@ -0,0 +1,130 @@
+/*
+ * QEMU PC System Flash
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "pc.h"
+#include "hw/boards.h"
+#include "loader.h"
+#include "sysemu.h"
+#include "flash.h"
+
+#define BIOS_FILENAME "bios.bin"
+
+#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024)
+
+static void pc_isa_bios_init(ram_addr_t ram_offset, int ram_size)
+{
+ int isa_bios_size;
+
+ /* map the last 128KB of the BIOS in ISA space */
+ isa_bios_size = ram_size;
+ if (isa_bios_size> (128 * 1024)) {
+ isa_bios_size = 128 * 1024;
+ }
+ ram_offset = ram_offset + ram_size - isa_bios_size;
+ cpu_register_physical_memory(0x100000 - isa_bios_size,
+ isa_bios_size,
+ ram_offset | IO_MEM_ROM);
+}
+
+static void pc_default_system_flash_init(void)
+{
+ QemuOpts *opts;
+ QEMUMachine *machine;
+ char *filename;
+
+ if (bios_name == NULL) {
+ bios_name = BIOS_FILENAME;
+ }
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+ fprintf(stderr, "ROM: %s\n", filename);
+
+ opts = drive_add(IF_PFLASH, -1, filename, "readonly=on");
+ if (opts == NULL) {
+ return;
+ }
+
+ machine = find_default_machine();
+ if (machine == NULL) {
+ return;
+ }
+
+ drive_init(opts, machine->use_scsi);
+}
+
+static void pc_system_flash_init(DriveInfo *pflash_drv)
+{
+ BlockDriverState *bdrv;
+ int64_t size;
+ target_phys_addr_t phys_addr;
+ ram_addr_t addr;
+ int sector_bits, sector_size;
+
+ bdrv = NULL;
+
+ bdrv = pflash_drv->bdrv;
+ size = bdrv_getlength(pflash_drv->bdrv);
+ sector_bits = 12;
+ sector_size = 1<< sector_bits;
+
+ if ((size % sector_size) != 0) {
+ fprintf(stderr,
+ "qemu: PC system firmware (pflash) must be a multiple of
0x%x\n",
+ sector_size);
+ exit(1);
+ }
+
+ phys_addr = 0x100000000ULL - size;
+ addr = qemu_ram_alloc(NULL, "system.flash", size);
+ pflash_cfi01_register(phys_addr, addr, bdrv,
+ sector_size, size>> sector_bits,
+ 4, 0x0000, 0x0000, 0x0000, 0x0000, 0);
+
+ pc_isa_bios_init(addr, size);
+}
+
+void pc_system_firmware_init(void)
+{
+ int flash_present;
+ DriveInfo *pflash_drv;
+
+ pflash_drv = drive_get(IF_PFLASH, 0, 0);
+ flash_present = (pflash_drv != NULL);
+
+ if (!flash_present) {
+ pc_default_system_flash_init();
+ pflash_drv = drive_get(IF_PFLASH, 0, 0);
+ flash_present = (pflash_drv != NULL);
+ }
+
+ if (!flash_present) {
+ fprintf(stderr, "qemu: PC system firmware (pflash) not available\n");
+ exit(1);
+ }
+
+ pc_system_flash_init(pflash_drv);
+}
+