2020-04-30 21:04:28 +08:00
|
|
|
let
|
2020-09-09 16:58:37 +08:00
|
|
|
zynq-rs = (import ./zynq-rs.nix);
|
|
|
|
pkgs = import <nixpkgs> { overlays = [ (import "${zynq-rs}/nix/mozilla-overlay.nix") ]; };
|
|
|
|
rustPlatform = (import "${zynq-rs}/nix/rust-platform.nix" { inherit pkgs; });
|
2020-10-13 21:51:40 +08:00
|
|
|
cargo-xbuild = (import zynq-rs).cargo-xbuild;
|
2020-09-09 16:58:37 +08:00
|
|
|
mkbootimage = import "${zynq-rs}/nix/mkbootimage.nix" { inherit pkgs; };
|
2020-05-03 08:25:19 +08:00
|
|
|
artiqpkgs = import <artiq-fast/default.nix> { inherit pkgs; };
|
|
|
|
vivado = import <artiq-fast/vivado.nix> { inherit pkgs; };
|
2020-11-14 03:17:18 +08:00
|
|
|
# FSBL configuration supplied by Vivado 2020.1 for these boards:
|
|
|
|
fsblTargets = ["zc702" "zc706" "zed"];
|
2021-12-03 17:19:42 +08:00
|
|
|
sat_variants = [
|
2021-12-03 19:20:54 +08:00
|
|
|
# kasli-soc satellite variants
|
|
|
|
"satellite"
|
|
|
|
# zc706 satellite variants
|
2021-12-03 17:19:42 +08:00
|
|
|
"nist_clock_satellite" "nist_qc2_satellite" "acpki_nist_clock_satellite" "acpki_nist_qc2_satellite"
|
|
|
|
"nist_clock_satellite_100mhz" "nist_qc2_satellite_100mhz" "acpki_nist_clock_satellite_100mhz" "acpki_nist_qc2_satellite_100mhz"
|
|
|
|
];
|
2021-02-15 19:52:13 +08:00
|
|
|
build = { target, variant, json ? null }: let
|
2020-11-14 03:17:18 +08:00
|
|
|
szl = (import zynq-rs)."${target}-szl";
|
|
|
|
fsbl = import "${zynq-rs}/nix/fsbl.nix" {
|
|
|
|
inherit pkgs;
|
|
|
|
board = target;
|
|
|
|
};
|
2021-10-08 16:25:13 +08:00
|
|
|
fwtype = if builtins.elem variant sat_variants then "satman" else "runtime";
|
2020-11-14 03:17:18 +08:00
|
|
|
|
2020-05-14 15:30:50 +08:00
|
|
|
firmware = rustPlatform.buildRustPackage rec {
|
2020-10-13 23:42:30 +08:00
|
|
|
# note: due to fetchCargoTarball, cargoSha256 depends on package name
|
2020-11-14 03:17:18 +08:00
|
|
|
name = "firmware";
|
2020-04-30 21:04:28 +08:00
|
|
|
|
2020-05-01 10:07:38 +08:00
|
|
|
src = ./src;
|
2022-01-06 01:54:34 +08:00
|
|
|
cargoSha256 = "sha256-uCqCeqXbTjTDEoZERPDb3kX+CTfzSJ/jGlrFxuKO8HQ=";
|
2020-04-30 21:04:28 +08:00
|
|
|
|
2020-05-01 10:07:38 +08:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.gnumake
|
2021-02-15 19:52:13 +08:00
|
|
|
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ ps.jsonschema migen migen-axi misoc artiq ])))
|
2020-10-13 21:51:40 +08:00
|
|
|
cargo-xbuild
|
2020-07-02 21:50:19 +08:00
|
|
|
pkgs.llvmPackages_9.llvm
|
|
|
|
pkgs.llvmPackages_9.clang-unwrapped
|
2020-05-01 10:07:38 +08:00
|
|
|
];
|
2020-04-30 21:04:28 +08:00
|
|
|
buildPhase = ''
|
2021-01-15 08:02:15 +08:00
|
|
|
export XARGO_RUST_SRC="${rustPlatform.rust.rustc}/lib/rustlib/src/rust/library"
|
2021-06-25 15:57:39 +08:00
|
|
|
export CLANG_EXTRA_INCLUDE_DIR="${pkgs.llvmPackages_9.clang-unwrapped.lib}/lib/clang/9.0.1/include"
|
2020-04-30 21:04:28 +08:00
|
|
|
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
|
2021-10-08 21:06:23 +08:00
|
|
|
make TARGET=${target} GWARGS="${if json == null then "-V ${variant}" else json}" ${fwtype}
|
2020-04-30 21:04:28 +08:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out $out/nix-support
|
2021-10-08 16:25:13 +08:00
|
|
|
cp ../build/${fwtype}.bin $out/${fwtype}.bin
|
|
|
|
cp ../build/firmware/armv7-none-eabihf/release/${fwtype} $out/${fwtype}.elf
|
|
|
|
echo file binary-dist $out/${fwtype}.bin >> $out/nix-support/hydra-build-products
|
|
|
|
echo file binary-dist $out/${fwtype}.elf >> $out/nix-support/hydra-build-products
|
2020-04-30 21:04:28 +08:00
|
|
|
'';
|
2020-05-01 10:07:38 +08:00
|
|
|
|
|
|
|
doCheck = false;
|
2020-04-30 21:04:28 +08:00
|
|
|
dontFixup = true;
|
|
|
|
};
|
2020-11-14 03:17:18 +08:00
|
|
|
gateware = pkgs.runCommand "${target}-${variant}-gateware"
|
2020-05-01 10:07:38 +08:00
|
|
|
{
|
|
|
|
nativeBuildInputs = [
|
2021-02-15 19:52:13 +08:00
|
|
|
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ ps.jsonschema migen migen-axi misoc artiq ])))
|
2020-05-01 10:07:38 +08:00
|
|
|
vivado
|
|
|
|
];
|
|
|
|
}
|
2020-04-30 21:04:28 +08:00
|
|
|
''
|
2021-02-15 19:52:13 +08:00
|
|
|
python ${./src/gateware}/${target}.py -g build ${if json == null then "-V ${variant}" else json}
|
2020-04-30 21:04:28 +08:00
|
|
|
mkdir -p $out $out/nix-support
|
|
|
|
cp build/top.bit $out
|
|
|
|
echo file binary-dist $out/top.bit >> $out/nix-support/hydra-build-products
|
|
|
|
'';
|
2020-05-06 16:53:52 +08:00
|
|
|
|
2020-08-25 10:49:00 +08:00
|
|
|
# SZL startup
|
2020-11-14 03:17:18 +08:00
|
|
|
jtag = pkgs.runCommand "${target}-${variant}-jtag" {}
|
2020-04-30 21:04:28 +08:00
|
|
|
''
|
|
|
|
mkdir $out
|
2020-11-14 03:17:18 +08:00
|
|
|
ln -s ${szl}/szl.elf $out
|
2021-10-08 16:25:13 +08:00
|
|
|
ln -s ${firmware}/${fwtype}.bin $out
|
2020-05-14 15:30:50 +08:00
|
|
|
ln -s ${gateware}/top.bit $out
|
2020-04-30 21:04:28 +08:00
|
|
|
'';
|
2020-11-14 03:17:18 +08:00
|
|
|
sd = pkgs.runCommand "${target}-${variant}-sd"
|
2020-05-01 11:23:00 +08:00
|
|
|
{
|
|
|
|
buildInputs = [ mkbootimage ];
|
|
|
|
}
|
|
|
|
''
|
2020-05-06 17:46:37 +08:00
|
|
|
# Do not use "long" paths in boot.bif, because embedded developers
|
|
|
|
# can't write software (mkbootimage will segfault).
|
|
|
|
bifdir=`mktemp -d`
|
|
|
|
cd $bifdir
|
2020-11-14 03:17:18 +08:00
|
|
|
ln -s ${szl}/szl.elf szl.elf
|
2021-10-08 21:18:23 +08:00
|
|
|
ln -s ${firmware}/${fwtype}.elf ${fwtype}.elf
|
2020-06-15 17:03:27 +08:00
|
|
|
ln -s ${gateware}/top.bit top.bit
|
2020-05-06 17:46:37 +08:00
|
|
|
cat > boot.bif << EOF
|
2020-05-01 11:23:00 +08:00
|
|
|
the_ROM_image:
|
|
|
|
{
|
2020-05-06 17:46:37 +08:00
|
|
|
[bootloader]szl.elf
|
2020-06-15 17:03:27 +08:00
|
|
|
top.bit
|
2021-10-08 21:18:23 +08:00
|
|
|
${fwtype}.elf
|
2020-05-01 11:23:00 +08:00
|
|
|
}
|
|
|
|
EOF
|
2020-06-15 17:03:27 +08:00
|
|
|
mkdir $out $out/nix-support
|
2020-05-06 17:46:37 +08:00
|
|
|
mkbootimage boot.bif $out/boot.bin
|
2020-06-15 17:03:27 +08:00
|
|
|
echo file binary-dist $out/boot.bin >> $out/nix-support/hydra-build-products
|
2020-05-01 11:23:00 +08:00
|
|
|
'';
|
2020-08-25 10:49:00 +08:00
|
|
|
|
|
|
|
# FSBL startup
|
2020-11-14 03:17:18 +08:00
|
|
|
fsbl-sd = pkgs.runCommand "${target}-${variant}-fsbl-sd"
|
2020-08-25 10:49:00 +08:00
|
|
|
{
|
|
|
|
buildInputs = [ mkbootimage ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
bifdir=`mktemp -d`
|
|
|
|
cd $bifdir
|
2020-11-14 03:17:18 +08:00
|
|
|
ln -s ${fsbl}/fsbl.elf fsbl.elf
|
2020-08-25 10:49:00 +08:00
|
|
|
ln -s ${gateware}/top.bit top.bit
|
2021-10-08 21:18:23 +08:00
|
|
|
ln -s ${firmware}/${fwtype}.elf ${fwtype}.elf
|
2020-08-25 10:49:00 +08:00
|
|
|
cat > boot.bif << EOF
|
|
|
|
the_ROM_image:
|
|
|
|
{
|
|
|
|
[bootloader]fsbl.elf
|
|
|
|
top.bit
|
2021-10-08 21:18:23 +08:00
|
|
|
${fwtype}.elf
|
2020-08-25 10:49:00 +08:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
mkdir $out $out/nix-support
|
|
|
|
mkbootimage boot.bif $out/boot.bin
|
|
|
|
echo file binary-dist $out/boot.bin >> $out/nix-support/hydra-build-products
|
|
|
|
'';
|
2020-05-14 15:30:50 +08:00
|
|
|
in {
|
2020-11-14 03:17:18 +08:00
|
|
|
"${target}-${variant}-firmware" = firmware;
|
|
|
|
"${target}-${variant}-gateware" = gateware;
|
|
|
|
"${target}-${variant}-jtag" = jtag;
|
|
|
|
"${target}-${variant}-sd" = sd;
|
|
|
|
} // (
|
|
|
|
if builtins.elem target fsblTargets
|
|
|
|
then {
|
|
|
|
"${target}-${variant}-fsbl-sd" = fsbl-sd;
|
|
|
|
}
|
|
|
|
else {}
|
|
|
|
);
|
2020-05-14 15:30:50 +08:00
|
|
|
in
|
|
|
|
(
|
2020-11-14 03:17:18 +08:00
|
|
|
(build { target = "zc706"; variant = "nist_clock"; }) //
|
2021-10-08 16:25:13 +08:00
|
|
|
(build { target = "zc706"; variant = "nist_clock_master"; }) //
|
|
|
|
(build { target = "zc706"; variant = "nist_clock_satellite"; }) //
|
2021-12-03 17:19:42 +08:00
|
|
|
(build { target = "zc706"; variant = "nist_clock_satellite_100mhz"; }) //
|
2020-11-14 03:17:18 +08:00
|
|
|
(build { target = "zc706"; variant = "nist_qc2"; }) //
|
2021-10-08 16:25:13 +08:00
|
|
|
(build { target = "zc706"; variant = "nist_qc2_master"; }) //
|
|
|
|
(build { target = "zc706"; variant = "nist_qc2_satellite"; }) //
|
2021-12-03 17:19:42 +08:00
|
|
|
(build { target = "zc706"; variant = "nist_qc2_satellite_100mhz"; }) //
|
2020-11-14 03:17:18 +08:00
|
|
|
(build { target = "zc706"; variant = "acpki_nist_clock"; }) //
|
2021-10-08 16:25:13 +08:00
|
|
|
(build { target = "zc706"; variant = "acpki_nist_clock_master"; }) //
|
|
|
|
(build { target = "zc706"; variant = "acpki_nist_clock_satellite"; }) //
|
2021-12-03 17:19:42 +08:00
|
|
|
(build { target = "zc706"; variant = "acpki_nist_clock_satellite_100mhz"; }) //
|
2020-11-14 03:17:18 +08:00
|
|
|
(build { target = "zc706"; variant = "acpki_nist_qc2"; }) //
|
2021-10-08 16:25:13 +08:00
|
|
|
(build { target = "zc706"; variant = "acpki_nist_qc2_master"; }) //
|
|
|
|
(build { target = "zc706"; variant = "acpki_nist_qc2_satellite"; }) //
|
2021-12-03 17:19:42 +08:00
|
|
|
(build { target = "zc706"; variant = "acpki_nist_qc2_satellite_100mhz"; }) //
|
2021-02-15 19:52:13 +08:00
|
|
|
(build { target = "kasli_soc"; variant = "demo"; json = ./demo.json; }) //
|
2021-10-08 16:25:13 +08:00
|
|
|
(build { target = "kasli_soc"; variant = "master"; json = ./kasli-soc-master.json; }) //
|
|
|
|
(build { target = "kasli_soc"; variant = "satellite"; json = ./kasli-soc-satellite.json; }) //
|
2020-09-09 19:22:08 +08:00
|
|
|
{ inherit zynq-rs; }
|
2020-05-14 15:30:50 +08:00
|
|
|
)
|