summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStafford Horne2022-02-09 22:40:45 +0100
committerStafford Horne2022-02-26 02:39:36 +0100
commit9576abf28280499a4497f39c2fae55bf97285e94 (patch)
treeaad5fcdbbfffe655732a18d1125a8b9265462c25
parenthw/openrisc/openrisc_sim: Add automatic device tree generation (diff)
downloadqemu-9576abf28280499a4497f39c2fae55bf97285e94.tar.gz
qemu-9576abf28280499a4497f39c2fae55bf97285e94.tar.xz
qemu-9576abf28280499a4497f39c2fae55bf97285e94.zip
hw/openrisc/openrisc_sim: Add support for initrd loading
The initrd passed via the command line is loaded into memory. It's location and size is then added to the device tree so the kernel knows where to find it. Signed-off-by: Stafford Horne <shorne@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hw/openrisc/openrisc_sim.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c
index e0e71c0faa..8184caa60b 100644
--- a/hw/openrisc/openrisc_sim.c
+++ b/hw/openrisc/openrisc_sim.c
@@ -315,6 +315,33 @@ static hwaddr openrisc_load_kernel(ram_addr_t ram_size,
return 0;
}
+static hwaddr openrisc_load_initrd(Or1ksimState *state, const char *filename,
+ hwaddr load_start, uint64_t mem_size)
+{
+ void *fdt = state->fdt;
+ int size;
+ hwaddr start;
+
+ /* We put the initrd right after the kernel; page aligned. */
+ start = TARGET_PAGE_ALIGN(load_start);
+
+ size = load_ramdisk(filename, start, mem_size - start);
+ if (size < 0) {
+ size = load_image_targphys(filename, start, mem_size - start);
+ if (size < 0) {
+ error_report("could not load ramdisk '%s'", filename);
+ exit(1);
+ }
+ }
+
+ qemu_fdt_setprop_cell(fdt, "/chosen",
+ "linux,initrd-start", start);
+ qemu_fdt_setprop_cell(fdt, "/chosen",
+ "linux,initrd-end", start + size);
+
+ return start + size;
+}
+
static uint32_t openrisc_load_fdt(Or1ksimState *state, hwaddr load_start,
uint64_t mem_size)
{
@@ -393,6 +420,10 @@ static void openrisc_sim_init(MachineState *machine)
load_addr = openrisc_load_kernel(ram_size, kernel_filename);
if (load_addr > 0) {
+ if (machine->initrd_filename) {
+ load_addr = openrisc_load_initrd(state, machine->initrd_filename,
+ load_addr, machine->ram_size);
+ }
boot_info.fdt_addr = openrisc_load_fdt(state, load_addr,
machine->ram_size);
}