nix-servo/flake.nix

240 lines
8.4 KiB
Nix
Raw Normal View History

2023-11-08 14:47:50 +08:00
{
description = "Not-OS port to the Zynq-7000 platform";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05;
inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
2023-11-08 14:47:50 +08:00
inputs.not-os.url = github:cleverca22/not-os;
inputs.not-os.inputs.nixpkgs.follows = "nixpkgs";
2023-11-08 14:47:50 +08:00
outputs = { self, nixpkgs, nixpkgs-unstable, not-os }:
2023-11-24 10:08:12 +08:00
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
# To be used for building u-boot.
pkgs-unstable = import nixpkgs-unstable { system = "x86_64-linux"; };
2023-11-24 10:08:12 +08:00
2023-11-24 17:33:24 +08:00
gnu-platform = "arm-none-eabi";
2023-11-24 10:08:12 +08:00
2023-11-24 17:33:24 +08:00
binutils-pkg = { zlib, extraConfigureFlags ? [] }: pkgs.stdenv.mkDerivation rec {
basename = "binutils";
version = "2.30";
name = "${basename}-${gnu-platform}-${version}";
src = pkgs.fetchurl {
url = "https://ftp.gnu.org/gnu/binutils/binutils-${version}.tar.bz2";
sha256 = "028cklfqaab24glva1ks2aqa1zxa6w6xmc8q34zs1sb7h22dxspg";
};
configureFlags = [
"--enable-deterministic-archives"
"--target=${gnu-platform}"
"--with-cpu=cortex-a9"
"--with-fpu=vfpv3"
"--with-float=hard"
"--with-mode=thumb"
] ++ extraConfigureFlags;
outputs = [ "out" "info" "man" ];
depsBuildBuild = [ pkgs.buildPackages.stdenv.cc ];
buildInputs = [ zlib ];
enableParallelBuilding = true;
meta = {
description = "Tools for manipulating binaries (linker, assembler, etc.)";
longDescription = ''
The GNU Binutils are a collection of binary tools. The main
ones are `ld' (the GNU linker) and `as' (the GNU assembler).
They also include the BFD (Binary File Descriptor) library,
`gprof', `nm', `strip', etc.
2023-11-24 10:08:12 +08:00
'';
2023-11-24 17:33:24 +08:00
homepage = http://www.gnu.org/software/binutils/;
license = pkgs.lib.licenses.gpl3Plus;
/* Give binutils a lower priority than gcc-wrapper to prevent a
collision due to the ld/as wrappers/symlinks in the latter. */
priority = "10";
};
};
gcc-pkg = { gmp, mpfr, libmpc, platform-binutils, extraConfigureFlags ? [] }: pkgs.stdenv.mkDerivation rec {
basename = "gcc";
version = "9.1.0";
name = "${basename}-${gnu-platform}-${version}";
src = pkgs.fetchurl {
url = "https://ftp.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
sha256 = "1817nc2bqdc251k0lpc51cimna7v68xjrnvqzvc50q3ax4s6i9kr";
};
preConfigure = ''
mkdir build
cd build
'';
configureScript = "../configure";
configureFlags = [
"--target=${gnu-platform}"
"--with-arch=armv7-a"
"--with-tune=cortex-a9"
"--with-fpu=vfpv3"
"--with-float=hard"
"--disable-libssp"
"--enable-languages=c"
"--with-as=${platform-binutils}/bin/${gnu-platform}-as"
"--with-ld=${platform-binutils}/bin/${gnu-platform}-ld" ] ++ extraConfigureFlags;
outputs = [ "out" "info" "man" ];
hardeningDisable = [ "format" "pie" ];
propagatedBuildInputs = [ gmp mpfr libmpc platform-binutils ];
enableParallelBuilding = true;
dontFixup = true;
};
newlib-pkg = { platform-binutils, platform-gcc }: pkgs.stdenv.mkDerivation rec {
pname = "newlib";
version = "3.1.0";
src = pkgs.fetchurl {
url = "ftp://sourceware.org/pub/newlib/newlib-${version}.tar.gz";
sha256 = "0ahh3n079zjp7d9wynggwrnrs27440aac04340chf1p9476a2kzv";
};
nativeBuildInputs = [ platform-binutils platform-gcc ];
configureFlags = [
"--target=${gnu-platform}"
"--with-cpu=cortex-a9"
"--with-fpu=vfpv3"
"--with-float=hard"
"--with-mode=thumb"
"--enable-interwork"
"--disable-multilib"
"--disable-newlib-supplied-syscalls"
"--with-gnu-ld"
"--with-gnu-as"
"--disable-newlib-io-float"
"--disable-werror"
];
dontFixup = true;
};
gnutoolchain = rec {
binutils-bootstrap = pkgs.callPackage binutils-pkg { };
gcc-bootstrap = pkgs.callPackage gcc-pkg {
platform-binutils = binutils-bootstrap;
extraConfigureFlags = [ "--disable-libgcc" ];
};
newlib = pkgs.callPackage newlib-pkg {
platform-binutils = binutils-bootstrap;
platform-gcc = gcc-bootstrap;
};
binutils = pkgs.callPackage binutils-pkg {
extraConfigureFlags = [ "--with-lib-path=${newlib}/arm-none-eabi/lib" ];
2023-11-24 10:08:12 +08:00
};
2023-11-24 17:33:24 +08:00
gcc = pkgs.callPackage gcc-pkg {
platform-binutils = binutils;
extraConfigureFlags = [ "--enable-newlib" "--with-headers=${newlib}/arm-none-eabi/include" ];
};
};
mkbootimage = pkgs.stdenv.mkDerivation {
pname = "mkbootimage";
version = "2.3dev";
src = pkgs.fetchFromGitHub {
owner = "antmicro";
repo = "zynq-mkbootimage";
rev = "872363ce32c249f8278cf107bc6d3bdeb38d849f";
sha256 = "sha256-5FPyAhUWZDwHbqmp9J2ZXTmjaXPz+dzrJMolaNwADHs=";
};
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-11-24 10:08:12 +08:00
2023-11-24 17:33:24 +08:00
fsbl = { board ? "zc706" }: pkgs.stdenv.mkDerivation {
name = "${board}-fsbl";
src = pkgs.fetchFromGitHub {
owner = "Xilinx";
repo = "embeddedsw";
rev = "65c849ed46c88c67457e1fc742744f96db968ff1";
sha256 = "1rvl06ha40dzd6s9aa4sylmksh4xb9dqaxq462lffv1fdk342pda";
};
patches = [ ./fsbl.patch ];
nativeBuildInputs = [
pkgs.gnumake
gnutoolchain.binutils
gnutoolchain.gcc
];
patchPhase = ''
patch -p1 -i ${./fsbl.patch}
patchShebangs lib/sw_apps/zynq_fsbl/misc/copy_bsp.sh
echo 'SEARCH_DIR("${gnutoolchain.newlib}/arm-none-eabi/lib");' >> lib/sw_apps/zynq_fsbl/src/lscript.ld
'';
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;
};
# U-boot needs the recent patch in master to fix cross-compile issues.
# See https://github.com/NixOS/nixpkgs/pull/265411.
u-boot = pkgs-unstable.pkgsCross.armv7l-hf-multiplatform.buildUBoot {
2023-11-24 17:33:24 +08:00
defconfig = "xilinx_zynq_virt_defconfig";
preConfigure = ''
export DEVICE_TREE=zynq-zc706
'';
extraMeta.platforms = ["armv7l-linux"];
filesToInstall = ["u-boot.elf"];
};
build = { target ? "zc706" }: let
fsblDrv = fsbl { board = "zc706"; };
u-bootDrv = u-boot;
bootimage = pkgs.runCommand "${target}-bootimage"
2023-11-24 10:08:12 +08:00
{
2023-11-24 17:33:24 +08:00
buildInputs = [ mkbootimage ];
2023-11-24 10:08:12 +08:00
}
''
bifdir=`mktemp -d`
cd $bifdir
2023-11-24 17:33:24 +08:00
ln -s ${fsblDrv}/fsbl.elf fsbl.elf
ln -s ${u-bootDrv}/u-boot.elf u-boot.elf
2023-11-24 10:08:12 +08:00
cat > boot.bif << EOF
the_ROM_image:
{
[bootloader]fsbl.elf
u-boot.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
'';
in {
2023-11-24 17:33:24 +08:00
"${target}-bootimage" = bootimage;
2023-11-24 10:08:12 +08:00
};
in rec {
2023-11-24 17:33:24 +08:00
packages.x86_64-linux = {
inherit mkbootimage u-boot;
zc706-fsbl = fsbl { board = "zc706"; };
2023-11-24 10:08:12 +08:00
} // (build { target = "zc706"; });
packages.armv7l-linux = let
platforms = (import not-os.inputs.nixpkgs { config = {}; }).platforms;
eval = (import "${not-os}" {
extraModules = [
2023-11-24 17:33:24 +08:00
"${not-os}/zynq_image.nix"
2023-11-24 10:08:12 +08:00
];
platform = system: platforms.armv7l-hf-multiplatform;
system = "x86_64-linux";
crossSystem.system = "armv7l-linux";
inherit (not-os.inputs) nixpkgs;
});
in {
zynq_image = eval.config.system.build.zynq_image;
};
2023-11-08 14:47:50 +08:00
};
}