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