rust-pitaya/default.nix

88 lines
2.8 KiB
Nix
Raw Normal View History

2020-10-14 15:56:10 +08:00
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;
rust-pitaya-szl = (import zynq-rs).rust-pitaya-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 = "097f4y54cc5m0pib08ypzwbf221knj5a079izixkhhz66g5fmgsq";
nativeBuildInputs = [
pkgs.gnumake
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ])))
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/runtime.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}/zc706.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 ${rust-pitaya-szl}/szl.elf $out
ln -s ${rust-pitaya-firmware}/firmware.bin $out
ln -s ${rust-pitaya-gateware}/top.bit $out
'';
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 ${rust-pitaya-szl}/szl.elf szl.elf
ln -s ${rust-pitaya-firmware}/runtime.elf runtime.elf
ln -s ${rust-pitaya-gateware}/top.bit top.bit
cat > boot.bif << EOF
the_ROM_image:
{
[bootloader]szl.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
'';
}