Skip to content

Commit 29cf0ab

Browse files
authored
Merge pull request #340 from desultory/dev
add basic regulator detection, bugfixed for other platform detection
2 parents f974188 + 1c9b7cf commit 29cf0ab

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

src/ugrd/kmod/input.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.0"
1+
__version__ = "0.2.1"
22

33
from pathlib import Path
44

@@ -38,7 +38,17 @@ def autodetect_input(self):
3838
f"[{input_dev.name}:{c_(keyboard_name, 'blue')}] Not enough keys detected: {c_(enabled_keys, 'yellow')} < {self.keyboard_key_threshold}"
3939
)
4040
continue
41-
keyboard_driver = (input_dev / "device" / "driver").resolve().name
41+
if (input_dev / "device" / "driver").exists():
42+
keyboard_driver = (input_dev / "device" / "driver").resolve().name
43+
elif (input_dev / "device" / "device" / "driver").exists():
44+
# Some devices may have an additional "device" directory
45+
keyboard_driver = (input_dev / "device" / "device" / "driver").resolve().name
46+
else:
47+
self.logger.error(
48+
f"[{input_dev.name}:{c_(keyboard_name, 'blue')}] Unable to resolve driver for input device: {c_(input_dev, 'red')}"
49+
)
50+
continue
51+
4252
self.logger.info(f"[{c_(keyboard_name, 'blue')}] Detected driver: {c_(keyboard_driver, 'cyan')}")
4353
self._kmod_auto = [keyboard_driver]
4454
found_keyboard = True

src/ugrd/kmod/platform.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from pathlib import Path
2+
13
from zenlib.util import colorize as c_
24
from zenlib.util import contains
35

4-
__version__ = "0.1.2"
6+
__version__ = "0.2.1"
57

68
VM_PRODUCT_NAMES = {
79
"Virtual Machine": ["virtio_blk"],
@@ -21,11 +23,19 @@
2123
@contains("hostonly", "hostonly is not enabled, skipping platform detection.", log_level=30)
2224
def get_platform_info(self):
2325
"""Detects plaform information such as the vendor and product name"""
24-
with open("/sys/class/dmi/id/product_name", "r") as f:
25-
self["_dmi_product_name"] = f.read().strip()
26+
try:
27+
with open("/sys/class/dmi/id/product_name", "r") as f:
28+
self["_dmi_product_name"] = f.read().strip()
29+
except FileNotFoundError:
30+
self.logger.warning("Could not read /sys/class/dmi/id/product_name, skipping product name detection.")
31+
self["_dmi_product_name"] = "Unknown Product"
2632

27-
with open("/sys/class/dmi/id/sys_vendor", "r") as f:
28-
self["_dmi_system_vendor"] = f.read().strip()
33+
try:
34+
with open("/sys/class/dmi/id/sys_vendor", "r") as f:
35+
self["_dmi_system_vendor"] = f.read().strip()
36+
except FileNotFoundError:
37+
self.logger.warning("Could not read /sys/class/dmi/id/sys_vendor, skipping system vendor detection.")
38+
self["_dmi_system_vendor"] = "Unknown Vendor"
2939

3040

3141
@contains("hostonly", "hostonly is not enabled, skipping VM detection.", log_level=30)
@@ -49,3 +59,44 @@ def autodetect_virtual_machine(self):
4959
self["kmod_init"] = vendor_kmods
5060
if product_kmods:
5161
self["_kmod_auto"] = product_kmods
62+
63+
@contains("hostonly", "hostonly is not enabled, skipping regulator driver detection.", log_level=30)
64+
def autodetect_regulator_drivers(self):
65+
""" Detects regulator drivers from /sys/class/regulator and adds them to the _kmod_auto list."""
66+
regulators_path = Path("/sys/class/regulator")
67+
if not regulators_path.exists():
68+
self.logger.warning(f"[{c_(regulators_path, 'yellow')}] Regulator path does not exist, skipping detection.")
69+
return
70+
71+
kmods = set()
72+
73+
for regulator in regulators_path.iterdir():
74+
if regulator.is_dir() and (regulator / "device").exists():
75+
name = (regulator / "name").read_text().strip() if (regulator / "name").exists() else regulator.name
76+
driver = (regulator / "device" / "driver").resolve().name
77+
kmods.add(driver)
78+
self.logger.debug(f"[{c_(name, 'cyan', bright=True)}] Detected regulator driver: {c_(driver, 'magenta', bright=True)}")
79+
80+
if not kmods:
81+
self.logger.info("No regulator drivers detected.")
82+
else:
83+
self.logger.info(f"Detected regulator drivers: {c_(', '.join(kmods), color='magenta', bright=True)}")
84+
self["_kmod_auto"] = list(kmods)
85+
86+
87+
@contains("hostonly", "hostonly is not enabled, skipping platform bus driver detection.", log_level=30)
88+
def autodetect_platform_bus_drivers(self):
89+
""" Reads drivers from /sys/bus/platform/drivers and adds them to the _kmod_auto list."""
90+
91+
drivers_path = Path("/sys/bus/platform/drivers")
92+
if not drivers_path.exists():
93+
self.logger.warning(f"[{c_(drivers_path, 'yellow')}] Platform bus drivers path does not exist, skipping detection.")
94+
return
95+
96+
drivers = [driver.name for driver in drivers_path.iterdir() if driver.is_dir()]
97+
if drivers:
98+
self["_kmod_auto"] = list(set(self.get("_kmod_auto", []) + drivers))
99+
self.logger.info(f"Detected platform bus drivers: {c_(', '.join(drivers), color='magenta', bright=True)}")
100+
else:
101+
self.logger.info("No platform bus drivers detected.")
102+

src/ugrd/kmod/platform.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[imports.build_enum]
2-
"ugrd.kmod.platform" = ["get_platform_info", "autodetect_virtual_machine"]
2+
"ugrd.kmod.platform" = ["get_platform_info", "autodetect_virtual_machine", "autodetect_regulator_drivers"]
33

44
[import_order.before]
55
"get_platform_info" = "autodetect_virtual_machine"

src/ugrd/kmod/standard_mask.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kmod_ignore_network = true
55
# These can always be ignored
66
kmod_ignore = [
77
'kvm', 'kvm_amd', 'kvm_intel', # virtualization
8-
'ch341', 'cp210x', 'joydev', 'binfmt_misc', 'xpad', # misc
8+
'reg_dummy', 'ch341', 'cp210x', 'joydev', 'binfmt_misc', 'xpad', # misc
99
'coretemp', 'x86_pkg_temp_thermal', 'k10temp', 'x86_pkg_temp_thermal', # thermal
1010
'iTCO_wdt', 'iTCO_vendor_support', 'sp5100_tco', # watchdog
1111
'intel_qat', 'intel_powerclamp', 'intel_cstate', 'rapl', 'intel_rapl_common', 'intel_rapl_msr', 'intel_pmc_bxt', #intel

0 commit comments

Comments
 (0)