• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コミットメタ情報

リビジョン8d8897accb1c9b28267b3c7eb402b6bc5d967f7e (tree)
日時2022-01-21 14:52:56
作者Anup Patel <apatel@vent...>
コミッターAlistair Francis

ログメッセージ

hw/riscv: spike: Allow using binary firmware as bios

Currently, we have to use OpenSBI firmware ELF as bios for the spike
machine because the HTIF console requires ELF for parsing "fromhost"
and "tohost" symbols.

The latest OpenSBI can now optionally pick-up HTIF register address
from HTIF DT node so using this feature spike machine can now use
OpenSBI firmware BIN as bios.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

変更サマリ

差分

--- a/hw/char/riscv_htif.c
+++ b/hw/char/riscv_htif.c
@@ -228,13 +228,25 @@ static const MemoryRegionOps htif_mm_ops = {
228228 .write = htif_mm_write,
229229 };
230230
231+bool htif_uses_elf_symbols(void)
232+{
233+ return (address_symbol_set == 3) ? true : false;
234+}
235+
231236 HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem,
232- CPURISCVState *env, Chardev *chr)
237+ CPURISCVState *env, Chardev *chr, uint64_t nonelf_base)
233238 {
234- uint64_t base = MIN(tohost_addr, fromhost_addr);
235- uint64_t size = MAX(tohost_addr + 8, fromhost_addr + 8) - base;
236- uint64_t tohost_offset = tohost_addr - base;
237- uint64_t fromhost_offset = fromhost_addr - base;
239+ uint64_t base, size, tohost_offset, fromhost_offset;
240+
241+ if (!htif_uses_elf_symbols()) {
242+ fromhost_addr = nonelf_base;
243+ tohost_addr = nonelf_base + 8;
244+ }
245+
246+ base = MIN(tohost_addr, fromhost_addr);
247+ size = MAX(tohost_addr + 8, fromhost_addr + 8) - base;
248+ tohost_offset = tohost_addr - base;
249+ fromhost_offset = fromhost_addr - base;
238250
239251 HTIFState *s = g_malloc0(sizeof(HTIFState));
240252 s->address_space = address_space;
@@ -249,12 +261,11 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem,
249261 qemu_chr_fe_init(&s->chr, chr, &error_abort);
250262 qemu_chr_fe_set_handlers(&s->chr, htif_can_recv, htif_recv, htif_event,
251263 htif_be_change, s, NULL, true);
252- if (address_symbol_set == 3) {
253- memory_region_init_io(&s->mmio, NULL, &htif_mm_ops, s,
254- TYPE_HTIF_UART, size);
255- memory_region_add_subregion_overlap(address_space, base,
256- &s->mmio, 1);
257- }
264+
265+ memory_region_init_io(&s->mmio, NULL, &htif_mm_ops, s,
266+ TYPE_HTIF_UART, size);
267+ memory_region_add_subregion_overlap(address_space, base,
268+ &s->mmio, 1);
258269
259270 return s;
260271 }
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -42,6 +42,7 @@
4242
4343 static const MemMapEntry spike_memmap[] = {
4444 [SPIKE_MROM] = { 0x1000, 0xf000 },
45+ [SPIKE_HTIF] = { 0x1000000, 0x1000 },
4546 [SPIKE_CLINT] = { 0x2000000, 0x10000 },
4647 [SPIKE_DRAM] = { 0x80000000, 0x0 },
4748 };
@@ -75,6 +76,10 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,
7576
7677 qemu_fdt_add_subnode(fdt, "/htif");
7778 qemu_fdt_setprop_string(fdt, "/htif", "compatible", "ucb,htif0");
79+ if (!htif_uses_elf_symbols()) {
80+ qemu_fdt_setprop_cells(fdt, "/htif", "reg",
81+ 0x0, memmap[SPIKE_HTIF].base, 0x0, memmap[SPIKE_HTIF].size);
82+ }
7883
7984 qemu_fdt_add_subnode(fdt, "/soc");
8085 qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
@@ -172,6 +177,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,
172177 if (cmdline) {
173178 qemu_fdt_add_subnode(fdt, "/chosen");
174179 qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
180+ qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif");
175181 }
176182 }
177183
@@ -241,10 +247,6 @@ static void spike_board_init(MachineState *machine)
241247 memory_region_add_subregion(system_memory, memmap[SPIKE_DRAM].base,
242248 machine->ram);
243249
244- /* create device tree */
245- create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline,
246- riscv_is_32bit(&s->soc[0]));
247-
248250 /* boot rom */
249251 memory_region_init_rom(mask_rom, NULL, "riscv.spike.mrom",
250252 memmap[SPIKE_MROM].size, &error_fatal);
@@ -266,6 +268,7 @@ static void spike_board_init(MachineState *machine)
266268 htif_symbol_callback);
267269 }
268270
271+ /* Load kernel */
269272 if (machine->kernel_filename) {
270273 kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0],
271274 firmware_end_addr);
@@ -273,17 +276,6 @@ static void spike_board_init(MachineState *machine)
273276 kernel_entry = riscv_load_kernel(machine->kernel_filename,
274277 kernel_start_addr,
275278 htif_symbol_callback);
276-
277- if (machine->initrd_filename) {
278- hwaddr start;
279- hwaddr end = riscv_load_initrd(machine->initrd_filename,
280- machine->ram_size, kernel_entry,
281- &start);
282- qemu_fdt_setprop_cell(s->fdt, "/chosen",
283- "linux,initrd-start", start);
284- qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end",
285- end);
286- }
287279 } else {
288280 /*
289281 * If dynamic firmware is used, it doesn't know where is the next mode
@@ -292,6 +284,22 @@ static void spike_board_init(MachineState *machine)
292284 kernel_entry = 0;
293285 }
294286
287+ /* Create device tree */
288+ create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline,
289+ riscv_is_32bit(&s->soc[0]));
290+
291+ /* Load initrd */
292+ if (machine->kernel_filename && machine->initrd_filename) {
293+ hwaddr start;
294+ hwaddr end = riscv_load_initrd(machine->initrd_filename,
295+ machine->ram_size, kernel_entry,
296+ &start);
297+ qemu_fdt_setprop_cell(s->fdt, "/chosen",
298+ "linux,initrd-start", start);
299+ qemu_fdt_setprop_cell(s->fdt, "/chosen", "linux,initrd-end",
300+ end);
301+ }
302+
295303 /* Compute the fdt load address in dram */
296304 fdt_load_addr = riscv_load_fdt(memmap[SPIKE_DRAM].base,
297305 machine->ram_size, s->fdt);
@@ -303,7 +311,8 @@ static void spike_board_init(MachineState *machine)
303311
304312 /* initialize HTIF using symbols found in load_kernel */
305313 htif_mm_init(system_memory, mask_rom,
306- &s->soc[0].harts[0].env, serial_hd(0));
314+ &s->soc[0].harts[0].env, serial_hd(0),
315+ memmap[SPIKE_HTIF].base);
307316 }
308317
309318 static void spike_machine_instance_init(Object *obj)
--- a/include/hw/char/riscv_htif.h
+++ b/include/hw/char/riscv_htif.h
@@ -52,8 +52,11 @@ extern const MemoryRegionOps htif_io_ops;
5252 void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,
5353 uint64_t st_size);
5454
55+/* Check if HTIF uses ELF symbols */
56+bool htif_uses_elf_symbols(void);
57+
5558 /* legacy pre qom */
5659 HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem,
57- CPURISCVState *env, Chardev *chr);
60+ CPURISCVState *env, Chardev *chr, uint64_t nonelf_base);
5861
5962 #endif
--- a/include/hw/riscv/spike.h
+++ b/include/hw/riscv/spike.h
@@ -43,6 +43,7 @@ struct SpikeState {
4343
4444 enum {
4545 SPIKE_MROM,
46+ SPIKE_HTIF,
4647 SPIKE_CLINT,
4748 SPIKE_DRAM
4849 };