summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorMartin Jansa <martin.jansa@gmail.com>2013-03-02 18:06:56 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-03-05 13:14:50 +0000
commit2b8f2e770e074ee6735440c2e44eb56397857858 (patch)
tree00817af99869f35b9f54cef67546cd987b9ac185 /meta/classes
parent93ec7b4d1550e07caec86e2998d0f94a01c7e785 (diff)
downloadpoky-2b8f2e770e074ee6735440c2e44eb56397857858.tar.gz
kernel: extract functions for kernel modules to separate bbclass
* this way we can reuse the same functionality also for external modules including module_autoload_foo and module_conf_foo functionality * MODULE_PACKAGES variable was removed (splited modules are now returned by do_split_packages * KERNEL_MODULES_META_PACKAGE is used to append all splitted packages to RDEPENDS. In kernel.bbclass it's old "kernel-modules" in module.bbclass it defaults to ${PN} for upgrade path from single PN with all modules to PN depending on all new kernel-module-* (From OE-Core rev: 51928b6b5ca0a46a9dcd754483a19af58b95fa18) Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/kernel-module-split.bbclass185
-rw-r--r--meta/classes/kernel.bbclass180
-rw-r--r--meta/classes/module.bbclass35
3 files changed, 191 insertions, 209 deletions
diff --git a/meta/classes/kernel-module-split.bbclass b/meta/classes/kernel-module-split.bbclass
new file mode 100644
index 0000000000..aa0c499b79
--- /dev/null
+++ b/meta/classes/kernel-module-split.bbclass
@@ -0,0 +1,185 @@
1pkg_postinst_modules () {
2if [ -z "$D" ]; then
3 depmod -a ${KERNEL_VERSION}
4else
5 depmodwrapper -a -b $D ${KERNEL_VERSION}
6fi
7}
8
9pkg_postrm_modules () {
10if [ -z "$D" ]; then
11 depmod -a ${KERNEL_VERSION}
12else
13 depmodwrapper -a -b $D ${KERNEL_VERSION}
14fi
15}
16
17autoload_postinst_fragment() {
18if [ x"$D" = "x" ]; then
19 modprobe %s || true
20fi
21}
22
23do_install_append() {
24 install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/
25}
26
27PACKAGESPLITFUNCS_prepend = "split_kernel_module_packages "
28
29KERNEL_MODULES_META_PACKAGE ?= "kernel-modules"
30
31python split_kernel_module_packages () {
32 import re
33
34 modinfoexp = re.compile("([^=]+)=(.*)")
35 kerverrexp = re.compile('^(.*-hh.*)[\.\+].*$')
36 depmodpat0 = re.compile("^(.*\.k?o):..*$")
37 depmodpat1 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*$")
38 depmodpat2 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*\\\$")
39 depmodpat3 = re.compile("^\t(.*\.k?o)\s*\\\$")
40 depmodpat4 = re.compile("^\t(.*\.k?o)\s*$")
41
42 def extract_modinfo(file):
43 import tempfile, subprocess
44 tempfile.tempdir = d.getVar("WORKDIR", True)
45 tf = tempfile.mkstemp()
46 tmpfile = tf[1]
47 cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX", True) or "", file, tmpfile)
48 subprocess.call(cmd, shell=True)
49 f = open(tmpfile)
50 l = f.read().split("\000")
51 f.close()
52 os.close(tf[0])
53 os.unlink(tmpfile)
54 vals = {}
55 for i in l:
56 m = modinfoexp.match(i)
57 if not m:
58 continue
59 vals[m.group(1)] = m.group(2)
60 return vals
61
62 def parse_depmod():
63
64 dvar = d.getVar('PKGD', True)
65
66 kernelver = d.getVar('KERNEL_VERSION', True)
67 kernelver_stripped = kernelver
68 m = kerverrexp.match(kernelver)
69 if m:
70 kernelver_stripped = m.group(1)
71 staging_kernel_dir = d.getVar("STAGING_KERNEL_DIR", True)
72 system_map_file = "%s/boot/System.map-%s" % (dvar, kernelver)
73 if not os.path.exists(system_map_file):
74 system_map_file = "%s/System.map-%s" % (staging_kernel_dir, kernelver)
75 if not os.path.exists(system_map_file):
76 bb.fatal("System.map-%s does not exist in '%s/boot' nor STAGING_KERNEL_DIR '%s'" % (kernelver, dvar, staging_kernel_dir))
77
78 cmd = "depmod -n -a -b %s -F %s %s" % (dvar, system_map_file, kernelver_stripped)
79 f = os.popen(cmd, 'r')
80
81 deps = {}
82 line = f.readline()
83 while line:
84 if not depmodpat0.match(line):
85 line = f.readline()
86 continue
87 m1 = depmodpat1.match(line)
88 if m1:
89 deps[m1.group(1)] = m1.group(2).split()
90 else:
91 m2 = depmodpat2.match(line)
92 if m2:
93 deps[m2.group(1)] = m2.group(2).split()
94 line = f.readline()
95 m3 = depmodpat3.match(line)
96 while m3:
97 deps[m2.group(1)].extend(m3.group(1).split())
98 line = f.readline()
99 m3 = depmodpat3.match(line)
100 m4 = depmodpat4.match(line)
101 deps[m2.group(1)].extend(m4.group(1).split())
102 line = f.readline()
103 f.close()
104 return deps
105
106 def get_dependencies(file, pattern, format):
107 # file no longer includes PKGD
108 file = file.replace(d.getVar('PKGD', True) or '', '', 1)
109 # instead is prefixed with /lib/modules/${KERNEL_VERSION}
110 file = file.replace("/lib/modules/%s/" % d.getVar('KERNEL_VERSION', True) or '', '', 1)
111
112 if module_deps.has_key(file):
113 dependencies = []
114 for i in module_deps[file]:
115 m = re.match(pattern, os.path.basename(i))
116 if not m:
117 continue
118 on = legitimize_package_name(m.group(1))
119 dependency_pkg = format % on
120 dependencies.append(dependency_pkg)
121 return dependencies
122 return []
123
124 def frob_metadata(file, pkg, pattern, format, basename):
125 vals = extract_modinfo(file)
126
127 dvar = d.getVar('PKGD', True)
128
129 # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append
130 # appropriate modprobe commands to the postinst
131 autoload = d.getVar('module_autoload_%s' % basename, True)
132 if autoload:
133 name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename)
134 f = open(name, 'w')
135 for m in autoload.split():
136 f.write('%s\n' % m)
137 f.close()
138 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
139 if not postinst:
140 bb.fatal("pkg_postinst_%s not defined" % pkg)
141 postinst += d.getVar('autoload_postinst_fragment', True) % autoload
142 d.setVar('pkg_postinst_%s' % pkg, postinst)
143
144 # Write out any modconf fragment
145 modconf = d.getVar('module_conf_%s' % basename, True)
146 if modconf:
147 name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
148 f = open(name, 'w')
149 f.write("%s\n" % modconf)
150 f.close()
151
152 files = d.getVar('FILES_%s' % pkg, True)
153 files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename)
154 d.setVar('FILES_%s' % pkg, files)
155
156 if vals.has_key("description"):
157 old_desc = d.getVar('DESCRIPTION_' + pkg, True) or ""
158 d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"])
159
160 rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or "")
161 for dep in get_dependencies(file, pattern, format):
162 if not dep in rdepends:
163 rdepends[dep] = []
164 d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
165
166 module_deps = parse_depmod()
167 module_regex = '^(.*)\.k?o$'
168 module_pattern = 'kernel-module-%s'
169
170 postinst = d.getVar('pkg_postinst_modules', True)
171 postrm = d.getVar('pkg_postrm_modules', True)
172
173 modules = do_split_packages(d, root='/lib/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='kernel-%s' % (d.getVar("KERNEL_VERSION", True)))
174 if modules:
175 metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE', True)
176 d.appendVar('RDEPENDS_' + metapkg, ' '.join(modules))
177
178 # If modules-load.d and modprobe.d are empty at this point, remove them to
179 # avoid warnings. removedirs only raises an OSError if an empty
180 # directory cannot be removed.
181 dvar = d.getVar('PKGD', True)
182 for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]:
183 if len(os.listdir(dir)) == 0:
184 os.rmdir(dir)
185}
diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
index 5fe435681a..0a0430e266 100644
--- a/meta/classes/kernel.bbclass
+++ b/meta/classes/kernel.bbclass
@@ -1,4 +1,4 @@
1inherit linux-kernel-base module_strip 1inherit linux-kernel-base module_strip kernel-module-split
2 2
3PROVIDES += "virtual/kernel" 3PROVIDES += "virtual/kernel"
4DEPENDS += "virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross" 4DEPENDS += "virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross"
@@ -281,190 +281,12 @@ else
281fi 281fi
282} 282}
283 283
284pkg_postinst_modules () {
285if [ -z "$D" ]; then
286 depmod -a ${KERNEL_VERSION}
287else
288 depmodwrapper -a -b $D ${KERNEL_VERSION}
289fi
290}
291
292pkg_postrm_modules () {
293if [ -z "$D" ]; then
294 depmod -a ${KERNEL_VERSION}
295else
296 depmodwrapper -a -b $D ${KERNEL_VERSION}
297fi
298}
299
300autoload_postinst_fragment() {
301if [ x"$D" = "x" ]; then
302 modprobe %s || true
303fi
304}
305
306PACKAGESPLITFUNCS_prepend = "split_kernel_packages " 284PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
307 285
308python split_kernel_packages () { 286python split_kernel_packages () {
309 import re
310
311 modinfoexp = re.compile("([^=]+)=(.*)")
312 kerverrexp = re.compile('^(.*-hh.*)[\.\+].*$')
313 depmodpat0 = re.compile("^(.*\.k?o):..*$")
314 depmodpat1 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*$")
315 depmodpat2 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*\\\$")
316 depmodpat3 = re.compile("^\t(.*\.k?o)\s*\\\$")
317 depmodpat4 = re.compile("^\t(.*\.k?o)\s*$")
318
319 def extract_modinfo(file):
320 import tempfile, subprocess
321 tempfile.tempdir = d.getVar("WORKDIR", True)
322 tf = tempfile.mkstemp()
323 tmpfile = tf[1]
324 cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX", True) or "", file, tmpfile)
325 subprocess.call(cmd, shell=True)
326 f = open(tmpfile)
327 l = f.read().split("\000")
328 f.close()
329 os.close(tf[0])
330 os.unlink(tmpfile)
331 vals = {}
332 for i in l:
333 m = modinfoexp.match(i)
334 if not m:
335 continue
336 vals[m.group(1)] = m.group(2)
337 return vals
338
339 def parse_depmod():
340
341 dvar = d.getVar('PKGD', True)
342
343 kernelver = d.getVar('KERNEL_VERSION', True)
344 kernelver_stripped = kernelver
345 m = kerverrexp.match(kernelver)
346 if m:
347 kernelver_stripped = m.group(1)
348 cmd = "depmod -n -a -b %s -F %s/boot/System.map-%s %s" % (dvar, dvar, kernelver, kernelver_stripped)
349 f = os.popen(cmd, 'r')
350
351 deps = {}
352 line = f.readline()
353 while line:
354 if not depmodpat0.match(line):
355 line = f.readline()
356 continue
357 m1 = depmodpat1.match(line)
358 if m1:
359 deps[m1.group(1)] = m1.group(2).split()
360 else:
361 m2 = depmodpat2.match(line)
362 if m2:
363 deps[m2.group(1)] = m2.group(2).split()
364 line = f.readline()
365 m3 = depmodpat3.match(line)
366 while m3:
367 deps[m2.group(1)].extend(m3.group(1).split())
368 line = f.readline()
369 m3 = depmodpat3.match(line)
370 m4 = depmodpat4.match(line)
371 deps[m2.group(1)].extend(m4.group(1).split())
372 line = f.readline()
373 f.close()
374 return deps
375
376 def get_dependencies(file, pattern, format):
377 # file no longer includes PKGD
378 file = file.replace(d.getVar('PKGD', True) or '', '', 1)
379 # instead is prefixed with /lib/modules/${KERNEL_VERSION}
380 file = file.replace("/lib/modules/%s/" % d.getVar('KERNEL_VERSION', True) or '', '', 1)
381
382 if module_deps.has_key(file):
383 dependencies = []
384 for i in module_deps[file]:
385 m = re.match(pattern, os.path.basename(i))
386 if not m:
387 continue
388 on = legitimize_package_name(m.group(1))
389 dependency_pkg = format % on
390 dependencies.append(dependency_pkg)
391 return dependencies
392 return []
393
394 def frob_metadata(file, pkg, pattern, format, basename):
395 vals = extract_modinfo(file)
396
397 dvar = d.getVar('PKGD', True)
398
399 # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append
400 # appropriate modprobe commands to the postinst
401 autoload = d.getVar('module_autoload_%s' % basename, True)
402 if autoload:
403 name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename)
404 f = open(name, 'w')
405 for m in autoload.split():
406 f.write('%s\n' % m)
407 f.close()
408 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
409 if not postinst:
410 bb.fatal("pkg_postinst_%s not defined" % pkg)
411 postinst += d.getVar('autoload_postinst_fragment', True) % autoload
412 d.setVar('pkg_postinst_%s' % pkg, postinst)
413
414 # Write out any modconf fragment
415 modconf = d.getVar('module_conf_%s' % basename, True)
416 if modconf:
417 name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
418 f = open(name, 'w')
419 f.write("%s\n" % modconf)
420 f.close()
421
422 files = d.getVar('FILES_%s' % pkg, True)
423 files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename)
424 d.setVar('FILES_%s' % pkg, files)
425
426 if vals.has_key("description"):
427 old_desc = d.getVar('DESCRIPTION_' + pkg, True) or ""
428 d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"])
429
430 rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or "")
431 for dep in get_dependencies(file, pattern, format):
432 if not dep in rdepends:
433 rdepends[dep] = []
434 d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
435
436 module_deps = parse_depmod()
437 module_regex = '^(.*)\.k?o$'
438 module_pattern = 'kernel-module-%s'
439
440 postinst = d.getVar('pkg_postinst_modules', True)
441 postrm = d.getVar('pkg_postrm_modules', True)
442
443 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') 287 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
444 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') 288 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
445 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.cis$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') 289 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.cis$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
446 do_split_packages(d, root='/lib/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='kernel-%s' % (d.getVar("KERNEL_VERSION", True)))
447
448 # If modules-load.d and modprobe.d are empty at this point, remove them to
449 # avoid warnings. removedirs only raises an OSError if an empty
450 # directory cannot be removed.
451 dvar = d.getVar('PKGD', True)
452 for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]:
453 if len(os.listdir(dir)) == 0:
454 os.rmdir(dir)
455
456 metapkg = "kernel-modules"
457 blacklist = [ 'kernel-dev', 'kernel-image', 'kernel-base', 'kernel-vmlinux' ]
458 for l in module_deps.values():
459 for i in l:
460 pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1))
461 blacklist.append(pkg)
462 metapkg_rdepends = []
463 packages = d.getVar('PACKAGES', True).split()
464 for pkg in packages[1:]:
465 if not pkg in blacklist and not pkg in metapkg_rdepends:
466 metapkg_rdepends.append(pkg)
467 d.setVar('RDEPENDS_' + metapkg, ' '.join(metapkg_rdepends))
468} 290}
469 291
470# Support checking the kernel size since some kernels need to reside in partitions 292# Support checking the kernel size since some kernels need to reside in partitions
diff --git a/meta/classes/module.bbclass b/meta/classes/module.bbclass
index 2c1888c8d2..ad6f7af1bb 100644
--- a/meta/classes/module.bbclass
+++ b/meta/classes/module.bbclass
@@ -1,6 +1,6 @@
1DEPENDS += "virtual/kernel" 1DEPENDS += "virtual/kernel"
2 2
3inherit module-base 3inherit module-base kernel-module-split
4 4
5addtask make_scripts after do_patch before do_compile 5addtask make_scripts after do_patch before do_compile
6do_make_scripts[lockfiles] = "${TMPDIR}/kernel-scripts.lock" 6do_make_scripts[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
@@ -24,34 +24,9 @@ module_do_install() {
24 modules_install 24 modules_install
25} 25}
26 26
27module_pkg_postinst () {
28if [ -z "$D" ]; then
29 depmod -a ${KERNEL_VERSION}
30else
31 depmodwrapper -a -b $D ${KERNEL_VERSION}
32fi
33}
34
35module_pkg_postrm () {
36if [ -z "$D" ]; then
37 depmod -a ${KERNEL_VERSION}
38else
39 depmodwrapper -a -b $D ${KERNEL_VERSION}
40fi
41}
42
43EXPORT_FUNCTIONS do_compile do_install 27EXPORT_FUNCTIONS do_compile do_install
44 28
45MODULE_PACKAGES ?= "${PN}" 29# add all splitted modules to PN RDEPENDS, PN can be empty now
46 30KERNEL_MODULES_META_PACKAGE = "${PN}"
47python __anonymous() { 31FILES_${PN} = ""
48 for package in d.getVar("MODULE_PACKAGES", True).split(): 32ALLOW_EMPTY_${PN} = "1"
49 d.appendVar("RDEPENDS_%s" % package, " kernel-image")
50 files = d.getVar("MODULE_FILES_%s" % package, True) or "/etc /lib/modules"
51 d.appendVar("FILES_%s" % package, " " + files)
52 d.appendVar('pkg_postinst_%s' % package, " " + d.getVar('module_pkg_postinst', True))
53 d.appendVar('pkg_postrm_%s' % package, " " + d.getVar('module_pkg_postrm', True))
54 if not package in d.getVar("PACKAGES", True):
55 d.prependVar("PACKAGES", package + " ")
56}
57