Use relative path for bios

Look for bios and other support files relative to qemu binary, rather than
a hardcoded prefix.

Signed-off-by: Paul Brook <paul@codesourcery.com>
This commit is contained in:
Paul Brook 2009-05-30 00:52:44 +01:00
parent abc0754527
commit 5cea8590ea
16 changed files with 365 additions and 121 deletions

View File

@ -118,7 +118,7 @@ void mips_jazz_init (ram_addr_t ram_size,
const char *cpu_model, const char *cpu_model,
enum jazz_model_e jazz_model) enum jazz_model_e jazz_model)
{ {
char buf[1024]; char *filename;
int bios_size, n; int bios_size, n;
CPUState *env; CPUState *env;
qemu_irq *rc4030, *i8259; qemu_irq *rc4030, *i8259;
@ -161,11 +161,17 @@ void mips_jazz_init (ram_addr_t ram_size,
/* load the BIOS image. */ /* load the BIOS image. */
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = load_image_targphys(buf, 0xfff00000LL, MAGNUM_BIOS_SIZE); if (filename) {
bios_size = load_image_targphys(filename, 0xfff00000LL,
MAGNUM_BIOS_SIZE);
qemu_free(filename);
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > MAGNUM_BIOS_SIZE) { if (bios_size < 0 || bios_size > MAGNUM_BIOS_SIZE) {
fprintf(stderr, "qemu: Could not load MIPS bios '%s'\n", fprintf(stderr, "qemu: Could not load MIPS bios '%s'\n",
buf); bios_name);
exit(1); exit(1);
} }

View File

@ -758,7 +758,7 @@ void mips_malta_init (ram_addr_t ram_size,
const char *kernel_filename, const char *kernel_cmdline, const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model) const char *initrd_filename, const char *cpu_model)
{ {
char buf[1024]; char *filename;
ram_addr_t ram_offset; ram_addr_t ram_offset;
ram_addr_t bios_offset; ram_addr_t bios_offset;
target_long bios_size; target_long bios_size;
@ -846,12 +846,18 @@ void mips_malta_init (ram_addr_t ram_size,
/* Load a BIOS image. */ /* Load a BIOS image. */
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = load_image_targphys(buf, 0x1fc00000LL, BIOS_SIZE); if (filename) {
bios_size = load_image_targphys(filename, 0x1fc00000LL,
BIOS_SIZE);
qemu_free(filename);
} else {
bios_size = -1;
}
if ((bios_size < 0 || bios_size > BIOS_SIZE) && !kernel_filename) { if ((bios_size < 0 || bios_size > BIOS_SIZE) && !kernel_filename) {
fprintf(stderr, fprintf(stderr,
"qemu: Could not load MIPS bios '%s', and no -kernel argument was specified\n", "qemu: Could not load MIPS bios '%s', and no -kernel argument was specified\n",
buf); bios_name);
exit(1); exit(1);
} }
} }

View File

@ -107,7 +107,7 @@ mips_mipssim_init (ram_addr_t ram_size,
const char *kernel_filename, const char *kernel_cmdline, const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model) const char *initrd_filename, const char *cpu_model)
{ {
char buf[1024]; char *filename;
ram_addr_t ram_offset; ram_addr_t ram_offset;
ram_addr_t bios_offset; ram_addr_t bios_offset;
CPUState *env; CPUState *env;
@ -140,13 +140,18 @@ mips_mipssim_init (ram_addr_t ram_size,
/* Load a BIOS / boot exception handler image. */ /* Load a BIOS / boot exception handler image. */
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = load_image_targphys(buf, 0x1fc00000LL, BIOS_SIZE); if (filename) {
bios_size = load_image_targphys(filename, 0x1fc00000LL, BIOS_SIZE);
qemu_free(filename);
} else {
bios_size = -1;
}
if ((bios_size < 0 || bios_size > BIOS_SIZE) && !kernel_filename) { if ((bios_size < 0 || bios_size > BIOS_SIZE) && !kernel_filename) {
/* Bail out if we have neither a kernel image nor boot vector code. */ /* Bail out if we have neither a kernel image nor boot vector code. */
fprintf(stderr, fprintf(stderr,
"qemu: Could not load MIPS bios '%s', and no -kernel argument was specified\n", "qemu: Could not load MIPS bios '%s', and no -kernel argument was specified\n",
buf); filename);
exit(1); exit(1);
} else { } else {
/* We have a boot vector start address. */ /* We have a boot vector start address. */

View File

@ -147,7 +147,7 @@ void mips_r4k_init (ram_addr_t ram_size,
const char *kernel_filename, const char *kernel_cmdline, const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model) const char *initrd_filename, const char *cpu_model)
{ {
char buf[1024]; char *filename;
ram_addr_t ram_offset; ram_addr_t ram_offset;
ram_addr_t bios_offset; ram_addr_t bios_offset;
int bios_size; int bios_size;
@ -196,14 +196,18 @@ void mips_r4k_init (ram_addr_t ram_size,
run. */ run. */
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = get_image_size(buf); if (filename) {
bios_size = get_image_size(filename);
} else {
bios_size = -1;
}
if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) { if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) {
bios_offset = qemu_ram_alloc(BIOS_SIZE); bios_offset = qemu_ram_alloc(BIOS_SIZE);
cpu_register_physical_memory(0x1fc00000, BIOS_SIZE, cpu_register_physical_memory(0x1fc00000, BIOS_SIZE,
bios_offset | IO_MEM_ROM); bios_offset | IO_MEM_ROM);
load_image_targphys(buf, 0x1fc00000, BIOS_SIZE); load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
} else if ((index = drive_get_index(IF_PFLASH, 0, 0)) > -1) { } else if ((index = drive_get_index(IF_PFLASH, 0, 0)) > -1) {
uint32_t mips_rom = 0x00400000; uint32_t mips_rom = 0x00400000;
bios_offset = qemu_ram_alloc(mips_rom); bios_offset = qemu_ram_alloc(mips_rom);
@ -216,7 +220,10 @@ void mips_r4k_init (ram_addr_t ram_size,
else { else {
/* not fatal */ /* not fatal */
fprintf(stderr, "qemu: Warning, could not load MIPS bios '%s'\n", fprintf(stderr, "qemu: Warning, could not load MIPS bios '%s'\n",
buf); bios_name);
}
if (filename) {
qemu_free(filename);
} }
if (kernel_filename) { if (kernel_filename) {

48
hw/pc.c
View File

@ -603,10 +603,10 @@ static void load_linux(target_phys_addr_t option_rom,
uint32_t gpr[8]; uint32_t gpr[8];
uint16_t seg[6]; uint16_t seg[6];
uint16_t real_seg; uint16_t real_seg;
int setup_size, kernel_size, initrd_size, cmdline_size; int setup_size, kernel_size, initrd_size = 0, cmdline_size;
uint32_t initrd_max; uint32_t initrd_max;
uint8_t header[1024]; uint8_t header[1024];
target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr; target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
FILE *f, *fi; FILE *f, *fi;
/* Align to 16 bytes as a paranoia measure */ /* Align to 16 bytes as a paranoia measure */
@ -805,14 +805,21 @@ static int load_option_rom(const char *oprom, target_phys_addr_t start,
target_phys_addr_t end) target_phys_addr_t end)
{ {
int size; int size;
char *filename;
size = get_image_size(oprom); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, oprom);
if (size > 0 && start + size > end) { if (filename) {
fprintf(stderr, "Not enough space to load option rom '%s'\n", size = get_image_size(filename);
oprom); if (size > 0 && start + size > end) {
exit(1); fprintf(stderr, "Not enough space to load option rom '%s'\n",
oprom);
exit(1);
}
size = load_image_targphys(filename, start, end - start);
qemu_free(filename);
} else {
size = -1;
} }
size = load_image_targphys(oprom, start, end - start);
if (size < 0) { if (size < 0) {
fprintf(stderr, "Could not load option rom '%s'\n", oprom); fprintf(stderr, "Could not load option rom '%s'\n", oprom);
exit(1); exit(1);
@ -830,7 +837,7 @@ static void pc_init1(ram_addr_t ram_size,
const char *initrd_filename, const char *initrd_filename,
int pci_enabled, const char *cpu_model) int pci_enabled, const char *cpu_model)
{ {
char buf[1024]; char *filename;
int ret, linux_boot, i; int ret, linux_boot, i;
ram_addr_t ram_addr, bios_offset, option_rom_offset; ram_addr_t ram_addr, bios_offset, option_rom_offset;
ram_addr_t below_4g_mem_size, above_4g_mem_size = 0; ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
@ -913,19 +920,26 @@ static void pc_init1(ram_addr_t ram_size,
/* BIOS load */ /* BIOS load */
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = get_image_size(buf); if (filename) {
bios_size = get_image_size(filename);
} else {
bios_size = -1;
}
if (bios_size <= 0 || if (bios_size <= 0 ||
(bios_size % 65536) != 0) { (bios_size % 65536) != 0) {
goto bios_error; goto bios_error;
} }
bios_offset = qemu_ram_alloc(bios_size); bios_offset = qemu_ram_alloc(bios_size);
ret = load_image(buf, qemu_get_ram_ptr(bios_offset)); ret = load_image(filename, qemu_get_ram_ptr(bios_offset));
if (ret != bios_size) { if (ret != bios_size) {
bios_error: bios_error:
fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", buf); fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
exit(1); exit(1);
} }
if (filename) {
qemu_free(filename);
}
/* map the last 128KB of the BIOS in ISA space */ /* map the last 128KB of the BIOS in ISA space */
isa_bios_size = bios_size; isa_bios_size = bios_size;
if (isa_bios_size > (128 * 1024)) if (isa_bios_size > (128 * 1024))
@ -941,14 +955,14 @@ static void pc_init1(ram_addr_t ram_size,
cpu_register_physical_memory(0xc0000, 0x20000, option_rom_offset); cpu_register_physical_memory(0xc0000, 0x20000, option_rom_offset);
if (using_vga) { if (using_vga) {
const char *vgabios_filename;
/* VGA BIOS load */ /* VGA BIOS load */
if (cirrus_vga_enabled) { if (cirrus_vga_enabled) {
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, vgabios_filename = VGABIOS_CIRRUS_FILENAME;
VGABIOS_CIRRUS_FILENAME);
} else { } else {
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); vgabios_filename = VGABIOS_FILENAME;
} }
oprom_area_size = load_option_rom(buf, 0xc0000, 0xe0000); oprom_area_size = load_option_rom(vgabios_filename, 0xc0000, 0xe0000);
} }
/* Although video roms can grow larger than 0x8000, the area between /* Although video roms can grow larger than 0x8000, the area between
* 0xc0000 - 0xc8000 is reserved for them. It means we won't be looking * 0xc0000 - 0xc8000 is reserved for them. It means we won't be looking

View File

@ -175,7 +175,7 @@ static void ref405ep_init (ram_addr_t ram_size,
const char *initrd_filename, const char *initrd_filename,
const char *cpu_model) const char *cpu_model)
{ {
char buf[1024]; char *filename;
ppc4xx_bd_info_t bd; ppc4xx_bd_info_t bd;
CPUPPCState *env; CPUPPCState *env;
qemu_irq *pic; qemu_irq *pic;
@ -236,13 +236,19 @@ static void ref405ep_init (ram_addr_t ram_size,
#ifdef DEBUG_BOARD_INIT #ifdef DEBUG_BOARD_INIT
printf("Load BIOS from file\n"); printf("Load BIOS from file\n");
#endif #endif
bios_offset = qemu_ram_alloc(BIOS_SIZE);
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_offset = qemu_ram_alloc(BIOS_SIZE); if (filename) {
bios_size = load_image(buf, qemu_get_ram_ptr(bios_offset)); bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
qemu_free(filename);
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > BIOS_SIZE) { if (bios_size < 0 || bios_size > BIOS_SIZE) {
fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf); fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
bios_name);
exit(1); exit(1);
} }
bios_size = (bios_size + 0xfff) & ~0xfff; bios_size = (bios_size + 0xfff) & ~0xfff;
@ -493,7 +499,7 @@ static void taihu_405ep_init(ram_addr_t ram_size,
const char *initrd_filename, const char *initrd_filename,
const char *cpu_model) const char *cpu_model)
{ {
char buf[1024]; char *filename;
CPUPPCState *env; CPUPPCState *env;
qemu_irq *pic; qemu_irq *pic;
ram_addr_t bios_offset; ram_addr_t bios_offset;
@ -548,10 +554,15 @@ static void taihu_405ep_init(ram_addr_t ram_size,
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
bios_offset = qemu_ram_alloc(BIOS_SIZE); bios_offset = qemu_ram_alloc(BIOS_SIZE);
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = load_image(buf, qemu_get_ram_ptr(bios_offset)); if (filename) {
bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > BIOS_SIZE) { if (bios_size < 0 || bios_size > BIOS_SIZE) {
fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf); fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
bios_name);
exit(1); exit(1);
} }
bios_size = (bios_size + 0xfff) & ~0xfff; bios_size = (bios_size + 0xfff) & ~0xfff;

View File

@ -34,20 +34,19 @@ static void *bamboo_load_device_tree(target_phys_addr_t addr,
void *fdt = NULL; void *fdt = NULL;
#ifdef HAVE_FDT #ifdef HAVE_FDT
uint32_t mem_reg_property[] = { 0, 0, ramsize }; uint32_t mem_reg_property[] = { 0, 0, ramsize };
char *path; char *filename;
int fdt_size; int fdt_size;
int pathlen;
int ret; int ret;
pathlen = snprintf(NULL, 0, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE) + 1; filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
path = qemu_malloc(pathlen); if (!filename) {
snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
fdt = load_device_tree(path, &fdt_size);
free(path);
if (fdt == NULL)
goto out; goto out;
}
fdt = load_device_tree(filename, &fdt_size);
qemu_free(filename);
if (fdt == NULL) {
goto out;
}
/* Manipulate device tree in memory. */ /* Manipulate device tree in memory. */

View File

@ -93,7 +93,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
const char *cpu_model) const char *cpu_model)
{ {
CPUState *env = NULL, *envs[MAX_CPUS]; CPUState *env = NULL, *envs[MAX_CPUS];
char buf[1024]; char *filename;
qemu_irq *pic, **openpic_irqs; qemu_irq *pic, **openpic_irqs;
int unin_memory; int unin_memory;
int linux_boot, i; int linux_boot, i;
@ -140,24 +140,35 @@ static void ppc_core99_init (ram_addr_t ram_size,
bios_offset = qemu_ram_alloc(BIOS_SIZE); bios_offset = qemu_ram_alloc(BIOS_SIZE);
if (bios_name == NULL) if (bios_name == NULL)
bios_name = PROM_FILENAME; bios_name = PROM_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | IO_MEM_ROM); cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | IO_MEM_ROM);
/* Load OpenBIOS (ELF) */ /* Load OpenBIOS (ELF) */
bios_size = load_elf(buf, 0, NULL, NULL, NULL); if (filename) {
bios_size = load_elf(filename, 0, NULL, NULL, NULL);
qemu_free(filename);
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > BIOS_SIZE) { if (bios_size < 0 || bios_size > BIOS_SIZE) {
hw_error("qemu: could not load PowerPC bios '%s'\n", buf); hw_error("qemu: could not load PowerPC bios '%s'\n", bios_name);
exit(1); exit(1);
} }
/* allocate and load VGA BIOS */ /* allocate and load VGA BIOS */
vga_bios_offset = qemu_ram_alloc(VGA_BIOS_SIZE); vga_bios_offset = qemu_ram_alloc(VGA_BIOS_SIZE);
vga_bios_ptr = qemu_get_ram_ptr(vga_bios_offset); vga_bios_ptr = qemu_get_ram_ptr(vga_bios_offset);
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, VGABIOS_FILENAME);
vga_bios_size = load_image(buf, vga_bios_ptr + 8); if (filename) {
vga_bios_size = load_image(filename, vga_bios_ptr + 8);
qemu_free(filename);
} else {
vga_bios_size = -1;
}
if (vga_bios_size < 0) { if (vga_bios_size < 0) {
/* if no bios is present, we can still work */ /* if no bios is present, we can still work */
fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf); fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n",
VGABIOS_FILENAME);
vga_bios_size = 0; vga_bios_size = 0;
} else { } else {
/* set a specific header (XXX: find real Apple format for NDRV /* set a specific header (XXX: find real Apple format for NDRV

View File

@ -122,7 +122,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
const char *cpu_model) const char *cpu_model)
{ {
CPUState *env = NULL, *envs[MAX_CPUS]; CPUState *env = NULL, *envs[MAX_CPUS];
char buf[1024]; char *filename;
qemu_irq *pic, **heathrow_irqs; qemu_irq *pic, **heathrow_irqs;
int linux_boot, i; int linux_boot, i;
ram_addr_t ram_offset, bios_offset, vga_bios_offset; ram_addr_t ram_offset, bios_offset, vga_bios_offset;
@ -173,24 +173,35 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
bios_offset = qemu_ram_alloc(BIOS_SIZE); bios_offset = qemu_ram_alloc(BIOS_SIZE);
if (bios_name == NULL) if (bios_name == NULL)
bios_name = PROM_FILENAME; bios_name = PROM_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | IO_MEM_ROM); cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | IO_MEM_ROM);
/* Load OpenBIOS (ELF) */ /* Load OpenBIOS (ELF) */
bios_size = load_elf(buf, 0, NULL, NULL, NULL); if (filename) {
bios_size = load_elf(filename, 0, NULL, NULL, NULL);
qemu_free(filename);
} else {
bios_size = -1;
}
if (bios_size < 0 || bios_size > BIOS_SIZE) { if (bios_size < 0 || bios_size > BIOS_SIZE) {
hw_error("qemu: could not load PowerPC bios '%s'\n", buf); hw_error("qemu: could not load PowerPC bios '%s'\n", bios_name);
exit(1); exit(1);
} }
/* allocate and load VGA BIOS */ /* allocate and load VGA BIOS */
vga_bios_offset = qemu_ram_alloc(VGA_BIOS_SIZE); vga_bios_offset = qemu_ram_alloc(VGA_BIOS_SIZE);
vga_bios_ptr = qemu_get_ram_ptr(vga_bios_offset); vga_bios_ptr = qemu_get_ram_ptr(vga_bios_offset);
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, VGABIOS_FILENAME);
vga_bios_size = load_image(buf, vga_bios_ptr + 8); if (filename) {
vga_bios_size = load_image(filename, vga_bios_ptr + 8);
qemu_free(filename);
} else {
vga_bios_size = -1;
}
if (vga_bios_size < 0) { if (vga_bios_size < 0) {
/* if no bios is present, we can still work */ /* if no bios is present, we can still work */
fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf); fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n",
VGABIOS_FILENAME);
vga_bios_size = 0; vga_bios_size = 0;
} else { } else {
/* set a specific header (XXX: find real Apple format for NDRV /* set a specific header (XXX: find real Apple format for NDRV

View File

@ -539,7 +539,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
const char *cpu_model) const char *cpu_model)
{ {
CPUState *env = NULL, *envs[MAX_CPUS]; CPUState *env = NULL, *envs[MAX_CPUS];
char buf[1024]; char *filename;
nvram_t nvram; nvram_t nvram;
m48t59_t *m48t59; m48t59_t *m48t59;
int PPC_io_memory; int PPC_io_memory;
@ -585,18 +585,25 @@ static void ppc_prep_init (ram_addr_t ram_size,
bios_offset = qemu_ram_alloc(BIOS_SIZE); bios_offset = qemu_ram_alloc(BIOS_SIZE);
if (bios_name == NULL) if (bios_name == NULL)
bios_name = BIOS_FILENAME; bios_name = BIOS_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
bios_size = get_image_size(buf); if (filename) {
bios_size = get_image_size(filename);
} else {
bios_size = -1;
}
if (bios_size > 0 && bios_size <= BIOS_SIZE) { if (bios_size > 0 && bios_size <= BIOS_SIZE) {
target_phys_addr_t bios_addr; target_phys_addr_t bios_addr;
bios_size = (bios_size + 0xfff) & ~0xfff; bios_size = (bios_size + 0xfff) & ~0xfff;
bios_addr = (uint32_t)(-bios_size); bios_addr = (uint32_t)(-bios_size);
cpu_register_physical_memory(bios_addr, bios_size, cpu_register_physical_memory(bios_addr, bios_size,
bios_offset | IO_MEM_ROM); bios_offset | IO_MEM_ROM);
bios_size = load_image_targphys(buf, bios_addr, bios_size); bios_size = load_image_targphys(filename, bios_addr, bios_size);
} }
if (bios_size < 0 || bios_size > BIOS_SIZE) { if (bios_size < 0 || bios_size > BIOS_SIZE) {
hw_error("qemu: could not load PPC PREP bios '%s'\n", buf); hw_error("qemu: could not load PPC PREP bios '%s'\n", bios_name);
}
if (filename) {
qemu_free(filename);
} }
if (env->nip < 0xFFF80000 && bios_size < 0x00100000) { if (env->nip < 0xFFF80000 && bios_size < 0x00100000) {
hw_error("PowerPC 601 / 620 / 970 need a 1MB BIOS\n"); hw_error("PowerPC 601 / 620 / 970 need a 1MB BIOS\n");

View File

@ -79,20 +79,19 @@ static void *mpc8544_load_device_tree(target_phys_addr_t addr,
void *fdt = NULL; void *fdt = NULL;
#ifdef HAVE_FDT #ifdef HAVE_FDT
uint32_t mem_reg_property[] = {0, ramsize}; uint32_t mem_reg_property[] = {0, ramsize};
char *path; char *filename;
int fdt_size; int fdt_size;
int pathlen;
int ret; int ret;
pathlen = snprintf(NULL, 0, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE) + 1; filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
path = qemu_malloc(pathlen); if (!filename) {
snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
fdt = load_device_tree(path, &fdt_size);
qemu_free(path);
if (fdt == NULL)
goto out; goto out;
}
fdt = load_device_tree(filename, &fdt_size);
qemu_free(filename);
if (fdt == NULL) {
goto out;
}
/* Manipulate device tree in memory. */ /* Manipulate device tree in memory. */
ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,

View File

@ -400,7 +400,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
ram_addr_t ram_offset, prom_offset, idreg_offset; ram_addr_t ram_offset, prom_offset, idreg_offset;
unsigned long kernel_size; unsigned long kernel_size;
int ret; int ret;
char buf[1024]; char *filename;
BlockDriverState *fd[MAX_FD]; BlockDriverState *fd[MAX_FD];
int drive_index; int drive_index;
void *fw_cfg; void *fw_cfg;
@ -451,13 +451,20 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
if (bios_name == NULL) if (bios_name == NULL)
bios_name = PROM_FILENAME; bios_name = PROM_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL); if (filename) {
if (ret < 0 || ret > PROM_SIZE_MAX) ret = load_elf(filename, hwdef->slavio_base - PROM_VADDR,
ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX); NULL, NULL, NULL);
if (ret < 0 || ret > PROM_SIZE_MAX)
ret = load_image_targphys(filename, hwdef->slavio_base,
PROM_SIZE_MAX);
qemu_free(filename);
} else {
ret = -1;
}
if (ret < 0 || ret > PROM_SIZE_MAX) { if (ret < 0 || ret > PROM_SIZE_MAX) {
fprintf(stderr, "qemu: could not load prom '%s'\n", fprintf(stderr, "qemu: could not load prom '%s'\n",
buf); bios_name);
exit(1); exit(1);
} }
@ -1185,7 +1192,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
ram_addr_t ram_offset, prom_offset; ram_addr_t ram_offset, prom_offset;
unsigned long kernel_size; unsigned long kernel_size;
int ret; int ret;
char buf[1024]; char *filename;
void *fw_cfg; void *fw_cfg;
/* init CPUs */ /* init CPUs */
@ -1233,13 +1240,20 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
if (bios_name == NULL) if (bios_name == NULL)
bios_name = PROM_FILENAME; bios_name = PROM_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL); if (filename) {
if (ret < 0 || ret > PROM_SIZE_MAX) ret = load_elf(filename, hwdef->slavio_base - PROM_VADDR,
ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX); NULL, NULL, NULL);
if (ret < 0 || ret > PROM_SIZE_MAX)
ret = load_image_targphys(filename, hwdef->slavio_base,
PROM_SIZE_MAX);
qemu_free(filename);
} else {
ret = -1;
}
if (ret < 0 || ret > PROM_SIZE_MAX) { if (ret < 0 || ret > PROM_SIZE_MAX) {
fprintf(stderr, "qemu: could not load prom '%s'\n", fprintf(stderr, "qemu: could not load prom '%s'\n",
buf); bios_name);
exit(1); exit(1);
} }
@ -1399,7 +1413,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
ram_addr_t ram_offset, prom_offset; ram_addr_t ram_offset, prom_offset;
unsigned long kernel_size; unsigned long kernel_size;
int ret; int ret;
char buf[1024]; char *filename;
BlockDriverState *fd[MAX_FD]; BlockDriverState *fd[MAX_FD];
int drive_index; int drive_index;
void *fw_cfg; void *fw_cfg;
@ -1440,13 +1454,20 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
if (bios_name == NULL) if (bios_name == NULL)
bios_name = PROM_FILENAME; bios_name = PROM_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL); if (filename) {
if (ret < 0 || ret > PROM_SIZE_MAX) ret = load_elf(filename, hwdef->slavio_base - PROM_VADDR,
ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX); NULL, NULL, NULL);
if (ret < 0 || ret > PROM_SIZE_MAX)
ret = load_image_targphys(filename, hwdef->slavio_base,
PROM_SIZE_MAX);
qemu_free(filename);
} else {
ret = -1;
}
if (ret < 0 || ret > PROM_SIZE_MAX) { if (ret < 0 || ret > PROM_SIZE_MAX) {
fprintf(stderr, "qemu: could not load prom '%s'\n", fprintf(stderr, "qemu: could not load prom '%s'\n",
buf); filename);
exit(1); exit(1);
} }

View File

@ -333,7 +333,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
const struct hwdef *hwdef) const struct hwdef *hwdef)
{ {
CPUState *env; CPUState *env;
char buf[1024]; char *filename;
m48t59_t *nvram; m48t59_t *nvram;
int ret, linux_boot; int ret, linux_boot;
unsigned int i; unsigned int i;
@ -392,17 +392,23 @@ static void sun4uv_init(ram_addr_t RAM_size,
if (bios_name == NULL) if (bios_name == NULL)
bios_name = PROM_FILENAME; bios_name = PROM_FILENAME;
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
ret = load_elf(buf, hwdef->prom_addr - PROM_VADDR, NULL, NULL, NULL); if (filename) {
if (ret < 0) { ret = load_elf(filename, hwdef->prom_addr - PROM_VADDR,
ret = load_image_targphys(buf, hwdef->prom_addr, NULL, NULL, NULL);
(PROM_SIZE_MAX + TARGET_PAGE_SIZE) &
TARGET_PAGE_MASK);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "qemu: could not load prom '%s'\n", ret = load_image_targphys(filename, hwdef->prom_addr,
buf); (PROM_SIZE_MAX + TARGET_PAGE_SIZE) &
exit(1); TARGET_PAGE_MASK);
} }
qemu_free(filename);
} else {
ret = -1;
}
if (ret < 0) {
fprintf(stderr, "qemu: could not load prom '%s'\n",
bios_name);
exit(1);
} }
kernel_size = 0; kernel_size = 0;

View File

@ -64,20 +64,20 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
kbd_layout_t * k) kbd_layout_t * k)
{ {
FILE *f; FILE *f;
char file_name[1024]; char * filename;
char line[1024]; char line[1024];
int len; int len;
snprintf(file_name, sizeof(file_name), filename = qemu_find_file(QEMU_FILE_TYPE_KEYMAP, language);
"%s/keymaps/%s", bios_dir, language);
if (!k) if (!k)
k = qemu_mallocz(sizeof(kbd_layout_t)); k = qemu_mallocz(sizeof(kbd_layout_t));
if (!(f = fopen(file_name, "r"))) { if (!(filename && (f = fopen(filename, "r")))) {
fprintf(stderr, fprintf(stderr,
"Could not read keymap file: '%s'\n", file_name); "Could not read keymap file: '%s'\n", language);
return 0; return 0;
} }
qemu_free(filename);
for(;;) { for(;;) {
if (fgets(line, 1024, f) == NULL) if (fgets(line, 1024, f) == NULL)
break; break;

View File

@ -10,7 +10,10 @@
/* vl.c */ /* vl.c */
extern const char *bios_name; extern const char *bios_name;
extern const char *bios_dir;
#define QEMU_FILE_TYPE_BIOS 0
#define QEMU_FILE_TYPE_KEYMAP 1
char *qemu_find_file(int type, const char *name);
extern int vm_running; extern int vm_running;
extern const char *qemu_name; extern const char *qemu_name;

148
vl.c
View File

@ -33,6 +33,7 @@
#include "config-host.h" #include "config-host.h"
#ifndef _WIN32 #ifndef _WIN32
#include <libgen.h>
#include <pwd.h> #include <pwd.h>
#include <sys/times.h> #include <sys/times.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -191,7 +192,7 @@ int main(int argc, char **argv)
/* XXX: use a two level table to limit memory usage */ /* XXX: use a two level table to limit memory usage */
#define MAX_IOPORTS 65536 #define MAX_IOPORTS 65536
const char *bios_dir = CONFIG_QEMU_SHAREDIR; static const char *data_dir;
const char *bios_name = NULL; const char *bios_name = NULL;
static void *ioport_opaque[MAX_IOPORTS]; static void *ioport_opaque[MAX_IOPORTS];
static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
@ -4795,6 +4796,128 @@ static void termsig_setup(void)
#endif #endif
#ifdef _WIN32
/* Look for support files in the same directory as the executable. */
static char *find_datadir(const char *argv0)
{
char *p;
char buf[MAX_PATH];
DWORD len;
len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
if (len == 0) {
return len;
}
buf[len] = 0;
p = buf + len - 1;
while (p != buf && *p != '\\')
p--;
*p = 0;
if (access(buf, R_OK) == 0) {
return qemu_strdup(buf);
}
return NULL;
}
#else /* !_WIN32 */
/* Find a likely location for support files using the location of the binary.
For installed binaries this will be "$bindir/../share/qemu". When
running from the build tree this will be "$bindir/../pc-bios". */
#define SHARE_SUFFIX "/share/qemu"
#define BUILD_SUFFIX "/pc-bios"
static char *find_datadir(const char *argv0)
{
char *dir;
char *p = NULL;
char *res;
#ifdef PATH_MAX
char buf[PATH_MAX];
#endif
#if defined(__linux__)
{
int len;
len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
if (len > 0) {
buf[len] = 0;
p = buf;
}
}
#elif defined(__FreeBSD__)
{
int len;
len = readlink("/proc/curproc/file", buf, sizeof(buf) - 1);
if (len > 0) {
buf[len] = 0;
p = buf;
}
}
#endif
/* If we don't have any way of figuring out the actual executable
location then try argv[0]. */
if (!p) {
#ifdef PATH_MAX
p = buf;
#endif
p = realpath(argv0, p);
if (!p) {
return NULL;
}
}
dir = dirname(p);
dir = dirname(dir);
res = qemu_mallocz(strlen(dir) +
MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1);
sprintf(res, "%s%s", dir, SHARE_SUFFIX);
if (access(res, R_OK)) {
sprintf(res, "%s%s", dir, BUILD_SUFFIX);
if (access(res, R_OK)) {
qemu_free(res);
res = NULL;
}
}
#ifndef PATH_MAX
free(p);
#endif
return res;
}
#undef SHARE_SUFFIX
#undef BUILD_SUFFIX
#endif
char *qemu_find_file(int type, const char *name)
{
int len;
const char *subdir;
char *buf;
/* If name contains path separators then try it as a straight path. */
if ((strchr(name, '/') || strchr(name, '\\'))
&& access(name, R_OK) == 0) {
return strdup(name);
}
switch (type) {
case QEMU_FILE_TYPE_BIOS:
subdir = "";
break;
case QEMU_FILE_TYPE_KEYMAP:
subdir = "keymaps/";
break;
default:
abort();
}
len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
buf = qemu_mallocz(len);
sprintf(buf, "%s/%s%s", data_dir, subdir, name);
if (access(buf, R_OK)) {
qemu_free(buf);
return NULL;
}
return buf;
}
int main(int argc, char **argv, char **envp) int main(int argc, char **argv, char **envp)
{ {
const char *gdbstub_dev = NULL; const char *gdbstub_dev = NULL;
@ -5234,7 +5357,7 @@ int main(int argc, char **argv, char **envp)
gdbstub_dev = optarg; gdbstub_dev = optarg;
break; break;
case QEMU_OPTION_L: case QEMU_OPTION_L:
bios_dir = optarg; data_dir = optarg;
break; break;
case QEMU_OPTION_bios: case QEMU_OPTION_bios:
bios_name = optarg; bios_name = optarg;
@ -5560,6 +5683,16 @@ int main(int argc, char **argv, char **envp)
} }
} }
/* If no data_dir is specified then try to find it relative to the
executable path. */
if (!data_dir) {
data_dir = find_datadir(argv[0]);
}
/* If all else fails use the install patch specified when building. */
if (!data_dir) {
data_dir = CONFIG_QEMU_SHAREDIR;
}
#if defined(CONFIG_KVM) && defined(CONFIG_KQEMU) #if defined(CONFIG_KVM) && defined(CONFIG_KQEMU)
if (kvm_allowed && kqemu_allowed) { if (kvm_allowed && kqemu_allowed) {
fprintf(stderr, fprintf(stderr,
@ -5705,19 +5838,24 @@ int main(int argc, char **argv, char **envp)
for (i = 0; i < nb_nics && i < 4; i++) { for (i = 0; i < nb_nics && i < 4; i++) {
const char *model = nd_table[i].model; const char *model = nd_table[i].model;
char buf[1024]; char buf[1024];
char *filename;
if (net_boot & (1 << i)) { if (net_boot & (1 << i)) {
if (model == NULL) if (model == NULL)
model = "ne2k_pci"; model = "ne2k_pci";
snprintf(buf, sizeof(buf), "%s/pxe-%s.bin", bios_dir, model); snprintf(buf, sizeof(buf), "pxe-%s.bin", model);
if (get_image_size(buf) > 0) { filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, buf);
if (filename && get_image_size(filename) > 0) {
if (nb_option_roms >= MAX_OPTION_ROMS) { if (nb_option_roms >= MAX_OPTION_ROMS) {
fprintf(stderr, "Too many option ROMs\n"); fprintf(stderr, "Too many option ROMs\n");
exit(1); exit(1);
} }
option_rom[nb_option_roms] = strdup(buf); option_rom[nb_option_roms] = qemu_strdup(buf);
nb_option_roms++; nb_option_roms++;
netroms++; netroms++;
} }
if (filename) {
qemu_free(filename);
}
} }
} }
if (netroms == 0) { if (netroms == 0) {