pure Nix build system
This commit is contained in:
parent
0ebe14c474
commit
c28c567e72
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
build/
|
||||
runtime/src/pl.rs
|
||||
target/
|
||||
result
|
||||
examples/*.elf
|
||||
__pycache__
|
||||
|
@ -1,6 +0,0 @@
|
||||
Build with:
|
||||
|
||||
```shell
|
||||
cargo xbuild -p runtime --release
|
||||
cargo xbuild -p szl --release
|
||||
```
|
72
default.nix
Normal file
72
default.nix
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
mozillaOverlay ? import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz),
|
||||
}:
|
||||
|
||||
let
|
||||
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
|
||||
artiq-fast = <artiq-fast>;
|
||||
rustPlatform = (import ./rustPlatform.nix { inherit pkgs; });
|
||||
buildFirmware = { name, src }:
|
||||
rustPlatform.buildRustPackage rec {
|
||||
inherit name;
|
||||
version = "0.1.0";
|
||||
|
||||
inherit src;
|
||||
cargoSha256 = (import "${src}/cargosha256.nix");
|
||||
|
||||
nativeBuildInputs = [ pkgs.cargo-xbuild pkgs.llvm_9 pkgs.clang_9 ];
|
||||
buildPhase = ''
|
||||
export XARGO_RUST_SRC="${rustPlatform.rust.rustc.src}/src"
|
||||
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
|
||||
cargo xbuild --release -p ${name}
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
installPhase = ''
|
||||
mkdir -p $out $out/nix-support
|
||||
cp target/armv7-none-eabihf/release/${name} $out/${name}.elf
|
||||
echo file binary-dist $out/${name}.elf >> $out/nix-support/hydra-build-products
|
||||
'';
|
||||
dontFixup = true;
|
||||
};
|
||||
|
||||
artiqpkgs = import "${artiq-fast}/default.nix" { inherit pkgs; };
|
||||
vivado = import "${artiq-fast}/vivado.nix" { inherit pkgs; };
|
||||
in
|
||||
rec {
|
||||
zc706-runtime-src = pkgs.runCommand "zc706-runtime-src"
|
||||
{ buildInputs = [
|
||||
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ])))
|
||||
]; }
|
||||
''
|
||||
cp --no-preserve=mode,ownership -R ${./firmware} $out
|
||||
cd $out/runtime/src
|
||||
python ${./zc706.py} rustif
|
||||
'';
|
||||
zc706-runtime = buildFirmware { name = "runtime"; src = zc706-runtime-src; };
|
||||
zc706-szl-src = pkgs.runCommand "zc706-szl-src"
|
||||
{ nativeBuildInputs = [ pkgs.llvm_9 ]; }
|
||||
''
|
||||
cp --no-preserve=mode,ownership -R ${./firmware} $out
|
||||
llvm-objcopy -O binary ${zc706-runtime}/runtime.elf $out/szl/src/payload.bin
|
||||
lzma $out/szl/src/payload.bin
|
||||
'';
|
||||
zc706-szl = buildFirmware { name = "szl"; src = zc706-szl-src; };
|
||||
zc706-gateware = pkgs.runCommand "zc706-gateware"
|
||||
{ buildInputs = [
|
||||
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ])))
|
||||
vivado
|
||||
]; }
|
||||
''
|
||||
python ${./zc706.py} gateware
|
||||
mkdir -p $out $out/nix-support
|
||||
cp build/top.bit $out
|
||||
echo file binary-dist $out/top.bit >> $out/nix-support/hydra-build-products
|
||||
'';
|
||||
zc706-jtag = pkgs.runCommand "zc706-jtag" {}
|
||||
''
|
||||
mkdir $out
|
||||
ln -s ${zc706-szl}/szl $out
|
||||
ln -s ${zc706-gateware}/top.bit $out
|
||||
'';
|
||||
}
|
0
Cargo.lock → firmware/Cargo.lock
generated
0
Cargo.lock → firmware/Cargo.lock
generated
1
firmware/cargosha256.nix
Normal file
1
firmware/cargosha256.nix
Normal file
@ -0,0 +1 @@
|
||||
"1mfprkcq4cr4jiihy1qn8q8qymxwhafh90vyr3i4brj4aq5kksn1"
|
@ -5,20 +5,8 @@ use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn main() {
|
||||
// FIXME: this is dirty and unreliable. How to depend on the output of the runtime build?
|
||||
let payload = "../target/armv7-none-eabihf/release/runtime";
|
||||
|
||||
let out = env::var("OUT_DIR").unwrap();
|
||||
let out_dir = &PathBuf::from(&out);
|
||||
let status = Command::new("llvm-objcopy")
|
||||
.args(&["-O", "binary", payload, &format!("{}/payload.bin", out)])
|
||||
.status().unwrap();
|
||||
assert!(status.success());
|
||||
let status = Command::new("lzma")
|
||||
.args(&["--keep", "-f", &format!("{}/payload.bin", out)])
|
||||
.status().unwrap();
|
||||
assert!(status.success());
|
||||
println!("cargo:rerun-if-changed={}", payload);
|
||||
|
||||
let status = Command::new("clang")
|
||||
.args(&["-target", "armv7-unknown-linux", "-fno-stack-protector",
|
@ -39,7 +39,7 @@ pub fn main_core0() {
|
||||
libboard_zynq::stdio::drop_uart(); // reinitialize UART after clocking change
|
||||
let mut ddr = zynq::ddr::DdrRam::new();
|
||||
|
||||
let payload = include_bytes!(concat!(env!("OUT_DIR"), "/payload.bin.lzma"));
|
||||
let payload = include_bytes!("payload.bin.lzma");
|
||||
info!("decompressing payload");
|
||||
let result = unsafe {
|
||||
unlzma_simple(payload.as_ptr(), payload.len() as i32, ddr.ptr(), lzma_error)
|
@ -8,6 +8,6 @@ TARGET_FOLDER=/tmp/zynq-\$USER
|
||||
|
||||
ssh $TARGET_HOST "mkdir -p $TARGET_FOLDER"
|
||||
rsync openocd/* $TARGET_HOST:$TARGET_FOLDER
|
||||
rsync target/armv7-none-eabihf/release/szl $TARGET_HOST:$TARGET_FOLDER
|
||||
rsync build/top.bit $TARGET_HOST:$TARGET_FOLDER
|
||||
rsync result/szl $TARGET_HOST:$TARGET_FOLDER
|
||||
rsync result/top.bit $TARGET_HOST:$TARGET_FOLDER
|
||||
ssh $TARGET_HOST "cd $TARGET_FOLDER; openocd -f zc706.cfg -c 'pld load 0 top.bit; load_image szl; resume 0; exit'"
|
||||
|
BIN
runtime.bin
BIN
runtime.bin
Binary file not shown.
24
rustPlatform.nix
Normal file
24
rustPlatform.nix
Normal file
@ -0,0 +1,24 @@
|
||||
{ pkgs }:
|
||||
|
||||
let
|
||||
rustcSrc = pkgs.fetchgit {
|
||||
url = "https://github.com/rust-lang/rust.git";
|
||||
# master of 2020-04-10
|
||||
rev = "94d346360da50f159e0dc777dc9bc3c5b6b51a00";
|
||||
sha256 = "1hcqdz4w2vqb12rrqqcjbfs5s0w4qwjn7z45d1zh0fzncdcf6f7d";
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
rustManifest = ./channel-rust-nightly.toml;
|
||||
|
||||
targets = [];
|
||||
rustChannelOfTargets = _channel: _date: targets:
|
||||
(pkgs.lib.rustLib.fromManifestFile rustManifest {
|
||||
inherit (pkgs) stdenv fetchurl patchelf;
|
||||
}).rust.override { inherit targets; };
|
||||
rust =
|
||||
rustChannelOfTargets "nightly" null targets;
|
||||
in
|
||||
pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
|
||||
rustc = rust // { src = rustcSrc; };
|
||||
cargo = rust;
|
||||
})
|
50
shell.nix
50
shell.nix
@ -1,50 +0,0 @@
|
||||
let
|
||||
mozillaOverlay = import (builtins.fetchTarball "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz");
|
||||
artiq-fast = builtins.fetchTarball "https://nixbld.m-labs.hk/channel/custom/artiq/fast-beta/artiq-fast/nixexprs.tar.xz";
|
||||
|
||||
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
|
||||
|
||||
rustcSrc = pkgs.fetchgit {
|
||||
url = "https://github.com/rust-lang/rust.git";
|
||||
# master of 2020-04-10
|
||||
rev = "94d346360da50f159e0dc777dc9bc3c5b6b51a00";
|
||||
sha256 = "1hcqdz4w2vqb12rrqqcjbfs5s0w4qwjn7z45d1zh0fzncdcf6f7d";
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
rustManifest = ./channel-rust-nightly.toml;
|
||||
|
||||
targets = [];
|
||||
rustChannelOfTargets = _channel: _date: targets:
|
||||
(pkgs.lib.rustLib.fromManifestFile rustManifest {
|
||||
inherit (pkgs) stdenv fetchurl patchelf;
|
||||
}).rust.override { inherit targets; };
|
||||
rust =
|
||||
rustChannelOfTargets "nightly" null targets;
|
||||
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
|
||||
rustc = rust // { src = rustcSrc; };
|
||||
cargo = rust;
|
||||
});
|
||||
|
||||
artiqpkgs = import "${artiq-fast}/default.nix" { inherit pkgs; };
|
||||
vivado = import "${artiq-fast}/vivado.nix" { inherit pkgs; };
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "artiq-zynq-env";
|
||||
buildInputs = [
|
||||
rustPlatform.rust.rustc
|
||||
rustPlatform.rust.cargo
|
||||
rustcSrc
|
||||
pkgs.clang_9
|
||||
pkgs.cacert
|
||||
pkgs.cargo-xbuild
|
||||
|
||||
pkgs.openssh pkgs.rsync
|
||||
|
||||
(pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ])))
|
||||
vivado
|
||||
pkgs.llvm_9
|
||||
pkgs.lld_9
|
||||
];
|
||||
|
||||
XARGO_RUST_SRC = "${rustcSrc}/src";
|
||||
}
|
3
zc706.py
3
zc706.py
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from migen import *
|
||||
|
||||
@ -71,7 +70,7 @@ def main():
|
||||
if action == "gateware":
|
||||
soc.build()
|
||||
elif action == "rustif":
|
||||
write_csr_file(soc, os.path.join("runtime", "src", "pl.rs"))
|
||||
write_csr_file(soc, "pl.rs")
|
||||
else:
|
||||
raise ValueError("invalid action", action)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user