commit 4f29bdd3ed9be1b16627522d8b247b9baf185566
parent f1c04c797978f9e404cd7a6c3d454f8028f1ba7f
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 20 Sep 2023 17:57:17 +0100
detect arch in kernel and uimage
also move kernel builder to pkgs/
FIXME we need to straighten out the mess in calling
dtb.nix/uimage.nix
Diffstat:
7 files changed, 71 insertions(+), 52 deletions(-)
diff --git a/kernel/uimage.nix b/kernel/uimage.nix
@@ -1,48 +0,0 @@
-{
- lzma
-, stdenv
-, ubootTools
-, dtc
-} :
-let
- objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
-in {
- kernel
-, commandLine
-, entryPoint
-, extraName ? "" # e.g. socFamily
-, loadAddress
-, dtb ? null
-} :
-stdenv.mkDerivation {
- name = "kernel.image";
- phases = [
- "preparePhase"
- (if dtb != null then "dtbPhase" else ":")
- "buildPhase"
- "installPhase" ];
- nativeBuildInputs = [
- lzma
- dtc
- stdenv.cc
- ubootTools
- ];
- preparePhase = ''
- cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
- '';
- dtbPhase = ''
- dtc -I dtb -O dts -o tmp.dts ${dtb}
- echo '/{ chosen { bootargs = ${builtins.toJSON commandLine}; }; };' >> tmp.dts
- dtc -I dts -O dtb -o tmp.dtb tmp.dts
- ${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=${dtb} vmlinux.elf
- '';
-
- buildPhase = ''
- ${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
- rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin
- mkimage -A mips -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n 'MIPS Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
- '';
- installPhase = ''
- cp kernel.uimage $out
- '';
-}
diff --git a/modules/kernel.nix b/modules/kernel.nix
@@ -24,7 +24,7 @@ in {
extraPatchPhase = mkOption {
default = "true";
type = types.lines;
- } ;
+ };
config = mkOption {
description = ''
Kernel config options, as listed in Kconfig* files in the
diff --git a/modules/outputs.nix b/modules/outputs.nix
@@ -62,14 +62,14 @@ in
kernel = liminix.builders.kernel.override {
inherit (config.kernel) config src extraPatchPhase;
};
- dtb = (callPackage ../kernel/dtb.nix {}) {
+ dtb = liminix.builders.dtb {
inherit (config.boot) commandLine;
dts = config.hardware.dts.src;
includes = config.hardware.dts.includes ++ [
"${kernel.headers}/include"
];
};
- uimage = (callPackage ../kernel/uimage.nix {}) {
+ uimage = liminix.builders.uimage {
commandLine = concatStringsSep " " config.boot.commandLine;
inherit (config.hardware) loadAddress entryPoint;
inherit kernel;
diff --git a/pkgs/default.nix b/pkgs/default.nix
@@ -16,6 +16,8 @@ in {
networking = callPackage ./liminix-tools/networking {};
builders = {
squashfs = callPackage ./liminix-tools/builders/squashfs.nix {};
+ dtb = callPackage ./kernel/dtb.nix {};
+ uimage = callPackage ./kernel/uimage.nix {};
kernel = callPackage ./kernel {};
};
callService = path : parameters :
diff --git a/pkgs/kernel/default.nix b/pkgs/kernel/default.nix
@@ -11,6 +11,12 @@
let
writeConfig = import ./write-kconfig.nix { inherit lib writeText; };
kconfigFile = writeConfig "kconfig" config;
+ arch = if stdenv.isMips
+ then "mips"
+ else if stdenv.isAarch64
+ then "arm64"
+ else throw "unknown arch";
+
inherit lib; in
stdenv.mkDerivation rec {
name = "kernel";
@@ -28,7 +34,7 @@ stdenv.mkDerivation rec {
"-I${openssl.dev}/include -L${openssl.out}/lib -L${ncurses.out}/lib";
PKG_CONFIG_PATH = "./pkgconfig";
CROSS_COMPILE = stdenv.cc.bintools.targetPrefix;
- ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel
+ ARCH = arch;
KBUILD_BUILD_HOST = "liminix.builder";
dontStrip = true;
diff --git a/kernel/dtb.nix b/pkgs/kernel/dtb.nix
diff --git a/pkgs/kernel/uimage.nix b/pkgs/kernel/uimage.nix
@@ -0,0 +1,59 @@
+{
+ lzma
+, stdenv
+, ubootTools
+, dtc
+, lib
+} :
+let
+ objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
+in {
+ kernel
+, commandLine
+, entryPoint
+, extraName ? "" # e.g. socFamily
+, loadAddress
+, dtb ? null
+} :
+stdenv.mkDerivation {
+ name = "kernel.image";
+ phases = [
+ "preparePhase"
+ (if dtb != null then "dtbPhase" else ":")
+ "buildPhase"
+ "installPhase" ];
+ nativeBuildInputs = [
+ lzma
+ dtc
+ stdenv.cc
+ ubootTools
+ ];
+ preparePhase = ''
+ cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
+ '';
+ dtbPhase = ''
+ dtc -I dtb -O dts -o tmp.dts ${dtb}
+ echo '/{ chosen { bootargs = ${builtins.toJSON commandLine}; }; };' >> tmp.dts
+ dtc -I dts -O dtb -o tmp.dtb tmp.dts
+ ${objcopy} --update-section .appended_dtb=tmp.dtb vmlinux.elf || ${objcopy} --add-section .appended_dtb=${dtb} vmlinux.elf
+ '';
+
+ buildPhase =
+ let arch =
+ # per output of "mkimage -A list". I *think* these
+ # are the same as the kernel arch convention, but
+ # maybe that's coincidence
+ if stdenv.isMips
+ then "mips"
+ else if stdenv.isAarch64
+ then "arm64"
+ else throw "unknown arch";
+ in ''
+ ${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
+ rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin
+ mkimage -A ${arch} -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n '${lib.toUpper arch} Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
+ '';
+ installPhase = ''
+ cp kernel.uimage $out
+ '';
+}