From fd60260a770739eb206f6f063cc30bf4beb21b88 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Sun, 25 Dec 2016 20:20:52 +0200 Subject: [PATCH 01/19] platforms.nix: selectPlatformBySystem: Convert to "switch-case" Looks generally nicer and used recently in nixpkgs in e.g. 3e197f7d8 ("top-level: Normalize stdenv booting") --- pkgs/top-level/platforms.nix | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/top-level/platforms.nix b/pkgs/top-level/platforms.nix index 671aaea4491a..e6c55241b354 100644 --- a/pkgs/top-level/platforms.nix +++ b/pkgs/top-level/platforms.nix @@ -443,12 +443,12 @@ rec { }; }; - selectPlatformBySystem = system: - if system == "armv6l-linux" then raspberrypi - else if system == "armv7l-linux" then armv7l-hf-multiplatform - else if system == "armv5tel-linux" then sheevaplug - else if system == "mips64el-linux" then fuloong2f_n32 - else if system == "x86_64-linux" then pc64 - else if system == "i686-linux" then pc32 - else pcBase; + selectPlatformBySystem = system: { + "i686-linux" = pc32; + "x86_64-linux" = pc64; + "armv5tel-linux" = sheevaplug; + "armv6l-linux" = raspberrypi; + "armv7l-linux" = armv7l-hf-multiplatform; + "mips64el-linux" = fuloong2f_n32; + }.${system} or pcBase; } From 41fd1ed90346a3d7f6b067301ac9e147ef4dcd5e Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Thu, 4 Feb 2016 20:24:46 +0200 Subject: [PATCH 02/19] glibc: Check that 'cross.float' is defined Because if we define it, then gcc compilation fails because it doesn't support --with-float for aarch64. --- pkgs/development/libraries/glibc/common.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/glibc/common.nix b/pkgs/development/libraries/glibc/common.nix index 4e03293fdf96..32c1b3647372 100644 --- a/pkgs/development/libraries/glibc/common.nix +++ b/pkgs/development/libraries/glibc/common.nix @@ -93,7 +93,7 @@ stdenv.mkDerivation ({ "--enable-kernel=2.6.32" ] ++ lib.optionals (cross != null) [ (if cross.withTLS then "--with-tls" else "--without-tls") - (if cross.float == "soft" then "--without-fp" else "--with-fp") + (if cross ? float && cross.float == "soft" then "--without-fp" else "--with-fp") ] ++ lib.optionals (cross != null && cross.platform ? kernelMajor && cross.platform.kernelMajor == "2.6") [ From 7c8a060c09799eb2ee70c00aa695ff08e5f07c6f Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 5 Feb 2016 00:47:23 +0200 Subject: [PATCH 03/19] stdenv: Bringup aarch64 architecture support --- lib/platforms.nix | 2 +- pkgs/build-support/cc-wrapper/default.nix | 1 + pkgs/stdenv/default.nix | 1 + pkgs/stdenv/generic/default.nix | 2 ++ pkgs/stdenv/linux/default.nix | 1 + .../stdenv/linux/make-bootstrap-tools-cross.nix | 16 +++++++++++++++- pkgs/top-level/platforms.nix | 17 +++++++++++++++++ 7 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/platforms.nix b/lib/platforms.nix index b068d080e752..0cd9485d4ccb 100644 --- a/lib/platforms.nix +++ b/lib/platforms.nix @@ -15,7 +15,7 @@ rec { freebsd = ["i686-freebsd" "x86_64-freebsd"]; gnu = linux; /* ++ hurd ++ kfreebsd ++ ... */ illumos = ["x86_64-solaris"]; - linux = ["i686-linux" "x86_64-linux" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "mips64el-linux"]; + linux = ["i686-linux" "x86_64-linux" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "mips64el-linux"]; netbsd = ["i686-netbsd" "x86_64-netbsd"]; openbsd = ["i686-openbsd" "x86_64-openbsd"]; unix = linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos; diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 95e0b360937a..95c6bee3cc77 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -272,6 +272,7 @@ stdenv.mkDerivation { if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else # ARM with a wildcard, which can be "" or "-armhf". if stdenv.isArm then "ld-linux*.so.3" else + if stdenv.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else if stdenv.system == "powerpc-linux" then "ld.so.1" else if stdenv.system == "mips64el-linux" then "ld.so.1" else if stdenv.system == "x86_64-darwin" then "/usr/lib/dyld" else diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index 78dbde13b89d..098caca0d890 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -44,6 +44,7 @@ in "armv5tel-linux" = stagesLinux; "armv6l-linux" = stagesLinux; "armv7l-linux" = stagesLinux; + "aarch64-linux" = stagesLinux; "mips64el-linux" = stagesLinux; "powerpc-linux" = /* stagesLinux */ stagesNative; "x86_64-darwin" = stagesDarwin; diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index 269d7ef893a1..2010e35f58a3 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -311,6 +311,7 @@ let || system == "armv5tel-linux" || system == "armv6l-linux" || system == "armv7l-linux" + || system == "aarch64-linux" || system == "mips64el-linux"; isGNU = system == "i686-gnu"; # GNU/Hurd isGlibc = isGNU # useful for `stdenvNative' @@ -348,6 +349,7 @@ let isArm = system == "armv5tel-linux" || system == "armv6l-linux" || system == "armv7l-linux"; + isAarch64 = system == "aarch64-linux"; isBigEndian = system == "powerpc-linux"; # Whether we should run paxctl to pax-mark binaries. diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 611628b35aba..41695b5c36b5 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -12,6 +12,7 @@ "armv5tel-linux" = import ./bootstrap-files/armv5tel.nix; "armv6l-linux" = import ./bootstrap-files/armv6l.nix; "armv7l-linux" = import ./bootstrap-files/armv7l.nix; + "aarch64-linux" = import ./bootstrap-files/aarch64.nix; "mips64el-linux" = import ./bootstrap-files/loongson2f.nix; }.${localSystem.system} or (abort "unsupported platform for the pure Linux stdenv") diff --git a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix index 38b3e611bc28..9cce27ba5b6b 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools-cross.nix @@ -50,10 +50,23 @@ let }; }; + aarch64-multiplatform-crossSystem = { + crossSystem = rec { + config = "aarch64-linux-gnu"; + bigEndian = false; + arch = "aarch64"; + withTLS = true; + libc = "glibc"; + platform = pkgsNoParams.platforms.aarch64-multiplatform; + inherit (platform) gcc; + }; + }; + selectedCrossSystem = if toolsArch == "armv5tel" then sheevaplugCrossSystem else if toolsArch == "armv6l" then raspberrypiCrossSystem else - if toolsArch == "armv7l" then armv7l-hf-multiplatform-crossSystem else null; + if toolsArch == "armv7l" then armv7l-hf-multiplatform-crossSystem else + if toolsArch == "aarch64" then aarch64-multiplatform-crossSystem else null; pkgsUnspliced = pkgsFun ({inherit system;} // selectedCrossSystem); pkgs = pkgsUnspliced.splicedPackages; @@ -265,4 +278,5 @@ rec { armv5tel = buildFor "armv5tel"; armv6l = buildFor "armv6l"; armv7l = buildFor "armv7l"; + aarch64 = buildFor "aarch64"; } diff --git a/pkgs/top-level/platforms.nix b/pkgs/top-level/platforms.nix index e6c55241b354..c740fbe6f8d1 100644 --- a/pkgs/top-level/platforms.nix +++ b/pkgs/top-level/platforms.nix @@ -443,12 +443,29 @@ rec { }; }; + aarch64-multiplatform = { + name = "aarch64-multiplatform"; + kernelMajor = "2.6"; # Using "2.6" enables 2.6 kernel syscalls in glibc. + kernelHeadersBaseConfig = "defconfig"; + kernelBaseConfig = "defconfig"; + kernelArch = "arm64"; + kernelDTB = true; + kernelAutoModules = false; + kernelExtraConfig = ""; + uboot = null; + kernelTarget = "Image"; + gcc = { + arch = "armv8-a"; + }; + }; + selectPlatformBySystem = system: { "i686-linux" = pc32; "x86_64-linux" = pc64; "armv5tel-linux" = sheevaplug; "armv6l-linux" = raspberrypi; "armv7l-linux" = armv7l-hf-multiplatform; + "aarch64-linux" = aarch64-multiplatform; "mips64el-linux" = fuloong2f_n32; }.${system} or pcBase; } From 6e46dbf8e7c2362aab5823207c27c6d7e3870f11 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 4 Mar 2016 12:46:38 +0200 Subject: [PATCH 04/19] gnu-config: init at 2016-12-31 --- .../libraries/gnu-config/default.nix | 39 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 41 insertions(+) create mode 100644 pkgs/development/libraries/gnu-config/default.nix diff --git a/pkgs/development/libraries/gnu-config/default.nix b/pkgs/development/libraries/gnu-config/default.nix new file mode 100644 index 000000000000..b46523071c7c --- /dev/null +++ b/pkgs/development/libraries/gnu-config/default.nix @@ -0,0 +1,39 @@ +{ stdenv, fetchurl }: + +let + rev = "6a82322dd05cdc57b4cd9f7effdf1e2fd6f7482b"; + + # Don't use fetchgit as this is needed during Aarch64 bootstrapping + configGuess = fetchurl { + url = "http://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=${rev}"; + sha256 = "1yj9yi94h7z4z6jzickddv64ksz1aq5kj0c7krgzjn8xf8p3avmh"; + }; + configSub = fetchurl { + url = "http://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=${rev}"; + sha256 = "1qsqdpla6icbzskkk7v3zxrpzlpqlc94ny9hyy5wh5lm5rwwfvb7"; + }; +in +stdenv.mkDerivation rec { + name = "gnu-config-${version}"; + version = "2016-12-31"; + + buildCommand = '' + mkdir -p $out + cp ${configGuess} $out/config.guess + cp ${configSub} $out/config.sub + ''; + + meta = with stdenv.lib; { + description = "Attempt to guess a canonical system name"; + homepage = http://savannah.gnu.org/projects/config; + license = licenses.gpl3; + # In addition to GPLv3: + # As a special exception to the GNU General Public License, if you + # distribute this file as part of a program that contains a + # configuration script generated by Autoconf, you may include it under + # the same distribution terms that you use for the rest of that + # program. + maintainers = [ maintainers.dezgeg ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1d924df6aea3..70e269ff87c3 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7457,6 +7457,8 @@ with pkgs; gnet = callPackage ../development/libraries/gnet { }; + gnu-config = callPackage ../development/libraries/gnu-config { }; + gnu-efi = callPackage ../development/libraries/gnu-efi { }; gnutls = gnutls34; From c909f1b18e9c5deecdfe6d46c7e9901fe3e6cf83 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Sat, 5 Mar 2016 02:28:23 +0200 Subject: [PATCH 05/19] stdenv: Add updateAutoconfGnuConfigScriptsHook for aarch64 This is required for Aarch64 since a lot of source tarballs ship with outdated configure scripts that don't recognize aarch64. Simply replacing the config.guess and config.sub with new versions from upstream makes them build again. This same approach is used by at least Buildroot and Fedora. In principle this could be enabled for all architectures but conditionalizing this on aarch64 avoids a mass rebuild on x86. --- .../update-autotools-gnu-config-scripts.sh | 12 ++++++++++++ pkgs/stdenv/adapters.nix | 1 + pkgs/stdenv/linux/default.nix | 14 ++++++++++---- pkgs/top-level/all-packages.nix | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh diff --git a/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh b/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh new file mode 100644 index 000000000000..5e33ace42b37 --- /dev/null +++ b/pkgs/build-support/setup-hooks/update-autotools-gnu-config-scripts.sh @@ -0,0 +1,12 @@ +preConfigurePhases+=" updateAutotoolsGnuConfigScriptsPhase" + +updateAutotoolsGnuConfigScriptsPhase() { + if [ -n "$dontUpdateAutotoolsGnuConfigScripts" ]; then return; fi + + for script in config.sub config.guess; do + for f in $(find . -name "$script"); do + echo "Updating Autotools / GNU config script to a newer upstream version: $f" + cp -f "@gnu_config@/$script" "$f" + done + done +} diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 7e0eaeddd2c4..90a55188f09e 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -92,6 +92,7 @@ rec { # without proper `file` command, libtool sometimes fails # to recognize 64-bit DLLs ++ stdenv.lib.optional (cross.config == "x86_64-w64-mingw32") pkgs.file + ++ stdenv.lib.optional (cross.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook ; # Cross-linking dynamic libraries, every buildInput should diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 41695b5c36b5..fe685a1e77ce 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -214,7 +214,9 @@ in isl = isl_0_14; }; }; - extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ]; + extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++ + # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. + lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; }) @@ -241,7 +243,9 @@ in shell = self.bash + "/bin/bash"; }; }; - extraBuildInputs = [ prevStage.patchelf prevStage.xz ]; + extraBuildInputs = [ prevStage.patchelf prevStage.xz ] ++ + # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. + lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; }) # Construct the final stdenv. It uses the Glibc and GCC, and adds @@ -269,7 +273,9 @@ in initialPath = ((import ../common-path.nix) {pkgs = prevStage;}); - extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ]; + extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++ + # Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64. + lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; cc = prevStage.gcc; @@ -288,7 +294,7 @@ in [ gzip bzip2 xz bash binutils coreutils diffutils findutils gawk glibc gnumake gnused gnutar gnugrep gnupatch patchelf attr acl paxctl zlib pcre linuxHeaders ed gcc gcc.cc libsigsegv - ]; + ] ++ lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook; */ overrides = self: super: { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 70e269ff87c3..f9959801f3bc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -79,6 +79,10 @@ with pkgs; } ''); + updateAutotoolsGnuConfigScriptsHook = makeSetupHook + { substitutions = { gnu_config = gnu-config;}; } + ../build-support/setup-hooks/update-autotools-gnu-config-scripts.sh; + buildEnv = callPackage ../build-support/buildenv { }; # not actually a package buildFHSUserEnv = callPackage ../build-support/build-fhs-userenv { }; From ed74fcf14b477bdf2d96fd80e514cd17c54fbdfe Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 25 Mar 2016 22:15:57 +0200 Subject: [PATCH 06/19] libsigsegv: Add Aarch64 patch --- pkgs/development/libraries/libsigsegv/aarch64.patch | 12 ++++++++++++ pkgs/development/libraries/libsigsegv/default.nix | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 pkgs/development/libraries/libsigsegv/aarch64.patch diff --git a/pkgs/development/libraries/libsigsegv/aarch64.patch b/pkgs/development/libraries/libsigsegv/aarch64.patch new file mode 100644 index 000000000000..7bb48a230cee --- /dev/null +++ b/pkgs/development/libraries/libsigsegv/aarch64.patch @@ -0,0 +1,12 @@ +diff --git a/configure b/configure +index 6c4e868..0298e19 100755 +--- a/configure ++++ b/configure +@@ -14501,6 +14501,7 @@ else + + case "$host_cpu" in + a29k | \ ++ aarch64* | \ + alpha* | \ + arc | \ + arm* | strongarm* | xscale* | \ diff --git a/pkgs/development/libraries/libsigsegv/default.nix b/pkgs/development/libraries/libsigsegv/default.nix index be3cbe39a302..3353fbf9e8d9 100644 --- a/pkgs/development/libraries/libsigsegv/default.nix +++ b/pkgs/development/libraries/libsigsegv/default.nix @@ -8,6 +8,12 @@ stdenv.mkDerivation rec { sha256 = "16hrs8k3nmc7a8jam5j1fpspd6sdpkamskvsdpcw6m29vnis8q44"; }; + # Based on https://github.com/davidgfnet/buildroot-Os/blob/69fe6065b9dd1cb4dcc0a4b554e42cc2e5bd0d60/package/libsigsegv/libsigsegv-0002-fix-aarch64-build.patch + # but applied directly to configure since we can't use autoreconf while bootstrapping. + patches = if stdenv.isAarch64 || stdenv.cross.arch or "" == "aarch64" + then [ ./aarch64.patch ] + else null; # TODO: change to lib.optional on next mass rebuild + # https://github.com/NixOS/nixpkgs/issues/6028 doCheck = false; From de3cac0eceb2c746aeba20ae743c03cefca232e2 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Mon, 26 Dec 2016 00:54:45 +0200 Subject: [PATCH 07/19] make-bootstrap-tools.nix test: Use busybox from store Our bootstrap tools are actually broken right now due to busybox not working when invoked directly from a store path. (It says e.g. "0qqqw19y4gmknajw8vg4fvhx9gxdqlhz-busybox: applet not found"). Make this test actually fail in such case, the next commit will fix the problem with busybox. --- pkgs/stdenv/linux/make-bootstrap-tools.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix index d31253075c9d..2e7b24af131d 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix @@ -170,8 +170,9 @@ rec { }; bootstrapFiles = { - busybox = "${build}/on-server/busybox"; - bootstrapTools = "${build}/on-server/bootstrap-tools.tar.xz"; + # Make them their own store paths to test that busybox still works when the binary is named /nix/store/HASH-busybox + busybox = runCommand "busybox" {} "cp ${build}/on-server/busybox $out"; + bootstrapTools = runCommand "bootstrap-tools.tar.xz" {} "cp ${build}/on-server/bootstrap-tools.tar.xz $out"; }; bootstrapTools = import ./bootstrap-tools { inherit system bootstrapFiles; }; From bfff3d6e23c02186043b9c8ce4dc2131b803dbac Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Sat, 3 Dec 2016 14:57:46 -0500 Subject: [PATCH 08/19] busybox: Fix in-store invocation of busybox This fixes the usage for stdenv bootstrap. Additionally, dezgeg ported the patch from 1.25.1 to 1.26.1 --- pkgs/os-specific/linux/busybox/busybox-in-store.patch | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/os-specific/linux/busybox/busybox-in-store.patch b/pkgs/os-specific/linux/busybox/busybox-in-store.patch index d3111efbdc48..0de7348c44fe 100644 --- a/pkgs/os-specific/linux/busybox/busybox-in-store.patch +++ b/pkgs/os-specific/linux/busybox/busybox-in-store.patch @@ -12,3 +12,12 @@ stdenv bootstrap. exit(busybox_main(argv)); # endif # if NUM_APPLETS > 0 +@@ -981,7 +981,7 @@ int main(int argc UNUSED_PARAM, char **argv) + + lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv)); + # if !ENABLE_BUSYBOX +- if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox")) ++ if (argv[1] && strstr(bb_basename(argv[0]), "busybox") != 0) + argv++; + # endif + applet_name = argv[0]; From 5c0a385e1cafb369529bb304ff8600c1f44b3fc3 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Tue, 24 Jan 2017 01:35:05 +0200 Subject: [PATCH 09/19] stdenv: Add aarch64 bootstrap files These are temporary and will be switched to Hydra-build ones once all the aarch4 changs are merged. --- pkgs/stdenv/linux/bootstrap-files/aarch64.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 pkgs/stdenv/linux/bootstrap-files/aarch64.nix diff --git a/pkgs/stdenv/linux/bootstrap-files/aarch64.nix b/pkgs/stdenv/linux/bootstrap-files/aarch64.nix new file mode 100644 index 000000000000..7f1acc83433b --- /dev/null +++ b/pkgs/stdenv/linux/bootstrap-files/aarch64.nix @@ -0,0 +1,11 @@ +{ + busybox = import { + url = http://nixos-arm.dezgeg.me/bootstrap-aarch64-for-merge/busybox; + sha256 = "12qcml1l67skpjhfjwy7gr10nc86gqcwjmz9ggp7knss8gq8pv7f"; + executable = true; + }; + bootstrapTools = import { + url = http://nixos-arm.dezgeg.me/bootstrap-aarch64-for-merge/bootstrap-tools.tar.xz; + sha256 = "10sqgh0dchp1906h06jznxh8gfflnzbpfy27hng2mmc1l0c7irjr"; + }; +} From 46991f88f70be9a8300f4e2f97af3eeeb38cf0f4 Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Sat, 3 Dec 2016 17:59:00 -0500 Subject: [PATCH 10/19] gnu-efi: fix discarded const qualifier on aarch64 --- .../gnu-efi/aarch64-fix-discarded-qualifier.patch | 13 +++++++++++++ pkgs/development/libraries/gnu-efi/default.nix | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch diff --git a/pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch b/pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch new file mode 100644 index 000000000000..2295a4bb8a37 --- /dev/null +++ b/pkgs/development/libraries/gnu-efi/aarch64-fix-discarded-qualifier.patch @@ -0,0 +1,13 @@ +diff -ru gnu-efi-3.0.4-orig/lib/aarch64/initplat.c gnu-efi-3.0.4/lib/aarch64/initplat.c +--- gnu-efi-3.0.4-orig/lib/aarch64/initplat.c 2016-03-17 09:53:14.000000000 -0400 ++++ gnu-efi-3.0.4/lib/aarch64/initplat.c 2016-12-03 17:53:57.166575974 -0500 +@@ -41,7 +41,8 @@ + + void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n) + { +- unsigned char *p = dest, *q = src; ++ unsigned char *p = dest; ++ const unsigned char *q = src; + + while (n--) + *p++ = *q++; diff --git a/pkgs/development/libraries/gnu-efi/default.nix b/pkgs/development/libraries/gnu-efi/default.nix index d679d88e91d1..aa644a3a4a83 100644 --- a/pkgs/development/libraries/gnu-efi/default.nix +++ b/pkgs/development/libraries/gnu-efi/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, pciutils }: +{ stdenv, fetchurl, pciutils }: with stdenv.lib; stdenv.mkDerivation rec { name = "gnu-efi-${version}"; @@ -9,6 +9,8 @@ stdenv.mkDerivation rec { sha256 = "1bzq5czw5dxlvpgs9ij2iz7q6krwhja87vc982r6vffcqcl0982i"; }; + patches = optional stdenv.isAarch64 ./aarch64-fix-discarded-qualifier.patch; + buildInputs = [ pciutils ]; hardeningDisable = [ "stackprotector" ]; From 2a82be9af1a3032810052a94093e040b7a32510c Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Sat, 3 Dec 2016 19:55:51 -0500 Subject: [PATCH 11/19] libunwind: add AArch64 support patch --- pkgs/development/libraries/libunwind/default.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/development/libraries/libunwind/default.nix b/pkgs/development/libraries/libunwind/default.nix index 6ed29a8abc3f..419a14551ba4 100644 --- a/pkgs/development/libraries/libunwind/default.nix +++ b/pkgs/development/libraries/libunwind/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, fetchpatch, xz }: +{ stdenv, fetchurl, fetchpatch, autoreconfHook, xz }: stdenv.mkDerivation rec { name = "libunwind-1.1"; @@ -8,13 +8,18 @@ stdenv.mkDerivation rec { sha256 = "16nhx2pahh9d62mvszc88q226q5lwjankij276fxwrm8wb50zzlx"; }; + buildInputs = stdenv.lib.optional stdenv.isAarch64 autoreconfHook; + patches = [ ./libunwind-1.1-lzma.patch ./cve-2015-3239.patch # https://lists.nongnu.org/archive/html/libunwind-devel/2014-04/msg00000.html (fetchpatch { url = "https://raw.githubusercontent.com/dropbox/pyston/1b2e676417b0f5f17526ece0ed840aa88c744145/libunwind_patches/0001-Change-the-RBP-validation-heuristic-to-allow-size-0-.patch"; sha256 = "1a0fsgfxmgd218nscswx7pgyb7rcn2gh6566252xhfvzhgn5i4ha"; }) - ]; + ] ++ stdenv.lib.optional stdenv.isAarch64 (fetchpatch { + url = "https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/77709d1c6d5c39e23c1535b1bd584be1455f2551/extra/libunwind/libunwind-aarch64.patch"; + sha256 = "1mpjs8izq9wxiaf5rl4gzaxrkz0s51f9qz5qc5dj72pr84mw50w8"; + }); postPatch = '' sed -i -e '/LIBLZMA/s:-lzma:-llzma:' configure From 15b63749183c3de4bcf077669c447bc01a7cd3c4 Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Sat, 3 Dec 2016 20:34:55 -0500 Subject: [PATCH 12/19] spidermonkey_17: add AArch64 support patch --- pkgs/development/interpreters/spidermonkey/17.nix | 2 ++ .../spidermonkey/aarch64-double-conversion.patch | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch diff --git a/pkgs/development/interpreters/spidermonkey/17.nix b/pkgs/development/interpreters/spidermonkey/17.nix index a2ecfb2ef97a..1b6eb98b49da 100644 --- a/pkgs/development/interpreters/spidermonkey/17.nix +++ b/pkgs/development/interpreters/spidermonkey/17.nix @@ -20,6 +20,8 @@ stdenv.mkDerivation rec { postPatch = '' # Fixes an issue with version detection under perl 5.22.x sed -i 's/(defined\((@TEMPLATE_FILE)\))/\1/' config/milestone.pl + '' + stdenv.lib.optionalString stdenv.isAarch64 '' + patch -p1 -d ../.. < ${./aarch64-double-conversion.patch} ''; preConfigure = '' diff --git a/pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch b/pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch new file mode 100644 index 000000000000..bf41ce0a8a21 --- /dev/null +++ b/pkgs/development/interpreters/spidermonkey/aarch64-double-conversion.patch @@ -0,0 +1,13 @@ +diff -ru mozjs17.0.0-orig/mfbt/double-conversion/utils.h mozjs17.0.0/mfbt/double-conversion/utils.h +--- mozjs17.0.0-orig/mfbt/double-conversion/utils.h 2013-02-11 17:33:28.000000000 -0500 ++++ mozjs17.0.0/mfbt/double-conversion/utils.h 2016-12-03 20:39:07.915042988 -0500 +@@ -58,7 +58,8 @@ + defined(__mips__) || defined(__powerpc__) || \ + defined(__sparc__) || defined(__sparc) || defined(__s390__) || \ + defined(__SH4__) || defined(__alpha__) || \ +- defined(_MIPS_ARCH_MIPS32R2) ++ defined(_MIPS_ARCH_MIPS32R2) || \ ++ defined(__AARCH64EL__) + #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 + #elif defined(_M_IX86) || defined(__i386__) || defined(__i386) + #if defined(_WIN32) From fcc51d32564737558714a12ab6c205af7b68cffb Mon Sep 17 00:00:00 2001 From: Nathan Zadoks Date: Sun, 4 Dec 2016 12:52:45 -0500 Subject: [PATCH 13/19] linux: fix installTargets for AArch64 [dezgeg: note that we are currently using just 'Image' instead of 'Image.gz' as U-Boot doesn't support the latter yet. We might switch once it does since the kernel images are quite big] --- pkgs/os-specific/linux/kernel/manual-config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 5f890b9b9fe6..83020ad35a2b 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -120,7 +120,7 @@ let # Some image types need special install targets (e.g. uImage is installed with make uinstall) installTargets = [ (if platform.kernelTarget == "uImage" then "uinstall" else - if platform.kernelTarget == "zImage" then "zinstall" else + if platform.kernelTarget == "zImage" || platform.kernelTarget == "Image.gz" then "zinstall" else "install") ]; postInstall = '' From 8999ab9e56d02cf230137d5096f56c76cc23b6d2 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 23 Dec 2016 02:11:08 +0200 Subject: [PATCH 14/19] fuse: Add Aarch64 patch from upstream git to fix build See e.g. https://bugs.launchpad.net/linaro-oe/+bug/1087757 --- pkgs/os-specific/linux/fuse/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/fuse/default.nix b/pkgs/os-specific/linux/fuse/default.nix index 34b6aa1378cd..3024c488a13e 100644 --- a/pkgs/os-specific/linux/fuse/default.nix +++ b/pkgs/os-specific/linux/fuse/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitHub, utillinux +{ stdenv, fetchFromGitHub, fetchpatch, utillinux , autoconf, automake, libtool, gettext }: stdenv.mkDerivation rec { @@ -14,6 +14,11 @@ stdenv.mkDerivation rec { buildInputs = [ utillinux autoconf automake libtool gettext ]; + patches = stdenv.lib.optional stdenv.isAarch64 (fetchpatch { + url = "https://github.com/libfuse/libfuse/commit/914871b20a901e3e1e981c92bc42b1c93b7ab81b.patch"; + sha256 = "1w4j6f1awjrycycpvmlv0x5v9gprllh4dnbjxl4dyl2jgbkaw6pa"; + }); + preConfigure = '' export MOUNT_FUSE_PATH=$out/sbin From 3519244c724d9db090fd186ab9e4e375cd5c9989 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 23 Dec 2016 01:09:35 +0200 Subject: [PATCH 15/19] raspberrypifw: Enable build on Aarch64 So that the boot blobs can be copied. FIXME: This makes the dynamic linker of the ARM binaries point to a aarch64 linker. --- pkgs/os-specific/linux/firmware/raspberrypi/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/firmware/raspberrypi/default.nix b/pkgs/os-specific/linux/firmware/raspberrypi/default.nix index 1c1b11f1ef4b..03281d2ee3a4 100644 --- a/pkgs/os-specific/linux/firmware/raspberrypi/default.nix +++ b/pkgs/os-specific/linux/firmware/raspberrypi/default.nix @@ -31,7 +31,7 @@ stdenv.mkDerivation rec { description = "Firmware for the Raspberry Pi board"; homepage = https://github.com/raspberrypi; license = licenses.unfree; - platforms = [ "armv6l-linux" "armv7l-linux" ]; + platforms = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ]; maintainers = with maintainers; [ viric tavyc ]; }; } From 2bfd83ab6d6d8c346f043843741641b8119cee19 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Tue, 27 Dec 2016 01:51:23 +0200 Subject: [PATCH 16/19] platforms.nix: Add some aarch64-specific kernel config This makes Raspberry Pi 3 and some Cavium ThunderX server hardware work. --- .../linux/kernel/common-config.nix | 2 +- pkgs/top-level/platforms.nix | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 44e4ebe17485..40c49509fd05 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -45,7 +45,7 @@ with stdenv.lib; # Bump the maximum number of CPUs to support systems like EC2 x1.* # instances and Xeon Phi. - ${optionalString (stdenv.system == "x86_64-linux") '' + ${optionalString (stdenv.system == "x86_64-linux" || stdenv.system == "aarch64-linux") '' NR_CPUS 384 ''} diff --git a/pkgs/top-level/platforms.nix b/pkgs/top-level/platforms.nix index c740fbe6f8d1..41cd0fff52ba 100644 --- a/pkgs/top-level/platforms.nix +++ b/pkgs/top-level/platforms.nix @@ -451,7 +451,32 @@ rec { kernelArch = "arm64"; kernelDTB = true; kernelAutoModules = false; - kernelExtraConfig = ""; + kernelExtraConfig = '' + # Raspberry Pi 3 stuff. Not needed for kernels >= 4.10. + ARCH_BCM2835 y + BCM2835_MBOX y + BCM2835_WDT y + BRCMFMAC m + DMA_BCM2835 m + DRM_VC4 m + I2C_BCM2835 m + PWM_BCM2835 m + RASPBERRYPI_FIRMWARE y + RASPBERRYPI_POWER y + SERIAL_8250_BCM2835AUX y + SERIAL_8250_EXTENDED y + SERIAL_8250_SHARE_IRQ y + SND_BCM2835_SOC_I2S m + SPI_BCM2835AUX m + SPI_BCM2835 m + + # Cavium ThunderX stuff. + PCI_HOST_THUNDER_ECAM y + THUNDER_NIC_RGX y + THUNDER_NIC_BGX y + THUNDER_NIC_PF y + THUNDER_NIC_VF y + ''; uboot = null; kernelTarget = "Image"; gcc = { From b29ee6c8ff11613c545dcd332f2f3ff37b00a068 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 20 Jan 2017 14:54:05 +0200 Subject: [PATCH 17/19] U-Boot: Add 64-bit Raspberry Pi 3 build And rename the old ubootRaspberryPi3 to ubootRaspberryPi3_32bit. --- .../installer/cd-dvd/sd-image-armv7l-multiplatform.nix | 2 +- pkgs/misc/uboot/default.nix | 8 +++++++- pkgs/top-level/all-packages.nix | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix b/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix index 456ef7c9f541..ded8af0a6ce2 100644 --- a/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix +++ b/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix @@ -46,7 +46,7 @@ in cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/$f boot/ done cp ${pkgs.ubootRaspberryPi2}/u-boot.bin boot/u-boot-rpi2.bin - cp ${pkgs.ubootRaspberryPi3}/u-boot.bin boot/u-boot-rpi3.bin + cp ${pkgs.ubootRaspberryPi3_32bit}/u-boot.bin boot/u-boot-rpi3.bin cp ${configTxt} boot/config.txt ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot ''; diff --git a/pkgs/misc/uboot/default.nix b/pkgs/misc/uboot/default.nix index 597866a80ab4..6179f05d42b0 100644 --- a/pkgs/misc/uboot/default.nix +++ b/pkgs/misc/uboot/default.nix @@ -100,12 +100,18 @@ in rec { filesToInstall = ["u-boot.bin"]; }; - ubootRaspberryPi3 = buildUBoot rec { + ubootRaspberryPi3_32bit = buildUBoot rec { defconfig = "rpi_3_32b_defconfig"; targetPlatforms = ["armv7l-linux"]; filesToInstall = ["u-boot.bin"]; }; + ubootRaspberryPi3_64bit = buildUBoot rec { + defconfig = "rpi_3_defconfig"; + targetPlatforms = ["aarch64-linux"]; + filesToInstall = ["u-boot.bin"]; + }; + ubootWandboard = buildUBoot rec { defconfig = "wandboard_defconfig"; targetPlatforms = ["armv7l-linux"]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f9959801f3bc..24cc664a3c81 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11813,7 +11813,8 @@ with pkgs; ubootPcduino3Nano ubootRaspberryPi ubootRaspberryPi2 - ubootRaspberryPi3 + ubootRaspberryPi3_32bit + ubootRaspberryPi3_64bit ubootWandboard ; From 0e4c1bfb43a4558fe9c2c420a907d40e757fa585 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Tue, 24 Jan 2017 00:52:25 +0200 Subject: [PATCH 18/19] installer: Add SD image expression for Aarch64 This one works on the Raspberry Pi 3 so far. --- .../installer/cd-dvd/sd-image-aarch64.nix | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 nixos/modules/installer/cd-dvd/sd-image-aarch64.nix diff --git a/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix b/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix new file mode 100644 index 000000000000..517ddc75c87c --- /dev/null +++ b/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix @@ -0,0 +1,61 @@ +{ config, lib, pkgs, ... }: + +let + extlinux-conf-builder = + import ../../system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix { + inherit pkgs; + }; +in +{ + imports = [ + ../../profiles/minimal.nix + ../../profiles/installation-device.nix + ./sd-image.nix + ]; + + assertions = lib.singleton { + assertion = pkgs.stdenv.system == "aarch64-linux"; + message = "sd-image-aarch64.nix can be only built natively on Aarch64 / ARM64; " + + "it cannot be cross compiled"; + }; + + # Needed by RPi firmware + nixpkgs.config.allowUnfree = true; + + boot.loader.grub.enable = false; + boot.loader.generic-extlinux-compatible.enable = true; + + boot.kernelPackages = pkgs.linuxPackages_latest; + boot.kernelParams = ["console=ttyS0,115200n8" "console=tty0"]; + boot.consoleLogLevel = 7; + + # FIXME: this probably should be in installation-device.nix + users.extraUsers.root.initialHashedPassword = ""; + + sdImage = { + populateBootCommands = let + # Contains a couple of fixes for booting a Linux kernel, will hopefully appear upstream soon. + patchedUboot = pkgs.ubootRaspberryPi3_64bit.overrideAttrs (oldAttrs: { + src = pkgs.fetchFromGitHub { + owner = "dezgeg"; + repo = "u-boot"; + rev = "baab53ec244fe44def01948a0f10e67342d401e6"; + sha256 = "0r5j2pc42ws3w3im0a9c6bh01czz5kapqrqp0ik9ra823cw73lxr"; + }; + }); + + configTxt = pkgs.writeText "config.txt" '' + kernel=u-boot-rpi3.bin + arm_control=0x200 + enable_uart=1 + ''; + in '' + for f in bootcode.bin fixup.dat start.elf; do + cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/$f boot/ + done + cp ${patchedUboot}/u-boot.bin boot/u-boot-rpi3.bin + cp ${configTxt} boot/config.txt + ${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot + ''; + }; +} From 32643dc07db92ed989c496f23037138802927dea Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Wed, 25 Jan 2017 15:07:37 +0200 Subject: [PATCH 19/19] installer: sd-image-*.nix: Document how to build them --- nixos/modules/installer/cd-dvd/sd-image-aarch64.nix | 2 ++ .../modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix | 2 ++ nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix | 2 ++ 3 files changed, 6 insertions(+) diff --git a/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix b/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix index 517ddc75c87c..8cf349fbd078 100644 --- a/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix +++ b/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix @@ -1,3 +1,5 @@ +# To build, use: +# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-aarch64.nix -A config.system.build.sdImage { config, lib, pkgs, ... }: let diff --git a/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix b/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix index ded8af0a6ce2..76f5d4bf6472 100644 --- a/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix +++ b/nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix @@ -1,3 +1,5 @@ +# To build, use: +# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-armv7l-multiplatform.nix -A config.system.build.sdImage { config, lib, pkgs, ... }: let diff --git a/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix b/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix index e7163f10a3c3..c7915b578d8a 100644 --- a/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix +++ b/nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix @@ -1,3 +1,5 @@ +# To build, use: +# nix-build nixos -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-raspberrypi.nix -A config.system.build.sdImage { config, lib, pkgs, ... }: let