diff --git a/rules/opentitan/qemu.bzl b/rules/opentitan/qemu.bzl index 97d26e3bfaa98..0b4bef372c5e9 100644 --- a/rules/opentitan/qemu.bzl +++ b/rules/opentitan/qemu.bzl @@ -431,6 +431,10 @@ def _test_dispatch(ctx, exec_env, firmware): } param["bootstrap_cmd"] = '--exec="no-op" # SKIPPING BOOTSTRAP' + # Attach SPI flash to SPI Host 0/SPI Device bus. Chosen model is W25Q256 (32MiB) + qemu_args += ["-global", "ot-earlgrey-board.spiflash0=w25q256"] + qemu_args += ["-drive", "if=mtd,file=spiflash0.bin,format=raw,bus=0"] + # Get the pre-test_cmd args. args = get_fallback(ctx, "attr.args", exec_env) args = " ".join(args).format(**param) diff --git a/rules/scripts/qemu_test.sh b/rules/scripts/qemu_test.sh index d09532d395b0c..f5881fab938b0 100644 --- a/rules/scripts/qemu_test.sh +++ b/rules/scripts/qemu_test.sh @@ -18,6 +18,7 @@ args=( __args__ ) mutable_flash="flash_img.bin" mutable_otp="otp_img.raw" +spiflash0="spiflash0.bin" test_args=( "$@" ) qemu_test_args=() @@ -52,6 +53,7 @@ cleanup() { wait "$qemu_pid" rm -f "${mutable_otp}" "${mutable_flash}" + rm -f "${spiflash0}" rm -f qemu-monitor qemu.log } trap cleanup EXIT @@ -63,6 +65,9 @@ if [ -n "${flash}" ]; then cp "${flash}" "${mutable_flash}" && chmod +w "${mutable_flash}" fi +# create backing storage for flash device on SPI Host 0/SPI Device SPI bus +dd if=/dev/zero of="${spiflash0}" bs=1M count=32 status=none && chmod +w "${spiflash0}" + # QEMU disconnects from `stdout` when it daemonizes so we need to stream # the log through a pipe: mkfifo qemu.log && cat qemu.log & diff --git a/sw/device/tests/BUILD b/sw/device/tests/BUILD index e01ca06722ae8..1e8e61f0babac 100644 --- a/sw/device/tests/BUILD +++ b/sw/device/tests/BUILD @@ -5762,6 +5762,12 @@ opentitan_test( """, test_harness = "//sw/host/tests/chip/spi_device:spi_passthru", ), + qemu = qemu_params( + test_cmd = """ + "{firmware:elf}" + """, + test_harness = "//sw/host/tests/chip/spi_device:spi_passthru", + ), silicon = silicon_params( test_cmd = """ --bootstrap="{firmware}"