2022-01-27 16:26:33 +08:00
|
|
|
{
|
|
|
|
description = "Bare-metal Rust on Zynq-7000";
|
|
|
|
|
2024-05-28 17:37:50 +08:00
|
|
|
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
|
2022-01-27 16:26:33 +08:00
|
|
|
inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; };
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, mozilla-overlay }:
|
|
|
|
let
|
2024-03-25 17:20:19 +08:00
|
|
|
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) crosspkgs-overlay ]; };
|
2022-01-27 16:26:33 +08:00
|
|
|
|
|
|
|
rustManifest = pkgs.fetchurl {
|
|
|
|
url = "https://static.rust-lang.org/dist/2021-01-29/channel-rust-nightly.toml";
|
|
|
|
sha256 = "sha256-EZKgw89AH4vxaJpUHmIMzMW/80wAFQlfcxRoBD9nz0c=";
|
|
|
|
};
|
|
|
|
rustTargets = [];
|
|
|
|
rustChannelOfTargets = _channel: _date: targets:
|
|
|
|
(pkgs.lib.rustLib.fromManifestFile rustManifest {
|
|
|
|
inherit (pkgs) stdenv lib fetchurl patchelf;
|
|
|
|
}).rust.override {
|
|
|
|
inherit targets;
|
|
|
|
extensions = ["rust-src"];
|
|
|
|
};
|
|
|
|
rust = rustChannelOfTargets "nightly" null rustTargets;
|
|
|
|
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
|
|
|
|
rustc = rust;
|
|
|
|
cargo = rust;
|
|
|
|
});
|
2024-05-23 14:07:42 +08:00
|
|
|
|
|
|
|
# https://doc.rust-lang.org/rustc/linker-plugin-lto.html#toolchain-compatibility
|
|
|
|
llvmPackages_11 = pkgs.recurseIntoAttrs (pkgs.callPackage (import ./llvm/11) ({
|
|
|
|
inherit (pkgs.stdenvAdapters) overrideCC;
|
|
|
|
buildLlvmTools = null;
|
|
|
|
targetLlvmLibraries = null;
|
|
|
|
targetLlvm = null;
|
|
|
|
}));
|
2022-01-27 16:26:33 +08:00
|
|
|
|
2024-03-25 17:20:19 +08:00
|
|
|
crosspkgs-overlay = (self: super: {
|
|
|
|
pkgsCross = super.pkgsCross // {
|
|
|
|
zynq-baremetal = import super.path {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
crossSystem = {
|
|
|
|
config = "arm-none-eabihf";
|
|
|
|
libc = "newlib";
|
|
|
|
gcc.cpu = "cortex-a9";
|
|
|
|
gcc.fpu = "vfpv3";
|
|
|
|
};
|
|
|
|
};
|
2022-01-27 16:26:33 +08:00
|
|
|
};
|
2024-03-25 17:20:19 +08:00
|
|
|
});
|
2022-01-27 16:26:33 +08:00
|
|
|
|
|
|
|
mkbootimage = pkgs.stdenv.mkDerivation {
|
|
|
|
pname = "mkbootimage";
|
2022-11-30 22:36:56 +08:00
|
|
|
version = "2.3dev";
|
2022-01-27 16:26:33 +08:00
|
|
|
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "antmicro";
|
|
|
|
repo = "zynq-mkbootimage";
|
2022-11-30 22:36:56 +08:00
|
|
|
rev = "872363ce32c249f8278cf107bc6d3bdeb38d849f";
|
|
|
|
sha256 = "sha256-5FPyAhUWZDwHbqmp9J2ZXTmjaXPz+dzrJMolaNwADHs=";
|
2022-01-27 16:26:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
propagatedBuildInputs = [ pkgs.libelf pkgs.pcre ];
|
|
|
|
patchPhase =
|
|
|
|
''
|
|
|
|
substituteInPlace Makefile --replace "git rev-parse --short HEAD" "echo nix"
|
|
|
|
'';
|
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cp mkbootimage $out/bin
|
|
|
|
'';
|
2023-12-03 16:16:22 +08:00
|
|
|
hardeningDisable = [ "fortify" ];
|
2022-01-27 16:26:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
fsbl = { board ? "zc706" }: pkgs.stdenv.mkDerivation {
|
|
|
|
name = "${board}-fsbl";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "Xilinx";
|
|
|
|
repo = "embeddedsw";
|
2024-03-25 17:16:56 +08:00
|
|
|
rev = "xilinx_v2022.2";
|
|
|
|
sha256 = "sha256-UDz9KK/Hw3qM1BAeKif30rE8Bi6C2uvuZlvyvtJCMfw=";
|
2022-01-27 16:26:33 +08:00
|
|
|
};
|
|
|
|
nativeBuildInputs = [
|
2024-03-25 17:20:19 +08:00
|
|
|
pkgs.pkgsCross.zynq-baremetal.buildPackages.binutils
|
|
|
|
pkgs.pkgsCross.zynq-baremetal.buildPackages.gcc
|
2022-01-27 16:26:33 +08:00
|
|
|
];
|
|
|
|
patchPhase = ''
|
|
|
|
patchShebangs lib/sw_apps/zynq_fsbl/misc/copy_bsp.sh
|
2024-03-25 17:20:19 +08:00
|
|
|
|
|
|
|
for x in lib/sw_apps/zynq_fsbl/src/Makefile lib/sw_apps/zynq_fsbl/misc/copy_bsp.sh lib/bsp/standalone/src/arm/cortexa9/gcc/Makefile; do
|
|
|
|
substituteInPlace $x \
|
|
|
|
--replace "arm-none-eabi-" "arm-none-eabihf-"
|
|
|
|
done
|
2022-01-27 16:26:33 +08:00
|
|
|
'';
|
|
|
|
buildPhase = ''
|
|
|
|
cd lib/sw_apps/zynq_fsbl/src
|
|
|
|
make BOARD=${board} "CFLAGS=-DFSBL_DEBUG_INFO -g"
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir $out
|
|
|
|
cp fsbl.elf $out
|
|
|
|
'';
|
|
|
|
doCheck = false;
|
|
|
|
dontFixup = true;
|
|
|
|
};
|
|
|
|
|
2023-12-03 10:55:05 +08:00
|
|
|
cargo-xbuild = pkgs.cargo-xbuild.overrideAttrs(oa: {
|
|
|
|
postPatch = "substituteInPlace src/sysroot.rs --replace 2021 2018";
|
|
|
|
});
|
|
|
|
|
2022-01-27 16:26:33 +08:00
|
|
|
build-crate = name: crate: features: rustPlatform.buildRustPackage rec {
|
|
|
|
name = "${crate}";
|
|
|
|
|
|
|
|
src = builtins.filterSource (path: type:
|
|
|
|
baseNameOf path != "target"
|
|
|
|
) ./.;
|
2024-07-19 15:45:46 +08:00
|
|
|
cargoLock = {
|
|
|
|
lockFile = src/Cargo.lock;
|
|
|
|
outputHashes = {
|
|
|
|
"core_io-0.1.20210325" = "sha256-2ZdKk+cgsh/WKPlWpCq9A/m+gHxN19Eqix/Om1IwaGM=";
|
|
|
|
};
|
|
|
|
};
|
2022-01-27 16:26:33 +08:00
|
|
|
|
2024-05-23 14:07:42 +08:00
|
|
|
nativeBuildInputs = [ cargo-xbuild llvmPackages_11.clang-unwrapped ];
|
2022-01-27 16:26:33 +08:00
|
|
|
buildPhase = ''
|
2023-05-27 18:20:53 +08:00
|
|
|
export XARGO_RUST_SRC="${rust}/lib/rustlib/src/rust/library"
|
2022-01-27 16:26:33 +08:00
|
|
|
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
|
|
|
|
pushd ${crate}
|
|
|
|
cargo xbuild --release --frozen \
|
|
|
|
--no-default-features \
|
|
|
|
--features=${features}
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = false;
|
|
|
|
dontFixup = true;
|
2023-12-03 11:09:31 +08:00
|
|
|
auditable = false;
|
2022-01-27 16:26:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
targetCrates = target: {
|
|
|
|
"${target}-experiments" = build-crate "${target}-experiments" "experiments" "target_${target}";
|
|
|
|
"${target}-szl" = build-crate "${target}-szl" "szl" "target_${target}";
|
|
|
|
};
|
|
|
|
targets = ["zc706" "coraz7" "redpitaya" "kasli_soc"];
|
|
|
|
allTargetCrates = (builtins.foldl' (results: target:
|
|
|
|
results // targetCrates target
|
|
|
|
) {} targets);
|
|
|
|
|
|
|
|
szl = pkgs.runCommand "szl" {} (builtins.foldl' (commands: target:
|
|
|
|
let
|
|
|
|
szlResult = builtins.getAttr "${target}-szl" allTargetCrates;
|
|
|
|
in
|
|
|
|
commands + "ln -s ${szlResult}/szl.elf $out/szl-${target}.elf\n"
|
|
|
|
) "mkdir $out\n" targets);
|
2022-02-04 18:42:35 +08:00
|
|
|
in rec {
|
|
|
|
packages.x86_64-linux = {
|
|
|
|
inherit cargo-xbuild szl mkbootimage;
|
2022-01-27 16:26:33 +08:00
|
|
|
zc706-fsbl = fsbl { board = "zc706"; };
|
|
|
|
} // allTargetCrates ;
|
|
|
|
|
|
|
|
hydraJobs = packages.x86_64-linux;
|
|
|
|
|
2024-05-23 14:07:42 +08:00
|
|
|
inherit rust rustPlatform llvmPackages_11;
|
2022-02-04 18:42:35 +08:00
|
|
|
|
2022-01-27 16:26:33 +08:00
|
|
|
devShell.x86_64-linux = pkgs.mkShell {
|
|
|
|
name = "zynq-rs-dev-shell";
|
2023-12-03 10:55:05 +08:00
|
|
|
buildInputs = [
|
2023-05-27 18:20:53 +08:00
|
|
|
rust
|
2022-01-27 16:26:33 +08:00
|
|
|
cargo-xbuild
|
2023-12-03 10:55:05 +08:00
|
|
|
mkbootimage
|
2022-01-27 16:26:33 +08:00
|
|
|
|
2023-12-03 10:55:05 +08:00
|
|
|
pkgs.openocd pkgs.gdb
|
|
|
|
pkgs.openssh pkgs.rsync
|
2024-05-23 14:07:42 +08:00
|
|
|
llvmPackages_11.clang-unwrapped
|
2023-12-03 10:55:05 +08:00
|
|
|
(pkgs.python3.withPackages(ps: [ ps.pyftdi ]))
|
|
|
|
];
|
|
|
|
};
|
2022-01-27 16:26:33 +08:00
|
|
|
};
|
2023-12-03 10:45:47 +08:00
|
|
|
}
|