Compare commits

..

No commits in common. "a834656fefc368201e762efe543d5346eeabff18" and "45d52a6c9957173dbad234ee5232a62700f75337" have entirely different histories.

11 changed files with 231 additions and 172 deletions

View File

@ -413,26 +413,3 @@ them work with a kernel for the other
As a result: now we have eth0 appearing, but not eth1? Guessing we
need to add some kconfig for the switch
Mon Oct 17 21:23:37 BST 2022
we are spending ridiculous amounts of cpu/io time copying kernel source
trees from place to place, because we have kernel tree preparation
and actual building as two separate derivations.
I think the answer is to have a generic kernel build derivation
in the overlay, and then have the device overlays override it with
an additional phase to do openwrt patching or whatever else they
need to do.
Tue Oct 18 23:02:43 BST 2022
* previous TODO list is Aug 02, need to review
* dts is hardcoded to gl-ar750, that needs cleaning up
* figure out persistent addresses for ethernet
* fix halt/reboot
* "link" services have a "device" attribute, would much rather
have everything referenced using outputs than having two
different mechanisms for reading similar things
* Kconfig.local do we still need it?
* check all config instead of differentiating config/checkedConfig

View File

@ -6,7 +6,7 @@
let
overlay = import ./overlay.nix;
nixpkgs = import <nixpkgs> (device.system // {overlays = [overlay device.overlay]; });
inherit (nixpkgs) callPackage writeText liminix fetchFromGitHub;
inherit (nixpkgs.pkgs) callPackage writeText liminix;
inherit (nixpkgs.lib) concatStringsSep;
config = (import ./merge-modules.nix) [
./modules/base.nix
@ -15,36 +15,25 @@ let
./modules/s6
./modules/users.nix
(if phram then ./modules/phram.nix else (args: {}))
] nixpkgs;
] nixpkgs.pkgs;
squashfs = liminix.builders.squashfs config.filesystem.contents;
openwrt = fetchFromGitHub {
name = "openwrt-source";
repo = "openwrt";
owner = "openwrt";
rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab";
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
kernel = callPackage ./kernel {
inherit (config.kernel) config checkedConfig;
};
outputs = rec {
inherit squashfs;
kernel = nixpkgs.kernel.override {
inherit (config.kernel) config checkedConfig;
inherit squashfs kernel;
dtb = kernel.dtb {
dts = "qca9531_glinet_gl-ar750.dts";
};
dtb = (callPackage ./kernel/dtb.nix {}) {
dts = "${openwrt}/target/linux/ath79/dts/qca9531_glinet_gl-ar750.dts";
includes = [
"${openwrt}/target/linux/ath79/dts"
"${kernel.headers}/include"
];
};
uimage = (callPackage ./kernel/uimage.nix {}) {
uimage = kernel.uimage {
commandLine = concatStringsSep " " config.boot.commandLine;
inherit (device.boot) loadAddress entryPoint;
inherit kernel;
inherit (kernel) vmlinux;
inherit dtb;
};
combined-image = nixpkgs.runCommand "firmware.bin" {
combined-image = nixpkgs.pkgs.runCommand "firmware.bin" {
nativeBuildInputs = [ nixpkgs.buildPackages.ubootTools ];
} ''
mkdir $out
@ -59,7 +48,7 @@ let
squashfsSize = 8;
cmd = "mtdparts=phram0:${toString squashfsSize}M(nix) phram.phram=phram0,0x${toHexString squashfsStart},${toString squashfsSize}Mi memmap=${toString squashfsSize}M\$0x${toHexString squashfsStart} root=1f00";
in
nixpkgs.buildPackages.writeScript "firmware.bin" ''
nixpkgs.pkgs.buildPackages.writeScript "firmware.bin" ''
setenv serverip 192.168.8.148
setenv ipaddr 192.168.8.251
setenv bootargs '${concatStringsSep " " config.boot.commandLine} ${cmd}'
@ -67,13 +56,13 @@ let
bootm 0x${toHexString uimageStart}
'';
directory = nixpkgs.runCommand "liminix" {} (''
directory = nixpkgs.pkgs.runCommand "liminix" {} (''
mkdir $out
cd $out
ln -s ${squashfs} squashfs
ln -s ${kernel} vmlinux
ln -s ${kernel.vmlinux} vmlinux
ln -s ${manifest} manifest
ln -s ${kernel.headers} build
ln -s ${kernel.vmlinux.modulesupport} build
'' +
(if device ? boot then ''
ln -s ${uimage} uimage
@ -83,7 +72,7 @@ let
# this exists so that you can run "nix-store -q --tree" on it and find
# out what's in the image, which is nice if it's unexpectedly huge
manifest = writeText "manifest.json" (builtins.toJSON config.filesystem.contents);
tftpd = nixpkgs.buildPackages.tufted;
tftpd = nixpkgs.pkgs.buildPackages.tufted;
};
in {
outputs = outputs // { default = outputs.${device.outputs.default}; };

View File

@ -32,33 +32,47 @@
overlay = final: prev:
let
openwrt = final.fetchFromGitHub {
inherit (final) fetchFromGitHub fetchgit stdenvNoCC;
openwrt = fetchFromGitHub {
name = "openwrt-source";
repo = "openwrt";
owner = "openwrt";
rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab";
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
};
mainline = fetchFromGitHub {
name = "kernel-source";
owner = "torvalds";
repo = "linux";
rev = "90c7e9b400c751dbd73885f494f421f90ca69721";
hash = "sha256-pq6QNa0PJVeheaZkuvAPD0rLuEeKrViKk65dz+y4kqo=";
};
in {
kernel = prev.kernel.override {
src = final.fetchurl {
name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz";
hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8=";
sources = {
inherit openwrt;
kernel = stdenvNoCC.mkDerivation {
name = "spindled-kernel-tree";
src = mainline;
phases = [
"unpackPhase" "patchPhase" "openWrtPatchPhase"
"patchScripts" "installPhase"
];
patches = [ ../../kernel/random.patch ];
patchScripts = ''
patchShebangs scripts/
'';
openWrtPatchPhase = ''
cp -av ${openwrt}/target/linux/generic/files/* .
chmod -R u+w .
cp -av ${openwrt}/target/linux/ath79/files/* .
chmod -R u+w .
for i in ${openwrt}/target/linux/ath79/patches-5.15/* ; do patch --batch --forward -p1 < $i ;done
'';
installPhase = ''
mkdir -p $out
cp -a . $out
'';
};
extraPatchPhase = ''
cp -av ${openwrt}/target/linux/generic/files/* .
chmod -R u+w .
cp -av ${openwrt}/target/linux/ath79/files/* .
chmod -R u+w .
patches() {
for i in $* ; do patch --batch --forward -p1 < $i ;done
}
patches ${openwrt}/target/linux/generic/backport-5.15/*.patch
patches ${openwrt}/target/linux/generic/pending-5.15/*.patch
patches ${openwrt}/target/linux/generic/hack-5.15/*.patch
patches ${openwrt}/target/linux/ath79/patches-5.15/*.patch
'';
};
};
kernel = rec {
@ -68,6 +82,8 @@
USE_OF = "y";
ATH79 = "y";
LIMINIX = "y";
SERIAL_8250_CONSOLE = "y";
SERIAL_8250 = "y";
SERIAL_CORE_CONSOLE = "y";
@ -95,11 +111,10 @@
NET_VENDOR_ATHEROS = "y";
AG71XX = "y"; # ethernet (qca,qca9530-eth)
MFD_SYSCON = "y"; # ethernet (compatible "syscon")
AR8216_PHY = "y"; # eth1 is behind a switch
MTD = "y";
MTD_CMDLINE_PARTS = "y";
MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs
};
config = {
CPU_LITTLE_ENDIAN= "n";
CPU_BIG_ENDIAN= "y";
# this is all copied from nixwrt ath79 config. Clearly not all
@ -107,6 +122,7 @@
# installation method config or ...
"CMDLINE_PARTITION" = "y";
"DEBUG_INFO" = "y";
"EARLY_PRINTK" = "y";
"FW_LOADER" = "y";
# we don't have a user helper, so we get multiple 60s pauses
@ -114,11 +130,27 @@
"FW_LOADER_USER_HELPER" = "n";
"MODULE_SIG" = "y";
"MTD_CMDLINE_PARTS" = "y";
"PARTITION_ADVANCED" = "y";
"PRINTK_TIME" = "y";
"SQUASHFS" = "y";
"SQUASHFS_XZ" = "y";
# "ASN1" = "y";
# "ASYMMETRIC_KEY_TYPE" = "y";
# "ASYMMETRIC_PUBLIC_KEY_SUBTYPE" = "y";
# "CRC_CCITT" = "y";
# "CRYPTO" = "y";
# "CRYPTO_ARC4" = "y";
# "CRYPTO_CBC" = "y";
# "CRYPTO_CCM" = "y";
# "CRYPTO_CMAC" = "y";
# "CRYPTO_GCM" = "y";
# "CRYPTO_HASH_INFO" = "y";
# "CRYPTO_LIB_ARC4" = "y";
# "CRYPTO_RSA" = "y";
# "CRYPTO_SHA1" = "y";
# "ENCRYPTED_KEYS" = "y";
# "KEYS" = "y";
};
};
outputs.default = "directory";

View File

@ -14,40 +14,157 @@
};
overlay = final: prev:
let inherit (final) stdenvNoCC fetchFromGitHub;
let inherit (final) fetchFromGitHub;
in {
kernel = prev.kernel.override {
# using fetchurl not fetchzip because it doesn't unpack, and
# copying 6GB of data from one store location to another
# takes an absolute bloody age
src = final.fetchurl {
name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.19.16.tar.gz";
hash = "sha256-m4NeoEsCEK0HSIKTZ6zYTgk1fD3W0PSOMXN6fyHpkP8=";
sources = {
kernel = fetchFromGitHub {
name = "kernel-source";
owner = "torvalds";
repo = "linux";
rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19
hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4=";
};
};
};
kernel = {
checkedConfig = {
config = {
SYSVIPC= "y";
NO_HZ= "y";
HIGH_RES_TIMERS= "y";
LOG_BUF_SHIFT = "15";
NAMESPACES= "y";
RELAY= "y";
EXPERT= "y";
PERF_EVENTS= "y";
COMPAT_BRK= "n";
SLAB= "y";
MIPS_MALTA= "y";
CPU_LITTLE_ENDIAN= "n";
CPU_BIG_ENDIAN= "y";
CPU_MIPS32_R2= "y";
SQUASHFS = "y";
SQUASHFS_XZ = "y";
VIRTIO_MENU = "y";
PCI = "y";
VIRTIO_PCI = "y";
BLOCK = "y";
VIRTIO_BLK = "y";
NETDEVICES = "y";
VIRTIO_NET = "y";
PAGE_SIZE_16KB= "y";
NR_CPUS= "1";
HZ_100= "y";
PCI= "y";
VIRTUALIZATION= "y";
KVM_MIPS_DEBUG_COP0_COUNTERS= "y";
MODULES= "y";
MODULE_UNLOAD= "y";
MODVERSIONS= "y";
MODULE_SRCVERSION_ALL= "y";
NET= "y";
PACKET= "y";
UNIX= "y";
NET_KEY= "y";
NET_KEY_MIGRATE= "y";
INET= "y";
IP_MULTICAST= "y";
IP_ADVANCED_ROUTER= "y";
IP_MULTIPLE_TABLES= "y";
IP_ROUTE_MULTIPATH= "y";
IP_ROUTE_VERBOSE= "y";
IP_PNP= "y";
IP_PNP_DHCP= "y";
IP_PNP_BOOTP= "y";
IP_MROUTE= "y";
IP_PIMSM_V1= "y";
IP_PIMSM_V2= "y";
SYN_COOKIES= "y";
TCP_MD5SIG= "y";
IPV6_ROUTER_PREF= "y";
IPV6_ROUTE_INFO= "y";
IPV6_OPTIMISTIC_DAD= "y";
IPV6_MROUTE= "y";
IPV6_PIMSM_V2= "y";
NETWORK_SECMARK= "y";
NETFILTER= "y";
NF_CONNTRACK_SECMARK= "y";
NF_CONNTRACK_EVENTS= "y";
IP_VS_IPV6= "y";
IP_VS_PROTO_TCP= "y";
IP_VS_PROTO_UDP= "y";
IP_VS_PROTO_ESP= "y";
IP_VS_PROTO_AH= "y";
VLAN_8021Q_GVRP= "y";
IPDDP_ENCAP= "y";
NET_SCHED= "y";
NET_CLS_ACT= "y";
NET_ACT_POLICE= "y";
GACT_PROB= "y";
MTD= "y";
MTD_BLOCK= "y";
MTD_CFI= "y";
MTD_CFI_INTELEXT= "y";
MTD_CFI_AMDSTD= "y";
MTD_CFI_STAA= "y";
MTD_PHYSMAP_OF= "y";
BLK_DEV_RAM= "y";
BLK_DEV_SD= "y";
BLK_DEV_SR= "y";
SCSI_CONSTANTS= "y";
SCSI_LOGGING= "y";
SCSI_SCAN_ASYNC= "y";
AIC7XXX_RESET_DELAY_MS="15000";
AIC7XXX_DEBUG_ENABLE= "n";
ATA= "y";
ATA_PIIX= "y";
PATA_OLDPIIX= "y";
PATA_MPIIX= "y";
ATA_GENERIC= "y";
PATA_LEGACY= "y";
MD= "y";
NETDEVICES= "y";
PCNET32= "y";
IPW2100_MONITOR= "y";
HOSTAP_FIRMWARE= "y";
HOSTAP_FIRMWARE_NVRAM= "y";
INPUT_MOUSEDEV= "y";
SERIAL_8250= "y";
SERIAL_8250_CONSOLE= "y";
POWER_RESET= "y";
POWER_RESET_PIIX4_POWEROFF= "y";
POWER_RESET_SYSCON= "y";
HWMON= "n";
FB= "y";
FB_CIRRUS= "y";
VGA_CONSOLE= "n";
FRAMEBUFFER_CONSOLE= "y";
RTC_CLASS= "y";
RTC_DRV_CMOS= "y";
EXT2_FS= "y";
EXT3_FS= "y";
JFS_POSIX_ACL= "y";
JFS_SECURITY= "y";
QUOTA= "y";
QFMT_V2= "y";
JOLIET= "y";
ZISOFS= "y";
PROC_KCORE= "y";
TMPFS= "y";
CONFIGFS_FS= "y";
JFFS2_FS_XATTR= "y";
JFFS2_COMPRESSION_OPTIONS= "y";
JFFS2_RUBIN= "y";
# NFS_FS= "y";
# ROOT_NFS= "y";
# NFSD= "y";
# NFSD_V3= "y";
CRYPTO_HMAC= "y";
RCU_CPU_STALL_TIMEOUT = "60";
ENABLE_DEFAULT_TRACERS = "y";
CFG80211= "y";
MAC80211= "y";
MAC80211_MESH= "y";
RFKILL= "y";
WLAN = "y";
MAC80211_HWSIM = "y";
SQUASHFS = "y";
SQUASHFS_XZ = "y";
VIRTIO_PCI = "y";
VIRTIO_BLK = "y";
VIRTIO_NET = "y";
};
};
outputs.default = "directory";

View File

@ -1,10 +1,15 @@
{
stdenv
, openwrt
, dtc
, kernel
}:
{ dts
, includes
}:let
includes = [
"${openwrt}/target/linux/ath79/dts"
"${kernel}/include"
];
cppDtSearchFlags = builtins.concatStringsSep " " (map (f: "-I${f}") includes);
dtcSearchFlags = builtins.concatStringsSep " " (map (f: "-i${f}") includes);
in stdenv.mkDerivation {
@ -12,7 +17,7 @@ in stdenv.mkDerivation {
phases = [ "buildPhase" ];
nativeBuildInputs = [ dtc ];
buildPhase = ''
${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${dts}
${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${openwrt}/target/linux/ath79/dts/${dts}
dtc ${dtcSearchFlags} -I dts -O dtb -o $out dtb.tmp
test -e $out
'';

View File

@ -7,7 +7,7 @@
let
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
in {
kernel
vmlinux
, commandLine
, entryPoint
, extraName ? "" # e.g. socFamily
@ -28,7 +28,7 @@ stdenv.mkDerivation {
ubootTools
];
preparePhase = ''
cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
cp ${vmlinux} vmlinux.elf; chmod +w vmlinux.elf
'';
dtbPhase = ''
dtc -I dtb -O dts -o tmp.dts ${dtb}

View File

@ -6,8 +6,7 @@
, config
, checkedConfig ? {}
, src
, extraPatchPhase ? "true"
, tree
} :
let writeConfig = name : config: writeText name
(builtins.concatStringsSep
@ -31,8 +30,8 @@ let writeConfig = name : config: writeText name
checkedConfigFile = writeConfig "checked_kconfig" checkedConfig ;
inherit lib; in
stdenv.mkDerivation rec {
name = "kernel";
inherit src extraPatchPhase;
name = "vmlinux";
hardeningDisable = ["all"];
nativeBuildInputs = [buildPackages.stdenv.cc] ++
(with buildPackages.pkgs;
@ -45,16 +44,11 @@ stdenv.mkDerivation rec {
PKG_CONFIG_PATH = "./pkgconfig";
CROSS_COMPILE = stdenv.cc.bintools.targetPrefix;
ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel
KBUILD_BUILD_HOST = "liminix.builder";
dontStrip = true;
dontPatchELF = true;
outputs = ["out" "headers"];
outputs = ["out" "modulesupport"];
phases = [
"unpackPhase"
"butcherPkgconfig"
"extraPatchPhase"
"patchScripts"
"configurePhase"
"checkConfigurationPhase"
"buildPhase"
@ -73,16 +67,12 @@ stdenv.mkDerivation rec {
for i in pkgconfig/*.pc; do test -f $i && sed -i 's/^Libs:/Libs: -L''${libdir} /' $i;done
'';
patchScripts = ''
patchShebangs scripts/
'';
configurePhase = ''
export KBUILD_OUTPUT=`pwd`
cp ${kconfigFile} .config
cp ${kconfigFile} .config.orig
cp ${kconfigLocal} Kconfig.local
make V=1 olddefconfig
( cd ${tree} && make V=1 olddefconfig )
'';
checkConfigurationPhase = ''
@ -94,15 +84,18 @@ stdenv.mkDerivation rec {
echo "OK"
'';
KBUILD_BUILD_HOST = "liminix.builder";
buildPhase = ''
make vmlinux modules_prepare
make -C ${tree} vmlinux modules_prepare
'';
installPhase = ''
${CROSS_COMPILE}strip -d vmlinux
cp vmlinux $out
mkdir -p $headers
cp -a include .config $headers/
mkdir -p $modulesupport
cp .config $modulesupport/config
make clean
cp -a . $modulesupport
'';
}

View File

@ -56,14 +56,6 @@ in {
MODULES = "y";
# basic networking protocols
NET = "y";
UNIX = "y";
INET = "y";
IPV6 = "y";
PACKET = "y"; # for ppp, tcpdump ...
SYSVIPC= "y";
# s6-linux-init mounts this on /dev
DEVTMPFS = "y";
# some or all of these may be fix for "tmpfs: Unknown parameter 'mode'" error

View File

@ -1,38 +0,0 @@
{ lib, pkgs, config, ...}:
let
inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ;
inherit (pkgs.pseudofile) dir symlink;
inherit (pkgs) busybox;
in {
config = {
kernel = rec {
checkedConfig = {
CFG80211= "y";
MAC80211= "y";
MAC80211_MESH= "y";
RFKILL= "y";
WLAN = "y";
# if/when we switch to using backported mac80211 drivers built
# as modules, based on nixwrt code we expect we will need this config
# to enable them
# "ASN1" = "y";
# "ASYMMETRIC_KEY_TYPE" = "y";
# "ASYMMETRIC_PUBLIC_KEY_SUBTYPE" = "y";
# "CRC_CCITT" = "y";
# "CRYPTO" = "y";
# "CRYPTO_ARC4" = "y";
# "CRYPTO_CBC" = "y";
# "CRYPTO_CCM" = "y";
# "CRYPTO_CMAC" = "y";
# "CRYPTO_GCM" = "y";
# "CRYPTO_HASH_INFO" = "y";
# "CRYPTO_LIB_ARC4" = "y";
# "CRYPTO_RSA" = "y";
# "CRYPTO_SHA1" = "y";
# "ENCRYPTED_KEYS" = "y";
# "KEYS" = "y";
};
};
};
}

View File

@ -12,7 +12,6 @@ final: prev: {
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
s6-rc-database = final.callPackage ./pkgs/s6-rc-database {};
kernel = final.callPackage ./pkgs/kernel {};
dnsmasq =
let d = prev.dnsmasq.overrideAttrs(o: {

View File

@ -13,13 +13,6 @@ in rec {
];
};
imports = [ ../../modules/wlan.nix ];
kernel.checkedConfig = {
MAC80211_HWSIM = "y";
};
services.wlan = interface { type = "hardware"; device = "wlan0"; };
services.hostap = hostapd (services.wlan) {