73e442
#! /bin/bash
73e442
#
73e442
# Called as filter-modules.sh list-of-modules Arch
73e442
73e442
# This script filters the modules into the kernel-core and kernel-modules
73e442
# subpackages.  We list out subsystems/subdirs to prune from the installed
73e442
# module directory.  What is left is put into the kernel-core package.  What is
73e442
# pruned is contained in the kernel-modules package.
73e442
#
73e442
# This file contains the default subsys/subdirs to prune from all architectures.
73e442
# If an architecture needs to differ, we source a per-arch filter-<arch>.sh file
73e442
# that contains the set of override lists to be used instead.  If a module or
73e442
# subsys should be in kernel-modules on all arches, please change the defaults
73e442
# listed here.
73e442
73e442
# Overrides is individual modules which need to remain in kernel-core due to deps.
73e442
overrides="cec"
73e442
73e442
# Set the default dirs/modules to filter out
73e442
driverdirs="atm auxdisplay bcma bluetooth firewire fpga infiniband leds media memstick mfd mmc mtd nfc ntb pcmcia platform power ssb soundwire staging tty uio w1"
73e442
73e442
chardrvs="mwave pcmcia"
73e442
73e442
netdrvs="appletalk can dsa hamradio ieee802154 ppp slip usb wireless"
73e442
73e442
ethdrvs="3com adaptec alteon amd aquantia atheros broadcom cadence calxeda chelsio cisco dec dlink emulex marvell mellanox neterion nvidia packetengines qlogic rdc sfc silan sis smsc stmicro sun tehuti ti wiznet xircom"
73e442
73e442
cryptdrvs="bcm caam cavium chelsio hisilicon marvell qat"
73e442
73e442
iiodrvs="accel light pressure proximity"
73e442
73e442
iiocommondrvs="cros_ec_sensors"
73e442
73e442
inputdrvs="gameport tablet touchscreen"
73e442
73e442
hiddrvs="surface-hid"
73e442
73e442
scsidrvs="aacraid aic7xxx be2iscsi bfa bnx2i bnx2fc csiostor cxgbi esas2r fcoe fnic isci libsas lpfc megaraid mpt3sas mvsas pm8001 qla2xxx qla4xxx sym53c8xx_2 ufs qedf"
73e442
73e442
usbdrvs="atm image misc serial"
73e442
73e442
fsdrvs="affs befs coda cramfs dlm ecryptfs hfs hfsplus jfs jffs2 minix nilfs2 ocfs2 reiserfs romfs sysv ubifs ufs"
73e442
73e442
netprots="6lowpan appletalk atm ax25 batman-adv bluetooth can dsa ieee802154 l2tp mac80211 mac802154 mpls netrom nfc rds rfkill rose sctp smc wireless"
73e442
6525d0
drmdrvs="amd ast bridge gma500 i2c i915 mgag200 nouveau panel radeon xe"
73e442
6525d0
singlemods="ntb_netdev iscsi_ibft iscsi_boot_sysfs megaraid pmcraid qedi qla1280 9pnet_rdma rpcrdma nvmet-rdma nvme-rdma hid-picolcd hid-prodikeys hwpoison-inject target_core_user sbp_target cxgbit  chcr parport_serial regmap-sdw regmap-sdw-mbq arizona-micsupp hid-asus iTCO_wdt rnbd-client rnbd-server mlx5_vdpa spi-altera-dfl nct6775 hid-playstation hid-nintendo asus_wmi_sensors asus_wmi_ec_sensors mlx5-vfio-pci video int3406_thermal apple_bl ptp_dfl_tod intel-m10-bmc-hwmon intel_rapl_tpmi pds_vdpa hp-wmi-sensors pds-vfio-pci gpio-ljca spi-ljca i2c-ljca dell-smm-hwmon"
73e442
73e442
# Grab the arch-specific filter list overrides
73e442
source ./filter-$2.sh
73e442
73e442
filter_dir() {
73e442
	filelist=$1
73e442
	dir=$2
73e442
73e442
	grep -v -e "${dir}/" ${filelist} > ${filelist}.tmp
73e442
73e442
	if [ $? -ne 0 ]
73e442
	then
73e442
		echo "Couldn't remove ${dir}.  Skipping."
73e442
	else
73e442
		grep -e "${dir}/" ${filelist} >> k-d.list
73e442
		mv ${filelist}.tmp $filelist
73e442
	fi
73e442
	
73e442
	return 0
73e442
}
73e442
73e442
filter_ko() {
73e442
	filelist=$1
73e442
	mod=$2
73e442
73e442
	grep -v -e "${mod}.ko" ${filelist} > ${filelist}.tmp
73e442
73e442
	if [ $? -ne 0 ]
73e442
	then
73e442
		echo "Couldn't remove ${mod}.ko  Skipping."
73e442
	else
73e442
		grep -e "${mod}.ko" ${filelist} >> k-d.list
73e442
		mv ${filelist}.tmp $filelist
73e442
	fi
73e442
	
73e442
	return 0
73e442
}
73e442
73e442
# Filter the drivers/ subsystems
73e442
for subsys in ${driverdirs}
73e442
do
73e442
	filter_dir $1 drivers/${subsys}
73e442
done
73e442
73e442
# Filter the networking drivers
73e442
for netdrv in ${netdrvs}
73e442
do
73e442
	filter_dir $1 drivers/net/${netdrv}
73e442
done
73e442
73e442
# Filter the char drivers
73e442
for char in ${chardrvs}
73e442
do
73e442
	filter_dir $1 drivers/char/${char}
73e442
done
73e442
73e442
# Filter the ethernet drivers
73e442
for eth in ${ethdrvs}
73e442
do
73e442
	filter_dir $1 drivers/net/ethernet/${eth}
73e442
done
73e442
73e442
# Filter the crypto drivers
73e442
for crypt in ${cryptdrvs}
73e442
do
73e442
	filter_dir $1 drivers/crypto/${crypt}
73e442
done
73e442
73e442
# SCSI
73e442
for scsi in ${scsidrvs}
73e442
do
73e442
	filter_dir $1 drivers/scsi/${scsi}
73e442
done
73e442
73e442
# IIO
73e442
for iio in ${iiodrvs}
73e442
do
73e442
        filter_dir $1 drivers/iio/${iio}
73e442
done
73e442
73e442
# IIO Common
73e442
for iio in ${iiocommondrvs}
73e442
do
73e442
        filter_dir $1 drivers/iio/common/${iio}
73e442
done
73e442
73e442
# Input
73e442
for input in ${inputdrvs}
73e442
do
73e442
	filter_dir $1 drivers/input/${input}
73e442
done
73e442
73e442
# hid
73e442
for hid in ${hiddrvs}
73e442
do
73e442
	filter_dir $1 drivers/hid/${hid}
73e442
done
73e442
73e442
# USB
73e442
for usb in ${usbdrvs}
73e442
do
73e442
	filter_dir $1 drivers/usb/${usb}
73e442
done
73e442
73e442
# Filesystems
73e442
for fs in ${fsdrvs}
73e442
do
73e442
	filter_dir $1 fs/${fs}
73e442
done
73e442
73e442
# Network protocols
73e442
for prot in ${netprots}
73e442
do
73e442
	filter_dir $1 kernel/net/${prot}
73e442
done
73e442
73e442
# DRM
73e442
for drm in ${drmdrvs}
73e442
do
73e442
	filter_dir $1 drivers/gpu/drm/${drm}
73e442
done
73e442
73e442
# Just kill sound.
73e442
filter_dir $1 kernel/sound
73e442
filter_dir $1 kernel/drivers/soundwire
73e442
73e442
# Now go through and filter any single .ko files that might have deps on the
73e442
# things we filtered above
73e442
for mod in ${singlemods}
73e442
do
73e442
        filter_ko $1 ${mod}
73e442
done
73e442
73e442
# Now process the override list to bring those modules back into core
73e442
for mod in ${overrides}
73e442
do
73e442
	grep -v -e "/${mod}.ko" k-d.list > k-d.list.tmp
73e442
	if [ $? -ne 0 ]
73e442
        then
73e442
                echo "Couldn't save ${mod}.ko  Skipping."
73e442
        else
73e442
                grep -e "/${mod}.ko" k-d.list >> $filelist
73e442
                mv k-d.list.tmp k-d.list
73e442
        fi
73e442
73e442
done
73e442
73e442
# Go through our generated drivers list and remove the .ko files.  We'll
73e442
# restore them later.
73e442
for mod in `cat k-d.list`
73e442
do
73e442
	rm -rf $mod
73e442
done