From 2439ba1f881b36a7aa1a50aa3b61928bf80c9068 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 1 May 2020 10:07:38 +0800 Subject: [PATCH] add impure incremental build process, document --- .gitignore | 5 ++ README.md | 23 ++++++++ default.nix | 70 ++++++++++-------------- firmware/cargosha256.nix | 1 - remote_run.sh | 31 ++++++++--- shell.nix | 28 ++++++++++ {firmware => src}/.cargo/config | 0 {firmware => src}/Cargo.lock | 0 {firmware => src}/Cargo.toml | 0 src/Makefile | 23 ++++++++ {firmware => src}/armv7-none-eabihf.json | 0 {firmware => src}/libdyld/Cargo.toml | 0 {firmware => src}/libdyld/src/elf.rs | 0 {firmware => src}/libdyld/src/file.rs | 0 {firmware => src}/libdyld/src/image.rs | 0 {firmware => src}/libdyld/src/lib.rs | 0 {firmware => src}/libdyld/src/reloc.rs | 0 {firmware => src}/runtime/Cargo.toml | 0 {firmware => src}/runtime/build.rs | 0 {firmware => src}/runtime/link.x | 0 {firmware => src}/runtime/src/comms.rs | 0 {firmware => src}/runtime/src/kernel.rs | 0 {firmware => src}/runtime/src/main.rs | 0 {firmware => src}/runtime/src/moninj.rs | 0 {firmware => src}/runtime/src/proto.rs | 0 {firmware => src}/runtime/src/rtio.rs | 0 {firmware => src}/szl/Cargo.toml | 0 {firmware => src}/szl/build.rs | 0 {firmware => src}/szl/link.x | 0 {firmware => src}/szl/src/main.rs | 0 {firmware => src}/szl/src/unlzma.c | 0 zc706.py => src/zc706.py | 18 +++--- 32 files changed, 141 insertions(+), 58 deletions(-) create mode 100644 README.md delete mode 100644 firmware/cargosha256.nix create mode 100644 shell.nix rename {firmware => src}/.cargo/config (100%) rename {firmware => src}/Cargo.lock (100%) rename {firmware => src}/Cargo.toml (100%) create mode 100644 src/Makefile rename {firmware => src}/armv7-none-eabihf.json (100%) rename {firmware => src}/libdyld/Cargo.toml (100%) rename {firmware => src}/libdyld/src/elf.rs (100%) rename {firmware => src}/libdyld/src/file.rs (100%) rename {firmware => src}/libdyld/src/image.rs (100%) rename {firmware => src}/libdyld/src/lib.rs (100%) rename {firmware => src}/libdyld/src/reloc.rs (100%) rename {firmware => src}/runtime/Cargo.toml (100%) rename {firmware => src}/runtime/build.rs (100%) rename {firmware => src}/runtime/link.x (100%) rename {firmware => src}/runtime/src/comms.rs (100%) rename {firmware => src}/runtime/src/kernel.rs (100%) rename {firmware => src}/runtime/src/main.rs (100%) rename {firmware => src}/runtime/src/moninj.rs (100%) rename {firmware => src}/runtime/src/proto.rs (100%) rename {firmware => src}/runtime/src/rtio.rs (100%) rename {firmware => src}/szl/Cargo.toml (100%) rename {firmware => src}/szl/build.rs (100%) rename {firmware => src}/szl/link.x (100%) rename {firmware => src}/szl/src/main.rs (100%) rename {firmware => src}/szl/src/unlzma.c (100%) rename zc706.py => src/zc706.py (83%) diff --git a/.gitignore b/.gitignore index c275520..98466b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ result examples/*.elf __pycache__ + +src/runtime/src/pl.rs +src/szl/src/payload.bin +src/szl/src/payload.bin.lzma +src/target diff --git a/README.md b/README.md new file mode 100644 index 0000000..d627fc5 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +Configure Nix channels: +`` +nix-channel --add https://nixbld.m-labs.hk/channel/custom/artiq/fast-beta/artiq-fast +nix-channel --update +`` + +Pure build with Nix: +`` +nix-build -A zc706-jtag +./remote_run.sh +`` + +Impure incremental build: +`` +nix-shell +cd src +./zc706.py -g # build gateware +make # build firmware +cd .. +./remote_run.sh -i +`` + +The impure build process can also be used on non-Nix systems. diff --git a/default.nix b/default.nix index 3db24b2..35c8319 100644 --- a/default.nix +++ b/default.nix @@ -6,59 +6,49 @@ let pkgs = import { overlays = [ mozillaOverlay ]; }; artiq-fast = ; rustPlatform = (import ./rustPlatform.nix { inherit pkgs; }); - buildFirmware = { name, src }: - rustPlatform.buildRustPackage rec { - inherit name; + artiqpkgs = import "${artiq-fast}/default.nix" { inherit pkgs; }; + vivado = import "${artiq-fast}/vivado.nix" { inherit pkgs; }; +in + rec { + zc706-szl = rustPlatform.buildRustPackage rec { + name = "szl"; version = "0.1.0"; - inherit src; - cargoSha256 = (import "${src}/cargosha256.nix"); + src = ./src; + cargoSha256 = "199qfs7fbbj8kxkyb0dcns6hdq9hvlppk7l3pnz204j9zkd7dkcp"; - nativeBuildInputs = [ pkgs.cargo-xbuild pkgs.llvm_9 pkgs.clang_9 ]; + nativeBuildInputs = [ + pkgs.gnumake + (pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ]))) + 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} + make clean + make + ''; + + installPhase = '' + mkdir -p $out $out/nix-support + cp target/armv7-none-eabihf/release/szl $out/$szl.elf + echo file binary-dist $out/szl.elf >> $out/nix-support/hydra-build-products ''; 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 - ]; } + { + nativeBuildInputs = [ + (pkgs.python3.withPackages(ps: (with artiqpkgs; [ migen migen-axi misoc artiq ]))) + vivado + ]; + } '' - python ${./zc706.py} gateware + python ${./src/zc706.py} -g mkdir -p $out $out/nix-support cp build/top.bit $out echo file binary-dist $out/top.bit >> $out/nix-support/hydra-build-products diff --git a/firmware/cargosha256.nix b/firmware/cargosha256.nix deleted file mode 100644 index a49548f..0000000 --- a/firmware/cargosha256.nix +++ /dev/null @@ -1 +0,0 @@ -"199qfs7fbbj8kxkyb0dcns6hdq9hvlppk7l3pnz204j9zkd7dkcp" diff --git a/remote_run.sh b/remote_run.sh index 5710795..ac6e1fb 100755 --- a/remote_run.sh +++ b/remote_run.sh @@ -2,12 +2,29 @@ set -e -TARGET_HOST=$1 +target_host="rpi-4.m-labs.hk" +impure=0 -TARGET_FOLDER=/tmp/zynq-\$USER +while getopts "h:i" opt; do + case "$opt" in + \?) exit 0 + ;; + h) target_host=$OPTARG + ;; + i) impure=1 + ;; + esac +done -ssh $TARGET_HOST "mkdir -p $TARGET_FOLDER" -rsync openocd/* $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'" +target_folder=/tmp/zynq-\$USER + +ssh $target_host "mkdir -p $target_folder" +rsync openocd/* $target_host:$target_folder +if [ $impure -eq 1 ]; then + rsync src/target/armv7-none-eabihf/release/szl $target_host:$target_folder + rsync src/build/top.bit $target_host:$target_folder +else + rsync result/szl $target_host:$target_folder + rsync result/top.bit $target_host:$target_folder +fi +ssh $target_host "cd $target_folder; openocd -f zc706.cfg -c 'pld load 0 top.bit; load_image szl; resume 0; exit'" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..3d584e7 --- /dev/null +++ b/shell.nix @@ -0,0 +1,28 @@ +let + mozillaOverlay = import (builtins.fetchTarball "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz"); + pkgs = import { overlays = [ mozillaOverlay ]; }; + artiq-fast = ; + rustPlatform = (import ./rustPlatform.nix { inherit pkgs; }); + 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 = [ + pkgs.gnumake + rustPlatform.rust.rustc + rustPlatform.rust.cargo + 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 = "${rustPlatform.rust.rustc.src}/src"; + } diff --git a/firmware/.cargo/config b/src/.cargo/config similarity index 100% rename from firmware/.cargo/config rename to src/.cargo/config diff --git a/firmware/Cargo.lock b/src/Cargo.lock similarity index 100% rename from firmware/Cargo.lock rename to src/Cargo.lock diff --git a/firmware/Cargo.toml b/src/Cargo.toml similarity index 100% rename from firmware/Cargo.toml rename to src/Cargo.toml diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..f13b5d2 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,23 @@ +all: target/armv7-none-eabihf/release/szl + +clean: + rm -f runtime/src/pl.rs + rm -f szl/src/payload.bin + rm -f szl/src/payload.bin.lzma + rm -rf target + +.PHONY: all clean + + +runtime/src/pl.rs: zc706.py + python zc706.py -r runtime/src/pl.rs + +target/armv7-none-eabihf/release/runtime: .cargo/* armv7-none-eabihf.json Cargo.lock Cargo.toml libdyld/* libdyld/src/* runtime/* runtime/src/* runtime/src/pl.rs + cargo xbuild --release -p runtime + +szl/src/payload.bin.lzma: target/armv7-none-eabihf/release/runtime + llvm-objcopy -O binary target/armv7-none-eabihf/release/runtime szl/src/payload.bin + lzma --keep -f szl/src/payload.bin + +target/armv7-none-eabihf/release/szl: .cargo/* armv7-none-eabihf.json Cargo.lock Cargo.toml szl/* szl/src/* szl/src/payload.bin.lzma + cargo xbuild --release -p szl diff --git a/firmware/armv7-none-eabihf.json b/src/armv7-none-eabihf.json similarity index 100% rename from firmware/armv7-none-eabihf.json rename to src/armv7-none-eabihf.json diff --git a/firmware/libdyld/Cargo.toml b/src/libdyld/Cargo.toml similarity index 100% rename from firmware/libdyld/Cargo.toml rename to src/libdyld/Cargo.toml diff --git a/firmware/libdyld/src/elf.rs b/src/libdyld/src/elf.rs similarity index 100% rename from firmware/libdyld/src/elf.rs rename to src/libdyld/src/elf.rs diff --git a/firmware/libdyld/src/file.rs b/src/libdyld/src/file.rs similarity index 100% rename from firmware/libdyld/src/file.rs rename to src/libdyld/src/file.rs diff --git a/firmware/libdyld/src/image.rs b/src/libdyld/src/image.rs similarity index 100% rename from firmware/libdyld/src/image.rs rename to src/libdyld/src/image.rs diff --git a/firmware/libdyld/src/lib.rs b/src/libdyld/src/lib.rs similarity index 100% rename from firmware/libdyld/src/lib.rs rename to src/libdyld/src/lib.rs diff --git a/firmware/libdyld/src/reloc.rs b/src/libdyld/src/reloc.rs similarity index 100% rename from firmware/libdyld/src/reloc.rs rename to src/libdyld/src/reloc.rs diff --git a/firmware/runtime/Cargo.toml b/src/runtime/Cargo.toml similarity index 100% rename from firmware/runtime/Cargo.toml rename to src/runtime/Cargo.toml diff --git a/firmware/runtime/build.rs b/src/runtime/build.rs similarity index 100% rename from firmware/runtime/build.rs rename to src/runtime/build.rs diff --git a/firmware/runtime/link.x b/src/runtime/link.x similarity index 100% rename from firmware/runtime/link.x rename to src/runtime/link.x diff --git a/firmware/runtime/src/comms.rs b/src/runtime/src/comms.rs similarity index 100% rename from firmware/runtime/src/comms.rs rename to src/runtime/src/comms.rs diff --git a/firmware/runtime/src/kernel.rs b/src/runtime/src/kernel.rs similarity index 100% rename from firmware/runtime/src/kernel.rs rename to src/runtime/src/kernel.rs diff --git a/firmware/runtime/src/main.rs b/src/runtime/src/main.rs similarity index 100% rename from firmware/runtime/src/main.rs rename to src/runtime/src/main.rs diff --git a/firmware/runtime/src/moninj.rs b/src/runtime/src/moninj.rs similarity index 100% rename from firmware/runtime/src/moninj.rs rename to src/runtime/src/moninj.rs diff --git a/firmware/runtime/src/proto.rs b/src/runtime/src/proto.rs similarity index 100% rename from firmware/runtime/src/proto.rs rename to src/runtime/src/proto.rs diff --git a/firmware/runtime/src/rtio.rs b/src/runtime/src/rtio.rs similarity index 100% rename from firmware/runtime/src/rtio.rs rename to src/runtime/src/rtio.rs diff --git a/firmware/szl/Cargo.toml b/src/szl/Cargo.toml similarity index 100% rename from firmware/szl/Cargo.toml rename to src/szl/Cargo.toml diff --git a/firmware/szl/build.rs b/src/szl/build.rs similarity index 100% rename from firmware/szl/build.rs rename to src/szl/build.rs diff --git a/firmware/szl/link.x b/src/szl/link.x similarity index 100% rename from firmware/szl/link.x rename to src/szl/link.x diff --git a/firmware/szl/src/main.rs b/src/szl/src/main.rs similarity index 100% rename from firmware/szl/src/main.rs rename to src/szl/src/main.rs diff --git a/firmware/szl/src/unlzma.c b/src/szl/src/unlzma.c similarity index 100% rename from firmware/szl/src/unlzma.c rename to src/szl/src/unlzma.c diff --git a/zc706.py b/src/zc706.py similarity index 83% rename from zc706.py rename to src/zc706.py index 06f6388..52de70c 100755 --- a/zc706.py +++ b/src/zc706.py @@ -58,21 +58,19 @@ def write_csr_file(soc, filename): def main(): parser = argparse.ArgumentParser( description="ARTIQ port to the ZC706 Zynq development kit") - parser.add_argument("action", metavar="ACTION", nargs="*", - default="gateware rustif".split(), - help="actions to perform, default: %(default)s") + parser.add_argument("-r", default=None, + help="build Rust interface into the specified file") + parser.add_argument("-g", action="store_true", + help="build gateware") args = parser.parse_args() soc = ZC706() soc.finalize() - for action in args.action: - if action == "gateware": - soc.build() - elif action == "rustif": - write_csr_file(soc, "pl.rs") - else: - raise ValueError("invalid action", action) + if args.g: + soc.build() + if args.r is not None: + write_csr_file(soc, args.r) if __name__ == "__main__":