Compare commits

..

9 Commits

Author SHA1 Message Date
Daniel Barlow a834656fef wot i thunk 2022-10-19 17:36:58 +01:00
Daniel Barlow 0a46ba7fc3 move some wifi-related comments into wlan module 2022-10-19 17:36:31 +01:00
Daniel Barlow f1b7780537 speed up kernel build
by having two separate derivations for patching the kernel source tree
and building it, we have to copy said source trees from one store
location to another which takes non-neglible time on spinning rust
(literally minutes on my machine). Replace with a single derivation
that can do more things on one tree in-place
2022-10-19 17:34:22 +01:00
Daniel Barlow d1dda7bf74 remove redundant nixpkgs.pkgs 2022-10-19 17:10:35 +01:00
Daniel Barlow 3ef30056c4 trim down the qemu kernel config
just retain the options we need to pass the tests
2022-10-18 22:28:07 +01:00
Daniel Barlow c6ed5d6f2d add ipv4/v6 to base kernel config 2022-10-18 18:56:29 +01:00
Daniel Barlow 026932a745 add unix-domain socket support
this is a curious config option to default to "n", I think
2022-10-18 15:48:37 +01:00
Daniel Barlow 3ff9e49085 enable eth1 2022-10-18 15:48:29 +01:00
Daniel Barlow c2bcf2dd3e fixup 4b513cd 2022-10-18 15:47:27 +01:00
11 changed files with 168 additions and 227 deletions

View File

@ -413,3 +413,26 @@ 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.pkgs) callPackage writeText liminix;
inherit (nixpkgs) callPackage writeText liminix fetchFromGitHub;
inherit (nixpkgs.lib) concatStringsSep;
config = (import ./merge-modules.nix) [
./modules/base.nix
@ -15,25 +15,36 @@ let
./modules/s6
./modules/users.nix
(if phram then ./modules/phram.nix else (args: {}))
] nixpkgs.pkgs;
] nixpkgs;
squashfs = liminix.builders.squashfs config.filesystem.contents;
kernel = callPackage ./kernel {
inherit (config.kernel) config checkedConfig;
openwrt = fetchFromGitHub {
name = "openwrt-source";
repo = "openwrt";
owner = "openwrt";
rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab";
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
};
outputs = rec {
inherit squashfs kernel;
dtb = kernel.dtb {
dts = "qca9531_glinet_gl-ar750.dts";
inherit squashfs;
kernel = nixpkgs.kernel.override {
inherit (config.kernel) config checkedConfig;
};
uimage = kernel.uimage {
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 {}) {
commandLine = concatStringsSep " " config.boot.commandLine;
inherit (device.boot) loadAddress entryPoint;
inherit (kernel) vmlinux;
inherit kernel;
inherit dtb;
};
combined-image = nixpkgs.pkgs.runCommand "firmware.bin" {
combined-image = nixpkgs.runCommand "firmware.bin" {
nativeBuildInputs = [ nixpkgs.buildPackages.ubootTools ];
} ''
mkdir $out
@ -48,7 +59,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.pkgs.buildPackages.writeScript "firmware.bin" ''
nixpkgs.buildPackages.writeScript "firmware.bin" ''
setenv serverip 192.168.8.148
setenv ipaddr 192.168.8.251
setenv bootargs '${concatStringsSep " " config.boot.commandLine} ${cmd}'
@ -56,13 +67,13 @@ let
bootm 0x${toHexString uimageStart}
'';
directory = nixpkgs.pkgs.runCommand "liminix" {} (''
directory = nixpkgs.runCommand "liminix" {} (''
mkdir $out
cd $out
ln -s ${squashfs} squashfs
ln -s ${kernel.vmlinux} vmlinux
ln -s ${kernel} vmlinux
ln -s ${manifest} manifest
ln -s ${kernel.vmlinux.modulesupport} build
ln -s ${kernel.headers} build
'' +
(if device ? boot then ''
ln -s ${uimage} uimage
@ -72,7 +83,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.pkgs.buildPackages.tufted;
tftpd = nixpkgs.buildPackages.tufted;
};
in {
outputs = outputs // { default = outputs.${device.outputs.default}; };

View File

@ -32,47 +32,33 @@
overlay = final: prev:
let
inherit (final) fetchFromGitHub fetchgit stdenvNoCC;
openwrt = fetchFromGitHub {
openwrt = final.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 {
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
'';
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=";
};
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 {
@ -82,8 +68,6 @@
USE_OF = "y";
ATH79 = "y";
LIMINIX = "y";
SERIAL_8250_CONSOLE = "y";
SERIAL_8250 = "y";
SERIAL_CORE_CONSOLE = "y";
@ -111,10 +95,11 @@
NET_VENDOR_ATHEROS = "y";
AG71XX = "y"; # ethernet (qca,qca9530-eth)
MFD_SYSCON = "y"; # ethernet (compatible "syscon")
AR8216_PHY = "y"; # eth1 is behind a switch
};
config = {
CPU_LITTLE_ENDIAN= "n";
MTD = "y";
MTD_CMDLINE_PARTS = "y";
MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs
CPU_BIG_ENDIAN= "y";
# this is all copied from nixwrt ath79 config. Clearly not all
@ -122,7 +107,6 @@
# 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
@ -130,27 +114,11 @@
"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,157 +14,40 @@
};
overlay = final: prev:
let inherit (final) fetchFromGitHub;
let inherit (final) stdenvNoCC fetchFromGitHub;
in {
sources = {
kernel = fetchFromGitHub {
name = "kernel-source";
owner = "torvalds";
repo = "linux";
rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19
hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4=";
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=";
};
};
};
kernel = {
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";
checkedConfig = {
MIPS_MALTA= "y";
CPU_LITTLE_ENDIAN= "n";
CPU_BIG_ENDIAN= "y";
CPU_MIPS32_R2= "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_MENU = "y";
PCI = "y";
VIRTIO_PCI = "y";
BLOCK = "y";
VIRTIO_BLK = "y";
NETDEVICES = "y";
VIRTIO_NET = "y";
SERIAL_8250= "y";
SERIAL_8250_CONSOLE= "y";
};
};
outputs.default = "directory";

View File

@ -1,15 +1,10 @@
{
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 {
@ -17,7 +12,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 ${openwrt}/target/linux/ath79/dts/${dts}
${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${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 {
vmlinux
kernel
, commandLine
, entryPoint
, extraName ? "" # e.g. socFamily
@ -28,7 +28,7 @@ stdenv.mkDerivation {
ubootTools
];
preparePhase = ''
cp ${vmlinux} vmlinux.elf; chmod +w vmlinux.elf
cp ${kernel} vmlinux.elf; chmod +w vmlinux.elf
'';
dtbPhase = ''
dtc -I dtb -O dts -o tmp.dts ${dtb}

View File

@ -56,6 +56,14 @@ 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

38
modules/wlan.nix Normal file
View File

@ -0,0 +1,38 @@
{ 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,6 +12,7 @@ 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

@ -6,7 +6,8 @@
, config
, checkedConfig ? {}
, tree
, src
, extraPatchPhase ? "true"
} :
let writeConfig = name : config: writeText name
(builtins.concatStringsSep
@ -30,8 +31,8 @@ let writeConfig = name : config: writeText name
checkedConfigFile = writeConfig "checked_kconfig" checkedConfig ;
inherit lib; in
stdenv.mkDerivation rec {
name = "vmlinux";
name = "kernel";
inherit src extraPatchPhase;
hardeningDisable = ["all"];
nativeBuildInputs = [buildPackages.stdenv.cc] ++
(with buildPackages.pkgs;
@ -44,11 +45,16 @@ 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" "modulesupport"];
outputs = ["out" "headers"];
phases = [
"unpackPhase"
"butcherPkgconfig"
"extraPatchPhase"
"patchScripts"
"configurePhase"
"checkConfigurationPhase"
"buildPhase"
@ -67,12 +73,16 @@ 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
( cd ${tree} && make V=1 olddefconfig )
make V=1 olddefconfig
'';
checkConfigurationPhase = ''
@ -84,18 +94,15 @@ stdenv.mkDerivation rec {
echo "OK"
'';
KBUILD_BUILD_HOST = "liminix.builder";
buildPhase = ''
make -C ${tree} vmlinux modules_prepare
make vmlinux modules_prepare
'';
installPhase = ''
${CROSS_COMPILE}strip -d vmlinux
cp vmlinux $out
mkdir -p $modulesupport
cp .config $modulesupport/config
make clean
cp -a . $modulesupport
mkdir -p $headers
cp -a include .config $headers/
'';
}

View File

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