Justin Vreeland 3a5fd3
#! /bin/bash
Justin Vreeland 3a5fd3
#
Justin Vreeland 3a5fd3
# Called as filter-modules.sh list-of-modules Arch
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# This script filters the modules into the kernel-core and kernel-modules
Justin Vreeland 3a5fd3
# subpackages.  We list out subsystems/subdirs to prune from the installed
Justin Vreeland 3a5fd3
# module directory.  What is left is put into the kernel-core package.  What is
Justin Vreeland 3a5fd3
# pruned is contained in the kernel-modules package.
Justin Vreeland 3a5fd3
#
Justin Vreeland 3a5fd3
# This file contains the default subsys/subdirs to prune from all architectures.
Justin Vreeland 3a5fd3
# If an architecture needs to differ, we source a per-arch filter-<arch>.sh file
Justin Vreeland 3a5fd3
# that contains the set of override lists to be used instead.  If a module or
Justin Vreeland 3a5fd3
# subsys should be in kernel-modules on all arches, please change the defaults
Justin Vreeland 3a5fd3
# listed here.
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Overrides is individual modules which need to remain in kernel-core due to deps.
Justin Vreeland 3a5fd3
overrides="cec"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Set the default dirs/modules to filter out
Justin Vreeland 3a5fd3
driverdirs="atm auxdisplay bcma bluetooth firewire fpga infiniband leds media memstick mfd mmc mtd nfc ntb pcmcia platform power ssb soundwire staging tty uio w1"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
chardrvs="mwave pcmcia"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
netdrvs="appletalk can dsa hamradio ieee802154 ppp slip usb wireless"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
ethdrvs="3com adaptec alteon amd aquantia atheros broadcom cadence calxeda chelsio cisco dec dlink emulex marvell mellanox neterion nvidia packetengines qlogic rdc sfc silan sis smsc stmicro sun tehuti ti wiznet xircom"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
inputdrvs="gameport tablet touchscreen"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
hiddrvs="surface-hid"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
scsidrvs="aacraid aic7xxx be2iscsi bfa bnx2i bnx2fc csiostor cxgbi esas2r fcoe fnic isci libsas lpfc megaraid mpt3sas mvsas pm8001 qla2xxx qla4xxx sym53c8xx_2 ufs qedf"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
usbdrvs="atm image misc serial"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
fsdrvs="affs befs coda cramfs dlm ecryptfs hfs hfsplus jfs jffs2 minix nilfs2 ocfs2 reiserfs romfs squashfs sysv ubifs ufs"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
netprots="6lowpan appletalk atm ax25 batman-adv bluetooth can dsa ieee802154 l2tp mac80211 mac802154 mpls netrom nfc rds rfkill rose sctp smc wireless"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
drmdrvs="amd ast bridge gma500 i2c i915 mgag200 nouveau panel radeon"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
singlemods="ntb_netdev iscsi_ibft iscsi_boot_sysfs megaraid pmcraid qedi qla1280 9pnet_rdma rpcrdma nvmet-rdma nvme-rdma hid-picolcd hid-prodikeys hwpoison-inject target_core_user sbp_target cxgbit  chcr parport_serial regmap-sdw regmap-sdw-mbq arizona-micsupp hid-asus iTCO_wdt rnbd-client rnbd-server mlx5_vdpa spi-altera-dfl"
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Grab the arch-specific filter list overrides
Justin Vreeland 3a5fd3
source ./filter-$2.sh
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
filter_dir() {
Justin Vreeland 3a5fd3
	filelist=$1
Justin Vreeland 3a5fd3
	dir=$2
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
	grep -v -e "${dir}/" ${filelist} > ${filelist}.tmp
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
	if [ $? -ne 0 ]
Justin Vreeland 3a5fd3
	then
Justin Vreeland 3a5fd3
		echo "Couldn't remove ${dir}.  Skipping."
Justin Vreeland 3a5fd3
	else
Justin Vreeland 3a5fd3
		grep -e "${dir}/" ${filelist} >> k-d.list
Justin Vreeland 3a5fd3
		mv ${filelist}.tmp $filelist
Justin Vreeland 3a5fd3
	fi
Justin Vreeland 3a5fd3
	
Justin Vreeland 3a5fd3
	return 0
Justin Vreeland 3a5fd3
}
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
filter_ko() {
Justin Vreeland 3a5fd3
	filelist=$1
Justin Vreeland 3a5fd3
	mod=$2
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
	grep -v -e "${mod}.ko" ${filelist} > ${filelist}.tmp
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
	if [ $? -ne 0 ]
Justin Vreeland 3a5fd3
	then
Justin Vreeland 3a5fd3
		echo "Couldn't remove ${mod}.ko  Skipping."
Justin Vreeland 3a5fd3
	else
Justin Vreeland 3a5fd3
		grep -e "${mod}.ko" ${filelist} >> k-d.list
Justin Vreeland 3a5fd3
		mv ${filelist}.tmp $filelist
Justin Vreeland 3a5fd3
	fi
Justin Vreeland 3a5fd3
	
Justin Vreeland 3a5fd3
	return 0
Justin Vreeland 3a5fd3
}
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Filter the drivers/ subsystems
Justin Vreeland 3a5fd3
for subsys in ${driverdirs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/${subsys}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Filter the networking drivers
Justin Vreeland 3a5fd3
for netdrv in ${netdrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/net/${netdrv}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Filter the char drivers
Justin Vreeland 3a5fd3
for char in ${chardrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/char/${char}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Filter the ethernet drivers
Justin Vreeland 3a5fd3
for eth in ${ethdrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/net/ethernet/${eth}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# SCSI
Justin Vreeland 3a5fd3
for scsi in ${scsidrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/scsi/${scsi}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Input
Justin Vreeland 3a5fd3
for input in ${inputdrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/input/${input}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# hid
Justin Vreeland 3a5fd3
for hid in ${hiddrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/hid/${hid}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# USB
Justin Vreeland 3a5fd3
for usb in ${usbdrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/usb/${usb}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Filesystems
Justin Vreeland 3a5fd3
for fs in ${fsdrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 fs/${fs}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Network protocols
Justin Vreeland 3a5fd3
for prot in ${netprots}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 kernel/net/${prot}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# DRM
Justin Vreeland 3a5fd3
for drm in ${drmdrvs}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	filter_dir $1 drivers/gpu/drm/${drm}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Just kill sound.
Justin Vreeland 3a5fd3
filter_dir $1 kernel/sound
Justin Vreeland 3a5fd3
filter_dir $1 kernel/drivers/soundwire
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Now go through and filter any single .ko files that might have deps on the
Justin Vreeland 3a5fd3
# things we filtered above
Justin Vreeland 3a5fd3
for mod in ${singlemods}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
        filter_ko $1 ${mod}
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Now process the override list to bring those modules back into core
Justin Vreeland 3a5fd3
for mod in ${overrides}
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	grep -v -e "/${mod}.ko" k-d.list > k-d.list.tmp
Justin Vreeland 3a5fd3
	if [ $? -ne 0 ]
Justin Vreeland 3a5fd3
        then
Justin Vreeland 3a5fd3
                echo "Couldn't save ${mod}.ko  Skipping."
Justin Vreeland 3a5fd3
        else
Justin Vreeland 3a5fd3
                grep -e "/${mod}.ko" k-d.list >> $filelist
Justin Vreeland 3a5fd3
                mv k-d.list.tmp k-d.list
Justin Vreeland 3a5fd3
        fi
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
done
Justin Vreeland 3a5fd3
Justin Vreeland 3a5fd3
# Go through our generated drivers list and remove the .ko files.  We'll
Justin Vreeland 3a5fd3
# restore them later.
Justin Vreeland 3a5fd3
for mod in `cat k-d.list`
Justin Vreeland 3a5fd3
do
Justin Vreeland 3a5fd3
	rm -rf $mod
Justin Vreeland 3a5fd3
done