mirror of https://github.com/xemu-project/xemu.git
ppc/pegasos2: Add support for -initrd command line option
This also changes type of sz local variable to ssize_t because it is used to store return value of load_elf() and load_image_targphys() that return ssize_t. Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Message-ID: <20230704181920.27B58746335@zero.eik.bme.hu> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
053075097a
commit
ebe0e9bbcb
|
@ -44,6 +44,8 @@
|
|||
#define PROM_ADDR 0xfff00000
|
||||
#define PROM_SIZE 0x80000
|
||||
|
||||
#define INITRD_MIN_ADDR 0x600000
|
||||
|
||||
#define KVMPPC_HCALL_BASE 0xf000
|
||||
#define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0)
|
||||
#define KVMPPC_H_VOF_CLIENT (KVMPPC_HCALL_BASE + 0x5)
|
||||
|
@ -80,6 +82,8 @@ struct Pegasos2MachineState {
|
|||
uint64_t kernel_addr;
|
||||
uint64_t kernel_entry;
|
||||
uint64_t kernel_size;
|
||||
uint64_t initrd_addr;
|
||||
uint64_t initrd_size;
|
||||
};
|
||||
|
||||
static void *build_fdt(MachineState *machine, int *fdt_size);
|
||||
|
@ -117,7 +121,8 @@ static void pegasos2_init(MachineState *machine)
|
|||
I2CBus *i2c_bus;
|
||||
const char *fwname = machine->firmware ?: PROM_FILENAME;
|
||||
char *filename;
|
||||
int i, sz;
|
||||
int i;
|
||||
ssize_t sz;
|
||||
uint8_t *spd_data;
|
||||
|
||||
/* init CPU */
|
||||
|
@ -213,6 +218,20 @@ static void pegasos2_init(MachineState *machine)
|
|||
warn_report("Using Virtual OpenFirmware but no -kernel option.");
|
||||
}
|
||||
|
||||
if (machine->initrd_filename) {
|
||||
pm->initrd_addr = pm->kernel_addr + pm->kernel_size + 64 * KiB;
|
||||
pm->initrd_addr = ROUND_UP(pm->initrd_addr, 4);
|
||||
pm->initrd_addr = MAX(pm->initrd_addr, INITRD_MIN_ADDR);
|
||||
sz = load_image_targphys(machine->initrd_filename, pm->initrd_addr,
|
||||
machine->ram_size - pm->initrd_addr);
|
||||
if (sz <= 0) {
|
||||
error_report("Could not load initrd '%s'",
|
||||
machine->initrd_filename);
|
||||
exit(1);
|
||||
}
|
||||
pm->initrd_size = sz;
|
||||
}
|
||||
|
||||
if (!pm->vof && machine->kernel_cmdline && machine->kernel_cmdline[0]) {
|
||||
warn_report("Option -append may be ineffective with -bios.");
|
||||
}
|
||||
|
@ -335,6 +354,11 @@ static void pegasos2_machine_reset(MachineState *machine, ShutdownCause reason)
|
|||
error_report("Memory for kernel is in use");
|
||||
exit(1);
|
||||
}
|
||||
if (pm->initrd_size &&
|
||||
vof_claim(pm->vof, pm->initrd_addr, pm->initrd_size, 0) == -1) {
|
||||
error_report("Memory for initrd is in use");
|
||||
exit(1);
|
||||
}
|
||||
fdt = build_fdt(machine, &sz);
|
||||
/* FIXME: VOF assumes entry is same as load address */
|
||||
d[0] = cpu_to_be64(pm->kernel_entry);
|
||||
|
@ -966,6 +990,12 @@ static void *build_fdt(MachineState *machine, int *fdt_size)
|
|||
qemu_fdt_setprop_string(fdt, "/memory@0", "name", "memory");
|
||||
|
||||
qemu_fdt_add_subnode(fdt, "/chosen");
|
||||
if (pm->initrd_addr && pm->initrd_size) {
|
||||
qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
|
||||
pm->initrd_addr + pm->initrd_size);
|
||||
qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start",
|
||||
pm->initrd_addr);
|
||||
}
|
||||
qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
|
||||
machine->kernel_cmdline ?: "");
|
||||
qemu_fdt_setprop_string(fdt, "/chosen", "name", "chosen");
|
||||
|
|
Loading…
Reference in New Issue