Compare commits

...

3 Commits

Author SHA1 Message Date
Sebastien Bourdeauducq ad4f00e93d simplesoc_ecp5: load firmware 2019-06-06 18:11:54 +08:00
Sebastien Bourdeauducq a53c470d17 nmigen: bump 2019-06-06 18:11:31 +08:00
Sebastien Bourdeauducq 713f644072 minerva: bump 2019-06-06 18:04:56 +08:00
5 changed files with 34 additions and 11 deletions

View File

@ -6,8 +6,8 @@ python3Packages.buildPythonPackage {
src = fetchFromGitHub {
owner = "lambdaconcept";
repo = "minerva";
rev = "2a017224497d50505395b4d9e09ab74412ccd131";
sha256 = "1bc0phlmxhcw15d1b23xgrsazgxxxi2l1h3mvk7zb68h5pgq4svm";
rev = "eefcbd066f2144422b06b398b4651dbd86db52b6";
sha256 = "0kv5sgyggic90hf4s3xf2aanwqn1961zhvng6hhzmjsqn1m17rdq";
};
propagatedBuildInputs = [ nmigen jtagtap ];

View File

@ -19,7 +19,7 @@ rec {
binutils-riscv = pkgs.callPackage ./compilers/binutils.nix { platform = "riscv32"; };
rust-riscv32imc-crates = pkgs.callPackage ./compilers/rust-riscv32imc-crates.nix { };
helloworld = pkgs.callPackage ./firmware { inherit rust-riscv32imc-crates binutils-riscv; };
fw-helloworld = pkgs.callPackage ./firmware { inherit rust-riscv32imc-crates binutils-riscv; };
};
lib = {
symbiflow = import ./eda/symbiflow.nix { inherit pkgs; inherit (drvs) yosys; };

View File

@ -6,13 +6,13 @@ python3Packages.buildPythonPackage {
src = fetchFromGitHub {
owner = "m-labs";
repo = "nmigen";
rev = "c337246fc581ccac0273f5661f65815266144862";
sha256 = "03gbd5k87w9ifa8iz0wprpswv7qn93swzcvjnvs5czn39lwvwgh4";
rev = "b45c5119f573e156a3aad4a362ca210d6e40505e";
sha256 = "1qyh6h8amqz9z6l2h0rj4lzpkm1i2fgbxn5m0p6igwflqk0svffz";
};
checkPhase = "PATH=${yosys}/bin:${symbiyosys}/bin:${yices}/bin:$PATH python -m unittest discover nmigen.test -v";
propagatedBuildInputs = [ python3Packages.bitarray python3Packages.pyvcd ];
propagatedBuildInputs = [ python3Packages.bitarray python3Packages.pyvcd python3Packages.jinja2 ];
meta = with stdenv.lib; {
description = "A refreshed Python toolbox for building complex digital hardware";

View File

@ -7,7 +7,7 @@ let
''
mkdir $out
python ${./simplesoc_ecp5.py} > $out/top.il
python ${./simplesoc_ecp5.py} ${hx.drvs.fw-helloworld}/helloworld.bin $out/top.il
cat > $out/top.lpf << EOF
LOCATE COMP "clk100" SITE "P3";

View File

@ -1,3 +1,6 @@
import argparse
import struct
from nmigen import *
from nmigen.back import rtlil
@ -24,9 +27,10 @@ class SimpleWishboneSerial(Elaboratable):
class Top(Elaboratable):
def __init__(self):
def __init__(self, firmware):
self.clk100 = Signal()
self.serial_tx = Signal()
self.firmware = firmware
def elaborate(self, platform):
m = Module()
@ -36,7 +40,7 @@ class Top(Elaboratable):
m.d.comb += cd_sync.clk.eq(self.clk100)
m.submodules.cpu = cpu = Minerva(with_icache=False, with_dcache=False, with_muldiv=False)
m.submodules.ram = ram = wishbone.SRAM(Memory(32, 1024))
m.submodules.ram = ram = wishbone.SRAM(Memory(32, 1024, init=self.firmware))
m.submodules.uart = uart = SimpleWishboneSerial(self.serial_tx, 100e6)
m.submodules.con = con = wishbone.InterconnectShared(
[cpu.ibus, cpu.dbus],
@ -48,11 +52,30 @@ class Top(Elaboratable):
return m
def read_firmware(file):
firmware = []
with open(file, "rb") as f:
while True:
word = f.read(4)
if len(word) < 4:
break
firmware.append(struct.unpack(">I", word)[0])
return firmware
def main():
top = Top()
parser = argparse.ArgumentParser()
parser.add_argument("firmware_bin")
parser.add_argument("output_file")
args = parser.parse_args()
firmware = read_firmware(args.firmware_bin)
top = Top(firmware)
output = rtlil.convert(Fragment.get(top, None),
ports=(top.clk100, top.serial_tx))
print(output)
with open(args.output_file, "w") as f:
f.write(output)
if __name__ == "__main__":
main()