2023-05-02 01:19:16 +00:00
|
|
|
{ lib
|
|
|
|
, buildLinux
|
2023-08-15 10:49:07 +00:00
|
|
|
, fetchpatch
|
2023-09-10 11:47:05 +00:00
|
|
|
, fetchFromGitea
|
2023-05-03 10:19:40 +00:00
|
|
|
, pkgs
|
2023-08-18 02:20:38 +00:00
|
|
|
# modem_power is incompatible with eg25-manager: <https://gitlab.com/mobian1/eg25-manager/-/issues/38>
|
|
|
|
, withModemPower ? true
|
2023-08-11 21:30:50 +00:00
|
|
|
# something inside nixpkgs calls `override` on the kernel and passes in extra arguments
|
2023-05-02 01:19:16 +00:00
|
|
|
, ...
|
2023-08-11 21:30:50 +00:00
|
|
|
}@args:
|
2022-08-09 21:39:42 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2022-12-03 08:41:23 +00:00
|
|
|
let
|
2023-05-03 22:48:07 +00:00
|
|
|
# HOW TO UPDATE:
|
2023-10-03 00:29:42 +00:00
|
|
|
# - see: <https://xnux.eu/log/094.html>
|
2023-09-10 11:47:05 +00:00
|
|
|
# - `wget https://xff.cz/kernels/git/orange-pi-active.bundle`
|
|
|
|
# - `git fetch torvalds`
|
2024-03-29 18:18:37 +00:00
|
|
|
# - `curl -o .bundle https://xff.cz/kernels/git/orange-pi-active.bundle`
|
|
|
|
# - `git fetch .bundle '+refs/heads/*:refs/remotes/megi/*'`
|
|
|
|
# - OR: `git bundle unbundle .bundle`
|
2023-09-10 11:47:05 +00:00
|
|
|
# - there should be some new tag, like `refs/tags/orange-pi-6.4-20230907-1427`
|
2023-10-03 00:29:42 +00:00
|
|
|
# checkout the revision associated with the tag, then:
|
|
|
|
# - manually retag it, because `git bundle` doesn't actually import the tag
|
2023-11-25 05:41:50 +00:00
|
|
|
# - `git checkout <commit> ; git tag <tagname>`
|
2023-10-03 00:29:42 +00:00
|
|
|
# - `git push origin <tag>`
|
2023-05-12 10:35:33 +00:00
|
|
|
# - grab VERSION/PATCHLEVEL/SUBLEVEL/EXTRAVERSION from Makefile.
|
2024-02-01 12:51:53 +00:00
|
|
|
# - `rg '^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION) =' Makefile`
|
|
|
|
# for extra safety, pin to the same version as postmarketOS, in pmaports:
|
|
|
|
# - device/main/linux-postmarketos-allwinner/APKBUILD
|
|
|
|
# if `withModemPower = false` then update the commit for the "drop-modem-power" patch from pmOS, below
|
|
|
|
#
|
|
|
|
# build via: `nix build '.#hostConfigs.moby.boot.kernelPackages.kernel'`
|
2023-10-03 00:29:42 +00:00
|
|
|
#
|
2023-07-13 23:36:22 +00:00
|
|
|
# - megi publishes release notes as the most recent commit on any release tag, so just `git show` or `git log`
|
2023-05-03 22:48:07 +00:00
|
|
|
# - orange-pi is listed as the "main integration branch".
|
2023-07-13 23:36:22 +00:00
|
|
|
# - this suggests it's NOT a stable branch, only `orange-pi-X.YY-YYYYMMDD-NNNN` tags are "formal" releases
|
2023-05-03 22:48:07 +00:00
|
|
|
# - specific branches like `pp` (pinephone) are dev branches, and probably less stable.
|
2024-03-29 18:18:37 +00:00
|
|
|
rev = "orange-pi-6.7-20240306-2359";
|
|
|
|
base = "6.7.9";
|
|
|
|
hash = "sha256-UQanb0l9yNWrccQLuKNln4CfvoaMy9zDKtBhnDG7yPE=";
|
2023-05-12 10:35:33 +00:00
|
|
|
# set to empty if not a release candidate, else `-rc<N>`
|
2023-08-21 04:49:46 +00:00
|
|
|
rc = "";
|
2023-05-03 22:48:07 +00:00
|
|
|
|
|
|
|
# pinephone uses the linux dtb at arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi
|
|
|
|
# - this includes sun50i-a64.dtsi
|
|
|
|
# - and sun50i-a64-cpu-opp.dtsi
|
|
|
|
# - no need to touch the allwinner-h6 stuff: that's the SBC pine product
|
|
|
|
# - i think it's safe to ignore sun9i stuff, but i don't know what it is
|
|
|
|
kernelConfig = with lib.kernel; {
|
|
|
|
# NB: nix adds the CONFIG_ prefix to each of these.
|
|
|
|
# if you add the prefix yourself nix will IGNORE YOUR CONFIG.
|
2023-08-11 21:30:50 +00:00
|
|
|
|
|
|
|
# optimize for faster builds.
|
|
|
|
# see <repo:kernel.org/linux:Documentation/admin-guide/quickly-build-trimmed-linux.rst>
|
|
|
|
DEBUG_KERNEL = lib.mkForce no; # option group which seems to just gate the other DEBUG_ opts?
|
|
|
|
DEBUG_INFO = lib.mkForce no; # for gdb debugging
|
|
|
|
DEBUG_INFO_BTF = lib.mkForce no; # BPF debug symbols. rec by <https://nixos.wiki/wiki/Linux_kernel#Too_high_ram_usage>
|
2023-10-11 05:39:47 +00:00
|
|
|
# SCHED_DEBUG = lib.mkForce no; # determines /sys/kernel/debug/sched
|
2023-08-11 21:30:50 +00:00
|
|
|
# SUNRPC_DEBUG = lib.mkForce no; # i use NFS though
|
|
|
|
|
2023-08-18 02:20:38 +00:00
|
|
|
MODEM_POWER = lib.mkIf (!withModemPower) no;
|
2023-09-10 11:47:05 +00:00
|
|
|
# normally a module; try inline? for vibration/haptics
|
|
|
|
INPUT_GPIO_VIBRA = yes;
|
2023-09-10 12:56:37 +00:00
|
|
|
INPUT_PWM_VIBRA = yes;
|
|
|
|
PWM_SUN4I = yes;
|
|
|
|
# DRM_SUN4I = yes;
|
|
|
|
# DRM_SUN8I_MIXER = yes;
|
|
|
|
# DRM_SUN6I_DSI = yes;
|
2023-08-15 10:49:07 +00:00
|
|
|
|
2023-08-11 21:30:50 +00:00
|
|
|
# taken from mobile-nixos config?? or upstream megous config??
|
2023-05-03 22:48:07 +00:00
|
|
|
RTL8723CS = module;
|
|
|
|
BT_HCIUART_3WIRE = yes;
|
|
|
|
BT_HCIUART_RTL = yes;
|
|
|
|
RTL8XXXU_UNTESTED = yes;
|
|
|
|
BT_BNEP_MC_FILTER = yes;
|
|
|
|
BT_BNEP_PROTO_FILTER = yes;
|
|
|
|
BT_HS = yes;
|
|
|
|
BT_LE = yes;
|
|
|
|
#
|
|
|
|
### BUILD FIXES, NOT SPECIFIC TO MY PREFERENCES
|
|
|
|
#
|
|
|
|
# disabling the sun5i_eink driver avoids this compilation error:
|
|
|
|
# CC [M] drivers/video/fbdev/sun5i-eink-neon.o
|
|
|
|
# aarch64-unknown-linux-gnu-gcc: error: unrecognized command line option '-mfloat-abi=softfp'
|
|
|
|
# aarch64-unknown-linux-gnu-gcc: error: unrecognized command line option '-mfpu=neon'
|
|
|
|
# make[3]: *** [../scripts/Makefile.build:289: drivers/video/fbdev/sun5i-eink-neon.o] Error 1
|
|
|
|
FB_SUN5I_EINK = no;
|
|
|
|
# used by the pinephone pro, but fails to compile with:
|
|
|
|
# ../drivers/media/i2c/ov8858.c:1834:27: error: implicit declaration of function 'compat_ptr'
|
|
|
|
VIDEO_OV8858 = no;
|
2023-11-25 05:41:50 +00:00
|
|
|
BES2600 = no; # fails to compile
|
2023-05-03 22:48:07 +00:00
|
|
|
#
|
|
|
|
### RELEVANT CONFIGS INHERITED FROM NIXOS DEFAULTS (OR ABOVE ADDITIONS):
|
|
|
|
#
|
|
|
|
# CONFIG_BT=m
|
|
|
|
# CONFIG_BT_BREDR=y
|
|
|
|
# CONFIG_BT_RFCOMM=m
|
|
|
|
# CONFIG_BT_RFCOMM_TTY=y
|
|
|
|
# CONFIG_BT_BNEP=m
|
|
|
|
# CONFIG_BT_HIDP=m
|
|
|
|
# CONFIG_BT_RTL=m
|
|
|
|
# CONFIG_BT_HCIBTUSB=m
|
|
|
|
# CONFIG_BT_HCIBTUSB_BCM=y
|
|
|
|
# CONFIG_BT_HCIBTUSB_RTL=y
|
|
|
|
# CONFIG_BT_HCIUART=m
|
|
|
|
# CONFIG_BT_HCIUART_SERDEV=y
|
|
|
|
# CONFIG_BT_HCIUART_H4=y
|
|
|
|
# CONFIG_BT_HCIUART_LL=y
|
|
|
|
# CONFIG_RTL_CARDS=m
|
|
|
|
# CONFIG_RTLWIFI=m
|
|
|
|
# CONFIG_RTLWIFI_PCI=m
|
|
|
|
# CONFIG_RTLWIFI_USB=m
|
|
|
|
# CONFIG_RTLWIFI_DEBUG=y
|
|
|
|
# CONFIG_RTL8723_COMMON=m
|
|
|
|
# CONFIG_RTLBTCOEXIST=m
|
|
|
|
# CONFIG_RTL8XXXU=m
|
|
|
|
# CONFIG_RTLLIB=m
|
|
|
|
# consider adding (from mobile-nixos):
|
|
|
|
# maybe: CONFIG_BT_HCIUART_3WIRE=y
|
|
|
|
# maybe: CONFIG_BT_HCIUART_RTL=y
|
|
|
|
# maybe: CONFIG_RTL8XXXU_UNTESTED=y
|
|
|
|
# consider adding (from manjaro):
|
|
|
|
# CONFIG_BT_6LOWPAN=m (not listed as option in nixos kernel)
|
|
|
|
# these are referenced in the rtl8723 source, but not known to config (and not in mobile-nixos config
|
|
|
|
# maybe: CONFIG_RTL_ODM_WLAN_DRIVER
|
|
|
|
# maybe: CONFIG_RTL_TRIBAND_SUPPORT
|
|
|
|
# maybe: CONFIG_SDIO_HCI
|
|
|
|
# maybe: CONFIG_USB_HCI
|
|
|
|
};
|
|
|
|
|
2023-05-03 10:19:40 +00:00
|
|
|
# `pkgs.kernelPatches` is a set of common patches
|
|
|
|
# while `kernelPatches` callarg is a list.
|
|
|
|
# weird idiom, means we have to access pkgs.kernelPatches to access the actual patch directory:
|
|
|
|
extraKernelPatches = [
|
|
|
|
pkgs.kernelPatches.bridge_stp_helper
|
|
|
|
pkgs.kernelPatches.request_key_helper
|
2023-08-11 21:30:50 +00:00
|
|
|
# (patchDefconfig kernelConfig)
|
2023-10-08 17:12:09 +00:00
|
|
|
# wake on wireless lan (WOWLAN) patches:
|
|
|
|
# see: <https://gist.github.com/Peetz0r/bf8fd93a60962b4afcf2daeb4305da40>
|
|
|
|
# see: <https://xnux.eu/log/031.html>
|
|
|
|
# see: <https://irclog.whitequark.org/linux-sunxi/2021-02-19>
|
|
|
|
# most of the relevant bits here (e.g. CONFIG_WOWLAN=y) have been merged
|
2023-10-14 09:44:57 +00:00
|
|
|
# {
|
|
|
|
# # the pinephone device tree to `keep-power-in-suspend` for the WiFi peripherals
|
|
|
|
# # unclear if this is truly needed: a *different* piece of the device tree was set for keep-power-in-suspend
|
|
|
|
# # when megi merged Peetz0r's patch.
|
|
|
|
# # there appears to be support for WOWLAN even with this patch dropped.
|
|
|
|
# name = "pinephone-dt-keep-power-in-suspend";
|
|
|
|
# patch = fetchpatch {
|
|
|
|
# url = "https://git.uninsane.org/colin/linux/commit/afd6514fd3098047000b3f1f198c2256478dce46.patch";
|
|
|
|
# hash = "sha256-8OtGXpCPJbk3c3Z4DcurS0F+Ogqx+xahEv+256+4dcY=";
|
|
|
|
# };
|
|
|
|
# }
|
2023-10-08 17:12:09 +00:00
|
|
|
# {
|
|
|
|
# # experimental: set CONFIG_LPS_MODE = 0
|
|
|
|
# # uncertain what this does, LPS = "Leisure Power Savings"
|
|
|
|
# name = "disable-rtl8723cs-lps";
|
|
|
|
# patch = fetchpatch {
|
|
|
|
# url = "https://git.uninsane.org/colin/linux/commit/8bee908739b3b3aa505b22e558397d2d59060951.patch";
|
|
|
|
# hash = "sha256-DnLDseL1Ar5gE31CQUTrGNxxNu88jGCzj8ko99Z8vUA=";
|
|
|
|
# };
|
|
|
|
# }
|
2023-10-13 10:29:16 +00:00
|
|
|
# {
|
|
|
|
# # experimental: set CONFIG_ARP_KEEP_ALIVE and CONFIG_GTK_OL if CONFIG_WOWLAN=y
|
|
|
|
# # this patch just uncomments some commented-out #defines.
|
|
|
|
# # they were commented out from the first time megi imported this driver, never touched.
|
|
|
|
# # this may be problematic, occasionally requiring a driver re-probe. see other notes on wowlan/8723cs.
|
|
|
|
# # if continued errors, try removing the CONFIG_GTK_OL and keeping just CONFIG_ARP_KEEP_ALIVE.
|
|
|
|
# # seems to infrequently disrupt waking on ARP packets, as well.
|
|
|
|
# name = "enable-wowlan-offloads";
|
|
|
|
# patch = fetchpatch {
|
|
|
|
# url = "https://git.uninsane.org/colin/linux/commit/c4d2d12e31ae70bb43c6190eccc49e42ad645090.patch";
|
|
|
|
# hash = "sha256-B1rxeVu6y5hP/iMLSbl3ExwrEIXL7WShWsMFh6ko6yk=";
|
|
|
|
# };
|
|
|
|
# }
|
|
|
|
{
|
|
|
|
name = "pinephone: wowlan: disable unicast";
|
|
|
|
patch = fetchpatch {
|
|
|
|
url = "https://git.uninsane.org/colin/linux/commit/3b3328cfb35b6cea3480c6358faf4d4175146372.patch";
|
|
|
|
hash = "sha256-aBa63UHaU+KSWNzeXEamcMhJr2bRkJGZPTM7nBNu9wk=";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
# {
|
|
|
|
# name = "pinephone: wowlan: disable unicast/deauth/magic packet/arp";
|
|
|
|
# patch = fetchpatch {
|
|
|
|
# url = "https://git.uninsane.org/colin/linux/commit/624315afd2ebd44fc6d0056c206b502e50d92775.patch";
|
|
|
|
# hash = "sha256-KlgIJigK7G89obT7qWGdHqQ+eavYrCkuwo2d0wdUrpE=";
|
|
|
|
# };
|
|
|
|
# }
|
2023-10-10 05:24:57 +00:00
|
|
|
{
|
2023-10-13 10:29:16 +00:00
|
|
|
# enables /proc/net/rtl8723cs/wlan0/gpio_info and gpio_set_direction, gpio_set_output_value.
|
|
|
|
# `cat gpio_info` -> `get_gpio 0:0`
|
|
|
|
# writing to gpio_set_output_value does change the value of gpio_info, but not of
|
|
|
|
# /sys/kernel/debug/gpio
|
|
|
|
name = "pinephone: rtl8723cs: enable CONFIG_GPIO_API";
|
2023-10-10 05:24:57 +00:00
|
|
|
patch = fetchpatch {
|
2023-10-13 10:29:16 +00:00
|
|
|
url = "https://git.uninsane.org/colin/linux/commit/51dea574a4559bd30fda2b0f852e42cad6cb6757.patch";
|
|
|
|
hash = "sha256-pAmif5vMdZzgmyzkLmvdOltoXdeXeBeOhvGbpHWzIkc=";
|
2023-10-10 05:24:57 +00:00
|
|
|
};
|
|
|
|
}
|
2023-10-13 10:29:16 +00:00
|
|
|
# {
|
|
|
|
# # this changes the IRQ definition in the devicetree, and at runtime the decompiled
|
|
|
|
# # fdt shows this change, but /proc/interrupts still shows as an edge interrupt.
|
|
|
|
# # no IRQs or GPIOs were changed at all, actually.
|
|
|
|
# # likely something else is configuring the IRQ at runtime.
|
|
|
|
# name = "pinephone: rtl8723cs: IRQ on LEVEL_LOW instead of EDGE_FALLING";
|
|
|
|
# patch = fetchpatch {
|
|
|
|
# url = "https://git.uninsane.org/colin/linux/commit/223046eac02c5b1ca6203f68df495d35ce191280.patch";
|
|
|
|
# hash = "sha256-Quhvz7hiM3TbpZ2pKuHVXrO8OLn3r7WNYYIjQc1CWcQ=";
|
|
|
|
# };
|
|
|
|
# }
|
2023-08-18 02:20:38 +00:00
|
|
|
] ++ lib.optionals (!withModemPower) [
|
2023-08-15 10:49:07 +00:00
|
|
|
{
|
|
|
|
# Drop modem-power from DT to allow eg25-manager to have full control.
|
|
|
|
# source: <https://github.com/NixOS/mobile-nixos/pull/573>
|
|
|
|
name = "remove-modem-power-from-devicetree";
|
|
|
|
patch = fetchpatch {
|
2024-02-01 12:51:53 +00:00
|
|
|
url = "https://gitlab.com/postmarketOS/pmaports/-/raw/05a3c22d81591dd6b4b41a0ffebe1159be49b09b/device/main/linux-postmarketos-allwinner/0006-dts-pinephone-drop-modem-power-node.patch";
|
|
|
|
hash = "sha256-dyxlzp73hQ2AsaQbLIl0B7bR7Z1PHIMUS+CFN0kkMTs=";
|
2023-08-15 10:49:07 +00:00
|
|
|
};
|
|
|
|
}
|
2023-05-03 10:19:40 +00:00
|
|
|
];
|
2023-05-03 22:48:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
# create a kernelPatch which overrides nixos' defconfig with extra options
|
2023-08-11 21:30:50 +00:00
|
|
|
# patchDefconfig = config: {
|
|
|
|
# # defconfig options. this method comes from here:
|
|
|
|
# # - https://discourse.nixos.org/t/the-correct-way-to-override-the-latest-kernel-config/533/9
|
|
|
|
# name = "linux-megous-defconfig";
|
|
|
|
# patch = null;
|
|
|
|
# extraStructuredConfig = config;
|
|
|
|
# };
|
2023-05-03 22:48:07 +00:00
|
|
|
|
2023-08-11 21:30:50 +00:00
|
|
|
in buildLinux (args // {
|
|
|
|
version = base + rc;
|
2022-08-09 21:39:42 +00:00
|
|
|
|
2023-08-11 21:30:50 +00:00
|
|
|
# modDirVersion needs to be x.y.z, where `z` could be `Z-rcN`
|
|
|
|
# nix kernel build will sanity check us if we get the modDirVersion wrong
|
|
|
|
modDirVersion = base + rc;
|
2022-08-09 21:39:42 +00:00
|
|
|
|
2023-08-11 21:30:50 +00:00
|
|
|
# branchVersion needs to be x.y
|
|
|
|
extraMeta.branch = versions.majorMinor base;
|
2023-05-02 01:19:16 +00:00
|
|
|
|
2023-09-10 11:47:05 +00:00
|
|
|
src = fetchFromGitea {
|
|
|
|
domain = "git.uninsane.org";
|
|
|
|
owner = "colin";
|
2023-08-11 21:30:50 +00:00
|
|
|
repo = "linux";
|
|
|
|
inherit rev hash;
|
2022-08-09 21:39:42 +00:00
|
|
|
};
|
2023-08-11 21:30:50 +00:00
|
|
|
|
2023-09-22 19:48:51 +00:00
|
|
|
kernelPatches = extraKernelPatches ++ (
|
|
|
|
# this patch only applies to nixpkgs kernel (and is probably not necessary on megi's).
|
|
|
|
# TODO: remove the patch and this logic here once fixed in nixpkgs: <https://github.com/NixOS/nixpkgs/issues/255803>
|
|
|
|
lib.filter
|
|
|
|
(p: p.name != "backport-nfs4-selinux-fix")
|
|
|
|
(args.kernelPatches or [])
|
|
|
|
);
|
2023-08-11 21:30:50 +00:00
|
|
|
|
|
|
|
structuredExtraConfig = (args.structuredExtraConfig or {}) // kernelConfig;
|
|
|
|
})
|