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