Skip to content

Commit 61833a3

Browse files
dixitparmar19rpurdie
authored andcommitted
kernel-module-split: fix conf file generation when KERNEL_SPLIT_MODULES=0
When KERNEL_SPLIT_MODULES=0 modprobe and autoload conf files are not getting generated for the kernel modules. Separated out conf file handling mechanism as handle_conf_files() function from hook frob_metadata() function. handle_conf_files() gets re-used from the existing hook function and add_conf_files function which got introduced for splitmods=0 flow in this patch. [YOCTO #15145] Signed-off-by: Dixit Parmar <dixitparmar19@gmail.com> Cc: George Thopas <george.thopas@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
1 parent ea2ed76 commit 61833a3

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

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

Lines changed: 67 additions & 14 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()
@@ -101,7 +97,7 @@ python split_kernel_module_packages () {
10197
bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename))
10298
if basename in autoloadlist:
10399
conf = '%s/%s.conf' % (d.getVar('modulesloaddir'), basename)
104-
name = '%s%s' % (dvar, conf)
100+
name = '%s%s' % (d.getVar('PKGD'), conf)
105101
os.makedirs(os.path.dirname(name), exist_ok=True)
106102
with open(name, 'w') as f:
107103
if autoload:
@@ -123,7 +119,7 @@ python split_kernel_module_packages () {
123119
modconf = d.getVar('module_conf_%s' % basename)
124120
if modconf and basename in modconflist:
125121
conf = '%s/%s.conf' % (d.getVar('modprobedir'), basename)
126-
name = '%s%s' % (dvar, conf)
122+
name = '%s%s' % (d.getVar('PKGD'), conf)
127123
os.makedirs(os.path.dirname(name), exist_ok=True)
128124
with open(name, 'w') as f:
129125
f.write("%s\n" % modconf)
@@ -134,6 +130,63 @@ python split_kernel_module_packages () {
134130
elif modconf:
135131
bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename))
136132

133+
def add_conf_files(d, root, file_regex, output_pattern):
134+
"""
135+
Arguments:
136+
root -- the path in which to search
137+
file_regex -- regular expression to match searched files. Use
138+
parentheses () to mark the part of this expression
139+
that should be used to derive the module name (to be
140+
substituted where %s is used in other function
141+
arguments as noted below)
142+
output_pattern -- pattern to use for the package names. Must include %s.
143+
"""
144+
145+
dvar = d.getVar('PKGD')
146+
root = d.expand(root)
147+
output_pattern = d.expand(output_pattern)
148+
149+
# check if the root directory doesn't exist for safe side, don't error out later but silently do
150+
# no splitting.
151+
if not os.path.exists(dvar + root):
152+
bb.warn("kernel module root directory path does not exist")
153+
return []
154+
155+
# get list of modules
156+
objs = []
157+
for walkroot, dirs, files in os.walk(dvar + root):
158+
for file in files:
159+
relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
160+
if relpath:
161+
objs.append(relpath)
162+
163+
for o in sorted(objs):
164+
import re, stat
165+
if False:
166+
m = re.match(file_regex, o)
167+
else:
168+
m = re.match(file_regex, os.path.basename(o))
169+
170+
if not m:
171+
continue
172+
173+
file = os.path.join(dvar + root, o)
174+
mode = os.lstat(file).st_mode
175+
if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
176+
continue
177+
178+
on = legitimize_package_name(m.group(1))
179+
pkg = output_pattern % on
180+
181+
basename = m.group(1)
182+
handle_conf_files(d, basename, pkg)
183+
184+
def frob_metadata(file, pkg, pattern, format, basename):
185+
vals = extract_modinfo(file)
186+
dvar = d.getVar('PKGD')
187+
188+
handle_conf_files(d, basename, pkg)
189+
137190
if "description" in vals:
138191
old_desc = d.getVar('DESCRIPTION:' + pkg) or ""
139192
d.setVar('DESCRIPTION:' + pkg, old_desc + "; " + vals["description"])
@@ -167,19 +220,19 @@ python split_kernel_module_packages () {
167220
postinst = d.getVar('pkg_postinst:modules')
168221
postrm = d.getVar('pkg_postrm:modules')
169222

223+
module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$'
224+
module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX')
225+
module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX')
226+
module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix
227+
170228
if splitmods != '1':
171229
d.appendVar('FILES:' + metapkg, '%s %s %s/modules' %
172230
(d.getVar('modulesloaddir'), d.getVar('modprobedir'), d.getVar("nonarch_base_libdir")))
173231
d.appendVar('pkg_postinst:%s' % metapkg, postinst)
174-
d.prependVar('pkg_postrm:%s' % metapkg, postrm);
232+
d.prependVar('pkg_postrm:%s' % metapkg, postrm)
233+
add_conf_files(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern)
175234
return
176235

177-
module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$'
178-
179-
module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX')
180-
module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX')
181-
module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix
182-
183236
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))
184237
if modules:
185238
d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules))

0 commit comments

Comments
 (0)