summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDixit Parmar <dixitparmar19@gmail.com>2025-06-09 19:15:35 +0530
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-12 11:03:43 +0100
commit7f9f608d39cd11fb3d3da7b6c9ec5f447ed45745 (patch)
tree60061ceb9f1a15304ba6752d7138e51ab4c5d264
parent36b5c3e78c38bbf6aabd7d8e02092b9132869606 (diff)
downloadpoky-7f9f608d39cd11fb3d3da7b6c9ec5f447ed45745.tar.gz
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] (From OE-Core rev: cf998576ccfd20a61a9afa6df27fb73d93c8ed9a) Signed-off-by: Dixit Parmar <dixitparmar19@gmail.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/kernel-module-split.bbclass76
1 files changed, 61 insertions, 15 deletions
diff --git a/meta/classes-recipe/kernel-module-split.bbclass b/meta/classes-recipe/kernel-module-split.bbclass
index a2d81f18e2..75ed696b72 100644
--- a/meta/classes-recipe/kernel-module-split.bbclass
+++ b/meta/classes-recipe/kernel-module-split.bbclass
@@ -86,11 +86,7 @@ python split_kernel_module_packages () {
86 vals[m.group(1)] = m.group(2) 86 vals[m.group(1)] = m.group(2)
87 return vals 87 return vals
88 88
89 def frob_metadata(file, pkg, pattern, format, basename): 89 def handle_conf_files(d, basename, pkg):
90 vals = extract_modinfo(file)
91
92 dvar = d.getVar('PKGD')
93
94 # If autoloading is requested, output ${modulesloaddir}/<name>.conf and append 90 # If autoloading is requested, output ${modulesloaddir}/<name>.conf and append
95 # appropriate modprobe commands to the postinst 91 # appropriate modprobe commands to the postinst
96 autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split() 92 autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split()
@@ -102,7 +98,7 @@ python split_kernel_module_packages () {
102 98
103 # The .conf file can either be installed by a recipe or generated from module_autoload_* 99 # The .conf file can either be installed by a recipe or generated from module_autoload_*
104 conf = '%s/%s.conf' % (d.getVar('modulesloaddir'), basename) 100 conf = '%s/%s.conf' % (d.getVar('modulesloaddir'), basename)
105 name = '%s%s' % (dvar, conf) 101 name = '%s%s' % (d.getVar('PKGD'), conf)
106 # If module name is in KERNEL_MODULE_AUTOLOAD, then generate the .conf file and write to `name`. 102 # If module name is in KERNEL_MODULE_AUTOLOAD, then generate the .conf file and write to `name`.
107 if basename in autoloadlist: 103 if basename in autoloadlist:
108 os.makedirs(os.path.dirname(name), exist_ok=True) 104 os.makedirs(os.path.dirname(name), exist_ok=True)
@@ -120,7 +116,7 @@ python split_kernel_module_packages () {
120 d.appendVar('CONFFILES:%s' % pkg, conf2append) 116 d.appendVar('CONFFILES:%s' % pkg, conf2append)
121 postinst = d.getVar('pkg_postinst:%s' % pkg) 117 postinst = d.getVar('pkg_postinst:%s' % pkg)
122 if not postinst: 118 if not postinst:
123 bb.fatal("pkg_postinst:%s not defined" % pkg) 119 postinst = d.getVar('pkg_postinst:modules')
124 postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename) 120 postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename)
125 d.setVar('pkg_postinst:%s' % pkg, postinst) 121 d.setVar('pkg_postinst:%s' % pkg, postinst)
126 122
@@ -130,7 +126,7 @@ python split_kernel_module_packages () {
130 126
131 # The .conf file can either be installed by a recipe or generated from module_conf_* 127 # The .conf file can either be installed by a recipe or generated from module_conf_*
132 conf = '%s/%s.conf' % (d.getVar('modprobedir'), basename) 128 conf = '%s/%s.conf' % (d.getVar('modprobedir'), basename)
133 name = '%s%s' % (dvar, conf) 129 name = '%s%s' % (d.getVar('PKGD'), conf)
134 # If module name is in KERNEL_MODULE_PROBECONF, then generate the .conf file and write to `name`. 130 # If module name is in KERNEL_MODULE_PROBECONF, then generate the .conf file and write to `name`.
135 if modconf and basename in modconflist: 131 if modconf and basename in modconflist:
136 os.makedirs(os.path.dirname(name), exist_ok=True) 132 os.makedirs(os.path.dirname(name), exist_ok=True)
@@ -145,6 +141,55 @@ python split_kernel_module_packages () {
145 d.appendVar('FILES:%s' % pkg, conf2append) 141 d.appendVar('FILES:%s' % pkg, conf2append)
146 d.appendVar('CONFFILES:%s' % pkg, conf2append) 142 d.appendVar('CONFFILES:%s' % pkg, conf2append)
147 143
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
148 if "description" in vals: 193 if "description" in vals:
149 old_desc = d.getVar('DESCRIPTION:' + pkg) or "" 194 old_desc = d.getVar('DESCRIPTION:' + pkg) or ""
150 d.setVar('DESCRIPTION:' + pkg, old_desc + "; " + vals["description"]) 195 d.setVar('DESCRIPTION:' + pkg, old_desc + "; " + vals["description"])
@@ -178,19 +223,20 @@ python split_kernel_module_packages () {
178 postinst = d.getVar('pkg_postinst:modules') 223 postinst = d.getVar('pkg_postinst:modules')
179 postrm = d.getVar('pkg_postrm:modules') 224 postrm = d.getVar('pkg_postrm:modules')
180 225
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
188 module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$' 226 module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$'
189 227
190 module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX') 228 module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX')
191 module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX') 229 module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX')
192 module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix 230 module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix
193 231
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
194 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)) 240 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))
195 if modules: 241 if modules:
196 d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules)) 242 d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules))