e336be
#! /bin/bash
e336be
#
e336be
# Called as filter-modules.sh list-of-modules Arch
e336be
e336be
# This script filters the modules into the kernel-core and kernel-modules
e336be
# subpackages.  We list out subsystems/subdirs to prune from the installed
e336be
# module directory.  What is left is put into the kernel-core package.  What is
e336be
# pruned is contained in the kernel-modules package.
e336be
#
e336be
# This file contains the default subsys/subdirs to prune from all architectures.
e336be
# If an architecture needs to differ, we source a per-arch filter-<arch>.sh file
e336be
# that contains the set of override lists to be used instead.  If a module or
e336be
# subsys should be in kernel-modules on all arches, please change the defaults
e336be
# listed here.
e336be
e336be
# Set the default dirs/modules to filter out
e336be
driverdirs="atm auxdisplay bcma bluetooth firewire fmc fpga infiniband isdn leds media memstick mfd mmc mtd nfc ntb pcmcia platform power ssb soundwire staging tty uio uwb w1"
e336be
e336be
chardrvs="mwave pcmcia"
e336be
e336be
netdrvs="appletalk can dsa hamradio ieee802154 irda ppp slip usb wireless"
e336be
e336be
ethdrvs="3com adaptec alteon amd aquantia atheros broadcom cadence calxeda chelsio cisco dec dlink emulex icplus marvell mellanox neterion nvidia oki-semi packetengines qlogic rdc renesas sfc silan sis smsc stmicro sun tehuti ti wiznet xircom"
e336be
e336be
inputdrvs="gameport tablet touchscreen"
e336be
e336be
scsidrvs="aacraid advansys aic7xxx aic94xx be2iscsi bfa bnx2i bnx2fc csiostor cxgbi esas2r fcoe fnic isci libsas lpfc megaraid mpt2sas mpt3sas mvsas pm8001 qla2xxx qla4xxx sym53c8xx_2 ufs qedf wd719x"
e336be
e336be
usbdrvs="atm image misc serial wusbcore"
e336be
e336be
fsdrvs="affs befs coda cramfs dlm ecryptfs hfs hfsplus jfs jffs2 minix ncpfs nilfs2 ocfs2 reiserfs romfs squashfs sysv ubifs ufs"
e336be
e336be
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"
e336be
e336be
drmdrvs="amd ast bridge gma500 i2c i915 mgag200 nouveau panel radeon"
e336be
e336be
iiodrvs="accel adc afe common dac gyro health humidity light magnetometer multiplexer orientation potentiometer potentiostat pressure temperature"
e336be
e336be
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 target_core_user sbp_target cxgbit iw_cxgb3 iw_cxgb4 cxgb3i cxgb3i cxgb3i_ddp cxgb4i chcr chtls parport_serial regmap-sdw"
e336be
e336be
# Grab the arch-specific filter list overrides
e336be
source ./filter-$2.sh
e336be
e336be
filter_dir() {
e336be
	filelist=$1
e336be
	dir=$2
e336be
e336be
	grep -v -e "${dir}/" ${filelist} > ${filelist}.tmp
e336be
e336be
	if [ $? -ne 0 ]
e336be
	then
e336be
		echo "Couldn't remove ${dir}.  Skipping."
e336be
	else
e336be
		grep -e "${dir}/" ${filelist} >> k-d.list
e336be
		mv ${filelist}.tmp $filelist
e336be
	fi
e336be
	
e336be
	return 0
e336be
}
e336be
e336be
filter_ko() {
e336be
	filelist=$1
e336be
	mod=$2
e336be
e336be
	grep -v -e "${mod}.ko" ${filelist} > ${filelist}.tmp
e336be
e336be
	if [ $? -ne 0 ]
e336be
	then
e336be
		echo "Couldn't remove ${mod}.ko  Skipping."
e336be
	else
e336be
		grep -e "${mod}.ko" ${filelist} >> k-d.list
e336be
		mv ${filelist}.tmp $filelist
e336be
	fi
e336be
	
e336be
	return 0
e336be
}
e336be
e336be
# Filter the drivers/ subsystems
e336be
for subsys in ${driverdirs}
e336be
do
e336be
	filter_dir $1 drivers/${subsys}
e336be
done
e336be
e336be
# Filter the networking drivers
e336be
for netdrv in ${netdrvs}
e336be
do
e336be
	filter_dir $1 drivers/net/${netdrv}
e336be
done
e336be
e336be
# Filter the char drivers
e336be
for char in ${chardrvs}
e336be
do
e336be
	filter_dir $1 drivers/char/${input}
e336be
done
e336be
e336be
# Filter the ethernet drivers
e336be
for eth in ${ethdrvs}
e336be
do
e336be
	filter_dir $1 drivers/net/ethernet/${eth}
e336be
done
e336be
e336be
# SCSI
e336be
for scsi in ${scsidrvs}
e336be
do
e336be
	filter_dir $1 drivers/scsi/${scsi}
e336be
done
e336be
e336be
# Input
e336be
for input in ${inputdrvs}
e336be
do
e336be
	filter_dir $1 drivers/input/${input}
e336be
done
e336be
e336be
# USB
e336be
for usb in ${usbdrvs}
e336be
do
e336be
	filter_dir $1 drivers/usb/${usb}
e336be
done
e336be
e336be
# Filesystems
e336be
for fs in ${fsdrvs}
e336be
do
e336be
	filter_dir $1 fs/${fs}
e336be
done
e336be
e336be
# Network protocols
e336be
for prot in ${netprots}
e336be
do
e336be
	filter_dir $1 kernel/net/${prot}
e336be
done
e336be
e336be
# DRM
e336be
for drm in ${drmdrvs}
e336be
do
e336be
	filter_dir $1 drivers/gpu/drm/${drm}
e336be
done
e336be
e336be
# Just kill sound.
e336be
filter_dir $1 kernel/sound
e336be
e336be
# Now go through and filter any single .ko files that might have deps on the
e336be
# things we filtered above
e336be
for mod in ${singlemods}
e336be
do
e336be
        filter_ko $1 ${mod}
e336be
done
e336be
e336be
# Go through our generated drivers list and remove the .ko files.  We'll
e336be
# restore them later.
e336be
for mod in `cat k-d.list`
e336be
do
e336be
	rm -rf $mod
e336be
done