Improve RISC-V spike machine bios support
Subsystems (2)
v3 cover Improve RISC-V spike machine bios support
This series aims at improving RISC-V spike machine BIOS support by allowing use of binary firmware as bios. Further, this also allows us to totally remove the ELF bios images shipped with QEMU RISC-V.
These patches can also be found in riscv_spike_imp_v3 branch at:
https://github.com/avpatel/qemu.git
Changes since v2:
- Remove ELF file names from .gitlab-ci.d/opensbi.yml in PATCH3
Changes since v1:
- Use htif_uses_elf_symbols() in htif_mm_init() for PATCH1
- Added PATCH2 and PATCH3 to remove ELF bios images
Anup Patel (3):
hw/riscv: spike: Allow using binary firmware as bios hw/riscv: Remove macros for ELF BIOS image names roms/opensbi: Remove ELF images
.gitlab-ci.d/opensbi.yml | 2 - hw/char/riscv_htif.c | 33 ++++++++----- hw/riscv/spike.c | 45 +++++++++++------- include/hw/char/riscv_htif.h | 5 +- include/hw/riscv/boot.h | 2 - include/hw/riscv/spike.h | 1 + pc-bios/meson.build | 2 - .../opensbi-riscv32-generic-fw_dynamic.elf | Bin 838904 -> 0 bytes .../opensbi-riscv64-generic-fw_dynamic.elf | Bin 934696 -> 0 bytes roms/Makefile | 2 - 10 files changed, 54 insertions(+), 38 deletions(-) delete mode 100644 pc-bios/opensbi-riscv32-generic-fw_dynamic.elf delete mode 100644 pc-bios/opensbi-riscv64-generic-fw_dynamic.elf
Signature · 1 line
2.25.1
PATCH v3 1/3 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.
--- hw/char/riscv_htif.c | 33 +++++++++++++++++++---------- hw/riscv/spike.c | 41 ++++++++++++++++++++++-------------- include/hw/char/riscv_htif.h | 5 ++++- include/hw/riscv/spike.h | 1 + 4 files changed, 52 insertions(+), 28 deletions(-)
hw/char/riscv_htif.c +22 -11
@@ -228,13 +228,25 @@ static const MemoryRegionOps htif_mm_ops = { .write = htif_mm_write, }; +bool htif_uses_elf_symbols (void ) +{ +return (address_symbol_set ==3 ) ? true : false; +} +HTIFState *htif_mm_init (MemoryRegion *address_space,MemoryRegion *main_mem, -CPURISCVState *env,Chardev *chr) +CPURISCVState *env,Chardev *chr,uint64_t nonelf_base) { -uint64_t base =MIN (tohost_addr, fromhost_addr); -uint64_t size =MAX (tohost_addr +8 , fromhost_addr +8 ) - base; -uint64_t tohost_offset = tohost_addr - base; -uint64_t fromhost_offset = fromhost_addr - base; +uint64_t base, size, tohost_offset, fromhost_offset; + +if (!htif_uses_elf_symbols ()) { + fromhost_addr = nonelf_base; + tohost_addr = nonelf_base +8 ; + } + + base =MIN (tohost_addr, fromhost_addr); + size =MAX (tohost_addr +8 , fromhost_addr +8 ) - base; + tohost_offset = tohost_addr - base; + fromhost_offset = fromhost_addr - base;HTIFState *s =g_malloc0 (sizeof (HTIFState)); s->address_space = address_space;
@@ -249,12 +261,11 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem,qemu_chr_fe_init (&s->chr, chr, &error_abort);qemu_chr_fe_set_handlers (&s->chr, htif_can_recv, htif_recv, htif_event, htif_be_change, s,NULL , true); -if (address_symbol_set ==3 ) { -memory_region_init_io (&s->mmio,NULL , &htif_mm_ops, s, -TYPE_HTIF_UART , size); -memory_region_add_subregion_overlap (address_space, base, - &s->mmio,1 ); - } + +memory_region_init_io (&s->mmio,NULL , &htif_mm_ops, s, +TYPE_HTIF_UART , size); +memory_region_add_subregion_overlap (address_space, base, + &s->mmio,1 );return s; }
hw/riscv/spike.c +25 -16
89 lines not on this page · raw message
include/hw/char/riscv_htif.h +4 -1
@@ -52,8 +52,11 @@ extern const MemoryRegionOps htif_io_ops;void htif_symbol_callback (const char *st_name,int st_info,uint64_t st_value,uint64_t st_size); +/* Check if HTIF uses ELF symbols */ +bool htif_uses_elf_symbols (void ); +/* legacy pre qom */ HTIFState *htif_mm_init (MemoryRegion *address_space,MemoryRegion *main_mem, -CPURISCVState *env,Chardev *chr); +CPURISCVState *env,Chardev *chr,uint64_t nonelf_base);#endif
include/hw/riscv/spike.h +1 -0
@@ -43,6 +43,7 @@ struct SpikeState {enum {SPIKE_MROM , +SPIKE_HTIF ,SPIKE_CLINT ,SPIKE_DRAM };
Signature · 1 line
2.25.1
PATCH v3 2/3 hw/riscv: Remove macros for ELF BIOS image names
In reply to Anup PatelNow that RISC-V Spike machine can use BIN BIOS images, we remove the macros used for ELF BIOS image names.
--- hw/riscv/spike.c | 4 ++-- include/hw/riscv/boot.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-)
hw/riscv/spike.c +2 -2
@@ -260,11 +260,11 @@ static void spike_board_init(MachineState *machine)*/ if (riscv_is_32bit (&s->soc[0 ])) { firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV32_BIOS_ELF , memmap[SPIKE_DRAM ].base, +RISCV32_BIOS_BIN , memmap[SPIKE_DRAM ].base, htif_symbol_callback); }else { firmware_end_addr =riscv_find_and_load_firmware (machine, -RISCV64_BIOS_ELF , memmap[SPIKE_DRAM ].base, +RISCV64_BIOS_BIN , memmap[SPIKE_DRAM ].base, htif_symbol_callback); }
include/hw/riscv/boot.h +0 -2
@@ -25,9 +25,7 @@#include "hw/riscv/riscv_hart.h" #define RISCV32_BIOS_BIN "opensbi-riscv32-generic-fw_dynamic.bin" -#define RISCV32_BIOS_ELF "opensbi-riscv32-generic-fw_dynamic.elf"#define RISCV64_BIOS_BIN "opensbi-riscv64-generic-fw_dynamic.bin" -#define RISCV64_BIOS_ELF "opensbi-riscv64-generic-fw_dynamic.elf"bool riscv_is_32bit (RISCVHartArrayState *harts);
Signature · 1 line
2.25.1
PATCH v3 3/3 roms/opensbi: Remove ELF images
In reply to Anup PatelNow that all RISC-V machines can use OpenSBI BIN images, we remove OpenSBI ELF images and also exclude these images from BIOS build.
--- .gitlab-ci.d/opensbi.yml | 2 -- pc-bios/meson.build | 2 -- pc-bios/opensbi-riscv32-generic-fw_dynamic.elf | Bin 838904 -> 0 bytes pc-bios/opensbi-riscv64-generic-fw_dynamic.elf | Bin 934696 -> 0 bytes roms/Makefile | 2 -- 5 files changed, 6 deletions(-) delete mode 100644 pc-bios/opensbi-riscv32-generic-fw_dynamic.elf delete mode 100644 pc-bios/opensbi-riscv64-generic-fw_dynamic.elf
.gitlab-ci.d/opensbi.yml +0 -2
@@ -43,9 +43,7 @@ build-opensbi: artifacts: paths: # 'artifacts.zip' will contains the following files: - pc-bios/opensbi-riscv32-generic-fw_dynamic.bin - - pc-bios/opensbi-riscv32-generic-fw_dynamic.elf - pc-bios/opensbi-riscv64-generic-fw_dynamic.bin - - pc-bios/opensbi-riscv64-generic-fw_dynamic.elf - opensbi32-generic-stdout.log - opensbi32-generic-stderr.log - opensbi64-generic-stdout.log
pc-bios/meson.build +0 -2
@@ -80,8 +80,6 @@ blobs = files( 'hppa-firmware.img', 'opensbi-riscv32-generic-fw_dynamic.bin', 'opensbi-riscv64-generic-fw_dynamic.bin', - 'opensbi-riscv32-generic-fw_dynamic.elf', - 'opensbi-riscv64-generic-fw_dynamic.elf', 'npcm7xx_bootrom.bin', )
pc-bios/opensbi-riscv32-generic-fw_dynamic.elf deleted binary +0 -0
pc-bios/opensbi-riscv64-generic-fw_dynamic.elf deleted binary +0 -0
roms/Makefile +0 -2
@@ -178,14 +178,12 @@ opensbi32-generic: CROSS_COMPILE=$(riscv32_cross_prefix) \ PLATFORM="generic" cp opensbi/build/platform/generic/firmware/fw_dynamic.bin ../pc-bios/opensbi-riscv32-generic-fw_dynamic.bin - cp opensbi/build/platform/generic/firmware/fw_dynamic.elf ../pc-bios/opensbi-riscv32-generic-fw_dynamic.elf opensbi64-generic: $(MAKE) -C opensbi \ CROSS_COMPILE=$(riscv64_cross_prefix) \ PLATFORM="generic" cp opensbi/build/platform/generic/firmware/fw_dynamic.bin ../pc-bios/opensbi-riscv64-generic-fw_dynamic.bin - cp opensbi/build/platform/generic/firmware/fw_dynamic.elf ../pc-bios/opensbi-riscv64-generic-fw_dynamic.elf MESON = meson NINJA = ninja
Signature · 1 line
2.25.1
Alistair Francis
AppliedQuoted 11 lines · Anup Patel
This series aims at improving RISC-V spike machine BIOS support by allowing use of binary firmware as bios. Further, this also allows us to totally remove the ELF bios images shipped with QEMU RISC-V.
These patches can also be found in
riscv_spike_imp_v3branch at:
https://github.com/avpatel/qemu.gitChanges since v2:
- Remove ELF file names from.gitlab-ci.d/opensbi.ymlin PATCH3
Quoted 8 lines
Changes since v1:
- Usehtif_uses_elf_symbols()inhtif_mm_init()for PATCH1
- Added PATCH2 and PATCH3 to remove ELF bios imagesAnup Patel (3):
hw/riscv: spike: Allow using binary firmware as bios hw/riscv: Remove macros for ELF BIOS image names roms/opensbi: Remove ELF images
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 19 lines
.gitlab-ci.d/opensbi.yml | 2 - hw/char/riscv_htif.c | 33 ++++++++----- hw/riscv/spike.c | 45 +++++++++++------- include/hw/char/riscv_htif.h | 5 +- include/hw/riscv/boot.h | 2 - include/hw/riscv/spike.h | 1 + pc-bios/meson.build | 2 - .../opensbi-riscv32-generic-fw_dynamic.elf | Bin 838904 -> 0 bytes .../opensbi-riscv64-generic-fw_dynamic.elf | Bin 934696 -> 0 bytes roms/Makefile | 2 - 10 files changed, 54 insertions(+), 38 deletions(-) delete mode 100644 pc-bios/opensbi-riscv32-generic-fw_dynamic.elf delete mode 100644 pc-bios/opensbi-riscv64-generic-fw_dynamic.elf--
2.25.1