summary refs log tree commit diff
path: root/pkgs/os-specific/linux
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific/linux')
-rw-r--r--pkgs/os-specific/linux/kernel/manual-config.nix47
1 files changed, 33 insertions, 14 deletions
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index f097f2562d0..d96c8e5494c 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 \