Skip to content

Commit 1ae4ac7

Browse files
committed
add toggle to disable normalization of kmod names
in some cases, such as for apple-bce, it seems it can't be queried by the name with an underscore Signed-off-by: Zen <[email protected]>
1 parent 8149d59 commit 1ae4ac7

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ The following parameters can be used to change the kernel module pulling and ini
178178
* `kmod_ignore` - Kernel modules to ignore. Modules which depend on ignored modules will also be ignored.
179179
* `kmod_ignore_softdeps` (false) Ignore softdeps when checking kernel module dependencies.
180180
* `no_kmod` (false) Disable kernel modules entirely.
181+
* `kmod_no_normalize` - A list of kernel module names to not normalize (replace dashes with underscores).
181182

182183
##### ugrd.kmod.input
183184

src/ugrd/kmod/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
from typing import Union
2-
3-
4-
def _normalize_kmod_name(module: Union[str, list]) -> str:
5-
"""Replaces -'s with _'s in a kernel module name."""
6-
if isinstance(module, list) and not isinstance(module, str):
7-
return [_normalize_kmod_name(m) for m in module]
8-
return module.replace("-", "_")
9-
10-
111
class DependencyResolutionError(Exception):
122
pass
133

src/ugrd/kmod/kmod.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
__author__ = "desultory"
2-
__version__ = "3.4.1"
2+
__version__ = "3.5.0"
33

44
from pathlib import Path
55
from platform import uname
66
from struct import error as StructError
77
from struct import unpack
88
from subprocess import run
9+
from typing import Union
910

1011
from ugrd.exceptions import AutodetectError, ValidationError
1112
from ugrd.kmod import (
1213
BuiltinModuleError,
1314
DependencyResolutionError,
1415
IgnoredModuleError,
1516
MissingModuleError,
16-
_normalize_kmod_name,
1717
)
1818
from zenlib.util import colorize as c_
1919
from zenlib.util import contains, unset
2020

2121
MODULE_METADATA_FILES = ["modules.order", "modules.builtin", "modules.builtin.modinfo"]
2222

23+
def _normalize_kmod_name(self, module: Union[str, list]) -> str:
24+
"""Replaces -'s with _'s in a kernel module name.
25+
ignores modules defined in kmod_no_normalize.
26+
"""
27+
if isinstance(module, list) and not isinstance(module, str):
28+
return [_normalize_kmod_name(self, m) for m in module]
29+
if module in self.get("kmod_no_normalize", []):
30+
self.logger.debug(f"Not normalizing kernel module name: {module}")
31+
return module
32+
if "-" in module:
33+
self.logger.log(5, f"Replacing - with _ in kernel module name: {module}")
34+
return module.replace("-", "_")
35+
2336

2437
def _process_kernel_modules_multi(self, module: str) -> None:
2538
"""Adds kernel modules to self['kernel_modules']."""
26-
module = _normalize_kmod_name(module)
39+
module = _normalize_kmod_name(self, module)
2740
if module in self["kmod_ignore"]:
2841
self.logger.debug("[%s] Module is in the ignore list." % module)
2942
self["_kmod_removed"] = module
@@ -35,7 +48,7 @@ def _process_kernel_modules_multi(self, module: str) -> None:
3548

3649
def _process_kmod_init_multi(self, module: str) -> None:
3750
"""Adds init modules to self['kernel_modules']."""
38-
module = _normalize_kmod_name(module)
51+
module = _normalize_kmod_name(self, module)
3952
if module in self["kmod_ignore"]:
4053
raise IgnoredModuleError("kmod_init module is in the ignore list: %s" % module)
4154
self["kmod_init"].append(module)
@@ -45,7 +58,7 @@ def _process_kmod_init_multi(self, module: str) -> None:
4558

4659
def _process_kmod_init_optional_multi(self, module: str) -> None:
4760
"""Adds an optional kmod init module"""
48-
module = _normalize_kmod_name(module)
61+
module = _normalize_kmod_name(self, module)
4962
if module in self["kmod_ignore"]:
5063
self.logger.warning(f"Optional kmod_init module is in the ignore list: {c_(module, 'yellow', bold=True)}")
5164
self["_kmod_removed"] = module
@@ -59,7 +72,7 @@ def _process_kmod_init_optional_multi(self, module: str) -> None:
5972

6073
def _process__kmod_auto_multi(self, module: str) -> None:
6174
"""Adds autodetected modules to self['kernel_modules']."""
62-
module = _normalize_kmod_name(module)
75+
module = _normalize_kmod_name(self, module)
6376
if module in self["kmod_ignore"]:
6477
self.logger.debug("Autodetected module is in the ignore list: %s" % module)
6578
self["_kmod_removed"] = module
@@ -73,7 +86,7 @@ def _get_kmod_info(self, module: str):
7386
Runs modinfo on a kernel module, parses the output and stored the results in self['_kmod_modinfo'].
7487
!!! Should be run after metadata is processed so the kver is set properly !!!
7588
"""
76-
module = _normalize_kmod_name(module)
89+
module = _normalize_kmod_name(self, module)
7790
if module in self["_kmod_modinfo"]:
7891
return self.logger.debug("[%s] Module info already exists." % module)
7992
args = ["modinfo", module, "--set-version", self["kernel_version"]]
@@ -94,9 +107,9 @@ def _get_kmod_info(self, module: str):
94107
module_info["filename"] = line.split()[1]
95108
elif line.startswith("depends:") and line != "depends:":
96109
if "," in line:
97-
module_info["depends"] = _normalize_kmod_name(line.split(":")[1].lstrip().split(","))
110+
module_info["depends"] = _normalize_kmod_name(self, line.split(":")[1].lstrip().split(","))
98111
else:
99-
module_info["depends"] = _normalize_kmod_name([line.split()[1]])
112+
module_info["depends"] = _normalize_kmod_name(self, [line.split()[1]])
100113
elif line.startswith("softdep:"):
101114
if "softdep" not in module_info:
102115
module_info["softdep"] = []
@@ -296,7 +309,7 @@ def _add_kmod_firmware(self, kmod: str) -> None:
296309
297310
Attempts to run even if no_kmod is set; this will not work if there are no kmods/no kernel version set
298311
"""
299-
kmod = _normalize_kmod_name(kmod)
312+
kmod = _normalize_kmod_name(self, kmod)
300313

301314
if kmod not in self["_kmod_modinfo"]:
302315
if self["no_kmod"]:
@@ -319,7 +332,7 @@ def _add_kmod_firmware(self, kmod: str) -> None:
319332

320333
def _add_firmware_dep(self, kmod: str, firmware: str) -> None:
321334
"""Adds a kernel module firmware file to the initramfs dependencies."""
322-
kmod = _normalize_kmod_name(kmod)
335+
kmod = _normalize_kmod_name(self, kmod)
323336
firmware_path = Path("/lib/firmware") / firmware
324337
if not firmware_path.exists():
325338
if firmware_path.with_suffix(firmware_path.suffix + ".xz").exists():
@@ -345,7 +358,7 @@ def _process_kmod_dependencies(self, kmod: str, mod_tree=None) -> None:
345358
If the dependency is already in the module tree, skip it to prevent infinite recursion.
346359
"""
347360
mod_tree = mod_tree or set()
348-
kmod = _normalize_kmod_name(kmod)
361+
kmod = _normalize_kmod_name(self, kmod)
349362
_get_kmod_info(self, kmod)
350363

351364
# Get kernel module dependencies, softedeps if not ignored

src/ugrd/kmod/kmod.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ kernel_modules = "NoDupFlatList" # Kernel modules to pull into the initramfs
2222
kmod_init = "NoDupFlatList" # Kernel modules to load at initramfs startup
2323
kmod_init_optional = "NoDupFlatList" # Kernel modules to try to add to kmod_init
2424
no_kmod = "bool" # Disables kernel modules entirely
25+
kmod_no_normalize = "NoDupFlatList" # Kernel modules to not normalize (i.e. not convert dashes to underscores)
2526

2627
[imports.config_processing]
2728
"ugrd.kmod.kmod" = [ "_process_kernel_version",

0 commit comments

Comments
 (0)