rust-pitaya/default.nix

88 lines
2.8 KiB
Nix

let
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;
redpitaya-szl = (import zynq-rs).redpitaya-szl;
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; };
in rec {
rust-pitaya-firmware = rustPlatform.buildRustPackage {
name = "rust-pitaya-firmware";
src = ./src;
cargoSha256 = "173013gdlk8mljps6lar892zqgxrmxa7fkv8is3wgvgf7dnifjzs";
nativeBuildInputs = [
pkgs.gnumake
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc ])))
cargo-xbuild
pkgs.llvmPackages_9.llvm
pkgs.llvmPackages_9.clang-unwrapped
];
buildPhase = ''
export XARGO_RUST_SRC="${rustPlatform.rust.rustc.src}/library"
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
make
'';
installPhase = ''
mkdir -p $out $out/nix-support
cp ../build/firmware.bin $out/firmware.bin
cp ../build/firmware/armv7-none-eabihf/release/firmware $out/firmware.elf
echo file binary-dist $out/firmware.bin >> $out/nix-support/hydra-build-products
echo file binary-dist $out/firmware.elf >> $out/nix-support/hydra-build-products
'';
doCheck = false;
dontFixup = true;
};
rust-pitaya-gateware = pkgs.runCommand "rust-pitaya-gateware"
{
nativeBuildInputs = [
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc ])))
vivado
];
}
''
python ${./src/gateware}/rust-pitaya.py -g build
mkdir -p $out $out/nix-support
cp build/top.bit $out
echo file binary-dist $out/top.bit >> $out/nix-support/hydra-build-products
'';
rust-pitaya-jtag = pkgs.runCommand "rust-pitaya-jtag" {}
''
mkdir $out
ln -s ${redpitaya-szl}/szl.elf $out
ln -s ${rust-pitaya-firmware}/firmware.bin $out
ln -s ${rust-pitaya-gateware}/top.bit $out
'';
rust-pitaya-sd = pkgs.runCommand "rust-pitaya-sd"
{
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 ${redpitaya-szl}/szl.elf szl.elf
ln -s ${rust-pitaya-firmware}/firmware.elf firmware.elf
ln -s ${rust-pitaya-gateware}/top.bit top.bit
cat > boot.bif << EOF
the_ROM_image:
{
[bootloader]szl.elf
top.bit
firmware.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
'';
}