Skip to content

Commit 5920c3c

Browse files
authored
Merge pull request #64 from desultory/nokmod
separate kconfig code from kmod code, add more sound/network masks
2 parents 269a51c + afb6208 commit 5920c3c

File tree

5 files changed

+59
-47
lines changed

5 files changed

+59
-47
lines changed

src/ugrd/kmod/kconfig.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
__author__ = 'desultory'
2+
__version__ = '0.1.0'
3+
4+
from zenlib.util import contains
5+
6+
7+
def _normalize_kconfig_option(self, option: str) -> str:
8+
""" Normalizes a kernel config option. """
9+
option = option.upper()
10+
if not option.startswith('CONFIG_'):
11+
option = 'CONFIG_' + option
12+
return option
13+
14+
15+
@contains('kernel_config_file', "Cannot check config, kernel config file not found.")
16+
def _check_kernel_config(self, option: str):
17+
"""
18+
Checks if an option is set in the kernel config file.
19+
Checks that the line starts with the option, and is set to 'y' or 'm'.
20+
If a match is found, return the line, otherwise return None
21+
"""
22+
option = _normalize_kconfig_option(self, option)
23+
with open(self['kernel_config_file'], 'r') as f:
24+
for line in f.readlines():
25+
if line.startswith(option):
26+
if line.split('=')[1].strip()[0] in ['y', 'm']:
27+
self.logger.debug("Kernel config option is set: %s" % option)
28+
return line
29+
else:
30+
return self.logger.debug("Kernel config option is not set: %s" % option)
31+
self.logger.debug("Kernel config option not found: %s" % option)
32+
33+
34+
def find_kernel_config(self) -> None:
35+
""" Tries to find the kernel config file associated with the current kernel version. """
36+
build_dir = self['_kmod_dir'] / 'build'
37+
source_dir = self['_kmod_dir'] / 'source'
38+
for d in [build_dir, source_dir]:
39+
if d.exists():
40+
config_file = d / '.config'
41+
if config_file.exists():
42+
self.logger.info("Found kernel config file: %s" % config_file)
43+
self['kernel_config_file'] = config_file
44+
break
45+
else:
46+
self.logger.warning("Kernel config file not found.")

src/ugrd/kmod/kconfig.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[custom_parameters]
2+
kernel_config_file = "Path" # Path to the kernel configuration file
3+
4+
[imports.build_pre]
5+
"ugrd.kmod.kmod" = [ "find_kernel_config" ]

src/ugrd/kmod/kmod.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -153,48 +153,6 @@ def autodetect_modules(self) -> None:
153153
self.logger.warning("No kernel modules were autodetected.")
154154

155155

156-
def _normalize_kconfig_option(self, option: str) -> str:
157-
""" Normalizes a kernel config option. """
158-
option = option.upper()
159-
if not option.startswith('CONFIG_'):
160-
option = 'CONFIG_' + option
161-
return option
162-
163-
164-
@contains('_kernel_config_file', "Cannot check config, kernel config file not found.")
165-
def _check_kernel_config(self, option: str):
166-
"""
167-
Checks if an option is set in the kernel config file.
168-
Checks that the line starts with the option, and is set to 'y' or 'm'.
169-
If a match is found, return the line, otherwise return None
170-
"""
171-
option = _normalize_kconfig_option(self, option)
172-
with open(self['_kernel_config_file'], 'r') as f:
173-
for line in f.readlines():
174-
if line.startswith(option):
175-
if line.split('=')[1].strip()[0] in ['y', 'm']:
176-
self.logger.debug("Kernel config option is set: %s" % option)
177-
return line
178-
else:
179-
return self.logger.debug("Kernel config option is not set: %s" % option)
180-
self.logger.debug("Kernel config option not found: %s" % option)
181-
182-
183-
def find_kernel_config(self) -> None:
184-
""" Tries to find the kernel config file associated with the current kernel version. """
185-
build_dir = self['_kmod_dir'] / 'build'
186-
source_dir = self['_kmod_dir'] / 'source'
187-
for d in [build_dir, source_dir]:
188-
if d.exists():
189-
config_file = d / '.config'
190-
if config_file.exists():
191-
self.logger.info("Found kernel config file: %s" % config_file)
192-
self['_kernel_config_file'] = config_file
193-
break
194-
else:
195-
self.logger.warning("Kernel config file not found.")
196-
197-
198156
def get_kernel_metadata(self) -> None:
199157
""" Gets metadata for all kernel modules. """
200158
if not self.get('kernel_version'):
@@ -212,7 +170,6 @@ def get_kernel_metadata(self) -> None:
212170
self.logger.warning("Kernel module directory does not exist, but no_kmod is set.")
213171
else:
214172
raise DependencyResolutionError(f"Kernel module directory does not exist for kernel: {self['kernel_version']}")
215-
find_kernel_config(self) # Used to check kernel config options
216173

217174

218175
@contains('kmod_init', "kmod_init is empty, skipping.")

src/ugrd/kmod/nonetwork.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
kmod_ignore = [
22
'rfkill', 'bluetooth', 'cfg80211', 'mac80211', # Wireless
33
'iwlwifi', 'iwlmvm', 'btusb', 'btintel', 'btrtl', 'btbcm', 'btmtk', # wireless vendor
4-
'cdc_ether', 'stp', '8021q', 'llc', 'garp', 'mrp', 'bridge', 'bonding', # Ethernet
4+
'mt76', 'mt76x2_common', 'mt7921_common', 'mt76x0_common', 'mt76_usb', 'mt76x02_lib', # mediatek
5+
'cdc_acm', 'cdc_ncm', 'cdc_wdm', 'cdc_ether', # USB CDC
6+
'stp', '8021q', 'llc', 'garp', 'mrp', 'bridge', 'bonding', # Ethernet
57
'r8169', 'r8152', 'r8153_ecm', 'igb', 'ixgbe', 'tg3', 'e1000e', 'e1000', # Ethernet cards
68
'tun', 'tap', 'wireguard', 'udp_tunnel', 'ip6_udp_tunnel', # Tunnels
79
'net_failover', 'failover','vhost_net','usbnet', # Misc
810
'tls', 'sctp', # Misc protocols
11+
'rtl2832', 'r820t', 'dvb_usb_rtl28xxu', 'dvb_core', 'dvb_usb_v2', # SDR
912
'grace', 'nfs_acl', 'nfsd', 'lockd', 'sunrpc', 'auth_rpcgss', 'nfs', 'netfs', # NFS
1013
'nf_nat', 'nfnetlink', 'nfnetlink_queue', 'nfnetlink_log', # Netfilter base
1114
'nf_conntrack', 'nf_conntrack_netlink', # Netfilter conntrack

src/ugrd/kmod/nosound.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ kmod_ignore = [
33
'snd_timer', 'snd_hrtimer', # alsa
44
'snd_pcm', 'snd_rawmidi', 'snd_seq_device', 'snd_seq', 'snd_seq_dummy', 'snd_ump', # subtypes
55
'snd_usb_audio', 'snd_usbmidi_lib', # usb
6-
'snd_soc_core', 'snd_soc_acpi', # soc
6+
'snd_soc_core', 'snd_soc_acpi', 'snd_acp_config', # soc
77
'snd_soc_acpi_intel_match', # intel soc
8-
'snd_sof_utils', 'snd_sof_pci', # sof
8+
'snd_sof', 'snd_sof_utils', 'snd_sof_pci', 'snd_sof_xtensa_dsp', # sof
99
'snd_sof_intel_hda', # intel sof
1010
'snd_hda_intel', 'snd_intel_sdw_acpi', 'snd_intel_dspcfg', # intel
11+
'ac97_bus', 'snd_rpl_pci_acp6x', 'snd_rn_pci_acp3x', 'snd_pci_acp3x', # AMD
1112
'snd_hda_codec_hdmi', # hdmi
1213
'soundwire_cadence', 'soundwire_bus', 'soundwire_generic_allocation', # soundwire
13-
'ledtrig_audio', # misc
14+
'ledtrig_audio', 'ac97_bus', # misc
1415
]

0 commit comments

Comments
 (0)