Merge pull request 'Add flake' (#7) from Artturin/riscv-bluespec-classic:addflake into main

Reviewed-on: ReferenceProjects/riscv-bluespec-classic#7
This commit is contained in:
Yehowshua 2025-04-18 19:35:18 +00:00
commit d03cceb283
12 changed files with 216 additions and 39 deletions

2
.gitignore vendored
View file

@ -16,6 +16,8 @@ verilog_RTL
# files generated for FPGA ULX3s implementation # files generated for FPGA ULX3s implementation
ulx3s_fpga/mkTop.d ulx3s_fpga/mkTop.d
ulx3s_fpga/mkTop.json ulx3s_fpga/mkTop.json
ulx3s_fpga/mkTop.bit
ulx3s_fpga/mkTop.config
# generated experiment outputs # generated experiment outputs
experiments/bram/*.cxx experiments/bram/*.cxx

View file

@ -159,7 +159,7 @@ v_sim_vcd:
# ---------------------------------------------------------------- # ----------------------------------------------------------------
fpga: fpga:
make -C ulx3s_fpga make -C ulx3s_fpga mkTop.bit
.PHONY: clean .PHONY: clean
clean: clean:

View file

@ -49,4 +49,3 @@ mkSerialize fileHandle = do
ftdiState := ftdiState' ftdiState ftdiState := ftdiState' ftdiState
when (ftdiState == IDLE) when (ftdiState == IDLE)
bitLineOut = ftdiTxOut bitLineOut = ftdiTxOut

25
default.nix Normal file
View file

@ -0,0 +1,25 @@
{
system ? builtins.currentSystem,
}:
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
root = lock.nodes.${lock.root};
inherit (lock.nodes.${root.inputs.flake-compat}.locked)
owner
repo
rev
narHash
;
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.defaultNix

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1744536153,
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

78
flake.nix Normal file
View file

@ -0,0 +1,78 @@
{
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
utils.url = "github:numtide/flake-utils";
};
outputs =
inputs:
inputs.utils.lib.eachDefaultSystem (
system:
let
pkgs = import inputs.nixpkgs {
localSystem = system;
overlays = [
(final: prev: {
riscv-bluespec-classic = pkgs.callPackage (
{
stdenv,
bluespec,
nextpnr,
openfpgaloader,
trellis,
which,
yosys,
}:
stdenv.mkDerivation {
pname = "riscv-bluespec-classic";
version = "0.1.0";
src = ./.;
# Versions can be checked with
# `nix eval --json ".#riscv-bluespec-classic.nativeBuildInputs" | nix-shell -p jq --run jq`
nativeBuildInputs = [
bluespec
nextpnr
openfpgaloader
trellis
which
yosys
];
makeFlags = [
"fpga"
];
installPhase = ''
runHook preInstall
mkdir -p "$out"
cp "./ulx3s_fpga/mkTop.bit" "$out/"
runHook postInstall
'';
}
) { };
})
];
};
in
{
packages = {
default = inputs.self.packages."${system}".riscv-bluespec-classic;
riscv-bluespec-classic = pkgs.riscv-bluespec-classic;
};
devShells.default =
with pkgs;
mkShell {
inputsFrom = [ riscv-bluespec-classic ];
};
}
);
}

View file

@ -1,14 +1,25 @@
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/d34a98666913267786d9ab4aa803a1fc75f81f4d.tar.gz") {} }: {
system ? builtins.currentSystem,
}:
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
pkgs.mkShell { root = lock.nodes.${lock.root};
buildInputs = [ inherit (lock.nodes.${root.inputs.flake-compat}.locked)
pkgs.yosys owner
pkgs.nextpnr repo
pkgs.bluespec rev
pkgs.yosys-bluespec narHash
]; ;
shellHook = '' flake-compat = fetchTarball {
echo "Dev environment for Manna Chip." url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
''; sha256 = narHash;
} };
flake = import flake-compat {
inherit system;
src = ./.;
};
in
flake.shellNix

View file

@ -5,7 +5,7 @@ IDCODE ?= 0x41113043 # 85f
all: prog all: prog
../verilog_RTL/$(TOPMODULE).v: ../src/Top.bsv ../verilog_RTL/$(TOPMODULE).v: ../bs/Top.bs
V_SIM=verilator TOPMODULE=$(TOPMODULE) make -C ../ v_compile V_SIM=verilator TOPMODULE=$(TOPMODULE) make -C ../ v_compile
$(TOPMODULE).json: ../verilog_RTL/$(TOPMODULE).v $(TOPMODULE).json: ../verilog_RTL/$(TOPMODULE).v
@ -21,6 +21,7 @@ $(TOPMODULE).config: $(TOPMODULE).json
--textcfg $@ \ --textcfg $@ \
--lpf ulx3s_v20.lpf \ --lpf ulx3s_v20.lpf \
--85k \ --85k \
--lpf-allow-unconstrained \
--package CABGA381 --package CABGA381
$(TOPMODULE).bit: $(TOPMODULE).config $(TOPMODULE).bit: $(TOPMODULE).config