Skip to content

Commit

Permalink
qemu: Getting spiflash emulation working.
Browse files Browse the repository at this point in the history
  • Loading branch information
mithro committed Apr 2, 2017
1 parent 7b7714d commit 286bba2
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions mkimage.py
Expand Up @@ -16,6 +16,7 @@ def main():
parser.add_argument("--override-gateware")
parser.add_argument("--override-bios")
parser.add_argument("--override-firmware")
parser.add_argument("--force-image-size")

args = parser.parse_args()

Expand Down Expand Up @@ -118,6 +119,13 @@ def main():
" ({} Megabits, {:.2f} Megabytes)"
).format(total, int(total*8/1024/1024), total/1024/1024))

if args.force_image_size:
if args.force_image_size.lower() in ("true", "1"):
flash_size = platform.spiflash_total_size
else:
flash_size = int(args.force_image_size)
f.write(b'\xff' * (flash_size - f.tell()))

print()
print("Flash image: {}".format(output))
flash_image_data = open(output, "rb").read()
Expand Down
1 change: 1 addition & 0 deletions platforms/atlys.py
Expand Up @@ -619,6 +619,7 @@ class Platform(XilinxPlatform):
# Micron N25Q128 (ID 0x0018ba20)
# FIXME: Create a "spi flash module" object in the same way we have SDRAM
# module objects.
spiflash_model = "n25q128"
spiflash_read_dummy_bits = 10
spiflash_clock_div = 4
spiflash_total_size = int((128/8)*1024*1024) # 128Mbit
Expand Down
1 change: 1 addition & 0 deletions platforms/mimasv2.py
Expand Up @@ -130,6 +130,7 @@ class Platform(XilinxPlatform):
# module objects.
# /* name, erase_cmd, chip_erase_cmd, device_id, pagesize, sectorsize, size_in_bytes */
# FLASH_ID("st m25p16", 0xd8, 0xc7, 0x00152020, 0x100, 0x10000, 0x200000),
spiflash_model = "m25p16"
spiflash_read_dummy_bits = 8
spiflash_clock_div = 4
spiflash_total_size = int((16/8)*1024*1024) # 16Mbit
Expand Down
1 change: 1 addition & 0 deletions platforms/minispartan6.py
Expand Up @@ -159,6 +159,7 @@ class Platform(XilinxPlatform):
# Mac 25L6405' (ID 0x001720c2)
# FIXME: Create a "spi flash module" object in the same way we have SDRAM
# module objects.
spiflash_model = "25l6405"
spiflash_read_dummy_bits = 4
spiflash_clock_div = 4
spiflash_total_size = int((64/8)*1024*1024) # 64Mbit
Expand Down
2 changes: 2 additions & 0 deletions platforms/netv2.py
Expand Up @@ -82,6 +82,8 @@ class Platform(XilinxPlatform):
default_clk_name = "clk100"
default_clk_period = 20.0

spiflash_model = "n25q128"

def __init__(self, toolchain="vivado", programmer="vivado"):
XilinxPlatform.__init__(self, "xc7a50t-csg325-2", _io,
toolchain=toolchain)
Expand Down
2 changes: 2 additions & 0 deletions platforms/nexys_video.py
Expand Up @@ -130,6 +130,8 @@ class Platform(XilinxPlatform):
default_clk_name = "clk100"
default_clk_period = 10.0

spiflash_model = "n25q128"

def __init__(self, toolchain="vivado", programmer="vivado"):
XilinxPlatform.__init__(self, "xc7a200t-sbg484-1", _io,
toolchain=toolchain)
Expand Down
1 change: 1 addition & 0 deletions platforms/opsis.py
Expand Up @@ -507,6 +507,7 @@ class Platform(XilinxPlatform):
# Pretends to be a Micron N25Q128 (ID 0x0018ba20)
# FIXME: Create a "spi flash module" object in the same way we have SDRAM
# module objects.
spiflash_model = "n25q128"
spiflash_read_dummy_bits = 10
spiflash_clock_div = 4
spiflash_total_size = int((128/8)*1024*1024) # 128Mbit
Expand Down
1 change: 1 addition & 0 deletions platforms/pipistrello.py
Expand Up @@ -140,6 +140,7 @@ class Platform(XilinxPlatform):
# Micron N25Q128 (ID 0x0018ba20)
# FIXME: Create a "spi flash module" object in the same way we have SDRAM
# module objects.
spiflash_model = "n25q128"
spiflash_read_dummy_bits = 10
spiflash_clock_div = 4
spiflash_total_size = int((128/8)*1024*1024) # 128Mbit
Expand Down
8 changes: 6 additions & 2 deletions scripts/build-qemu.sh
Expand Up @@ -89,7 +89,8 @@ cd $TARGET_QEMU_BUILD_DIR
make -j8
cd $OLD_DIR

/usr/bin/env python mkimage.py --output-file=qemu.bin --override-gateware=none
/usr/bin/env python mkimage.py --output-file=qemu.bin --override-gateware=none --force-image-size=true
$TARGET_QEMU_BUILD_DIR/qemu-img convert -f raw $TARGET_BUILD_DIR/qemu.bin -O qcow2 -S 16M $TARGET_BUILD_DIR/qemu.qcow2

HAS_LITEETH=$(grep -q ETHMAC_BASE $TARGET_BUILD_DIR/software/include/generated/csr.h && echo 1 || echo 0)

Expand All @@ -108,13 +109,16 @@ if [ $HAS_LITEETH -eq 1 ]; then
make tftp
fi

SPIFLASH_MODEL=$(grep spiflash_model platforms/$PLATFORM.py | sed -e's/[^"]*"//' -e's/".*$//')
echo $SPIFLASH_MODEL

$TARGET_QEMU_BUILD_DIR/$QEMU_ARCH/qemu-system-$QEMU_CPU \
-M litex \
-nographic -nodefaults \
-monitor pty \
-serial stdio \
-bios $TARGET_BUILD_DIR/software/bios/bios.bin \
-kernel $TARGET_BUILD_DIR/qemu.bin \
-drive if=mtd,format=qcow2,file=$TARGET_BUILD_DIR/qemu.qcow2,serial=$SPIFLASH_MODEL \
$EXTRA_ARGS


0 comments on commit 286bba2

Please sign in to comment.