Skip to content

Commit 1139d23

Browse files
committed
[qemu] Create and attach flash device for SPI Host 0/SPI Device
Depends on lowRISC/qemu#255 Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent 19ca9ac commit 1139d23

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

rules/opentitan/qemu.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ def _test_dispatch(ctx, exec_env, firmware):
431431
}
432432
param["bootstrap_cmd"] = '--exec="no-op" # SKIPPING BOOTSTRAP'
433433

434+
# Attach SPI flash to SPI Host 0/SPI Device bus. Chosen model is W25Q256 (32MiB)
435+
qemu_args += ["-global", "ot-earlgrey-board.spiflash0=w25q256"]
436+
qemu_args += ["-drive", "if=mtd,file=spiflash0.bin,format=raw,bus=0"]
437+
434438
# Get the pre-test_cmd args.
435439
args = get_fallback(ctx, "attr.args", exec_env)
436440
args = " ".join(args).format(**param)

rules/scripts/qemu_test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ args=( __args__ )
1818

1919
mutable_flash="flash_img.bin"
2020
mutable_otp="otp_img.raw"
21+
spiflash0="spiflash0.bin"
2122

2223
test_args=( "$@" )
2324
qemu_test_args=()
@@ -52,6 +53,7 @@ cleanup() {
5253
wait "$qemu_pid"
5354

5455
rm -f "${mutable_otp}" "${mutable_flash}"
56+
rm -f "${spiflash0}"
5557
rm -f qemu-monitor qemu.log
5658
}
5759
trap cleanup EXIT
@@ -63,6 +65,9 @@ if [ -n "${flash}" ]; then
6365
cp "${flash}" "${mutable_flash}" && chmod +w "${mutable_flash}"
6466
fi
6567

68+
# create backing storage for flash device on SPI Host 0/SPI Device SPI bus
69+
dd if=/dev/zero of="${spiflash0}" bs=1M count=32 status=none && chmod +w "${spiflash0}"
70+
6671
# QEMU disconnects from `stdout` when it daemonizes so we need to stream
6772
# the log through a pipe:
6873
mkfifo qemu.log && cat qemu.log &

0 commit comments

Comments
 (0)