44a40b
#! /bin/bash
44a40b
#
44a40b
# Called as filter-modules.sh list-of-modules Arch
44a40b
44a40b
# This script filters the modules into the kernel-core and kernel-modules
44a40b
# subpackages.  We list out subsystems/subdirs to prune from the installed
44a40b
# module directory.  What is left is put into the kernel-core package.  What is
44a40b
# pruned is contained in the kernel-modules package.
44a40b
#
44a40b
# This file contains the default subsys/subdirs to prune from all architectures.
44a40b
# If an architecture needs to differ, we source a per-arch filter-<arch>.sh file
44a40b
# that contains the set of override lists to be used instead.  If a module or
44a40b
# subsys should be in kernel-modules on all arches, please change the defaults
44a40b
# listed here.
44a40b
44a40b
# Overrides is individual modules which need to remain in kernel-core due to deps.
44a40b
overrides="cec"
44a40b
44a40b
# Set the default dirs/modules to filter out
44a40b
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"
44a40b
44a40b
chardrvs="mwave pcmcia"
44a40b
44a40b
netdrvs="appletalk can dsa hamradio ieee802154 irda ppp slip usb wireless"
44a40b
44a40b
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"
44a40b
44a40b
inputdrvs="gameport tablet touchscreen"
44a40b
44a40b
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"
44a40b
44a40b
usbdrvs="atm image misc serial wusbcore"
44a40b
44a40b
fsdrvs="affs befs cifs coda cramfs ecryptfs hfs hfsplus jfs minix ncpfs nilfs2 ocfs2 reiserfs romfs squashfs sysv ubifs ufs"
44a40b
44a40b
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"
44a40b
44a40b
drmdrvs="amd ast gma500 i2c i915 mgag200 nouveau radeon via "
44a40b
44a40b
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 chtls parport_serial ism regmap-sdw regmap-sdw-mbq arizona-micsupp hid-asus"
44a40b
44a40b
# Grab the arch-specific filter list overrides
44a40b
source ./filter-$2.sh
44a40b
44a40b
filter_dir() {
44a40b
	filelist=$1
44a40b
	dir=$2
44a40b
44a40b
	grep -v -e "${dir}/" ${filelist} > ${filelist}.tmp
44a40b
44a40b
	if [ $? -ne 0 ]
44a40b
	then
44a40b
		echo "Couldn't remove ${dir}.  Skipping."
44a40b
	else
44a40b
		grep -e "${dir}/" ${filelist} >> k-d.list
44a40b
		mv ${filelist}.tmp $filelist
44a40b
	fi
44a40b
	
44a40b
	return 0
44a40b
}
44a40b
44a40b
filter_ko() {
44a40b
	filelist=$1
44a40b
	mod=$2
44a40b
44a40b
	grep -v -e "${mod}.ko" ${filelist} > ${filelist}.tmp
44a40b
44a40b
	if [ $? -ne 0 ]
44a40b
	then
44a40b
		echo "Couldn't remove ${mod}.ko  Skipping."
44a40b
	else
44a40b
		grep -e "${mod}.ko" ${filelist} >> k-d.list
44a40b
		mv ${filelist}.tmp $filelist
44a40b
	fi
44a40b
	
44a40b
	return 0
44a40b
}
44a40b
44a40b
# Filter the drivers/ subsystems
44a40b
for subsys in ${driverdirs}
44a40b
do
44a40b
	filter_dir $1 drivers/${subsys}
44a40b
done
44a40b
44a40b
# Filter the networking drivers
44a40b
for netdrv in ${netdrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/net/${netdrv}
44a40b
done
44a40b
44a40b
# Filter the char drivers
44a40b
for char in ${chardrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/char/${char}
44a40b
done
44a40b
44a40b
# Filter the ethernet drivers
44a40b
for eth in ${ethdrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/net/ethernet/${eth}
44a40b
done
44a40b
44a40b
# SCSI
44a40b
for scsi in ${scsidrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/scsi/${scsi}
44a40b
done
44a40b
44a40b
# Input
44a40b
for input in ${inputdrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/input/${input}
44a40b
done
44a40b
44a40b
# USB
44a40b
for usb in ${usbdrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/usb/${usb}
44a40b
done
44a40b
44a40b
# Filesystems
44a40b
for fs in ${fsdrvs}
44a40b
do
44a40b
	filter_dir $1 fs/${fs}
44a40b
done
44a40b
44a40b
# Network protocols
44a40b
for prot in ${netprots}
44a40b
do
44a40b
	filter_dir $1 kernel/net/${prot}
44a40b
done
44a40b
44a40b
# DRM
44a40b
for drm in ${drmdrvs}
44a40b
do
44a40b
	filter_dir $1 drivers/gpu/drm/${drm}
44a40b
done
44a40b
44a40b
# Just kill sound.
44a40b
filter_dir $1 kernel/sound
44a40b
filter_dir $1 kernel/drivers/soundwire
44a40b
44a40b
# Now go through and filter any single .ko files that might have deps on the
44a40b
# things we filtered above
44a40b
for mod in ${singlemods}
44a40b
do
44a40b
        filter_ko $1 ${mod}
44a40b
done
44a40b
44a40b
# Now process the override list to bring those modules back into core
44a40b
for mod in ${overrides}
44a40b
do
44a40b
	grep -v -e "/${mod}.ko" k-d.list > k-d.list.tmp
44a40b
	if [ $? -ne 0 ]
44a40b
        then
44a40b
                echo "Couldn't save ${mod}.ko  Skipping."
44a40b
        else
44a40b
                grep -e "/${mod}.ko" k-d.list >> $filelist
44a40b
                mv k-d.list.tmp k-d.list
44a40b
        fi
44a40b
44a40b
done
44a40b
44a40b
# Go through our generated drivers list and remove the .ko files.  We'll
44a40b
# restore them later.
44a40b
for mod in `cat k-d.list`
44a40b
do
44a40b
	rm -rf $mod
44a40b
done