Skip to content

Commit 6aaf639

Browse files
dixitparmar19rpurdie
authored andcommitted
kernel-module-split: fix conf file generation when KERNEL_SPLIT_MODULES=0
KERNEL_MODULE_AUTOLOAD defines the list of the kernel modules to be autoloaded on boot. kernel-module-split.bbclass generates the required modules.load.d and conf files for each kernel module. This conf files inturn read by system service to perform module loading and configuration. When a kernel module is added to KERNEL_MODULE_AUTOLOAD the conf files must be generated in all cases. When KERNEL_SPLIT_MODULES=0 modprobe and autoload conf files are not getting generated for the kernel modules. To fix that enhanced the class implementation by separating out conf file handling mechanism in two functions, generate_conf_files() and frob_metadata(). generate_conf_files() handles no-split case where as frob_metadata() keeps handling the existing case for spliting the modules. Splitted common handling/generation of conf files stuff in to handle_conf_files() function which gets invoked by both frob_metadata() and generate_conf_files() on top of the scenario specific handling done in respective functions. This implementation covers generation of the conf files for in-tree kernel modules as well as standalone kernel module built as seperate package/recipe. [YOCTO #15145] Signed-off-by: Dixit Parmar <dixitparmar19@gmail.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
1 parent 41cbd1d commit 6aaf639

File tree

1 file changed

+61
-15
lines changed

1 file changed

+61
-15
lines changed

meta/classes-recipe/kernel-module-split.bbclass

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ python split_kernel_module_packages () {
8686
vals[m.group(1)] = m.group(2)
8787
return vals
8888

89-
def frob_metadata(file, pkg, pattern, format, basename):
90-
vals = extract_modinfo(file)
91-
92-
dvar = d.getVar('PKGD')
93-
89+
def handle_conf_files(d, basename, pkg):
9490
# If autoloading is requested, output ${modulesloaddir}/<name>.conf and append
9591
# appropriate modprobe commands to the postinst
9692
autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split()
@@ -102,7 +98,7 @@ python split_kernel_module_packages () {
10298

10399
# The .conf file can either be installed by a recipe or generated from module_autoload_*
104100
conf = '%s/%s.conf' % (d.getVar('modulesloaddir'), basename)
105-
name = '%s%s' % (dvar, conf)
101+
name = '%s%s' % (d.getVar('PKGD'), conf)
106102
# If module name is in KERNEL_MODULE_AUTOLOAD, then generate the .conf file and write to `name`.
107103
if basename in autoloadlist:
108104
os.makedirs(os.path.dirname(name), exist_ok=True)
@@ -120,7 +116,7 @@ python split_kernel_module_packages () {
120116
d.appendVar('CONFFILES:%s' % pkg, conf2append)
121117
postinst = d.getVar('pkg_postinst:%s' % pkg)
122118
if not postinst:
123-
bb.fatal("pkg_postinst:%s not defined" % pkg)
119+
postinst = d.getVar('pkg_postinst:modules')
124120
postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename)
125121
d.setVar('pkg_postinst:%s' % pkg, postinst)
126122

@@ -130,7 +126,7 @@ python split_kernel_module_packages () {
130126

131127
# The .conf file can either be installed by a recipe or generated from module_conf_*
132128
conf = '%s/%s.conf' % (d.getVar('modprobedir'), basename)
133-
name = '%s%s' % (dvar, conf)
129+
name = '%s%s' % (d.getVar('PKGD'), conf)
134130
# If module name is in KERNEL_MODULE_PROBECONF, then generate the .conf file and write to `name`.
135131
if modconf and basename in modconflist:
136132
os.makedirs(os.path.dirname(name), exist_ok=True)
@@ -145,6 +141,55 @@ python split_kernel_module_packages () {
145141
d.appendVar('FILES:%s' % pkg, conf2append)
146142
d.appendVar('CONFFILES:%s' % pkg, conf2append)
147143

144+
def generate_conf_files(d, root, file_regex, output_pattern):
145+
"""
146+
Arguments:
147+
root -- the path in which to search. Contains system lib path
148+
so needs expansion.
149+
file_regex -- regular expression to match searched files. Use
150+
parentheses () to mark the part of this expression
151+
that should be used to derive the module name (to be
152+
substituted where %s is used in other function
153+
arguments as noted below)
154+
output_pattern -- pattern to use for the package names. Must include %s.
155+
"""
156+
import re, stat
157+
158+
dvar = d.getVar('PKGD')
159+
root = d.expand(root)
160+
161+
# if the root directory doesn't exist, it's fatal - exit from the current execution.
162+
if not os.path.exists(dvar + root):
163+
bb.fatal("kernel module root directory path does not exist")
164+
165+
# walk through kernel module directory. for each entry in the directory, check if it
166+
# matches the desired regex pattern and file type. if it fullfills, process it to generate
167+
# it's conf file based on its package name.
168+
for walkroot, dirs, files in os.walk(dvar + root):
169+
for file in files:
170+
relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
171+
if not relpath:
172+
continue
173+
m = re.match(file_regex, os.path.basename(relpath))
174+
if not m:
175+
continue
176+
file_f = os.path.join(dvar + root, relpath)
177+
mode = os.lstat(file_f).st_mode
178+
if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
179+
continue
180+
181+
basename = m.group(1)
182+
on = legitimize_package_name(basename)
183+
pkg = output_pattern % on
184+
handle_conf_files(d, basename, pkg)
185+
186+
187+
def frob_metadata(file, pkg, pattern, format, basename):
188+
vals = extract_modinfo(file)
189+
dvar = d.getVar('PKGD')
190+
191+
handle_conf_files(d, basename, pkg)
192+
148193
if "description" in vals:
149194
old_desc = d.getVar('DESCRIPTION:' + pkg) or ""
150195
d.setVar('DESCRIPTION:' + pkg, old_desc + "; " + vals["description"])
@@ -178,19 +223,20 @@ python split_kernel_module_packages () {
178223
postinst = d.getVar('pkg_postinst:modules')
179224
postrm = d.getVar('pkg_postrm:modules')
180225

181-
if splitmods != '1':
182-
d.appendVar('FILES:' + metapkg, '%s %s %s/modules' %
183-
(d.getVar('modulesloaddir'), d.getVar('modprobedir'), d.getVar("nonarch_base_libdir")))
184-
d.appendVar('pkg_postinst:%s' % metapkg, postinst)
185-
d.prependVar('pkg_postrm:%s' % metapkg, postrm);
186-
return
187-
188226
module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$'
189227

190228
module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX')
191229
module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX')
192230
module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix
193231

232+
if splitmods != '1':
233+
d.appendVar('FILES:' + metapkg, '%s %s %s/modules' %
234+
(d.getVar('modulesloaddir'), d.getVar('modprobedir'), d.getVar("nonarch_base_libdir")))
235+
d.appendVar('pkg_postinst:%s' % metapkg, postinst)
236+
d.prependVar('pkg_postrm:%s' % metapkg, postrm)
237+
generate_conf_files(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern)
238+
return
239+
194240
modules = do_split_packages(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='%s-%s' % (kernel_package_name, kernel_version))
195241
if modules:
196242
d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules))

0 commit comments

Comments
 (0)