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