2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * QEMU OpenRISC boot helpers.
6 * (c) 2022 Stafford Horne <shorne@gmail.com>
9 #include "qemu/osdep.h"
11 #include "exec/cpu-defs.h"
13 #include "hw/loader.h"
14 #include "hw/openrisc/boot.h"
15 #include "sysemu/device_tree.h"
16 #include "sysemu/qtest.h"
17 #include "sysemu/reset.h"
18 #include "qemu/error-report.h"
22 #define KERNEL_LOAD_ADDR 0x100
24 hwaddr
openrisc_load_kernel(ram_addr_t ram_size
,
25 const char *kernel_filename
,
26 uint32_t *bootstrap_pc
)
33 if (kernel_filename
&& !qtest_enabled()) {
34 kernel_size
= load_elf(kernel_filename
, NULL
, NULL
, NULL
,
35 &elf_entry
, NULL
, &high_addr
, NULL
, 1,
38 if (kernel_size
< 0) {
39 kernel_size
= load_uimage(kernel_filename
,
40 &entry
, NULL
, NULL
, NULL
, NULL
);
41 high_addr
= entry
+ kernel_size
;
43 if (kernel_size
< 0) {
44 kernel_size
= load_image_targphys(kernel_filename
,
46 ram_size
- KERNEL_LOAD_ADDR
);
47 high_addr
= KERNEL_LOAD_ADDR
+ kernel_size
;
51 entry
= KERNEL_LOAD_ADDR
;
54 if (kernel_size
< 0) {
55 error_report("couldn't load the kernel '%s'", kernel_filename
);
58 *bootstrap_pc
= entry
;
65 hwaddr
openrisc_load_initrd(void *fdt
, const char *filename
,
66 hwaddr load_start
, uint64_t mem_size
)
71 /* We put the initrd right after the kernel; page aligned. */
72 start
= TARGET_PAGE_ALIGN(load_start
);
74 size
= load_ramdisk(filename
, start
, mem_size
- start
);
76 size
= load_image_targphys(filename
, start
, mem_size
- start
);
78 error_report("could not load ramdisk '%s'", filename
);
84 qemu_fdt_setprop_cell(fdt
, "/chosen",
85 "linux,initrd-start", start
);
86 qemu_fdt_setprop_cell(fdt
, "/chosen",
87 "linux,initrd-end", start
+ size
);
93 uint32_t openrisc_load_fdt(void *fdt
, hwaddr load_start
,
98 int fdtsize
= fdt_totalsize(fdt
);
101 error_report("invalid device-tree");
105 /* We put fdt right after the kernel and/or initrd. */
106 fdt_addr
= TARGET_PAGE_ALIGN(load_start
);
109 /* Should only fail if we've built a corrupted tree */
111 /* copy in the device tree */
112 qemu_fdt_dumpdtb(fdt
, fdtsize
);
114 rom_add_blob_fixed_as("fdt", fdt
, fdtsize
, fdt_addr
,
115 &address_space_memory
);
116 qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds
,
117 rom_ptr_for_as(&address_space_memory
, fdt_addr
, fdtsize
));