build kernel only once for multiple outputs

e.g. vmlinux + zImage
pull/2/head
Daniel Barlow 2024-01-02 19:40:57 +00:00
parent e4ed9dbec9
commit ff991508ae
4 changed files with 23 additions and 13 deletions

View File

@ -4,6 +4,7 @@
kernel.config = {
OF = "y";
};
kernel.makeTargets = ["arch/arm/boot/zImage"];
hardware.ram.startAddress = lim.parseInt "0x40000000";
system.outputs.u-boot = pkgs.ubootQemuArm;
};

View File

@ -9,6 +9,7 @@ let
inherit (pkgs.pseudofile) dir symlink;
inherit (pkgs.liminix.networking) address interface;
inherit (pkgs.liminix.services) bundle;
inherit (pkgs) liminix;
type_service = pkgs.liminix.lib.types.service;
@ -41,11 +42,25 @@ in {
};
'';
};
makeTargets = mkOption {
type = types.listOf types.str;
};
};
};
config = {
system.outputs =
let k = liminix.builders.kernel.override {
inherit (config.kernel) config src extraPatchPhase;
targets = config.kernel.makeTargets;
};
in {
kernel = k.vmlinux;
zimage = k.zImage;
};
kernel = rec {
modular = true; # disabling this is not yet supported
makeTargets = ["vmlinux"];
config = {
IKCONFIG = "y";
IKCONFIG_PROC = "y";

View File

@ -99,26 +99,18 @@ in
};
config = {
system.outputs = rec {
kernel = liminix.builders.kernel.override {
inherit (config.kernel) config src extraPatchPhase;
};
zimage = liminix.builders.kernel.override {
targets = ["arch/arm/boot/zImage"];
inherit (config.kernel) config src extraPatchPhase;
};
dtb = liminix.builders.dtb {
inherit (config.boot) commandLine;
dts = config.hardware.dts.src;
includes = config.hardware.dts.includes ++ [
"${kernel.headers}/include"
"${o.kernel.headers}/include"
];
};
uimage = liminix.builders.uimage {
commandLine = concatStringsSep " " config.boot.commandLine;
inherit (config.hardware) loadAddress entryPoint;
inherit (config.boot) imageFormat;
inherit kernel;
inherit dtb;
inherit (o) kernel dtb;
};
rootdir =
let

View File

@ -13,6 +13,7 @@ let
writeConfig = import ./write-kconfig.nix { inherit lib writeText; };
kconfigFile = writeConfig "kconfig" config;
arch = stdenv.hostPlatform.linuxArch;
targetNames = map baseNameOf targets;
inherit lib; in
stdenv.mkDerivation rec {
name = "kernel";
@ -35,7 +36,7 @@ stdenv.mkDerivation rec {
dontStrip = true;
dontPatchELF = true;
outputs = ["out" "headers" "modulesupport"];
outputs = ["out" "headers" "modulesupport"] ++ targetNames;
phases = [
"unpackPhase"
"butcherPkgconfig"
@ -92,12 +93,13 @@ stdenv.mkDerivation rec {
'';
buildPhase = ''
make ${lib.concatStringsSep " " (map baseNameOf targets)} modules_prepare -j$NIX_BUILD_CORES
make ${lib.concatStringsSep " " targetNames} modules_prepare -j$NIX_BUILD_CORES
'';
installPhase = ''
${CROSS_COMPILE}strip -d vmlinux
cp ${lib.concatStringsSep " " targets} $out
${lib.concatStringsSep "\n" (map (f: "cp ${f} \$${baseNameOf f}") targets)}
cp vmlinux $out
mkdir -p $headers
cp -a include .config $headers/
mkdir -p $modulesupport