1
0
Fork 0
artiq-zynq/default.nix

130 lines
4.2 KiB
Nix
Raw Normal View History

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; });
cargo-xbuild = (import zynq-rs).cargo-xbuild;
zc706-szl = (import zynq-rs).zc706-szl;
2020-09-09 16:58:37 +08:00
zc706-fsbl = import "${zynq-rs}/nix/fsbl.nix" { inherit pkgs; };
mkbootimage = import "${zynq-rs}/nix/mkbootimage.nix" { inherit pkgs; };
artiqpkgs = import <artiq-fast/default.nix> { inherit pkgs; };
vivado = import <artiq-fast/vivado.nix> { inherit pkgs; };
2020-05-14 15:30:50 +08:00
build-zc706 = { variant }: let
firmware = rustPlatform.buildRustPackage rec {
2020-10-13 23:42:30 +08:00
# note: due to fetchCargoTarball, cargoSha256 depends on package name
name = "zc706-firmware";
2020-04-30 21:04:28 +08:00
src = ./src;
2020-10-30 16:59:24 +08:00
cargoSha256 = "1hmhnwvkn3z7qw4z6lxhczjl9r402k7xpycp987fnw7rfrqj9cp7";
2020-04-30 21:04:28 +08:00
nativeBuildInputs = [
pkgs.gnumake
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ])))
cargo-xbuild
2020-07-02 21:50:19 +08:00
pkgs.llvmPackages_9.llvm
pkgs.llvmPackages_9.clang-unwrapped
];
2020-04-30 21:04:28 +08:00
buildPhase = ''
2020-10-13 19:12:55 +08:00
export XARGO_RUST_SRC="${rustPlatform.rust.rustc.src}/library"
2020-04-30 21:04:28 +08:00
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
2020-05-14 15:30:50 +08:00
make VARIANT=${variant}
2020-04-30 21:04:28 +08:00
'';
installPhase = ''
mkdir -p $out $out/nix-support
2020-09-01 09:41:02 +08:00
cp ../build/runtime.bin $out/runtime.bin
2020-05-07 13:52:40 +08:00
cp ../build/firmware/armv7-none-eabihf/release/runtime $out/runtime.elf
2020-09-01 09:41:02 +08:00
echo file binary-dist $out/runtime.bin >> $out/nix-support/hydra-build-products
echo file binary-dist $out/runtime.elf >> $out/nix-support/hydra-build-products
2020-04-30 21:04:28 +08:00
'';
doCheck = false;
2020-04-30 21:04:28 +08:00
dontFixup = true;
};
2020-05-14 15:30:50 +08:00
gateware = pkgs.runCommand "zc706-${variant}-gateware"
{
nativeBuildInputs = [
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ])))
vivado
];
}
2020-04-30 21:04:28 +08:00
''
2020-07-13 10:44:25 +08:00
python ${./src/gateware}/zc706.py -g build -V ${variant}
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
'';
# SZL startup
2020-05-14 15:30:50 +08:00
jtag = pkgs.runCommand "zc706-${variant}-jtag" {}
2020-04-30 21:04:28 +08:00
''
mkdir $out
ln -s ${zc706-szl}/szl.elf $out
2020-09-01 09:41:02 +08:00
ln -s ${firmware}/runtime.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-05-14 15:30:50 +08:00
sd = pkgs.runCommand "zc706-${variant}-sd"
2020-05-01 11:23:00 +08:00
{
buildInputs = [ mkbootimage ];
}
''
# Do not use "long" paths in boot.bif, because embedded developers
# can't write software (mkbootimage will segfault).
bifdir=`mktemp -d`
cd $bifdir
ln -s ${zc706-szl}/szl.elf szl.elf
2020-09-01 09:41:02 +08:00
ln -s ${firmware}/runtime.elf runtime.elf
ln -s ${gateware}/top.bit top.bit
cat > boot.bif << EOF
2020-05-01 11:23:00 +08:00
the_ROM_image:
{
[bootloader]szl.elf
top.bit
2020-09-01 09:41:02 +08:00
runtime.elf
2020-05-01 11:23: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-01 11:23:00 +08:00
'';
# FSBL startup
fsbl-sd = pkgs.runCommand "zc706-${variant}-fsbl-sd"
{
buildInputs = [ mkbootimage ];
}
''
bifdir=`mktemp -d`
cd $bifdir
ln -s ${zc706-fsbl}/fsbl.elf fsbl.elf
ln -s ${gateware}/top.bit top.bit
ln -s ${firmware}/runtime.elf runtime.elf
cat > boot.bif << EOF
the_ROM_image:
{
[bootloader]fsbl.elf
top.bit
runtime.elf
}
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 {
"zc706-${variant}-firmware" = firmware;
"zc706-${variant}-gateware" = gateware;
"zc706-${variant}-jtag" = jtag;
"zc706-${variant}-sd" = sd;
"zc706-${variant}-fsbl-sd" = fsbl-sd;
2020-05-14 15:30:50 +08:00
};
in
(
(build-zc706 { variant = "simple"; }) //
(build-zc706 { variant = "nist_clock"; }) //
2020-08-04 13:17:33 +08:00
(build-zc706 { variant = "nist_qc2"; }) //
(build-zc706 { variant = "acpki_simple"; }) //
(build-zc706 { variant = "acpki_nist_clock"; }) //
2020-09-09 19:22:08 +08:00
(build-zc706 { variant = "acpki_nist_qc2"; }) //
{ inherit zynq-rs; }
2020-05-14 15:30:50 +08:00
)