Add support for setting memory contents during synthesis

This commit is contained in:
Olof Kindgren 2018-11-26 09:49:08 +01:00
parent e1f5bcc4f3
commit 12039dec0e
9 changed files with 2159 additions and 5 deletions

View file

@ -4,8 +4,7 @@ module serv_wrapper
input wire wb_clk,
output wire q);
parameter memfile = "helloservice4000.hex";
// parameter memfile = "bitbang.hex";
parameter memfile = "zephyr_hello.hex";
reg [4:0] rst_reg = 5'b11111;

View file

@ -78,7 +78,6 @@ module serv_decode
wire running;
wire mem_op;
wire shift_op;
wire csr_op;
wire slt_op;
wire branch_op;
wire e_op;

View file

@ -22,8 +22,8 @@ filesets:
mem_files:
files:
- bitbang.hex : {copyto : bitbang.hex}
- helloservice4000.hex : {copyto : helloservice4000.hex}
- sw/blinky.hex : {copyto : blinky.hex}
- sw/zephyr_hello.hex : {copyto : zephyr_hello.hex}
file_type : user
serv_top_tb:
@ -65,6 +65,7 @@ targets:
icebreaker:
default_tool : icestorm
filesets : [core, mem_files, wrapper, icebreaker]
parameters : [memfile]
tools:
icestorm:
nextpnr_options: [--up5k, --freq, 12]
@ -79,6 +80,7 @@ targets:
tinyfpga_bx:
default_tool : icestorm
filesets : [core, mem_files, wrapper, tinyfpga_bx]
parameters : [memfile]
tools:
icestorm:
nextpnr_options : [--lp8k, --package, cm81, --freq, 16]
@ -120,8 +122,14 @@ parameters:
firmware:
datatype : file
description : Preload RAM with a hex file at runtime (overrides memfile)
paramtype : plusarg
memfile:
datatype : file
description : Preload RAM with a hex file at compile-time
paramtype : vlogparam
signature:
datatype : file
paramtype : plusarg

9
sw/Makefile Normal file
View file

@ -0,0 +1,9 @@
%.elf: %.S
riscv64-unknown-elf-gcc -nostartfiles -march=rv32i -mabi=ilp32 -Tlink.ld -o$@ $<
%.bin: %.elf
riscv64-unknown-elf-objcopy -O binary $< $@
%.hex: %.bin
python3 makehex.py $< 2048 > $@
clean:
rm -f *.elf *.bin *.hex

46
sw/blinky.S Normal file
View file

@ -0,0 +1,46 @@
/*
* LED Blinker
* Assuming that GPIO_BASE is mapped to a GPIO core, which in turn is
* connected to LEDs, this will light the LEDs one at a time.
* Useful as smoke test to see that serv is running correctly
*/
#ifndef GPIO_BASE
#define GPIO_BASE 0x40000000
#endif
#ifndef DELAY
#define DELAY 0x100000 /* Loop 100000 times before inverting the LED */
#endif
/*
a0 = GPIO Base address
t0 = Value
t1 = Timer max value
t2 = Current timer value
*/
.globl _start
_start:
/* Load GPIO base address to a0 */
lui a0, %hi(GPIO_BASE)
addi a0, a0, %lo(GPIO_BASE)
/* Set timer value to control blink speed */
li t1, DELAY
bl1:
/* Write to LEDs */
sb t0, 0(a0)
/* invert LED */
xori t0, t0, 1
/* Reset timer */
and t2, zero, zero
/* Delay loop */
time1:
addi t2, t2, 1
bne t1, t2, time1
j bl1

2048
sw/blinky.hex Normal file

File diff suppressed because it is too large Load diff

18
sw/link.ld Normal file
View file

@ -0,0 +1,18 @@
OUTPUT_ARCH( "riscv" )
ENTRY(_start)
SECTIONS
{
. = 0x00000000;
.text.init : { *(.text.init) }
. = ALIGN(0x1000);
.tohost : { *(.tohost) }
. = ALIGN(0x1000);
.text : { *(.text) }
. = ALIGN(0x1000);
.data : { *(.data) }
.data.string : { *(.data.string)}
.bss : { *(.bss) }
_end = .;
}

27
sw/makehex.py Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env python3
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
from sys import argv
binfile = argv[1]
nwords = int(argv[2])
with open(binfile, "rb") as f:
bindata = f.read()
assert len(bindata) < 4*nwords
assert len(bindata) % 4 == 0
for i in range(nwords):
if i < len(bindata) // 4:
w = bindata[4*i : 4*i+4]
print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]))
else:
print("0")