From 008992619f0ca5a61d6cd91394c818c5da345050 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 31 Dec 2013 22:38:06 -0500 Subject: [PATCH] linux/manual-config: Cross-compiling support With this, I was able to successfully compile a defconfig kernel for the sheevaplug, though I didn't actually try to run it (not having a sheevaplug myself). For native compiles, the most significant difference is that the platform's kernel target is built directly rather than hoping the default make target will pull it in. Also some stylistic improvements along the way. Signed-off-by: Shea Levy --- .../linux/kernel/manual-config.nix | 47 +++++++++++++------ pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index f097f2562d02..d96c8e5494cf 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -1,4 +1,4 @@ -{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile }: +{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile, ubootChooser }: let inherit (stdenv.lib) @@ -58,10 +58,10 @@ in }: let - installkernel = name: writeTextFile { name = "installkernel"; executable=true; text = '' - #!/bin/sh - mkdir $4 - cp -av $2 $4/${name} + installkernel = writeTextFile { name = "installkernel"; executable=true; text = '' + #!${stdenv.shell} -e + mkdir -p $4 + cp -av $2 $4 cp -av $3 $4 '';}; @@ -72,9 +72,10 @@ let commonMakeFlags = [ "O=$(buildRoot)" - "INSTALL_PATH=$(out)" - ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)") - ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware"; + ]; + + # Some image types need special install targets (e.g. uImage is installed with make uinstall) + installTarget = target: [ (if target == "uImage" then "uinstall" else "install") ]; sourceRoot = stdenv.mkDerivation { name = "linux-${version}-source"; @@ -126,16 +127,34 @@ stdenv.mkDerivation { runHook postConfigure ''; - nativeBuildInputs = [ perl bc nettools ]; + nativeBuildInputs = [ perl bc nettools ] ++ optional (stdenv.platform.uboot != null) + (ubootChooser stdenv.platform.uboot); makeFlags = commonMakeFlags ++ [ - "INSTALLKERNEL=${installkernel stdenv.platform.kernelTarget}" + "ARCH=${stdenv.platform.kernelArch}" ]; - crossAttrs = { + buildFlags = [ stdenv.platform.kernelTarget ] ++ optional isModular "modules"; + + installFlags = [ + "INSTALLKERNEL=${installkernel}" + "INSTALL_PATH=$(out)" + ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)") + ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware"; + + installTargets = installTarget stdenv.platform.kernelTarget; + + crossAttrs = let cp = stdenv.cross.platform; in { + buildFlags = [ cp.kernelTarget ] ++ optional isModular "modules"; + makeFlags = commonMakeFlags ++ [ - "INSTALLKERNEL=${installkernel stdenv.cross.platform.kernelTarget}" + "ARCH=${cp.kernelArch}" + "CROSS_COMPILE=$(crossConfig)-" ]; + + installTargets = installTarget cp.kernelTarget; + + buildInputs = optional (cp.uboot != null) (ubootChooser cp.uboot).crossDrv; }; postInstall = optionalString installsFirmware '' @@ -143,7 +162,7 @@ stdenv.mkDerivation { '' + (if isModular then '' make modules_install $makeFlags "''${makeFlagsArray[@]}" \ $installFlags "''${installFlagsArray[@]}" - rm -f $out/lib/modules/${modDirVersion}/build + unlink $out/lib/modules/${modDirVersion}/build mkdir -p $dev/lib/modules/${modDirVersion} mv $out/lib/modules/${modDirVersion}/source $dev/lib/modules/${modDirVersion}/source mv $buildRoot $dev/lib/modules/${modDirVersion}/build @@ -154,7 +173,7 @@ stdenv.mkDerivation { postFixup = if isModular then '' if [ -z "$dontStrip" ]; then - find $out -name "*.ko" -print0 | xargs -0 -r strip -S + find $out -name "*.ko" -print0 | xargs -0 -r ''${crossConfig+$crossConfig-}strip -S # Remove all references to the source directory to avoid unneeded # runtime dependencies find $out -name "*.ko" -print0 | xargs -0 -r sed -i \ diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 020d5b3c8e61..f5c93f37f73e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6952,7 +6952,7 @@ let # A function to build a manually-configured kernel linuxManualConfig = import ../os-specific/linux/kernel/manual-config.nix { - inherit (pkgs) stdenv runCommand nettools bc perl kmod writeTextFile; + inherit (pkgs) stdenv runCommand nettools bc perl kmod writeTextFile ubootChooser; }; keyutils = callPackage ../os-specific/linux/keyutils { };