Skip to content

Commit

Permalink
lib.systems.platforms: Make selection more flexible
Browse files Browse the repository at this point in the history
We dont have to match on exact strings if we get accessed to `parsed`.

Co-authored-by: Matthew Bauer <[email protected]>
  • Loading branch information
Ericson2314 and matthewbauer committed Nov 29, 2020
1 parent 947f27f commit 40e7be1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 18 additions & 13 deletions lib/systems/platforms.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

1 comment on commit 40e7be1

@andir
Copy link
Member

@andir andir commented on 40e7be1 Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke the build of arm-trusted firmare for rk3399. It seems like before we always used pcBase for arm-none but are now using some "proper" arm platform. I am not sure what the correct version here is and if this created a bug or just uncovered another one.

$ nix-build -A ubootRockPi4 --system aarch64-linux
trace: { _type = "cpu-type"; arch = "armv8-a"; bits = 64; family = "arm"; name = "aarch64"; significantByte = { _type = "significant-byte"; name = "littleEndian"; }; version = "8"; }
trace: { _type = "cpu-type"; arch = "armv8-a"; bits = 64; family = "arm"; name = "aarch64"; significantByte = { _type = "significant-byte"; name = "littleEndian"; }; version = "8"; }
trace: { _type = "cpu-type"; bits = 32; family = "arm"; name = "arm"; significantByte = { _type = "significant-byte"; name = "littleEndian"; }; }
trace: {"cpu":{"_type":"cpu-type","bits":32,"family":"arm","name":"arm","significantByte":{"_type":"significant-byte","name":"littleEndian"}},"system":"arm-none"}
these derivations will be built:
  /nix/store/v0yibdhkfzc8z2s3qq1vlblz952ficrk-arm-trusted-firmware-rk3399-2.3.drv
  /nix/store/y0216nmqzqcw5liiv4h1cd2kmkrr0mpb-uboot-rock-pi-4-rk3399_defconfig-2020.10.drv
building '/nix/store/v0yibdhkfzc8z2s3qq1vlblz952ficrk-arm-trusted-firmware-rk3399-2.3.drv' on 'ssh://[email protected]'...
unpacking sources
unpacking source archive /nix/store/05hqrfd2y6nxz61vbvgnw0zqrdsdilvy-source
source root is source
patching sources
updateAutotoolsGnuConfigScriptsPhase
configuring
no configure script, doing nothing
building
build flags: SHELL=/nix/store/p9nhdcj6swgiwkfnl9biziq6755p8v6f-bash-4.4-p23/bin/bash CROSS_COMPILE= PLAT=rk3399 bl31
  CC      bl31/bl31_context_mgmt.c
  CC      bl31/bl31_main.c
  CC      bl31/interrupt_mgmt.c
  CC      common/runtime_svc.c
  CC      drivers/arm/cci/cci.c
  CC      drivers/arm/gic/v3/arm_gicv3_common.c
  CC      drivers/arm/gic/v3/gic500.c
  CC      drivers/arm/gic/v3/gicdv3_helpers.c
  CC      drivers/arm/gic/v3/gicrv3_helpers.c
  CC      drivers/arm/gic/v3/gicv3_helpers.c
  CC      drivers/arm/gic/v3/gicv3_main.c
  CC      drivers/delay_timer/delay_timer.c
  CC      drivers/delay_timer/generic_delay_timer.c
  CC      drivers/gpio/gpio.c
  CC      lib/cpus/errata_report.c
  CC      lib/el3_runtime/aarch64/context_mgmt.c
  CC      lib/el3_runtime/cpu_data_array.c
  CC      lib/extensions/spe/spe.c
  CC      lib/locks/bakery/bakery_lock_coherent.c
  CC      lib/psci/psci_common.c
  CC      lib/psci/psci_main.c
  CC      lib/psci/psci_mem_protect.c
  CC      lib/psci/psci_off.c
  CC      lib/psci/psci_on.c
  CC      lib/psci/psci_setup.c
  CC      lib/psci/psci_suspend.c
  CC      lib/psci/psci_system_off.c
  CC      plat/common/plat_gicv3.c
  CC      plat/rockchip/common/aarch64/platform_common.c
  CC      plat/rockchip/common/bl31_plat_setup.c
  CC      plat/rockchip/common/params_setup.c
  CC      plat/rockchip/common/plat_pm.c
  CC      plat/rockchip/common/plat_topology.c
  CC      plat/rockchip/common/rockchip_gicv3.c
  CC      plat/rockchip/common/rockchip_sip_svc.c
  CC      plat/rockchip/rk3399/drivers/dram/dfs.c
  CC      plat/rockchip/rk3399/drivers/dram/dram.c
  CC      plat/rockchip/rk3399/drivers/dram/dram_spec_timing.c
  CC      plat/rockchip/rk3399/drivers/dram/suspend.c
  CC      plat/rockchip/rk3399/drivers/gpio/rk3399_gpio.c
  CC      plat/rockchip/rk3399/drivers/pmu/m0_ctl.c
  CC      plat/rockchip/rk3399/drivers/pmu/pmu.c
make -C plat/rockchip/rk3399/drivers/m0 BUILD=/build/source/build/rk3399/release/m0
make[1]: Entering directory '/build/source/plat/rockchip/rk3399/drivers/m0'
  CC      src/dram.c
arm-none-eabi-gcc -g -mcpu=cortex-m0 -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common -Iinclude/ -I../../include/shared/ -MMD -MT /build/source/build/rk3399/release/m0/dram.o -c src/dram.c -o /build/source/build/rk3399/release/m0/dram.o
cc1: warning: switch '-mcpu=cortex-m0' conflicts with '-march=armv5te' switch
/build/cc31avEv.s: Assembler messages:
/build/cc31avEv.s:342: Error: selected processor does not support `wfi' in Thumb mode
make[1]: *** [Makefile:125: /build/source/build/rk3399/release/m0/dram.o] Error 1
make[1]: Leaving directory '/build/source/plat/rockchip/rk3399/drivers/m0'
make: *** [plat/rockchip/rk3399/platform.mk:106: build/rk3399/release/m0/rk3399m0.bin] Error 2
error: build of '/nix/store/v0yibdhkfzc8z2s3qq1vlblz952ficrk-arm-trusted-firmware-rk3399-2.3.drv' on 'ssh://[email protected]' failed: error: --- Error --- nix-daemon
builder for '/nix/store/v0yibdhkfzc8z2s3qq1vlblz952ficrk-arm-trusted-firmware-rk3399-2.3.drv' failed with exit code 2; last 10 log lines:
  make -C plat/rockchip/rk3399/drivers/m0 BUILD=/build/source/build/rk3399/release/m0
  make[1]: Entering directory '/build/source/plat/rockchip/rk3399/drivers/m0'
    CC      src/dram.c
  arm-none-eabi-gcc -g -mcpu=cortex-m0 -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common -Iinclude/ -I../../include/shared/ -MMD -MT /build/source/build/rk3399/release/m0/dram.o -c src/dram.c -o /build/source/build/rk3399/release/m0/dram.o 
  cc1: warning: switch '-mcpu=cortex-m0' conflicts with '-march=armv5te' switch
  /build/cc31avEv.s: Assembler messages:
  /build/cc31avEv.s:342: Error: selected processor does not support `wfi' in Thumb mode
  make[1]: *** [Makefile:125: /build/source/build/rk3399/release/m0/dram.o] Error 1
  make[1]: Leaving directory '/build/source/plat/rockchip/rk3399/drivers/m0'
  make: *** [plat/rockchip/rk3399/platform.mk:106: build/rk3399/release/m0/rk3399m0.bin] Error 2
builder for '/nix/store/v0yibdhkfzc8z2s3qq1vlblz952ficrk-arm-trusted-firmware-rk3399-2.3.drv' failed with exit code 1
cannot build derivation '/nix/store/y0216nmqzqcw5liiv4h1cd2kmkrr0mpb-uboot-rock-pi-4-rk3399_defconfig-2020.10.drv': 1 dependencies couldn't be built
error: build of '/nix/store/y0216nmqzqcw5liiv4h1cd2kmkrr0mpb-uboot-rock-pi-4-rk3399_defconfig-2020.10.drv' failed

The above was produced with this diff applied:

diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix
index a01f167a02b..2fb5b1e428d 100644
--- a/lib/systems/platforms.nix
+++ b/lib/systems/platforms.nix
@@ -469,7 +469,7 @@ rec {
     '';
   };
 
-  select = platform:
+  select = platform: (builtins.trace platform.parsed.cpu (
     # x86
     /**/ if platform.isx86_32 then pc32
     else if platform.isx86_64 then pc64
@@ -477,14 +477,14 @@ rec {
     # ARM
     else if platform.isAarch32 then let
       version = platform.parsed.cpu.version or "";
-      in     if lib.versionOlder version "6" then sheevaplug
+      in     lib.trace (builtins.toJSON { inherit(platform.parsed) cpu; inherit (platform) system; }) (if lib.versionOlder version "6" then sheevaplug
         else if lib.versionOlder version "7" then raspberrypi
-        else armv7l-hf-multiplatform
+        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;
+    else pcBase));
 }

Please sign in to comment.