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