Skip to content

Commit 21bd08b

Browse files
run_qemu: add a flag to choose OpenSBI's fw_payload as RISC-V's bios
1 parent 4b25318 commit 21bd08b

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

pycheribuild/projects/run_qemu.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ def setup_config_options(cls, default_ssh_port: "Optional[int]" = None, **kwargs
219219
"bios", metavar="BIOS", help="If set, force QEMU to use the given bios binary"
220220
)
221221

222+
cls.use_opensbi_payload = cls.add_bool_option(
223+
"use-opensbi-fw-payload ",
224+
default=False,
225+
show_help=True,
226+
help="Force QEMU to use OpenSBI's fw_payload variant instead of fw_jump. This is only for RISC-V.",
227+
)
228+
222229
def __init__(self, *args, **kwargs):
223230
super().__init__(*args, **kwargs)
224231
self.current_kernel: Optional[Path] = None
@@ -236,13 +243,14 @@ def __init__(self, *args, **kwargs):
236243
self._after_disk_options = []
237244

238245
@staticmethod
239-
def riscv_bios_arguments(xtarget: CrossCompileTarget, caller: SimpleProject, prefer_bbl=True) -> "list[str]":
246+
def riscv_bios_arguments(
247+
xtarget: CrossCompileTarget, caller: SimpleProject, prefer_bbl=True, prefer_opensbi_payload=False
248+
) -> "list[str]":
240249
assert xtarget.is_riscv(include_purecap=True)
241-
xlen = 32 if xtarget.is_riscv32() else 64
242250
if xtarget.is_hybrid_or_purecap_cheri([CPUArchitecture.RISCV64]):
243251
# FIXME: QEMU does not yet default to the correct BIOS image name.
244252
if xtarget.is_experimental_cheri093_std(caller.config):
245-
bios_file = BuildAllianceOpenSBI.get_cheri_bios(caller, xtarget)
253+
bios_file = BuildAllianceOpenSBI.get_cheri_bios(caller, xtarget, prefer_opensbi_payload)
246254
elif prefer_bbl:
247255
# Always use a purecap bbl
248256
bios_file = BuildBBLNoPayload.get_cheri_bios(caller, xtarget)
@@ -253,17 +261,17 @@ def riscv_bios_arguments(xtarget: CrossCompileTarget, caller: SimpleProject, pre
253261
return ["-bios", bios_file.name]
254262
return ["-bios", str(bios_file)]
255263
if xtarget.target_info_cls.is_linux():
256-
# For Linux non-CHERI targets, use the bundled openSBI firmware
257-
# even when launching CHERI QEMU since bbl does not work with Linux
258-
return ["-bios", f"opensbi-riscv{xlen}-generic-fw_dynamic.bin"]
259-
# For non-CHERI we prefer the OpenSBI bios that is bundled with QEMU
260-
# return BuildOpenSBI.get_nocap_bios(caller)
264+
# For non-CHERI we prefer the OpenSBI bios that is bundled with QEMU
265+
bios_file = BuildAllianceOpenSBI.get_nocap_bios(caller, xtarget, prefer_opensbi_payload)
266+
return ["-bios", bios_file]
261267
return ["-bios", "default"]
262268

263269
def get_riscv_bios_args(self) -> "list[str]":
264270
if self.bios:
265271
return ["-bios", str(self.bios)]
266-
return self.riscv_bios_arguments(self.crosscompile_target, self)
272+
return self.riscv_bios_arguments(
273+
self.crosscompile_target, self, prefer_opensbi_payload=self.use_opensbi_payload
274+
)
267275

268276
@classmethod
269277
def targets_reset(cls) -> None:

0 commit comments

Comments
 (0)