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