From 62fe1409c695b0247453971835ddf8a3225c5996 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Wed, 30 Sep 2020 18:52:58 -0400 Subject: [PATCH 01/32] kernel-builder: Rework its ergonomics --- overlay/mobile-nixos/kernel/builder.nix | 141 +++++++++++++++----- overlay/mobile-nixos/kernel/compiler-gcc6.h | 69 ++++++++++ 2 files changed, 173 insertions(+), 37 deletions(-) create mode 100644 overlay/mobile-nixos/kernel/compiler-gcc6.h diff --git a/overlay/mobile-nixos/kernel/builder.nix b/overlay/mobile-nixos/kernel/builder.nix index a6d4ccb43..ddc8d8a3e 100644 --- a/overlay/mobile-nixos/kernel/builder.nix +++ b/overlay/mobile-nixos/kernel/builder.nix @@ -12,6 +12,8 @@ # It is also an experiments ground for a more ergonomic interface. # +# This is the callPackage signature. +# These are dependencies for dependency injection. { stdenv , path , buildPackages @@ -27,6 +29,7 @@ , gmp , libmpc , mpfr +, dtc , libelf , utillinux @@ -41,42 +44,59 @@ }: let - # FIXME : implement some basic rules for most version strings. + # For now this is a no-op. modDirify = v: v; + + # Shortcuts + inherit (stdenv.lib) optionals optional optionalString; + inherit (stdenv.hostPlatform) platform; + + maybeString = str: optionalString (str != null) str; in +# This is the builder function signature. + +# We have to be provided with a source { src +# And a version , version , modDirVersion ? modDirify version +# Additionally, a config file is required. , configfile -, hasDTB ? false -, kernelPatches ? [] +# Togglable common quirks +, enableCenteredLinuxLogo ? true +, enableLinuxLogoReplacement ? true +, linuxLogo224PPMFile ? ./logo_linux_clut224.ppm +, enableRemovingWerror ? false +, enableCompilerGcc6Quirk ? false + +# Usual stdenv arguments we are also setting. +# Use the ones given by the user for composition. +, nativeBuildInputs ? [] , patches ? [] -, postPatch ? "" , makeFlags ? [] -, nativeBuildInputs ? [] +, prePatch ? null +, postPatch ? null +, postInstall ? null # Part of the "API" of the kernel builder. # Image builders expect this attribute to know where to find the kernel file. +# XXX : review if we can detect this instead in a safe manner , file ? stdenv.hostPlatform.platform.kernelTarget -# FIXME : useful? -, isModular ? true +# Part of the usual NixOS kernel builder API , installsFirmware ? true +, isModular ? true +, kernelPatches ? [] -}: +, ... +} @ inputArgs: let - commonMakeFlags = [ - "O=$(buildRoot)" - ] - ++ stdenv.lib.optionals (stdenv.hostPlatform.platform ? kernelMakeFlags) stdenv.hostPlatform.platform.kernelMakeFlags - ; - # Path within to refer to the kernel build system's file. - nixosPath = "${path}/pkgs/os-specific/linux/kernel/"; + nixosKernelPath = "${path}/pkgs/os-specific/linux/kernel/"; # Same installer as in , though they don't expose it :/. installkernel = writeTextFile { @@ -92,17 +112,19 @@ let # Inspired from #91991 # https://github.com/NixOS/nixpkgs/pull/91991 + # (required for menuconfig) pkgconfig-helper = writeShellScriptBin "pkg-config" '' exec ${buildPackages.pkgconfig}/bin/${buildPackages.pkgconfig.targetPrefix}pkg-config "$@" ''; - # Shortcuts - inherit (stdenv.lib) optionals optional optionalString; - inherit (stdenv.hostPlatform) platform; + hasDTB = stdenv.hostPlatform.platform.kernelDTB; in -# We'll append to this derivation inside passthru. -let kernel = stdenv.mkDerivation { +# This `let` block allows us to have a self-reference to this derivation. +# We'll re-use this derivation inside passthru for normalizedConfig and menuconfig. +let kernelDerivation = + +stdenv.mkDerivation (inputArgs // { pname = "linux"; inherit src version file; @@ -116,13 +138,16 @@ let kernel = stdenv.mkDerivation { ++ optional (stdenv.lib.versionAtLeast version "4.14") libelf ++ optional (stdenv.lib.versionAtLeast version "4.15") utillinux ++ optionals (stdenv.lib.versionAtLeast version "4.16") [ bison flex ] + # Mobile NixOS inputs. + # While some kernels might not need those, most will. + ++ [ dtc ] ++ nativeBuildInputs ; patches = map (p: p.patch) kernelPatches # Required for deterministic builds along with some postPatch magic. - ++ optional (stdenv.lib.versionAtLeast version "4.13") "${nixosPath}/randstruct-provide-seed.patch" + ++ optional (stdenv.lib.versionAtLeast version "4.13") "${nixosKernelPath}/randstruct-provide-seed.patch" ++ patches ; @@ -135,9 +160,12 @@ let kernel = stdenv.mkDerivation { if [ -e scripts/ld-version.sh ]; then sed -i scripts/ld-version.sh -e "s|/usr/bin/awk|${buildPackages.gawk}/bin/awk|" fi - ''; + '' + + maybeString prePatch + ; postPatch = '' + echo ":: Patching for reproducibility" # Set randstruct seed to a deterministic but diversified value. Note: # we could have instead patched gen-random-seed.sh to take input from # the buildFlags, but that would require also patching the kernel's @@ -149,27 +177,55 @@ let kernel = stdenv.mkDerivation { $(echo ${src} ${configfile} | sha256sum | cut -d ' ' -f 1 | tr -d '\n') fi - # FIXME : make optional... + echo ":: Removing default OEM-provided certificates" + rm -vf *.x509 + + echo ":: Patching tools/ shebangs" + patchShebangs tools + + '' + optionalString enableLinuxLogoReplacement '' + echo ":: Replacing the logo" + cp ${linuxLogo224PPMFile} drivers/video/logo/logo_linux_clut224.ppm + + '' + optionalString enableCenteredLinuxLogo '' # Makes the "logo" option show only one logo and not dependent on cores. # This should be "safer" than a patch on a greater range of kernel versions. # Also defaults to centering when possible. + echo ":: Patching for centered linux logo" if [ -e drivers/video/fbdev/core/fbmem.c ]; then + # Force showing only one logo sed -i -e 's/num_online_cpus()/1/g' \ drivers/video/fbdev/core/fbmem.c + + # Force centering logo sed -i -e '/^bool fb_center_logo/ s/;/ = true;/' \ drivers/video/fbdev/core/fbmem.c fi + if [ -e drivers/video/fbmem.c ]; then + # Force showing only one logo sed -i -e 's/num_online_cpus()/1/g' \ drivers/video/fbmem.c fi - # Overrides the kernel logo - cp ${./logo_linux_clut224.ppm} drivers/video/logo/logo_linux_clut224.ppm + '' + optionalString enableRemovingWerror '' + echo ":: Removing all -Werror from makefiles" + ( + for i in $(find . -type f -name Makefile) $(find . -type f -name Kbuild); do + sed -i 's/-Werror-/-W/g' "$i" + sed -i 's/-Werror=/-W/g' "$i" + sed -i 's/-Werror//g' "$i" + done + ) - ${postPatch} - ''; + '' + optionalString enableCompilerGcc6Quirk '' + echo ":: Adding GCC6 compiler compatibility shim" + cp -v "${./compiler-gcc6.h}" "./include/linux/compiler-gcc6.h" + + '' + + maybeString postPatch + ; configurePhase = '' runHook preConfigure @@ -229,7 +285,8 @@ let kernel = stdenv.mkDerivation { exit 1 fi - # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged. + # We have to keep this around, even when Linux supports this in mainline, as kernel forks might + # be older than the mainline fix. buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)") cd $buildRoot @@ -258,25 +315,34 @@ let kernel = stdenv.mkDerivation { mkdir -p $out/dtbs/ make $makeFlags "''${makeFlagsArray[@]}" dtbs dtbs_install INSTALL_DTBS_PATH=$out/dtbs '' + + maybeString postInstall ; hardeningDisable = [ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ]; - # Absolute paths for compilers avoid any PATH-clobbering issues. - makeFlags = commonMakeFlags ++ [ + makeFlags = [ + "O=$(buildRoot)" "CC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" "HOSTCC=${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc" "ARCH=${stdenv.hostPlatform.platform.kernelArch}" - ] ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ - "CROSS_COMPILE=${stdenv.cc.targetPrefix}" - ] ++ makeFlags; + "DTC_EXT=${buildPackages.dtc}/bin/dtc" + ] + # Use platform-specific flags + ++ stdenv.lib.optionals (stdenv.hostPlatform.platform ? kernelMakeFlags) stdenv.hostPlatform.platform.kernelMakeFlags + # Mark as cross-compilation + ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ "CROSS_COMPILE=${stdenv.cc.targetPrefix}" ] + # User-provided makeFlags + ++ makeFlags + ; + requiredSystemFeatures = [ "big-parallel" ]; enableParallelBuilding = true; dontStrip = true; + # {{{ passthru = { - normalizedConfig = kernel.overrideAttrs({ ... }: { + normalizedConfig = kernelDerivation.overrideAttrs({ ... }: { forceNormalizedConfig = false; buildPhase = "echo Skipping build phase..."; installPhase = '' @@ -284,7 +350,7 @@ let kernel = stdenv.mkDerivation { ''; }); # Patching over this configuration to expose menuconfig. - menuconfig = kernel.overrideAttrs({nativeBuildInputs ? [] , ...}: { + menuconfig = kernelDerivation.overrideAttrs({nativeBuildInputs ? [] , ...}: { nativeBuildInputs = nativeBuildInputs ++ [ ncurses pkgconfig-helper @@ -374,5 +440,6 @@ let kernel = stdenv.mkDerivation { ''; }); }; -}; -in kernel + # }}} +}); +in kernelDerivation diff --git a/overlay/mobile-nixos/kernel/compiler-gcc6.h b/overlay/mobile-nixos/kernel/compiler-gcc6.h new file mode 100644 index 000000000..844706318 --- /dev/null +++ b/overlay/mobile-nixos/kernel/compiler-gcc6.h @@ -0,0 +1,69 @@ +// SOURCE: +// https://github.com/NextThingCo/CHIP-u-boot/issues/10#issuecomment-287515505 + +#ifndef __LINUX_COMPILER_H +#error "Please don't include directly, include instead." +#endif + +#define __used __attribute__((__used__)) +#define __must_check __attribute__((warn_unused_result)) +#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) + +/* Mark functions as cold. gcc will assume any path leading to a call + to them will be unlikely. This means a lot of manual unlikely()s + are unnecessary now for any paths leading to the usual suspects + like BUG(), printk(), panic() etc. [but let's keep them for now for + older compilers] + + Early snapshots of gcc 4.3 don't support this and we can't detect this + in the preprocessor, but we can live with this because they're unreleased. + Maketime probing would be overkill here. + + gcc also has a __attribute__((__hot__)) to move hot functions into + a special section, but I don't see any sense in this right now in + the kernel context */ +#define __cold __attribute__((__cold__)) + +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) + +#ifndef __CHECKER__ +# define __compiletime_warning(message) __attribute__((warning(message))) +# define __compiletime_error(message) __attribute__((error(message))) +#endif /* __CHECKER__ */ + +/* + * Mark a position in code as unreachable. This can be used to + * suppress control flow warnings after asm blocks that transfer + * control elsewhere. + * + * Early snapshots of gcc 4.5 don't support this and we can't detect + * this in the preprocessor, but we can live with this because they're + * unreleased. Really, we need to have autoconf for the kernel. + */ +#define unreachable() __builtin_unreachable() + +/* Mark a function definition as prohibited from being cloned. */ +#define __noclone __attribute__((__noclone__)) + +/* + * Tell the optimizer that something else uses this function or variable. + */ +#define __visible __attribute__((externally_visible)) + +/* + * GCC 'asm goto' miscompiles certain code sequences: + * + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 + * + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. + * + * (asm goto is automatically volatile - the naming reflects this.) + */ +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) + +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#define __HAVE_BUILTIN_BSWAP16__ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ + From 1889893a4328725c90c9a66120fa4af6645c6644 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 18:56:08 -0400 Subject: [PATCH 02/32] kernel-builder: implement QCDT configuration in the builder --- modules/system-types/android/default.nix | 4 ++++ overlay/mobile-nixos/kernel/builder.nix | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/system-types/android/default.nix b/modules/system-types/android/default.nix index fb8809aba..be350c30b 100644 --- a/modules/system-types/android/default.nix +++ b/modules/system-types/android/default.nix @@ -130,6 +130,10 @@ in }; }) + (lib.mkIf kernelPackage.isQcdt { + mobile.system.android.bootimg.dt = "${kernelPackage}/dt.img"; + }) + { mobile.boot.stage-1.bootConfig = { device = { diff --git a/overlay/mobile-nixos/kernel/builder.nix b/overlay/mobile-nixos/kernel/builder.nix index ddc8d8a3e..71885159e 100644 --- a/overlay/mobile-nixos/kernel/builder.nix +++ b/overlay/mobile-nixos/kernel/builder.nix @@ -30,6 +30,7 @@ , libmpc , mpfr , dtc +, dtbTool , libelf , utillinux @@ -65,6 +66,10 @@ in # Additionally, a config file is required. , configfile +# Handling of QCDT dt.img +, isQcdt ? false +, qcdt_dtbs ? "arch/${platform.kernelArch}/boot/" + # Togglable common quirks , enableCenteredLinuxLogo ? true , enableLinuxLogoReplacement ? true @@ -127,6 +132,7 @@ let kernelDerivation = stdenv.mkDerivation (inputArgs // { pname = "linux"; inherit src version file; + inherit qcdt_dtbs; # Allows disabling the kernel config normalization. # Set to false when normalizing the kernel config. @@ -141,6 +147,7 @@ stdenv.mkDerivation (inputArgs // { # Mobile NixOS inputs. # While some kernels might not need those, most will. ++ [ dtc ] + ++ optional isQcdt dtbTool ++ nativeBuildInputs ; @@ -309,11 +316,24 @@ stdenv.mkDerivation (inputArgs // { ; postInstall = '' + echo ":: Copying configuration file" # Helpful in cases where the kernel isn't built with /proc/config.gz cp -v "$buildRoot/.config" "$out/build.config" + '' + optionalString hasDTB '' + echo ":: Installing DTBs" mkdir -p $out/dtbs/ make $makeFlags "''${makeFlagsArray[@]}" dtbs dtbs_install INSTALL_DTBS_PATH=$out/dtbs + + '' + optionalString isQcdt '' + echo ":: Making and installing QCDT dt.img" + (PS4=" $ "; set -x + mkdir -p $out/ + dtbTool -s 2048 -p "scripts/dtc/" \ + -o "$out/dt.img" \ + "$qcdt_dtbs" + ) + '' + maybeString postInstall ; @@ -342,6 +362,10 @@ stdenv.mkDerivation (inputArgs // { # {{{ passthru = { + # This is an "API" for the kernel derivation. + inherit isQcdt; + + # Derivation with the as-built normalized kernel config normalizedConfig = kernelDerivation.overrideAttrs({ ... }: { forceNormalizedConfig = false; buildPhase = "echo Skipping build phase..."; From 9bac03b2f3a21aa7f6a9cd279563b630b75c9c92 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 23:19:47 -0400 Subject: [PATCH 03/32] kernel-builder: Encapsulate compressed images and dtb appended images --- overlay/mobile-nixos/kernel/builder.nix | 46 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/overlay/mobile-nixos/kernel/builder.nix b/overlay/mobile-nixos/kernel/builder.nix index 71885159e..d4c96c2d8 100644 --- a/overlay/mobile-nixos/kernel/builder.nix +++ b/overlay/mobile-nixos/kernel/builder.nix @@ -70,6 +70,11 @@ in , isQcdt ? false , qcdt_dtbs ? "arch/${platform.kernelArch}/boot/" +# Enable support for android-specific "Image.gz-dtb" appended images +, isImageGzDtb ? false +# Mark the kernel as compressed, assumes .gz +, isCompressed ? "gz" + # Togglable common quirks , enableCenteredLinuxLogo ? true , enableLinuxLogoReplacement ? true @@ -85,11 +90,7 @@ in , prePatch ? null , postPatch ? null , postInstall ? null - -# Part of the "API" of the kernel builder. -# Image builders expect this attribute to know where to find the kernel file. -# XXX : review if we can detect this instead in a safe manner -, file ? stdenv.hostPlatform.platform.kernelTarget +, installTargets ? [] # Part of the usual NixOS kernel builder API , installsFirmware ? true @@ -122,7 +123,11 @@ let exec ${buildPackages.pkgconfig}/bin/${buildPackages.pkgconfig.targetPrefix}pkg-config "$@" ''; - hasDTB = stdenv.hostPlatform.platform.kernelDTB; + hasDTB = platform.kernelDTB; + kernelFileExtension = if isCompressed != false then ".${isCompressed}" else ""; + kernelTarget = if platform.kernelTarget == "Image" + then "${platform.kernelTarget}${kernelFileExtension}" + else platform.kernelTarget; in # This `let` block allows us to have a self-reference to this derivation. @@ -131,7 +136,7 @@ let kernelDerivation = stdenv.mkDerivation (inputArgs // { pname = "linux"; - inherit src version file; + inherit src version; inherit qcdt_dtbs; # Allows disabling the kernel config normalization. @@ -140,7 +145,7 @@ stdenv.mkDerivation (inputArgs // { depsBuildBuild = [ buildPackages.stdenv.cc ]; nativeBuildInputs = [ perl bc nettools openssl rsync gmp libmpc mpfr ] - ++ optional (stdenv.hostPlatform.platform.kernelTarget == "uImage") buildPackages.ubootTools + ++ optional (platform.kernelTarget == "uImage") buildPackages.ubootTools ++ optional (stdenv.lib.versionAtLeast version "4.14") libelf ++ optional (stdenv.lib.versionAtLeast version "4.15") utillinux ++ optionals (stdenv.lib.versionAtLeast version "4.16") [ bison flex ] @@ -301,9 +306,10 @@ stdenv.mkDerivation (inputArgs // { buildFlags = [ "KBUILD_BUILD_VERSION=1-mobile-nixos" - platform.kernelTarget + kernelTarget "vmlinux" # for "perf" and things like that ] + ++ optional isImageGzDtb "${kernelTarget}-dtb" ++ optional isModular "modules" ; @@ -315,6 +321,13 @@ stdenv.mkDerivation (inputArgs // { ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware" ; + installTargets = [ + "install" + ] + ++ optional (isCompressed != false) "zinstall" + ++ installTargets + ; + postInstall = '' echo ":: Copying configuration file" # Helpful in cases where the kernel isn't built with /proc/config.gz @@ -334,6 +347,10 @@ stdenv.mkDerivation (inputArgs // { "$qcdt_dtbs" ) + '' + optionalString isImageGzDtb '' + echo ":: Copying platform-specific -dtb image file" + cp -v "$buildRoot/arch/${platform.kernelArch}/boot/${kernelTarget}-dtb" "$out/" + '' + maybeString postInstall ; @@ -344,11 +361,11 @@ stdenv.mkDerivation (inputArgs // { "O=$(buildRoot)" "CC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" "HOSTCC=${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc" - "ARCH=${stdenv.hostPlatform.platform.kernelArch}" + "ARCH=${platform.kernelArch}" "DTC_EXT=${buildPackages.dtc}/bin/dtc" ] # Use platform-specific flags - ++ stdenv.lib.optionals (stdenv.hostPlatform.platform ? kernelMakeFlags) stdenv.hostPlatform.platform.kernelMakeFlags + ++ stdenv.lib.optionals (platform ? kernelMakeFlags) platform.kernelMakeFlags # Mark as cross-compilation ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ "CROSS_COMPILE=${stdenv.cc.targetPrefix}" ] # User-provided makeFlags @@ -365,6 +382,9 @@ stdenv.mkDerivation (inputArgs // { # This is an "API" for the kernel derivation. inherit isQcdt; + # Internal API representing the filename of the desired output. + file = kernelTarget + optionalString isImageGzDtb "-dtb"; + # Derivation with the as-built normalized kernel config normalizedConfig = kernelDerivation.overrideAttrs({ ... }: { forceNormalizedConfig = false; @@ -450,8 +470,8 @@ stdenv.mkDerivation (inputArgs // { export PATH="$PATH:${buildPackages.gnumake}/bin" export KCONFIG_CONFIG="\$(readlink -f "\$1")"; shift - export SRCARCH="${stdenv.hostPlatform.platform.kernelArch}" - export ARCH="${stdenv.hostPlatform.platform.kernelArch}" + export SRCARCH="${platform.kernelArch}" + export ARCH="${platform.kernelArch}" export KERNELVERSION="${version}" cd "\$KERNEL_TREE" ${/* We're expanding the builder's makeFlags variable here. This is not a mistake. */""} From e8cd8a95cce5be48322a8a53b8f722e10a804138 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 18:18:57 -0400 Subject: [PATCH 04/32] kernel-builder: minor fixups --- overlay/mobile-nixos/kernel/builder.nix | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/overlay/mobile-nixos/kernel/builder.nix b/overlay/mobile-nixos/kernel/builder.nix index d4c96c2d8..c568f9889 100644 --- a/overlay/mobile-nixos/kernel/builder.nix +++ b/overlay/mobile-nixos/kernel/builder.nix @@ -56,9 +56,9 @@ let in # This is the builder function signature. - +{ # We have to be provided with a source -{ src + src # And a version , version , modDirVersion ? modDirify version @@ -72,14 +72,21 @@ in # Enable support for android-specific "Image.gz-dtb" appended images , isImageGzDtb ? false + # Mark the kernel as compressed, assumes .gz , isCompressed ? "gz" -# Togglable common quirks +# Linux logo centering (as a boot logo) , enableCenteredLinuxLogo ? true + +# Linux logo replacement , enableLinuxLogoReplacement ? true , linuxLogo224PPMFile ? ./logo_linux_clut224.ppm + +# Mainly to mask issues with newer compilers , enableRemovingWerror ? false + +# Older kernels don't know about gcc6+, and this is needed , enableCompilerGcc6Quirk ? false # Usual stdenv arguments we are also setting. @@ -340,12 +347,10 @@ stdenv.mkDerivation (inputArgs // { '' + optionalString isQcdt '' echo ":: Making and installing QCDT dt.img" - (PS4=" $ "; set -x mkdir -p $out/ dtbTool -s 2048 -p "scripts/dtc/" \ -o "$out/dt.img" \ "$qcdt_dtbs" - ) '' + optionalString isImageGzDtb '' echo ":: Copying platform-specific -dtb image file" @@ -377,12 +382,12 @@ stdenv.mkDerivation (inputArgs // { enableParallelBuilding = true; dontStrip = true; - # {{{ passthru = { - # This is an "API" for the kernel derivation. + # Used by consumers of the kernel derivation to configure the build + # appropriately for QCDT use. inherit isQcdt; - # Internal API representing the filename of the desired output. + # Used by consumers to refer to the kernel build product. file = kernelTarget + optionalString isImageGzDtb "-dtb"; # Derivation with the as-built normalized kernel config @@ -393,6 +398,7 @@ stdenv.mkDerivation (inputArgs // { cp .config $out ''; }); + # Patching over this configuration to expose menuconfig. menuconfig = kernelDerivation.overrideAttrs({nativeBuildInputs ? [] , ...}: { nativeBuildInputs = nativeBuildInputs ++ [ @@ -484,6 +490,5 @@ stdenv.mkDerivation (inputArgs // { ''; }); }; - # }}} }); in kernelDerivation From 47f6fc05b0ba403998cf7abcd80ef1130bb17c5e Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:13:50 -0400 Subject: [PATCH 05/32] asus-dumo: Update usage of kernel builder --- devices/asus-dumo/kernel/default.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/devices/asus-dumo/kernel/default.nix b/devices/asus-dumo/kernel/default.nix index ca507b711..ec0b48a60 100644 --- a/devices/asus-dumo/kernel/default.nix +++ b/devices/asus-dumo/kernel/default.nix @@ -5,12 +5,10 @@ , kernelPatches ? [] # FIXME }: -(mobile-nixos.kernel-builder { +mobile-nixos.kernel-builder { version = "5.8.0"; configfile = ./config.aarch64; - hasDTB = true; - src = fetchFromGitHub { owner = "torvalds"; repo = "linux"; @@ -26,4 +24,4 @@ ]; isModular = false; -}) +} From 8f59c5b4417fb36f71127861f18e7a33ecf2eaaf Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:16:14 -0400 Subject: [PATCH 06/32] asus-flo: Update usage of kernel builder --- devices/asus-flo/kernel/compiler-gcc6.h | 69 ------------------------- devices/asus-flo/kernel/default.nix | 32 ++---------- 2 files changed, 3 insertions(+), 98 deletions(-) delete mode 100644 devices/asus-flo/kernel/compiler-gcc6.h diff --git a/devices/asus-flo/kernel/compiler-gcc6.h b/devices/asus-flo/kernel/compiler-gcc6.h deleted file mode 100644 index 844706318..000000000 --- a/devices/asus-flo/kernel/compiler-gcc6.h +++ /dev/null @@ -1,69 +0,0 @@ -// SOURCE: -// https://github.com/NextThingCo/CHIP-u-boot/issues/10#issuecomment-287515505 - -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -#define __used __attribute__((__used__)) -#define __must_check __attribute__((warn_unused_result)) -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) - -/* Mark functions as cold. gcc will assume any path leading to a call - to them will be unlikely. This means a lot of manual unlikely()s - are unnecessary now for any paths leading to the usual suspects - like BUG(), printk(), panic() etc. [but let's keep them for now for - older compilers] - - Early snapshots of gcc 4.3 don't support this and we can't detect this - in the preprocessor, but we can live with this because they're unreleased. - Maketime probing would be overkill here. - - gcc also has a __attribute__((__hot__)) to move hot functions into - a special section, but I don't see any sense in this right now in - the kernel context */ -#define __cold __attribute__((__cold__)) - -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) - -#ifndef __CHECKER__ -# define __compiletime_warning(message) __attribute__((warning(message))) -# define __compiletime_error(message) __attribute__((error(message))) -#endif /* __CHECKER__ */ - -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - * - * Early snapshots of gcc 4.5 don't support this and we can't detect - * this in the preprocessor, but we can live with this because they're - * unreleased. Really, we need to have autoconf for the kernel. - */ -#define unreachable() __builtin_unreachable() - -/* Mark a function definition as prohibited from being cloned. */ -#define __noclone __attribute__((__noclone__)) - -/* - * Tell the optimizer that something else uses this function or variable. - */ -#define __visible __attribute__((externally_visible)) - -/* - * GCC 'asm goto' miscompiles certain code sequences: - * - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 - * - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. - * - * (asm goto is automatically volatile - the naming reflects this.) - */ -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) - -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ -#define __HAVE_BUILTIN_BSWAP16__ -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ - diff --git a/devices/asus-flo/kernel/default.nix b/devices/asus-flo/kernel/default.nix index e9697f8f6..43d86805e 100644 --- a/devices/asus-flo/kernel/default.nix +++ b/devices/asus-flo/kernel/default.nix @@ -4,12 +4,10 @@ , kernelPatches ? [] # FIXME }: -(mobile-nixos.kernel-builder-gcc6 { +mobile-nixos.kernel-builder-gcc6 { version = "3.4.113"; configfile = ./config.armv7; - file = "zImage"; - src = fetchFromGitHub { owner = "LineageOS"; repo = "android_kernel_google_msm"; @@ -27,30 +25,6 @@ ./99_framebuffer.patch ]; + enableCompilerGcc6Quirk = true; isModular = false; - - postPatch = '' - cp -v "${./compiler-gcc6.h}" "./include/linux/compiler-gcc6.h" - ''; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" ]; - postInstall = postInstall + '' - mkdir -p "$out/boot" - - # FIXME factor this out properly - # Copies all potential output files. - for f in zImage-dtb Image.gz-dtb zImage Image.gz Image; do - f=arch/arm/boot/$f - [ -e "$f" ] || continue - echo "zImage found: $f" - cp -v "$f" "$out/" - break - done - - mkdir -p $out/dtb - for f in arch/*/boot/dts/*.dtb; do - cp -v "$f" $out/dtb/ - done - - ''; -}) +} From c15684ddca7d8af4f6721a3649894227d65f6a45 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:16:20 -0400 Subject: [PATCH 07/32] asus-x018d: Update usage of kernel builder --- devices/asus-x018d/kernel/default.nix | 28 +++++---------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/devices/asus-x018d/kernel/default.nix b/devices/asus-x018d/kernel/default.nix index afbd1bd2a..a510c9a14 100644 --- a/devices/asus-x018d/kernel/default.nix +++ b/devices/asus-x018d/kernel/default.nix @@ -6,16 +6,10 @@ , buildPackages }: -let - inherit (buildPackages) dtc; -in -(mobile-nixos.kernel-builder-gcc49 { +mobile-nixos.kernel-builder-gcc49 { version = "3.18.35"; configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - src = fetchFromGitHub { owner = "mobile-nixos"; repo = "linux"; @@ -32,23 +26,11 @@ in ./0002-E262L-Green-LED-now-defaults-to-on.patch ]; - makeFlags = [ - "DTC_EXT=${dtc}/bin/dtc" - ]; - - isModular = false; - - postPatch = '' - patchShebangs tools - ''; - nativeBuildInputs = [ + # Needed for tools/dct/DrvGen.py python2 ]; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" "Image.gz-dtb" "install" ]; - postInstall = postInstall + '' - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) + isImageGzDtb = true; + isModular = false; +} From 7dc514e8ce930f5d4c8936a5c0a25da2240d9a3d Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:16:27 -0400 Subject: [PATCH 08/32] asus-z00t: Update usage of kernel builder --- devices/asus-z00t/default.nix | 1 - devices/asus-z00t/kernel/compiler-gcc6.h | 69 ------------------------ devices/asus-z00t/kernel/default.nix | 32 ++--------- 3 files changed, 4 insertions(+), 98 deletions(-) delete mode 100644 devices/asus-z00t/kernel/compiler-gcc6.h diff --git a/devices/asus-z00t/default.nix b/devices/asus-z00t/default.nix index 3f2007562..c2a8d3cf7 100644 --- a/devices/asus-z00t/default.nix +++ b/devices/asus-z00t/default.nix @@ -25,7 +25,6 @@ mobile.device.firmware = pkgs.callPackage ./firmware {}; mobile.system.android.bootimg = { - dt = "${config.mobile.boot.stage-1.kernel.package}/dtbs/asus-z00t.img"; flash = { offset_base = "0x10000000"; offset_kernel = "0x00008000"; diff --git a/devices/asus-z00t/kernel/compiler-gcc6.h b/devices/asus-z00t/kernel/compiler-gcc6.h deleted file mode 100644 index 844706318..000000000 --- a/devices/asus-z00t/kernel/compiler-gcc6.h +++ /dev/null @@ -1,69 +0,0 @@ -// SOURCE: -// https://github.com/NextThingCo/CHIP-u-boot/issues/10#issuecomment-287515505 - -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -#define __used __attribute__((__used__)) -#define __must_check __attribute__((warn_unused_result)) -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) - -/* Mark functions as cold. gcc will assume any path leading to a call - to them will be unlikely. This means a lot of manual unlikely()s - are unnecessary now for any paths leading to the usual suspects - like BUG(), printk(), panic() etc. [but let's keep them for now for - older compilers] - - Early snapshots of gcc 4.3 don't support this and we can't detect this - in the preprocessor, but we can live with this because they're unreleased. - Maketime probing would be overkill here. - - gcc also has a __attribute__((__hot__)) to move hot functions into - a special section, but I don't see any sense in this right now in - the kernel context */ -#define __cold __attribute__((__cold__)) - -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) - -#ifndef __CHECKER__ -# define __compiletime_warning(message) __attribute__((warning(message))) -# define __compiletime_error(message) __attribute__((error(message))) -#endif /* __CHECKER__ */ - -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - * - * Early snapshots of gcc 4.5 don't support this and we can't detect - * this in the preprocessor, but we can live with this because they're - * unreleased. Really, we need to have autoconf for the kernel. - */ -#define unreachable() __builtin_unreachable() - -/* Mark a function definition as prohibited from being cloned. */ -#define __noclone __attribute__((__noclone__)) - -/* - * Tell the optimizer that something else uses this function or variable. - */ -#define __visible __attribute__((externally_visible)) - -/* - * GCC 'asm goto' miscompiles certain code sequences: - * - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 - * - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. - * - * (asm goto is automatically volatile - the naming reflects this.) - */ -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) - -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ -#define __HAVE_BUILTIN_BSWAP16__ -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ - diff --git a/devices/asus-z00t/kernel/default.nix b/devices/asus-z00t/kernel/default.nix index cf608f087..465731d79 100644 --- a/devices/asus-z00t/kernel/default.nix +++ b/devices/asus-z00t/kernel/default.nix @@ -2,16 +2,12 @@ mobile-nixos , fetchFromGitHub , kernelPatches ? [] # FIXME -, dtbTool }: -(mobile-nixos.kernel-builder-gcc6 { +mobile-nixos.kernel-builder-gcc6 { version = "3.10.108"; configfile = ./config.aarch64; - file = "Image.gz"; - hasDTB = true; - src = fetchFromGitHub { owner = "LineageOS"; repo = "android_kernel_asus_msm8916"; @@ -40,27 +36,7 @@ ./90_dtbs-install.patch ./99_framebuffer.patch ]; - + qcdt_dtbs = "arch/arm/boot/"; isModular = false; - - postPatch = '' - cp -v "${./compiler-gcc6.h}" "./include/linux/compiler-gcc6.h" - ''; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" ]; - postInstall = postInstall + '' - ${dtbTool}/bin/dtbTool -s 2048 -p "scripts/dtc/" -o "arch/arm64/boot/asus-z00t.img" "arch/arm/boot/" - cp "arch/arm64/boot/asus-z00t.img" "$out/dtbs/asus-z00t.img" - - mkdir -p $out/dtb - for f in arch/*/boot/dts/*.dtb; do - cp -v "$f" $out/dtb/ - done - -# # FIXME: understand the specifics of why this needs to be catted together. -# ( -# cd $out -# cat Image.gz dtb/*.dtb > vmlinuz-dtb -# ) - ''; -}) + isQcdt = true; +} From f01f499a023e49b6288fac713bafd36d56deb4d6 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:16:43 -0400 Subject: [PATCH 09/32] google-marlin: Update usage of kernel builder --- devices/google-marlin/kernel/default.nix | 40 +++--------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/devices/google-marlin/kernel/default.nix b/devices/google-marlin/kernel/default.nix index f6142c496..1e54c52e0 100644 --- a/devices/google-marlin/kernel/default.nix +++ b/devices/google-marlin/kernel/default.nix @@ -2,19 +2,11 @@ mobile-nixos , fetchFromGitHub , kernelPatches ? [] # FIXME -, buildPackages }: -let - inherit (buildPackages) dtc; -in - -(mobile-nixos.kernel-builder-gcc6 { +mobile-nixos.kernel-builder-gcc6 { configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - version = "3.18.140"; src = fetchFromGitHub { owner = "android-linux-stable"; @@ -29,31 +21,7 @@ in ./99_framebuffer.patch ]; + enableRemovingWerror = true; + isImageGzDtb = true; isModular = false; - - postPatch = '' - # FIXME : factor out - ( - # Remove -Werror from all makefiles - local i - local makefiles="$(find . -type f -name Makefile) - $(find . -type f -name Kbuild)" - for i in $makefiles; do - sed -i 's/-Werror-/-W/g' "$i" - sed -i 's/-Werror=/-W/g' "$i" - sed -i 's/-Werror//g' "$i" - done - ) - - # Remove google's default dm-verity certs - rm -f *.x509 - ''; -}).overrideAttrs({ postInstall ? "", nativeBuildInputs, ... }: { - installTargets = [ "zinstall" "Image.gz-dtb" "install" ]; - - nativeBuildInputs = nativeBuildInputs ++ [ dtc ]; - - postInstall = postInstall + '' - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) +} From 802c0fbb50c1ab0d03860dda6cd7ded50c45aadf Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:16:48 -0400 Subject: [PATCH 10/32] google-walleye: Update usage of kernel builder --- devices/google-walleye/kernel/default.nix | 37 +++-------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/devices/google-walleye/kernel/default.nix b/devices/google-walleye/kernel/default.nix index 5a719af4f..a8cc40c63 100644 --- a/devices/google-walleye/kernel/default.nix +++ b/devices/google-walleye/kernel/default.nix @@ -2,19 +2,11 @@ mobile-nixos , fetchFromGitHub , kernelPatches ? [] # FIXME -, buildPackages }: -let - inherit (buildPackages) dtc; -in - -(mobile-nixos.kernel-builder { +mobile-nixos.kernel-builder { configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - version = "4.4.230"; src = fetchFromGitHub { owner = "android-linux-stable"; @@ -30,28 +22,7 @@ in ./0003-arch-arm64-Add-config-option-to-fix-bootloader-cmdli.patch ]; + enableRemovingWerror = true; + isImageGzDtb = true; isModular = false; - - postPatch = '' - # FIXME : factor out - ( - # Remove -Werror from all makefiles - local i - local makefiles="$(find . -type f -name Makefile) - $(find . -type f -name Kbuild)" - for i in $makefiles; do - sed -i 's/-Werror-/-W/g' "$i" - sed -i 's/-Werror=/-W/g' "$i" - sed -i 's/-Werror//g' "$i" - done - ) - ''; -}).overrideAttrs({ postInstall ? "", nativeBuildInputs, ... }: { - installTargets = [ "zinstall" "Image.gz-dtb" "install" ]; - - nativeBuildInputs = nativeBuildInputs ++ [ dtc ]; - - postInstall = postInstall + '' - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) +} From ccd3a542fc967c357ad543ba8a6cac11880c2fc4 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:16:57 -0400 Subject: [PATCH 11/32] motorola-addison: Update usage of kernel builder --- devices/motorola-addison/default.nix | 1 - .../motorola-addison/kernel/compiler-gcc6.h | 69 ------------------- devices/motorola-addison/kernel/default.nix | 46 ++----------- 3 files changed, 5 insertions(+), 111 deletions(-) delete mode 100644 devices/motorola-addison/kernel/compiler-gcc6.h diff --git a/devices/motorola-addison/default.nix b/devices/motorola-addison/default.nix index 5c73ff5dd..f7ebca2dc 100644 --- a/devices/motorola-addison/default.nix +++ b/devices/motorola-addison/default.nix @@ -22,7 +22,6 @@ mobile.device.firmware = pkgs.callPackage ./firmware {}; mobile.system.android.bootimg = { - dt = "${config.mobile.boot.stage-1.kernel.package}/dtbs/motorola-addison.img"; flash = { offset_base = "0x80000000"; offset_kernel = "0x00008000"; diff --git a/devices/motorola-addison/kernel/compiler-gcc6.h b/devices/motorola-addison/kernel/compiler-gcc6.h deleted file mode 100644 index 844706318..000000000 --- a/devices/motorola-addison/kernel/compiler-gcc6.h +++ /dev/null @@ -1,69 +0,0 @@ -// SOURCE: -// https://github.com/NextThingCo/CHIP-u-boot/issues/10#issuecomment-287515505 - -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -#define __used __attribute__((__used__)) -#define __must_check __attribute__((warn_unused_result)) -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) - -/* Mark functions as cold. gcc will assume any path leading to a call - to them will be unlikely. This means a lot of manual unlikely()s - are unnecessary now for any paths leading to the usual suspects - like BUG(), printk(), panic() etc. [but let's keep them for now for - older compilers] - - Early snapshots of gcc 4.3 don't support this and we can't detect this - in the preprocessor, but we can live with this because they're unreleased. - Maketime probing would be overkill here. - - gcc also has a __attribute__((__hot__)) to move hot functions into - a special section, but I don't see any sense in this right now in - the kernel context */ -#define __cold __attribute__((__cold__)) - -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) - -#ifndef __CHECKER__ -# define __compiletime_warning(message) __attribute__((warning(message))) -# define __compiletime_error(message) __attribute__((error(message))) -#endif /* __CHECKER__ */ - -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - * - * Early snapshots of gcc 4.5 don't support this and we can't detect - * this in the preprocessor, but we can live with this because they're - * unreleased. Really, we need to have autoconf for the kernel. - */ -#define unreachable() __builtin_unreachable() - -/* Mark a function definition as prohibited from being cloned. */ -#define __noclone __attribute__((__noclone__)) - -/* - * Tell the optimizer that something else uses this function or variable. - */ -#define __visible __attribute__((externally_visible)) - -/* - * GCC 'asm goto' miscompiles certain code sequences: - * - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 - * - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. - * - * (asm goto is automatically volatile - the naming reflects this.) - */ -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) - -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ -#define __HAVE_BUILTIN_BSWAP16__ -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ - diff --git a/devices/motorola-addison/kernel/default.nix b/devices/motorola-addison/kernel/default.nix index f8d4eb89e..14356ed6d 100644 --- a/devices/motorola-addison/kernel/default.nix +++ b/devices/motorola-addison/kernel/default.nix @@ -1,10 +1,8 @@ { mobile-nixos , stdenv -, hostPlatform , fetchFromGitHub , kernelPatches ? [] # FIXME -, dtbTool }: # @@ -16,16 +14,9 @@ # mobile.system.system = lib.mkForce "armv7l-linux"; # -let - inherit (stdenv.lib) optionalString; - cpuName = hostPlatform.parsed.cpu.name; -in -(mobile-nixos.kernel-builder-gcc6 { +mobile-nixos.kernel-builder-gcc6 { version = "3.18.71"; - configfile = ./. + "/config.${cpuName}"; - - file = if (cpuName == "aarch64") then "Image.gz" else "zImage"; - hasDTB = (cpuName == "aarch64"); + configfile = ./. + "/config.${stdenv.hostPlatform.parsed.cpu.name}"; src = fetchFromGitHub { owner = "LineageOS"; @@ -43,34 +34,7 @@ in ./0005-Allow-building-with-sound-disabled.patch ]; + enableRemovingWerror = true; isModular = false; - - postPatch = '' - cp -v "${./compiler-gcc6.h}" "./include/linux/compiler-gcc6.h" - - # FIXME : factor out - ( - # Remove -Werror from all makefiles - local i - local makefiles="$(find . -type f -name Makefile) - $(find . -type f -name Kbuild)" - for i in $makefiles; do - sed -i 's/-Werror-/-W/g' "$i" - sed -i 's/-Werror=/-W/g' "$i" - sed -i 's/-Werror//g' "$i" - done - ) - ''; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" "dtbs" ]; - postInstall = postInstall + '' - mkdir -p "$out/dtbs/" - '' - + optionalString (cpuName == "aarch64") '' - ${dtbTool}/bin/dtbTool -s 2048 -p "scripts/dtc/" -o "$out/dtbs/motorola-addison.img" "$out/dtbs/qcom/" - '' - + optionalString (cpuName == "armv7l") '' - ${dtbTool}/bin/dtbTool -s 2048 -p "scripts/dtc/" -o "$out/dtbs/motorola-addison.img" "arch/arm/boot" - '' - ; -}) + isQcdt = true; +} From 3c07e7f687584b961825d4fb19b3d2bd89126452 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:17:02 -0400 Subject: [PATCH 12/32] oneplus-oneplus3: Update usage of kernel builder --- .../oneplus-oneplus3/kernel/compiler-gcc6.h | 69 ------------------- devices/oneplus-oneplus3/kernel/default.nix | 33 +-------- 2 files changed, 3 insertions(+), 99 deletions(-) delete mode 100644 devices/oneplus-oneplus3/kernel/compiler-gcc6.h diff --git a/devices/oneplus-oneplus3/kernel/compiler-gcc6.h b/devices/oneplus-oneplus3/kernel/compiler-gcc6.h deleted file mode 100644 index 844706318..000000000 --- a/devices/oneplus-oneplus3/kernel/compiler-gcc6.h +++ /dev/null @@ -1,69 +0,0 @@ -// SOURCE: -// https://github.com/NextThingCo/CHIP-u-boot/issues/10#issuecomment-287515505 - -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -#define __used __attribute__((__used__)) -#define __must_check __attribute__((warn_unused_result)) -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) - -/* Mark functions as cold. gcc will assume any path leading to a call - to them will be unlikely. This means a lot of manual unlikely()s - are unnecessary now for any paths leading to the usual suspects - like BUG(), printk(), panic() etc. [but let's keep them for now for - older compilers] - - Early snapshots of gcc 4.3 don't support this and we can't detect this - in the preprocessor, but we can live with this because they're unreleased. - Maketime probing would be overkill here. - - gcc also has a __attribute__((__hot__)) to move hot functions into - a special section, but I don't see any sense in this right now in - the kernel context */ -#define __cold __attribute__((__cold__)) - -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) - -#ifndef __CHECKER__ -# define __compiletime_warning(message) __attribute__((warning(message))) -# define __compiletime_error(message) __attribute__((error(message))) -#endif /* __CHECKER__ */ - -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - * - * Early snapshots of gcc 4.5 don't support this and we can't detect - * this in the preprocessor, but we can live with this because they're - * unreleased. Really, we need to have autoconf for the kernel. - */ -#define unreachable() __builtin_unreachable() - -/* Mark a function definition as prohibited from being cloned. */ -#define __noclone __attribute__((__noclone__)) - -/* - * Tell the optimizer that something else uses this function or variable. - */ -#define __visible __attribute__((externally_visible)) - -/* - * GCC 'asm goto' miscompiles certain code sequences: - * - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 - * - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. - * - * (asm goto is automatically volatile - the naming reflects this.) - */ -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) - -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ -#define __HAVE_BUILTIN_BSWAP16__ -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ - diff --git a/devices/oneplus-oneplus3/kernel/default.nix b/devices/oneplus-oneplus3/kernel/default.nix index 20c7cb50b..15db75897 100644 --- a/devices/oneplus-oneplus3/kernel/default.nix +++ b/devices/oneplus-oneplus3/kernel/default.nix @@ -2,16 +2,11 @@ mobile-nixos , fetchFromGitHub , kernelPatches ? [] # FIXME -, buildPackages -, dtbTool }: -(mobile-nixos.kernel-builder-gcc6 { +mobile-nixos.kernel-builder-gcc6 { configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - version = "3.18.140"; src = fetchFromGitHub { owner = "android-linux-stable"; @@ -27,28 +22,6 @@ ./0001-oneplus3-Configure-LEDs-using-kernel-triggers.patch ]; + isImageGzDtb = true; isModular = false; - - postPatch = '' - cp -v "${./compiler-gcc6.h}" "./include/linux/compiler-gcc6.h" - - # FIXME : factor out - ( - # Remove -Werror from all makefiles - local i - local makefiles="$(find . -type f -name Makefile) - $(find . -type f -name Kbuild)" - for i in $makefiles; do - sed -i 's/-Werror-/-W/g' "$i" - sed -i 's/-Werror=/-W/g' "$i" - sed -i 's/-Werror//g' "$i" - done - ) - ''; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" "Image.gz-dtb" "install" ]; - postInstall = postInstall + '' - mkdir -p "$out/dtbs/" - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) +} From 52f48851bf709755216a3060a56105eea9d8f0c5 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:17:09 -0400 Subject: [PATCH 13/32] pine64-pinephone-braveheart: Update usage of kernel builder --- .../pine64-pinephone-braveheart/kernel/default.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/devices/pine64-pinephone-braveheart/kernel/default.nix b/devices/pine64-pinephone-braveheart/kernel/default.nix index 9bbb116ba..e85079f7c 100644 --- a/devices/pine64-pinephone-braveheart/kernel/default.nix +++ b/devices/pine64-pinephone-braveheart/kernel/default.nix @@ -1,11 +1,10 @@ { mobile-nixos , fetchFromGitHub -, fetchpatch , kernelPatches ? [] # FIXME }: -(mobile-nixos.kernel-builder { +mobile-nixos.kernel-builder { version = "5.8.0"; configfile = ./config.aarch64; src = fetchFromGitHub { @@ -17,10 +16,11 @@ patches = [ ./0001-dts-pinephone-Setup-default-on-and-panic-LEDs.patch ]; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "install" "dtbs" ]; - postInstall = postInstall + '' + + # Install *only* the desired FDTs + postInstall = '' + echo ":: Installing FDTs" mkdir -p "$out/dtbs/allwinner" cp -v $buildRoot/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-*.dtb $out/dtbs/allwinner/ ''; -}) +} From b4e30da9e5d20c2021240cdc57af22ddbaf589d0 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:17:20 -0400 Subject: [PATCH 14/32] sony-pioneer: Update usage of kernel builder --- devices/sony-pioneer/kernel/default.nix | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/devices/sony-pioneer/kernel/default.nix b/devices/sony-pioneer/kernel/default.nix index f7b51b954..2754ad5de 100644 --- a/devices/sony-pioneer/kernel/default.nix +++ b/devices/sony-pioneer/kernel/default.nix @@ -2,19 +2,12 @@ mobile-nixos , fetchFromGitHub , kernelPatches ? [] # FIXME -, buildPackages }: -let - inherit (buildPackages) dtc; -in -(mobile-nixos.kernel-builder-gcc49 { +mobile-nixos.kernel-builder-gcc49 { version = "4.4.205"; configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - # https://github.com/LineageOS/android_kernel_sony_sdm660 src = fetchFromGitHub { owner = "LineageOS"; @@ -30,15 +23,6 @@ in ./0003-arch-arm64-Add-config-option-to-fix-bootloader-cmdli.patch ]; - makeFlags = [ - "DTC_EXT=${dtc}/bin/dtc" - ]; - + isImageGzDtb = true; isModular = false; - -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" "Image.gz-dtb" "install" ]; - postInstall = postInstall + '' - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) +} From 0b9b59776c5be27349198314b2160305905c4541 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:17:25 -0400 Subject: [PATCH 15/32] xiaomi-begonia: Update usage of kernel builder --- devices/xiaomi-begonia/kernel/default.nix | 29 ++++------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/devices/xiaomi-begonia/kernel/default.nix b/devices/xiaomi-begonia/kernel/default.nix index 3594783d6..47755e11d 100644 --- a/devices/xiaomi-begonia/kernel/default.nix +++ b/devices/xiaomi-begonia/kernel/default.nix @@ -1,6 +1,5 @@ { mobile-nixos -, runCommand , fetchFromGitHub , kernelPatches ? [] # FIXME , buildPackages @@ -28,8 +27,6 @@ let sha256 = "1p08392pcavfjy5i0zc61dxibr0jq9kb3na1hdx85q0z3d9sfwp6"; }; - inherit (buildPackages) dtc; - # This may seem weird, but doing this inside the kernel build breaks the binary. # Note that `buildPackages.stdenv` is necessary since this is a tool for the host. dtc_overlay = buildPackages.stdenv.mkDerivation { @@ -54,13 +51,11 @@ let }; in -(mobile-nixos.kernel-builder-clang_9 { + +mobile-nixos.kernel-builder-clang_9 { version = "4.14.184"; configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - inherit src; patches = [ @@ -71,10 +66,7 @@ in ./0003-arch-arm64-Add-config-option-to-fix-bootloader-cmdli.patch ]; - makeFlags = [ - "DTC_EXT=${dtc}/bin/dtc" - ]; - + isImageGzDtb = true; isModular = false; postPatch = '' @@ -84,17 +76,4 @@ in cp ${dtc_overlay} scripts/dtc/dtc_overlay ) ''; -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ - # uh, things seem screwey with that vendor kernel tree, and dependencies - # are not resolved as expected, so let's ask for the compressed kernel - # explictly first :/. - "Image.gz" - "zinstall" - "Image.gz-dtb" - "install" - ]; - postInstall = postInstall + '' - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) +} From 9356bbd9aa0496f1d773cf7f8d5729ca0279621a Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:17:31 -0400 Subject: [PATCH 16/32] xiaomi-lavender: Update usage of kernel builder --- devices/xiaomi-lavender/kernel/default.nix | 23 +++------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/devices/xiaomi-lavender/kernel/default.nix b/devices/xiaomi-lavender/kernel/default.nix index 2d4bc06a4..b1836082d 100644 --- a/devices/xiaomi-lavender/kernel/default.nix +++ b/devices/xiaomi-lavender/kernel/default.nix @@ -2,7 +2,6 @@ mobile-nixos , fetchFromGitHub , kernelPatches ? [] # FIXME -, buildPackages }: # @@ -12,20 +11,13 @@ # # Things to note: # -# * The build will not succeed using the `dtc` scripts shipped with their kernel. # * Will not build or boot on all compilers. # -let - inherit (buildPackages) dtc; -in -(mobile-nixos.kernel-builder-gcc49 { +mobile-nixos.kernel-builder-gcc49 { version = "4.4.153"; configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; - # https://github.com/MiCode/Xiaomi_Kernel_OpenSource/tree/lavender-p-oss src = fetchFromGitHub { owner = "MiCode"; @@ -40,15 +32,6 @@ in ./0003-arch-arm64-Add-config-option-to-fix-bootloader-cmdli.patch ]; - makeFlags = [ - "DTC_EXT=${dtc}/bin/dtc" - ]; - + isImageGzDtb = true; isModular = false; - -}).overrideAttrs({ postInstall ? "", ... }: { - installTargets = [ "zinstall" "Image.gz-dtb" "install" ]; - postInstall = postInstall + '' - cp -v "$buildRoot/arch/arm64/boot/Image.gz-dtb" "$out/" - ''; -}) +} From ff49550c7b1a118ee170b8bd96b7d59b44ae4a5e Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Thu, 1 Oct 2020 02:17:37 -0400 Subject: [PATCH 17/32] xiaomi-tissot: Update usage of kernel builder --- devices/xiaomi-tissot/kernel/default.nix | 30 ++++-------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/devices/xiaomi-tissot/kernel/default.nix b/devices/xiaomi-tissot/kernel/default.nix index 7e6fb7910..10c7f3222 100644 --- a/devices/xiaomi-tissot/kernel/default.nix +++ b/devices/xiaomi-tissot/kernel/default.nix @@ -1,15 +1,11 @@ { mobile-nixos , fetchFromGitHub , kernelPatches ? [] -, dtbTool -, buildPackages }: -let inherit (buildPackages) dtc; in -(mobile-nixos.kernel-builder-gcc6 { + +mobile-nixos.kernel-builder-gcc6 { version = "3.18.71"; configfile = ./config.aarch64; - file = "Image.gz-dtb"; - hasDTB = true; src = fetchFromGitHub { owner = "lineageos"; repo = "android_kernel_xiaomi_msm8953"; @@ -21,24 +17,6 @@ let inherit (buildPackages) dtc; in ./0003-arch-arm64-Add-config-option-to-fix-bootloader-cmdli.patch ]; - postPatch = '' - # Remove -Werror from all makefiles - local i - local makefiles="$(find . -type f -name Makefile) - $(find . -type f -name Kbuild)" - for i in $makefiles; do - sed -i 's/-Werror-/-W/g' "$i" - sed -i 's/-Werror//g' "$i" - done - echo "Patched out -Werror" - ''; - - makeFlags = [ "DTC_EXT=${dtc}/bin/dtc" ]; - + isImageGzDtb = true; isModular = false; -}).overrideAttrs ({ postInstall ? "", ... }: { - installTargets = [ "Image.gz" "zinstall" "Image.gz-dtb" "install" ]; - postInstall = postInstall + '' - cp $buildRoot/arch/arm64/boot/Image.gz-dtb $out/ - ''; -}) +} From 5deb826577f5d8e9ab11c851fb830ed28d5a432e Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:45:58 -0400 Subject: [PATCH 18/32] asus-dumo: drop unused kernelPatches argument --- devices/asus-dumo/kernel/default.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/devices/asus-dumo/kernel/default.nix b/devices/asus-dumo/kernel/default.nix index ec0b48a60..78e150d87 100644 --- a/devices/asus-dumo/kernel/default.nix +++ b/devices/asus-dumo/kernel/default.nix @@ -2,7 +2,6 @@ mobile-nixos , fetchFromGitHub , fetchgit -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder { From f95f5f2df80aff98ba87d5b8b3643ef4744abc2d Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:46:46 -0400 Subject: [PATCH 19/32] asus-flo: drop unused kernelPatches argument --- devices/asus-flo/default.nix | 2 +- devices/asus-flo/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/asus-flo/default.nix b/devices/asus-flo/default.nix index 503595759..878a5df6c 100644 --- a/devices/asus-flo/default.nix +++ b/devices/asus-flo/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android.bootimg = { diff --git a/devices/asus-flo/kernel/default.nix b/devices/asus-flo/kernel/default.nix index 43d86805e..6ca88870f 100644 --- a/devices/asus-flo/kernel/default.nix +++ b/devices/asus-flo/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder-gcc6 { From 53b4c5ccd41fb691420d854030d8f202aa5270aa Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:46:51 -0400 Subject: [PATCH 20/32] asus-x018d: drop unused kernelPatches argument --- devices/asus-x018d/default.nix | 2 +- devices/asus-x018d/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/asus-x018d/default.nix b/devices/asus-x018d/default.nix index feaa3ff7c..8e64d16a5 100644 --- a/devices/asus-x018d/default.nix +++ b/devices/asus-x018d/default.nix @@ -17,7 +17,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/asus-x018d/kernel/default.nix b/devices/asus-x018d/kernel/default.nix index a510c9a14..1353d3772 100644 --- a/devices/asus-x018d/kernel/default.nix +++ b/devices/asus-x018d/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME , python2 , buildPackages }: From a3e2bfc00b115c219ad30340c0c98b8fc623ab25 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:46:58 -0400 Subject: [PATCH 21/32] asus-z00t: drop unused kernelPatches argument --- devices/asus-z00t/default.nix | 2 +- devices/asus-z00t/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/asus-z00t/default.nix b/devices/asus-z00t/default.nix index c2a8d3cf7..79a8a2b5b 100644 --- a/devices/asus-z00t/default.nix +++ b/devices/asus-z00t/default.nix @@ -19,7 +19,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.device.firmware = pkgs.callPackage ./firmware {}; diff --git a/devices/asus-z00t/kernel/default.nix b/devices/asus-z00t/kernel/default.nix index 465731d79..be4d4af44 100644 --- a/devices/asus-z00t/kernel/default.nix +++ b/devices/asus-z00t/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder-gcc6 { From c3037f6bf737df21e386c33dea766474a26a7e75 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:47:07 -0400 Subject: [PATCH 22/32] google-marlin: drop unused kernelPatches argument --- devices/google-marlin/default.nix | 2 +- devices/google-marlin/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/google-marlin/default.nix b/devices/google-marlin/default.nix index 5a945cdcd..0027feec5 100644 --- a/devices/google-marlin/default.nix +++ b/devices/google-marlin/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/google-marlin/kernel/default.nix b/devices/google-marlin/kernel/default.nix index 1e54c52e0..e32180b3c 100644 --- a/devices/google-marlin/kernel/default.nix +++ b/devices/google-marlin/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder-gcc6 { From dde7cd49611d3ffa9030d97ca151cb1571983d94 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:47:13 -0400 Subject: [PATCH 23/32] google-walleye: drop unused kernelPatches argument --- devices/google-walleye/default.nix | 2 +- devices/google-walleye/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/google-walleye/default.nix b/devices/google-walleye/default.nix index b774cbe0c..79f4c1153 100644 --- a/devices/google-walleye/default.nix +++ b/devices/google-walleye/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/google-walleye/kernel/default.nix b/devices/google-walleye/kernel/default.nix index a8cc40c63..390950664 100644 --- a/devices/google-walleye/kernel/default.nix +++ b/devices/google-walleye/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder { From 86d08e3da2583a5f0af12cbe4e7f85d486a4752e Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:47:22 -0400 Subject: [PATCH 24/32] motorola-addison: drop unused kernelPatches argument --- devices/motorola-addison/default.nix | 2 +- devices/motorola-addison/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/motorola-addison/default.nix b/devices/motorola-addison/default.nix index f7ebca2dc..aae797fd2 100644 --- a/devices/motorola-addison/default.nix +++ b/devices/motorola-addison/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.device.firmware = pkgs.callPackage ./firmware {}; diff --git a/devices/motorola-addison/kernel/default.nix b/devices/motorola-addison/kernel/default.nix index 14356ed6d..bb01560b2 100644 --- a/devices/motorola-addison/kernel/default.nix +++ b/devices/motorola-addison/kernel/default.nix @@ -2,7 +2,6 @@ mobile-nixos , stdenv , fetchFromGitHub -, kernelPatches ? [] # FIXME }: # From f17c31ece109b1058a984ec5f4a46ad2b0e06d2d Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:47:36 -0400 Subject: [PATCH 25/32] oneplus-oneplus3: drop unused kernelPatches argument --- devices/oneplus-oneplus3/default.nix | 2 +- devices/oneplus-oneplus3/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/oneplus-oneplus3/default.nix b/devices/oneplus-oneplus3/default.nix index 827314c98..c9a795480 100644 --- a/devices/oneplus-oneplus3/default.nix +++ b/devices/oneplus-oneplus3/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android.bootimg = { diff --git a/devices/oneplus-oneplus3/kernel/default.nix b/devices/oneplus-oneplus3/kernel/default.nix index 15db75897..61cad93d6 100644 --- a/devices/oneplus-oneplus3/kernel/default.nix +++ b/devices/oneplus-oneplus3/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder-gcc6 { From 70e7259cdc7dbd7d6b4c2f9a868c08a104672e57 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:47:47 -0400 Subject: [PATCH 26/32] pine64-pinephone-braveheart: drop unused kernelPatches argument --- devices/pine64-pinephone-braveheart/default.nix | 2 +- devices/pine64-pinephone-braveheart/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/pine64-pinephone-braveheart/default.nix b/devices/pine64-pinephone-braveheart/default.nix index 8d6397eed..a4f267d65 100644 --- a/devices/pine64-pinephone-braveheart/default.nix +++ b/devices/pine64-pinephone-braveheart/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; boot.kernelParams = [ diff --git a/devices/pine64-pinephone-braveheart/kernel/default.nix b/devices/pine64-pinephone-braveheart/kernel/default.nix index e85079f7c..601eacf13 100644 --- a/devices/pine64-pinephone-braveheart/kernel/default.nix +++ b/devices/pine64-pinephone-braveheart/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder { From 61b0145f14f0b820599450b9d8a54ec88acd6d8c Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:47:56 -0400 Subject: [PATCH 27/32] sony-pioneer: drop unused kernelPatches argument --- devices/sony-pioneer/default.nix | 2 +- devices/sony-pioneer/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/sony-pioneer/default.nix b/devices/sony-pioneer/default.nix index 599f207c6..6cbb39de7 100644 --- a/devices/sony-pioneer/default.nix +++ b/devices/sony-pioneer/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/sony-pioneer/kernel/default.nix b/devices/sony-pioneer/kernel/default.nix index 2754ad5de..c86567d7a 100644 --- a/devices/sony-pioneer/kernel/default.nix +++ b/devices/sony-pioneer/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: mobile-nixos.kernel-builder-gcc49 { From 7bff0070d96ea58f08bfedd232fe6e8d7710751d Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:48:01 -0400 Subject: [PATCH 28/32] xiaomi-begonia: drop unused kernelPatches argument --- devices/xiaomi-begonia/default.nix | 2 +- devices/xiaomi-begonia/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/xiaomi-begonia/default.nix b/devices/xiaomi-begonia/default.nix index d252de483..af61054f8 100644 --- a/devices/xiaomi-begonia/default.nix +++ b/devices/xiaomi-begonia/default.nix @@ -19,7 +19,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/xiaomi-begonia/kernel/default.nix b/devices/xiaomi-begonia/kernel/default.nix index 47755e11d..97a0a1648 100644 --- a/devices/xiaomi-begonia/kernel/default.nix +++ b/devices/xiaomi-begonia/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME , buildPackages }: From 6b2482578ea1c5fad736c3d2034c5a5434057e1c Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:48:07 -0400 Subject: [PATCH 29/32] xiaomi-lavender: drop unused kernelPatches argument --- devices/xiaomi-lavender/default.nix | 2 +- devices/xiaomi-lavender/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/xiaomi-lavender/default.nix b/devices/xiaomi-lavender/default.nix index 4acafe65b..63065ba09 100644 --- a/devices/xiaomi-lavender/default.nix +++ b/devices/xiaomi-lavender/default.nix @@ -19,7 +19,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/xiaomi-lavender/kernel/default.nix b/devices/xiaomi-lavender/kernel/default.nix index b1836082d..233f2b6e5 100644 --- a/devices/xiaomi-lavender/kernel/default.nix +++ b/devices/xiaomi-lavender/kernel/default.nix @@ -1,7 +1,6 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] # FIXME }: # From 0143cecfa02bfe2f72f10248e45d69ac75547ed6 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:48:15 -0400 Subject: [PATCH 30/32] xiaomi-tissot: drop unused kernelPatches argument --- devices/xiaomi-tissot/default.nix | 2 +- devices/xiaomi-tissot/kernel/default.nix | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/devices/xiaomi-tissot/default.nix b/devices/xiaomi-tissot/default.nix index 95513c65a..134b0be4f 100644 --- a/devices/xiaomi-tissot/default.nix +++ b/devices/xiaomi-tissot/default.nix @@ -16,7 +16,7 @@ }; mobile.boot.stage-1 = { - kernel.package = pkgs.callPackage ./kernel { kernelPatches = pkgs.defaultKernelPatches; }; + kernel.package = pkgs.callPackage ./kernel { }; }; mobile.system.android = { diff --git a/devices/xiaomi-tissot/kernel/default.nix b/devices/xiaomi-tissot/kernel/default.nix index 10c7f3222..2dac464a9 100644 --- a/devices/xiaomi-tissot/kernel/default.nix +++ b/devices/xiaomi-tissot/kernel/default.nix @@ -1,6 +1,5 @@ { mobile-nixos , fetchFromGitHub -, kernelPatches ? [] }: mobile-nixos.kernel-builder-gcc6 { From 9210f716d3b9b71c57af1c08a4f61d3e29bc452c Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 19:48:32 -0400 Subject: [PATCH 31/32] overlay: Dropped now unused defaultKernelPatches --- overlay/overlay.nix | 6 ------ 1 file changed, 6 deletions(-) diff --git a/overlay/overlay.nix b/overlay/overlay.nix index 9a72624e7..e7be1bf1a 100644 --- a/overlay/overlay.nix +++ b/overlay/overlay.nix @@ -44,12 +44,6 @@ in ; }; - # Default set of kernel patches. - defaultKernelPatches = with self.kernelPatches; [ - bridge_stp_helper - p9_fixes - ]; - # # New software to upstream # ------------------------ From 36a99a3711de8d3186866179c54976834622a68d Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 2 Oct 2020 20:41:42 -0400 Subject: [PATCH 32/32] doc: Add kernel-builder documentation --- doc/in-depth/kernel-builder.adoc | 93 ++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 doc/in-depth/kernel-builder.adoc diff --git a/doc/in-depth/kernel-builder.adoc b/doc/in-depth/kernel-builder.adoc new file mode 100644 index 000000000..44087933e --- /dev/null +++ b/doc/in-depth/kernel-builder.adoc @@ -0,0 +1,93 @@ += Notes about the kernel builder +include::_support/common.inc[] + +The “Kernel builder” is a set of attributes available on the `mobile-nixos` +attribute overlaid on top of Nixpkgs. + +``` +mobile-nixos.kernel-builder +mobile-nixos.kernel-builder-clang_9 +mobile-nixos.kernel-builder-gcc49 +mobile-nixos.kernel-builder-gcc6 +``` + +At the base level, they are made available pre-versioned with a +compiler-specific `stdenv` so that OEM kernels requiring a specific compiler to +either build or boot can use the right compiler version. + +The kernel builder additionally provides configuration options to work with +common quirks in kernel builds. + + +== Choosing the right builder + +There is no clear and fast rule for this. The most likely suggestion is to look +at the kernel version string for a kernel built from the sources you are using. +It should describe the compiler being used. + +Another way to figure out which builder to use is to compare kernel derivations +either for devices using the same SoC. It often happens that basic quirks like +requiring specific compilers are rooted in changes from the first party that +forked the kernels, the SoC vendor. + + +== Choosing quirks + +=== `isQcdt` + +When true, the build will use `dtbTool` to build a QCDT _device-tree image_. + +By default it will use the FDTs from the appropriate `arch/*/boot` folder from +the kernel build. The directory to use can be changed using `qcdt_dtbs`. + +=== `isImageGzDtb` + +When true, the build will enable support for android-specific "Image.gz-dtb" +appended images. + +It is most likely this is needed if `isQcdt` is not used for Android-based +devices. + +=== `isCompressed` + +Set to the compression algorithm for the kernel. For the time being only `"gz"` +or `false` are valid values. By default it is `"gz"`. + +=== `enableRemovingWerror` + +Goes through all `Makefile` files from the kernel source tree and removes the +instances of `-Werror`. + +This is generally used when building a kernel with a newer compiler than which +was used when the kernel was authored. + +=== `enableCompilerGcc6Quirk` + +When true, a `compiler-gcc6.h` is added to the expected location for the kernel +build. This is generally only needed for older kernels. + +=== `enableCenteredLinuxLogo` + +When enabled, the kernel source will be patched to force only one instance of +the _logo_ to be shown, and centered on the display. + +This is used to provide a graphical element before the stage-1 init is running. + +This is enabled by default. Note that on some systems the feature does not work +even when enabled. Keep it enabled as it is a no-op. + +=== `enableLinuxLogoReplacement` + +When enabled, the file `linuxLogo224PPMFile` points at will be used to replace +the `drivers/video/logo/logo_linux_clut224.ppm` file in the kernel source tree. + +This effectively replaces the Tux logo. + +By default an appropriate file is provided by Mobile NixOS. + + +== Making a new port + +There is no porting guides yet. The current recommendation is to look for a +kernel derivation from a device using the same or a similar SoC and use it as +a starting point.