From 40e7be11c8098d11217786d106462e958e1d8718 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Nov 2020 20:55:55 +0000 Subject: [PATCH 1/3] lib.systems.platforms: Make selection more flexible We dont have to match on exact strings if we get accessed to `parsed`. Co-authored-by: Matthew Bauer --- lib/systems/default.nix | 2 +- lib/systems/platforms.nix | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 9939743157e7..f6832945a23d 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -25,7 +25,7 @@ rec { system = parse.doubleFromSystem final.parsed; config = parse.tripleFromSystem final.parsed; # Just a guess, based on `system` - platform = platforms.selectBySystem final.system; + platform = platforms.select final; # Determine whether we are compatible with the provided CPU isCompatible = platform: parse.isCompatible final.parsed.cpu platform.parsed.cpu; # Derived meta-data diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index 42d9809fd7d0..a01f167a02b6 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -469,17 +469,22 @@ rec { ''; }; - selectBySystem = system: { - i486-linux = pc32; - i586-linux = pc32; - i686-linux = pc32; - x86_64-linux = pc64; - armv5tel-linux = sheevaplug; - armv6l-linux = raspberrypi; - armv7a-linux = armv7l-hf-multiplatform; - armv7l-linux = armv7l-hf-multiplatform; - aarch64-linux = aarch64-multiplatform; - mipsel-linux = fuloong2f_n32; - powerpc64le-linux = powernv; - }.${system} or pcBase; + select = platform: + # x86 + /**/ if platform.isx86_32 then pc32 + else if platform.isx86_64 then pc64 + + # ARM + else if platform.isAarch32 then let + version = platform.parsed.cpu.version or ""; + in if lib.versionOlder version "6" then sheevaplug + else if lib.versionOlder version "7" then raspberrypi + else armv7l-hf-multiplatform + else if platform.isAarch64 then aarch64-multiplatform + + else if platform.parsed.cpu == lib.systems.parse.cpuTypes.mipsel then fuloong2f_n32 + + else if platform.parsed.cpu == lib.systems.parse.cpuTypes.powerpc64le then powernv + + else pcBase; } From 04f6973200954f9ecd0f2fbc1d6ae029cd7ed857 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Nov 2020 21:57:00 +0000 Subject: [PATCH 2/3] lib, binutils: Move Risc-V bfdEmulation to be by the others --- lib/systems/platforms.nix | 1 - pkgs/build-support/bintools-wrapper/default.nix | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index a01f167a02b6..b3a4f9fc13cb 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -459,7 +459,6 @@ rec { riscv-multiplatform = bits: { name = "riscv-multiplatform"; kernelArch = "riscv"; - bfdEmulation = "elf${bits}lriscv"; kernelTarget = "vmlinux"; kernelAutoModules = true; kernelBaseConfig = "defconfig"; diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 3b1b8ff570a8..6da0e58436d0 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -167,7 +167,7 @@ stdenv.mkDerivation { else if targetPlatform.isWindows then "pe" else "elf" + toString targetPlatform.parsed.cpu.bits; endianPrefix = if targetPlatform.isBigEndian then "big" else "little"; - sep = optionalString (!targetPlatform.isMips && !targetPlatform.isPower) "-"; + sep = optionalString (!targetPlatform.isMips && !targetPlatform.isPower && !targetPlatform.isRiscV) "-"; arch = /**/ if targetPlatform.isAarch64 then endianPrefix + "aarch64" else if targetPlatform.isAarch32 then endianPrefix + "arm" @@ -187,6 +187,7 @@ stdenv.mkDerivation { else if targetPlatform.isAlpha then "alpha" else if targetPlatform.isVc4 then "vc4" else if targetPlatform.isOr1k then "or1k" + else if targetPlatform.isRiscV then "lriscv" else throw "unknown emulation for platform: ${targetPlatform.config}"; in if targetPlatform.useLLVM or false then "" else targetPlatform.platform.bfdEmulation or (fmt + sep + arch); From 9918ba2dbaf2d6533baa53330a9ef9c32cfbf8a5 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Nov 2020 22:15:10 +0000 Subject: [PATCH 3/3] lib/systems/exmaple: `riscv-multiplatform` no longer needs parameter --- lib/systems/examples.nix | 6 +++--- lib/systems/platforms.nix | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 3bbe61ed33a5..12c63c9bd5ed 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -7,7 +7,7 @@ let riscv = bits: { config = "riscv${bits}-unknown-linux-gnu"; - platform = platforms.riscv-multiplatform bits; + platform = platforms.riscv-multiplatform; }; in @@ -105,13 +105,13 @@ rec { riscv64-embedded = { config = "riscv64-none-elf"; libc = "newlib"; - platform = platforms.riscv-multiplatform "64"; + platform = platforms.riscv-multiplatform; }; riscv32-embedded = { config = "riscv32-none-elf"; libc = "newlib"; - platform = platforms.riscv-multiplatform "32"; + platform = platforms.riscv-multiplatform; }; mmix = { diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index b3a4f9fc13cb..6b9e258d4f08 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -456,7 +456,7 @@ rec { ## Other ## - riscv-multiplatform = bits: { + riscv-multiplatform = { name = "riscv-multiplatform"; kernelArch = "riscv"; kernelTarget = "vmlinux";