build a kernel, using malta_kvm_defconfig

(there's a lot in this config that I don't think is needed)
This commit is contained in:
Daniel Barlow 2022-09-20 18:54:27 +01:00
parent 41598a75f0
commit b2f7a429f7
7 changed files with 591 additions and 7 deletions

View file

@ -4,11 +4,13 @@
let let
overlay = import ./overlay.nix; overlay = import ./overlay.nix;
nixpkgs = import <nixpkgs> ( device.system // {overlays = [overlay]; }); nixpkgs = import <nixpkgs> ( device.system // {overlays = [overlay]; });
config = (import <liminix-config>) { baseConfig = {
config = { systemPackages = [];
systemPackages = []; services = {};
services = {}; kernel = device.kernel;
}; };
config = baseConfig // (import <liminix-config>) {
config = baseConfig;
tools = nixpkgs.pkgs.callPackage ./tools {}; tools = nixpkgs.pkgs.callPackage ./tools {};
inherit (nixpkgs) pkgs; inherit (nixpkgs) pkgs;
}; };
@ -18,4 +20,10 @@ let
(builtins.attrValues config.services) (builtins.attrValues config.services)
; ;
}; };
in (import ./make-image.nix) nixpkgs finalConfig squashfs = (import ./make-image.nix) nixpkgs finalConfig;
kernel = (import ./make-kernel.nix) nixpkgs finalConfig;
in {
outputs = {
inherit squashfs kernel;
};
}

View file

@ -8,4 +8,442 @@
}; };
}; };
}; };
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";
MIPS_MALTA= "y";
CPU_LITTLE_ENDIAN= "n";
CPU_BIG_ENDIAN= "n";
CPU_MIPS32_R2= "y";
PAGE_SIZE_16KB= "y";
NR_CPUS= "1";
HZ_100= "y";
PCI= "y";
VIRTUALIZATION= "y";
KVM= "m";
KVM_MIPS_DEBUG_COP0_COUNTERS= "y";
VHOST_NET= "m";
MODULES= "y";
MODULE_UNLOAD= "y";
MODVERSIONS= "y";
MODULE_SRCVERSION_ALL= "y";
NET= "y";
PACKET= "y";
UNIX= "y";
XFRM_USER= "m";
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";
NET_IPIP= "m";
IP_MROUTE= "y";
IP_PIMSM_V1= "y";
IP_PIMSM_V2= "y";
SYN_COOKIES= "y";
INET_AH= "m";
INET_ESP= "m";
INET_IPCOMP= "m";
INET_XFRM_MODE_TRANSPORT= "m";
INET_XFRM_MODE_TUNNEL= "m";
TCP_MD5SIG= "y";
IPV6_ROUTER_PREF= "y";
IPV6_ROUTE_INFO= "y";
IPV6_OPTIMISTIC_DAD= "y";
INET6_AH= "m";
INET6_ESP= "m";
INET6_IPCOMP= "m";
IPV6_TUNNEL= "m";
IPV6_MROUTE= "y";
IPV6_PIMSM_V2= "y";
NETWORK_SECMARK= "y";
NETFILTER= "y";
NF_CONNTRACK= "m";
NF_CONNTRACK_SECMARK= "y";
NF_CONNTRACK_EVENTS= "y";
NF_CONNTRACK_AMANDA= "m";
NF_CONNTRACK_FTP= "m";
NF_CONNTRACK_H323= "m";
NF_CONNTRACK_IRC= "m";
NF_CONNTRACK_PPTP= "m";
NF_CONNTRACK_SANE= "m";
NF_CONNTRACK_SIP= "m";
NF_CONNTRACK_TFTP= "m";
NF_CT_NETLINK= "m";
NETFILTER_XT_TARGET_CLASSIFY= "m";
NETFILTER_XT_TARGET_CONNMARK= "m";
NETFILTER_XT_TARGET_MARK= "m";
NETFILTER_XT_TARGET_NFLOG= "m";
NETFILTER_XT_TARGET_NFQUEUE= "m";
NETFILTER_XT_TARGET_TPROXY= "m";
NETFILTER_XT_TARGET_TRACE= "m";
NETFILTER_XT_TARGET_SECMARK= "m";
NETFILTER_XT_TARGET_TCPMSS= "m";
NETFILTER_XT_TARGET_TCPOPTSTRIP= "m";
NETFILTER_XT_MATCH_COMMENT= "m";
NETFILTER_XT_MATCH_CONNBYTES= "m";
NETFILTER_XT_MATCH_CONNLIMIT= "m";
NETFILTER_XT_MATCH_CONNMARK= "m";
NETFILTER_XT_MATCH_CONNTRACK= "m";
NETFILTER_XT_MATCH_DCCP= "m";
NETFILTER_XT_MATCH_ESP= "m";
NETFILTER_XT_MATCH_HASHLIMIT= "m";
NETFILTER_XT_MATCH_HELPER= "m";
NETFILTER_XT_MATCH_IPRANGE= "m";
NETFILTER_XT_MATCH_LENGTH= "m";
NETFILTER_XT_MATCH_LIMIT= "m";
NETFILTER_XT_MATCH_MAC= "m";
NETFILTER_XT_MATCH_MARK= "m";
NETFILTER_XT_MATCH_MULTIPORT= "m";
NETFILTER_XT_MATCH_OWNER= "m";
NETFILTER_XT_MATCH_POLICY= "m";
NETFILTER_XT_MATCH_PKTTYPE= "m";
NETFILTER_XT_MATCH_QUOTA= "m";
NETFILTER_XT_MATCH_RATEEST= "m";
NETFILTER_XT_MATCH_REALM= "m";
NETFILTER_XT_MATCH_RECENT= "m";
NETFILTER_XT_MATCH_SOCKET= "m";
NETFILTER_XT_MATCH_STATE= "m";
NETFILTER_XT_MATCH_STATISTIC= "m";
NETFILTER_XT_MATCH_STRING= "m";
NETFILTER_XT_MATCH_TCPMSS= "m";
NETFILTER_XT_MATCH_TIME= "m";
NETFILTER_XT_MATCH_U32= "m";
IP_VS= "m";
IP_VS_IPV6= "y";
IP_VS_PROTO_TCP= "y";
IP_VS_PROTO_UDP= "y";
IP_VS_PROTO_ESP= "y";
IP_VS_PROTO_AH= "y";
IP_VS_RR= "m";
IP_VS_WRR= "m";
IP_VS_LC= "m";
IP_VS_WLC= "m";
IP_VS_LBLC= "m";
IP_VS_LBLCR= "m";
IP_VS_DH= "m";
IP_VS_SH= "m";
IP_VS_SED= "m";
IP_VS_NQ= "m";
IP_NF_IPTABLES= "m";
IP_NF_MATCH_AH= "m";
IP_NF_MATCH_ECN= "m";
IP_NF_MATCH_TTL= "m";
IP_NF_FILTER= "m";
IP_NF_TARGET_REJECT= "m";
IP_NF_MANGLE= "m";
IP_NF_TARGET_CLUSTERIP= "m";
IP_NF_TARGET_ECN= "m";
IP_NF_TARGET_TTL= "m";
IP_NF_RAW= "m";
IP_NF_ARPTABLES= "m";
IP_NF_ARPFILTER= "m";
IP_NF_ARP_MANGLE= "m";
IP6_NF_MATCH_AH= "m";
IP6_NF_MATCH_EUI64= "m";
IP6_NF_MATCH_FRAG= "m";
IP6_NF_MATCH_OPTS= "m";
IP6_NF_MATCH_HL= "m";
IP6_NF_MATCH_IPV6HEADER= "m";
IP6_NF_MATCH_MH= "m";
IP6_NF_MATCH_RT= "m";
IP6_NF_TARGET_HL= "m";
IP6_NF_FILTER= "m";
IP6_NF_TARGET_REJECT= "m";
IP6_NF_MANGLE= "m";
IP6_NF_RAW= "m";
BRIDGE_NF_EBTABLES= "m";
BRIDGE_EBT_BROUTE= "m";
BRIDGE_EBT_T_FILTER= "m";
BRIDGE_EBT_T_NAT= "m";
BRIDGE_EBT_802_3= "m";
BRIDGE_EBT_AMONG= "m";
BRIDGE_EBT_ARP= "m";
BRIDGE_EBT_IP= "m";
BRIDGE_EBT_IP6= "m";
BRIDGE_EBT_LIMIT= "m";
BRIDGE_EBT_MARK= "m";
BRIDGE_EBT_PKTTYPE= "m";
BRIDGE_EBT_STP= "m";
BRIDGE_EBT_VLAN= "m";
BRIDGE_EBT_ARPREPLY= "m";
BRIDGE_EBT_DNAT= "m";
BRIDGE_EBT_MARK_T= "m";
BRIDGE_EBT_REDIRECT= "m";
BRIDGE_EBT_SNAT= "m";
BRIDGE_EBT_LOG= "m";
BRIDGE_EBT_NFLOG= "m";
IP_SCTP= "m";
BRIDGE= "m";
VLAN_8021Q= "m";
VLAN_8021Q_GVRP= "y";
ATALK= "m";
DEV_APPLETALK= "m";
IPDDP= "m";
IPDDP_ENCAP= "y";
PHONET= "m";
NET_SCHED= "y";
NET_SCH_CBQ= "m";
NET_SCH_HTB= "m";
NET_SCH_HFSC= "m";
NET_SCH_PRIO= "m";
NET_SCH_RED= "m";
NET_SCH_SFQ= "m";
NET_SCH_TEQL= "m";
NET_SCH_TBF= "m";
NET_SCH_GRED= "m";
NET_SCH_DSMARK= "m";
NET_SCH_NETEM= "m";
NET_SCH_INGRESS= "m";
NET_CLS_BASIC= "m";
NET_CLS_TCINDEX= "m";
NET_CLS_ROUTE4= "m";
NET_CLS_FW= "m";
NET_CLS_U32= "m";
NET_CLS_RSVP= "m";
NET_CLS_RSVP6= "m";
NET_CLS_FLOW= "m";
NET_CLS_ACT= "y";
NET_ACT_POLICE= "y";
NET_ACT_GACT= "m";
GACT_PROB= "y";
NET_ACT_MIRRED= "m";
NET_ACT_IPT= "m";
NET_ACT_NAT= "m";
NET_ACT_PEDIT= "m";
NET_ACT_SIMP= "m";
NET_ACT_SKBEDIT= "m";
CFG80211= "m";
MAC80211= "m";
MAC80211_MESH= "y";
RFKILL= "m";
DEVTMPFS= "y";
CONNECTOR= "m";
MTD= "y";
MTD_BLOCK= "y";
MTD_OOPS= "m";
MTD_CFI= "y";
MTD_CFI_INTELEXT= "y";
MTD_CFI_AMDSTD= "y";
MTD_CFI_STAA= "y";
MTD_PHYSMAP_OF= "y";
MTD_UBI= "m";
MTD_UBI_GLUEBI= "m";
BLK_DEV_FD= "m";
BLK_DEV_LOOP= "m";
BLK_DEV_CRYPTOLOOP= "m";
BLK_DEV_NBD= "m";
BLK_DEV_RAM= "y";
CDROM_PKTCDVD= "m";
ATA_OVER_ETH= "m";
RAID_ATTRS= "m";
BLK_DEV_SD= "y";
CHR_DEV_ST= "m";
CHR_DEV_OSST= "m";
BLK_DEV_SR= "y";
CHR_DEV_SG= "m";
SCSI_CONSTANTS= "y";
SCSI_LOGGING= "y";
SCSI_SCAN_ASYNC= "y";
SCSI_FC_ATTRS= "m";
ISCSI_TCP= "m";
BLK_DEV_3W_XXXX_RAID= "m";
SCSI_3W_9XXX= "m";
SCSI_ACARD= "m";
SCSI_AACRAID= "m";
SCSI_AIC7XXX= "m";
AIC7XXX_RESET_DELAY_MS="15000";
AIC7XXX_DEBUG_ENABLE= "n";
ATA= "y";
ATA_PIIX= "y";
PATA_IT8213= "m";
PATA_OLDPIIX= "y";
PATA_MPIIX= "y";
ATA_GENERIC= "y";
PATA_LEGACY= "y";
MD= "y";
BLK_DEV_MD= "m";
MD_LINEAR= "m";
MD_RAID0= "m";
MD_RAID1= "m";
MD_RAID10= "m";
MD_RAID456= "m";
MD_MULTIPATH= "m";
MD_FAULTY= "m";
BLK_DEV_DM= "m";
DM_CRYPT= "m";
DM_SNAPSHOT= "m";
DM_MIRROR= "m";
DM_ZERO= "m";
DM_MULTIPATH= "m";
NETDEVICES= "y";
BONDING= "m";
DUMMY= "m";
EQUALIZER= "m";
IFB= "m";
MACVLAN= "m";
TUN= "m";
VETH= "m";
PCNET32= "y";
CHELSIO_T3= "m";
AX88796= "m";
NETXEN_NIC= "m";
TC35815= "m";
BROADCOM_PHY= "m";
CICADA_PHY= "m";
DAVICOM_PHY= "m";
ICPLUS_PHY= "m";
LXT_PHY= "m";
MARVELL_PHY= "m";
QSEMI_PHY= "m";
REALTEK_PHY= "m";
SMSC_PHY= "m";
VITESSE_PHY= "m";
ATMEL= "m";
PCI_ATMEL= "m";
IPW2100= "m";
IPW2100_MONITOR= "y";
HOSTAP= "m";
HOSTAP_FIRMWARE= "y";
HOSTAP_FIRMWARE_NVRAM= "y";
HOSTAP_PLX= "m";
HOSTAP_PCI= "m";
PRISM54= "m";
LIBERTAS= "m";
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";
HID= "m";
RTC_CLASS= "y";
RTC_DRV_CMOS= "y";
UIO= "m";
UIO_CIF= "m";
EXT2_FS= "y";
EXT3_FS= "y";
REISERFS_FS= "m";
REISERFS_PROC_INFO= "y";
REISERFS_FS_XATTR= "y";
REISERFS_FS_POSIX_ACL= "y";
REISERFS_FS_SECURITY= "y";
JFS_FS= "m";
JFS_POSIX_ACL= "y";
JFS_SECURITY= "y";
XFS_FS= "m";
XFS_QUOTA= "y";
XFS_POSIX_ACL= "y";
QUOTA= "y";
QFMT_V2= "y";
FUSE_FS= "m";
ISO9660_FS= "m";
JOLIET= "y";
ZISOFS= "y";
UDF_FS= "m";
MSDOS_FS= "m";
VFAT_FS= "m";
PROC_KCORE= "y";
TMPFS= "y";
CONFIGFS_FS= "y";
AFFS_FS= "m";
HFS_FS= "m";
HFSPLUS_FS= "m";
BEFS_FS= "m";
BFS_FS= "m";
EFS_FS= "m";
JFFS2_FS= "m";
JFFS2_FS_XATTR= "y";
JFFS2_COMPRESSION_OPTIONS= "y";
JFFS2_RUBIN= "y";
CRAMFS= "m";
VXFS_FS= "m";
MINIX_FS= "m";
ROMFS_FS= "m";
SYSV_FS= "m";
UFS_FS= "m";
NFS_FS= "y";
ROOT_NFS= "y";
NFSD= "y";
NFSD_V3= "y";
NLS_CODEPAGE_437= "m";
NLS_CODEPAGE_737= "m";
NLS_CODEPAGE_775= "m";
NLS_CODEPAGE_850= "m";
NLS_CODEPAGE_852= "m";
NLS_CODEPAGE_855= "m";
NLS_CODEPAGE_857= "m";
NLS_CODEPAGE_860= "m";
NLS_CODEPAGE_861= "m";
NLS_CODEPAGE_862= "m";
NLS_CODEPAGE_863= "m";
NLS_CODEPAGE_864= "m";
NLS_CODEPAGE_865= "m";
NLS_CODEPAGE_866= "m";
NLS_CODEPAGE_869= "m";
NLS_CODEPAGE_936= "m";
NLS_CODEPAGE_950= "m";
NLS_CODEPAGE_932= "m";
NLS_CODEPAGE_949= "m";
NLS_CODEPAGE_874= "m";
NLS_ISO8859_8= "m";
NLS_CODEPAGE_1250= "m";
NLS_CODEPAGE_1251= "m";
NLS_ASCII= "m";
NLS_ISO8859_1= "m";
NLS_ISO8859_2= "m";
NLS_ISO8859_3= "m";
NLS_ISO8859_4= "m";
NLS_ISO8859_5= "m";
NLS_ISO8859_6= "m";
NLS_ISO8859_7= "m";
NLS_ISO8859_9= "m";
NLS_ISO8859_13= "m";
NLS_ISO8859_14= "m";
NLS_ISO8859_15= "m";
NLS_KOI8_R= "m";
NLS_KOI8_U= "m";
CRYPTO_CRYPTD= "m";
CRYPTO_LRW= "m";
CRYPTO_PCBC= "m";
CRYPTO_HMAC= "y";
CRYPTO_XCBC= "m";
CRYPTO_MD4= "m";
CRYPTO_SHA512= "m";
CRYPTO_TGR192= "m";
CRYPTO_WP512= "m";
CRYPTO_ANUBIS= "m";
CRYPTO_BLOWFISH= "m";
CRYPTO_CAMELLIA= "m";
CRYPTO_CAST5= "m";
CRYPTO_CAST6= "m";
CRYPTO_FCRYPT= "m";
CRYPTO_KHAZAD= "m";
CRYPTO_SERPENT= "m";
CRYPTO_TEA= "m";
CRYPTO_TWOFISH= "m";
RCU_CPU_STALL_TIMEOUT = "60";
ENABLE_DEFAULT_TRACERS = "y";
};
};
} }

29
make-kernel.nix Normal file
View file

@ -0,0 +1,29 @@
pkgs: config:
let
inherit (pkgs) callPackage buildPackages stdenvNoCC fetchFromGitHub;
source = fetchFromGitHub {
owner = "torvalds";
repo = "linux";
rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19
hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4=";
};
tree = stdenvNoCC.mkDerivation {
name = "spindled-kernel-tree";
src = source;
phases = [ "unpackPhase" "patchScripts" "installPhase" ];
patchScripts = ''
patchShebangs scripts/
# substituteInPlace Makefile --replace /bin/pwd ${buildPackages.pkgs.coreutils}/bin/pwd
'';
installPhase = ''
mkdir -p $out
cp -a . $out
'';
};
in
{
vmlinux = callPackage ./make-vmlinux.nix {
inherit tree;
config = config.kernel.config;
};
}

90
make-vmlinux.nix Normal file
View file

@ -0,0 +1,90 @@
{ stdenv
, buildPackages
, runCommand
, writeText
, lib
, config
, checkedConfig ? {}
, tree
} :
let writeConfig = name : config: writeText name
(builtins.concatStringsSep
"\n"
(lib.mapAttrsToList
(name: value: (if value == "n" then "# CONFIG_${name} is not set" else "CONFIG_${name}=${value}"))
config
));
kconfigFile = writeConfig "nixwrt_kconfig" config;
checkedConfigFile = writeConfig "checked_kconfig" checkedConfig ;
inherit lib; in
stdenv.mkDerivation rec {
name = "vmlinux";
hardeningDisable = ["all"];
nativeBuildInputs = [buildPackages.stdenv.cc] ++
(with buildPackages.pkgs;
[rsync bc bison flex pkgconfig openssl ncurses.all perl]);
CC = "${stdenv.cc.bintools.targetPrefix}gcc";
HOSTCC = "gcc -I${buildPackages.pkgs.openssl}/include -I${buildPackages.pkgs.ncurses}/include";
HOST_EXTRACFLAGS = "-I${buildPackages.pkgs.openssl.dev}/include -L${buildPackages.pkgs.openssl.out}/lib -L${buildPackages.pkgs.ncurses.out}/lib " ;
PKG_CONFIG_PATH = "./pkgconfig";
CROSS_COMPILE = stdenv.cc.bintools.targetPrefix;
ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel
dontStrip = true;
dontPatchELF = true;
outputs = ["out" "modulesupport"];
phases = ["butcherPkgconfig"
# "patchScripts"
"configurePhase"
"checkConfigurationPhase"
"buildPhase"
"installPhase"
];
# this is here to work around what I think is a bug in nixpkgs packaging
# of ncurses: it installs pkg-config data files which don't produce
# any -L options when queried with "pkg-config --lib ncurses". For a
# regular nixwrt compilation you'll never even notice, this only becomes
# an issue if you do a nix-shell in this derivation and expect "make nconfig"
# to work.
butcherPkgconfig = ''
cp -r ${buildPackages.pkgs.ncurses.dev}/lib/pkgconfig .
chmod +w pkgconfig pkgconfig/*.pc
for i in pkgconfig/*.pc; do test -f $i && sed -i 's/^Libs:/Libs: -L''${libdir} /' $i;done
'';
# patchScripts = ''
# patchShebangs --build scripts/
# '';
configurePhase = ''
export KBUILD_OUTPUT=`pwd`
cp ${kconfigFile} .config
cp ${kconfigFile} .config.orig
( cd ${tree} && make V=1 olddefconfig )
'';
checkConfigurationPhase = ''
echo Checking required config items:
if comm -2 -3 <(grep 'CONFIG' ${checkedConfigFile} |sort) <(grep 'CONFIG' .config|sort) |grep '.' ; then
echo -e "^^^ Some configuration lost :-(\nPerhaps you have mutually incompatible settings, or have disabled options on which these depend.\n"
exit 0
fi
echo "OK"
'';
KBUILD_BUILD_HOST = "nixwrt.builder";
buildPhase = ''
make -C ${tree} vmlinux
'';
installPhase = ''
${CROSS_COMPILE}strip -d vmlinux
cp vmlinux $out
make clean
mkdir -p $modulesupport
cp -a . $modulesupport
'';
}

6
run-qemu.sh Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p qemu
qemu-system-mips -M malta -m 256 \
-append "earlyprintk=serial,ttyS0 console=ttyS0,38400n8 panic=10 oops=panic init=/bin/init loglevel=8 root=/dev/vda" \
-kernel $1 -nographic -display none -serial mon:stdio

View file

@ -5,5 +5,5 @@ export TMPDIR=${TMPDIR-/tmp}
for i in tests/*/run.sh; do for i in tests/*/run.sh; do
echo $i echo $i
$i || exit 1 $i $* || exit 1
done done

13
tests/kernel/run.sh Executable file
View file

@ -0,0 +1,13 @@
set -e
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build -I liminix-config=./tests/smoke/configuration.nix --arg device "import ./devices/$DEVICE.nix" -A outputs.kernel.vmlinux -o vmlinux $*
TESTS=$(cat <<"EOF"
trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit 1' ERR
test -f vmlinux
file -L vmlinux | grep ' ELF 32-bit MSB executable, MIPS'
EOF
)
nix-shell -p s6-rc -p squashfsTools --run "$TESTS" || exit 1