Permalink
Browse files

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 <shea@shealevy.com>
  • Loading branch information...
1 parent 1a75b6b commit 75dd9043f601a5c2f0c03f56f3a1530227103dc1 @shlevy committed Mar 24, 2013
Showing with 37 additions and 19 deletions.
  1. +36 −18 pkgs/os-specific/linux/kernel/manual-config.nix
  2. +1 −1 pkgs/top-level/all-packages.nix
@@ -1,8 +1,7 @@
-{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile }:
-
-with stdenv.lib;
+{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile, ubootChooser }:
let
+ inherit (stdenv.lib) optional optionalString optionalAttrs getAttr hasAttr;
# Function to parse the config file into a nix expression
readConfig = configFile:
@@ -58,10 +57,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 +71,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,24 +126,42 @@ 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 ''
mkdir -p $out/lib/firmware
'' + (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 +172,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 \
@@ -167,8 +185,8 @@ stdenv.mkDerivation {
license = "GPLv2";
homepage = http://www.kernel.org/;
maintainers = [
- maintainers.shlevy
+ stdenv.lib.maintainers.shlevy
];
- platforms = lib.platforms.linux;
+ platforms = stdenv.lib.platforms.linux;
};
}
@@ -6079,7 +6079,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 { };

0 comments on commit 75dd904

Please sign in to comment.