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