diff options
author | Martin Jansa <martin.jansa@gmail.com> | 2013-03-02 18:06:56 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-03-05 13:14:50 +0000 |
commit | 2b8f2e770e074ee6735440c2e44eb56397857858 (patch) | |
tree | 00817af99869f35b9f54cef67546cd987b9ac185 /meta/classes/kernel.bbclass | |
parent | 93ec7b4d1550e07caec86e2998d0f94a01c7e785 (diff) | |
download | poky-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/kernel.bbclass')
-rw-r--r-- | meta/classes/kernel.bbclass | 180 |
1 files changed, 1 insertions, 179 deletions
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 @@ | |||
1 | inherit linux-kernel-base module_strip | 1 | inherit linux-kernel-base module_strip kernel-module-split |
2 | 2 | ||
3 | PROVIDES += "virtual/kernel" | 3 | PROVIDES += "virtual/kernel" |
4 | DEPENDS += "virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross" | 4 | DEPENDS += "virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross" |
@@ -281,190 +281,12 @@ else | |||
281 | fi | 281 | fi |
282 | } | 282 | } |
283 | 283 | ||
284 | pkg_postinst_modules () { | ||
285 | if [ -z "$D" ]; then | ||
286 | depmod -a ${KERNEL_VERSION} | ||
287 | else | ||
288 | depmodwrapper -a -b $D ${KERNEL_VERSION} | ||
289 | fi | ||
290 | } | ||
291 | |||
292 | pkg_postrm_modules () { | ||
293 | if [ -z "$D" ]; then | ||
294 | depmod -a ${KERNEL_VERSION} | ||
295 | else | ||
296 | depmodwrapper -a -b $D ${KERNEL_VERSION} | ||
297 | fi | ||
298 | } | ||
299 | |||
300 | autoload_postinst_fragment() { | ||
301 | if [ x"$D" = "x" ]; then | ||
302 | modprobe %s || true | ||
303 | fi | ||
304 | } | ||
305 | |||
306 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " | 284 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " |
307 | 285 | ||
308 | python split_kernel_packages () { | 286 | python 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 |