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