module bbclass: split each module into a kernel-module-<foo> subpackage and use PN as metapackage
RFC PATCH 1/1 module bbclass: split each module into a kernel-module-<foo> subpackage and use PN as metapackage
From: Koen Kooi <[email protected]>
--- classes/module.bbclass | 191 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 186 insertions(+), 5 deletions(-)
classes/module.bbclass +186 -5
@@ -24,19 +24,200 @@ module_do_install() { oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" ${MODULE_MAKE_FLAGS} modules_install } -pkg_postinst_append () { +python populate_packages_prepend () { + import os + def extract_modinfo(file): + import tempfile, re + tempfile.tempdir = bb.data.getVar("WORKDIR", d, 1) + tf = tempfile.mkstemp() + tmpfile = tf[1] + cmd = "PATH=\"%s\" %sobjcopy -j .modinfo -O binary %s %s" % (bb.data.getVar("PATH", d, 1), bb.data.getVar("HOST_PREFIX", d, 1) or "", file, tmpfile) + os.system(cmd) + f = open(tmpfile) + l = f.read().split("\000") + f.close() + os.close(tf[0]) + os.unlink(tmpfile) + exp = re.compile("([^=]+)=(.*)") + vals = {} + for i in l: + m = exp.match(i) + if not m: + continue + vals[m.group(1)] = m.group(2) + return vals + + def parse_depmod(): + import re + + dvar = bb.data.getVar('PKGD', d, 1) + if not dvar: + bb.error("PKGD not defined") + return + + kernelver = bb.data.getVar('KERNEL_VERSION', d, 1) + kerneldir = bb.data.getVar('STAGING_KERNEL_DIR', d, 1) + kernelver_stripped = kernelver + m = re.match('^(.*-hh.*)[\.\+].*$', kernelver) + if m: + kernelver_stripped = m.group(1) + path = bb.data.getVar("PATH", d, 1) + host_prefix = bb.data.getVar("HOST_PREFIX", d, 1) or "" + major_version = bb.data.getVar('KERNEL_MAJOR_VERSION', d, 1) + + cmd = "PATH=\"%s\" %sdepmod-%s -n -a -r -b %s -F %s/System.map-%s %s" % (path, host_prefix, major_version, dvar, kerneldir, kernelver, kernelver_stripped) + f = os.popen(cmd, 'r') + + deps = {} + pattern0 = "^(.*\.k?o):..*$" + pattern1 = "^(.*\.k?o):\s*(.*\.k?o)\s*$" + pattern2 = "^(.*\.k?o):\s*(.*\.k?o)\s*\\\$" + pattern3 = "^\t(.*\.k?o)\s*\\\$" + pattern4 = "^\t(.*\.k?o)\s*$" + + line = f.readline() + while line: + if not re.match(pattern0, line): + line = f.readline() + continue + m1 = re.match(pattern1, line) + if m1: + deps[m1.group(1)] = m1.group(2).split() + else: + m2 = re.match(pattern2, line) + if m2: + deps[m2.group(1)] = m2.group(2).split() + line = f.readline() + m3 = re.match(pattern3, line) + while m3: + deps[m2.group(1)].extend(m3.group(1).split()) + line = f.readline() + m3 = re.match(pattern3, line) + m4 = re.match(pattern4, line) + deps[m2.group(1)].extend(m4.group(1).split()) + line = f.readline() + f.close() + return deps + + def get_dependencies(file, pattern, format): + file = file.replace(bb.data.getVar('PKGD', d, 1) or '', '', 1) + + if module_deps.has_key(file): + import re + dependencies = [] + for i in module_deps[file]: + m = re.match(pattern, os.path.basename(i)) + if not m: + continue + on = legitimize_package_name(m.group(1)) + dependency_pkg = format % on + dependencies.append(dependency_pkg) + return dependencies + return [] + + def frob_metadata(file, pkg, pattern, format, basename): + import re + vals = extract_modinfo(file) + + dvar = bb.data.getVar('PKGD', d, 1) + + # If autoloading is requested, output /etc/modutils/<name> and append + # appropriate modprobe commands to the postinst + autoload = bb.data.getVar('module_autoload_%s' % basename, d, 1) + if not autoload: + # Also, try canonical name with dashes + autoload = bb.data.getVar('module_autoload_%s' % basename.replace('_', '-'), d, 1) + if autoload: + name = '%s/etc/modutils/%s' % (dvar, basename) + f = open(name, 'w') + for m in autoload.split(): + f.write('%s\n' % m) + f.close() + postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) + if not postinst: + bb.fatal("pkg_postinst_%s not defined" % pkg) + postinst += bb.data.getVar('autoload_postinst_fragment', d, 1) % autoload + bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) + + # Write out any modconf fragment + modconf = bb.data.getVar('module_conf_%s' % basename, d, 1) + if modconf: + if bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1) == "2.6": + name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) + else: + name = '%s/etc/modutils/%s.conf' % (dvar, basename) + f = open(name, 'w') + f.write("%s\n" % modconf) + f.close() + + files = bb.data.getVar('FILES_%s' % pkg, d, 1) + files = "%s /etc/modutils/%s /etc/modutils/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename, basename) + bb.data.setVar('FILES_%s' % pkg, files, d) + + if vals.has_key("description"): + old_desc = bb.data.getVar('DESCRIPTION_' + pkg, d, 1) or "" + bb.data.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"], d) + + rdepends_str = bb.data.getVar('RDEPENDS_' + pkg, d, 1) + if rdepends_str: + rdepends = rdepends_str.split() + else: + rdepends = [] + rdepends.extend(get_dependencies(file, pattern, format)) + bb.data.setVar('RDEPENDS_' + pkg, ' '.join(rdepends), d) + + module_deps = parse_depmod() + module_regex = '^(.*)\.k?o$' + module_pattern = 'kernel-module-%s' + + postinst = bb.data.getVar('pkg_postinst_modules', d, 1) + postrm = bb.data.getVar('pkg_postrm_modules', d, 1) + + maybe_update_modules = "update-modules " + if bb.data.getVar("ONLINE_PACKAGE_MANAGEMENT", d) == "none": + maybe_update_modules = "" + + do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') + do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') + 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='%skernel-%s' % (maybe_update_modules, bb.data.getVar("KERNEL_VERSION", d, 1))) + + import re + metapkg = bb.data.getVar("PN", d, 1) + bb.data.setVar('ALLOW_EMPTY_' + metapkg, "1", d) + bb.data.setVar('FILES_' + metapkg, "", d) + blacklist = [ metapkg, metapkg + '-doc', metapkg + '-dev', metapkg + '-dbg', metapkg + '-locale', metapkg + '-static' ] + depchains = (d.getVar("DEPCHAIN_POST", True) or "").split() + for l in module_deps.values(): + for i in l: + pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1)) + blacklist.append(pkg) + metapkg_rrecommends = [] + packages = bb.data.getVar('PACKAGES', d, 1).split() + for pkg in packages[1:]: + if not pkg in blacklist and not pkg in metapkg_rrecommends and not any(pkg.endswith(post) for post in depchains): + metapkg_rrecommends.append(pkg) + bb.data.setVar('RRECOMMENDS_' + metapkg, ' '.join(metapkg_rrecommends), d) + bb.data.setVar('DESCRIPTION_' + metapkg, metapkg + ' modules meta package', d) +} + +pkg_postinst_modules () { if [ -n "$D" ]; then - exit 1 + ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_VERSION} ${KERNEL_VERSION} else depmod -a ${KERNEL_VERSION} update-modules || true fi } -pkg_postrm_append () { - update-modules || true +pkg_postrm_modules () { +update-modules || true +} + +autoload_postinst_fragment() { +if [ x"$D" = "x" ]; then + modprobe %s || true +fi } EXPORT_FUNCTIONS do_compile do_install -FILES_${PN} = "/etc /lib/modules"
Signature · 1 line
1.6.6.1
Quoted 9 lines · Koen Kooi
From: Koen Kooi <[email protected]>
Signed-off-by Koen Kooi <[email protected]>--- classes/module.bbclass | 191 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 186 insertions(+), 5 deletions(-)
How about moving the common functions into oe.module or oe.package and using them from module.bbclass and kernel.bbclass?
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 13 lines · Chris Larson
Quoted 9 lines · Koen Kooi
From: Koen Kooi <[email protected]>
Signed-off-by Koen Kooi <[email protected]>--- classes/module.bbclass | 191 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 186 insertions(+), 5 deletions(-)
Quoted 2 lines
How about moving the common functions into oe.module or oe.package and using them from module.bbclass and kernel.bbclass?
I thought about that, but that needs more work :( We need to pass in a different path to System.map, use PN as metapackage name, use a different blacklist, etc.
That requires a lot more python skill than I currently have.
Apart from the horrendous code duplication, how does this look? It seems to do the right thing for the recipes I tested with :)
regards,
Koen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFMwyY2MkyGM64RGpERAvl7AJ9vvDrrfJoJv2uWbBYFNMtmUSQBlQCgqyU/ g7/rxYKqcNnGn5ar1d+mFSY=
=9tBi
-----END PGP SIGNATURE-----
Chris Larson
Acked-byQuoted 21 lines · Koen Kooi
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 6 lines · Chris Larson
Quoted 4 lines · Koen Kooi
From: Koen Kooi <[email protected]>
Signed-off-by Koen Kooi <[email protected]>Quoted 8 lines
Quoted 5 lines
--- classes/module.bbclass | 191 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 186 insertions(+), 5 deletions(-)How about moving the common functions into oe.module or oe.package and
using
Quoted 1 line
them from module.bbclass and kernel.bbclass?
Quoted 8 lines
I thought about that, but that needs more work :( We need to pass in a different path to System.map, use PN as metapackage name, use a different blacklist, etc.
That requires a lot more python skill than I currently have.Apart from the horrendous code duplication, how does this look? It seems to do the right thing for the recipes I tested with :)
Looks reasonable otherwise, can always consolidate in a second pass later on.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ping on the patch?
Quoted 22 lines · Koen Kooi
Quoted 13 lines · Chris Larson
Quoted 9 lines · Koen Kooi
From: Koen Kooi <[email protected]>
Signed-off-by Koen Kooi <[email protected]>--- classes/module.bbclass | 191 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 186 insertions(+), 5 deletions(-)Quoted 2 lines
How about moving the common functions into oe.module or oe.package and using them from module.bbclass and kernel.bbclass?
I thought about that, but that needs more work :( We need to pass in a different path to System.map, use PN as metapackage name, use a different blacklist, etc.
That requires a lot more python skill than I currently have.
Quoted 6 lines
Apart from the horrendous code duplication, how does this look? It seems to do the right thing for the recipes I tested with :)
regards,
Koen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
iD8DBQFM0AY1MkyGM64RGpERAiiyAJ943e16oJx5KQDr6qpidHbsLPEONwCfYKx1 pgEjHF82FwDETI6pPt94BcA=
=lO75
-----END PGP SIGNATURE-----
Quoted 16 lines · Koen Kooi
From: Koen Kooi <[email protected]>
Signed-off-by Koen Kooi <[email protected]>---
classes/module.bbclass | 191 ++++++++++++++++++++++++++++++++++++++++++++++-1 files changed, 186 insertions(+), 5 deletions(-)classes/module.bbclass +0
-0@@ -24,19 +24,200 @@ module_do_install() {oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" ${MODULE_MAKE_FLAGS}
modules_install}
classes/module.bbclass module_do_install() { · line 35
Quoted 10 lines
classes/module.bbclass +9
-1-pkg_postinst_append () { +python populate_packages_prepend () { + import os + def extract_modinfo(file): + import tempfile, re + tempfile.tempdir = bb.data.getVar("WORKDIR", d, 1) + tf = tempfile.mkstemp() + tmpfile = tf[1] + cmd = "PATH=\"%s\" %sobjcopy -j .modinfo -O binary %s %s" % (bb.data.getVar("PATH", d, 1), bb.data.getVar("HOST_PREFIX", d, 1) or "", file, tmpfile) + os.system(cmd)
may be we can get rid of os.system and use subprocess popen or something
Quoted 201 lines
+ f = open(tmpfile)
+ l = f.read().split("\000")
+f.close()
+os.close(tf[0])
+os.unlink(tmpfile)
+ exp = re.compile("([^=]+)=(.*)")
+ vals = {}
+ for i in l:
+ m =exp.match(i)
+ if not m:
+ continue
+ vals[m.group(1)] =m.group(2)
+ return valsclasses/module.bbclass +155
-0+ + def parse_depmod(): + import re + + dvar = bb.data.getVar('PKGD', d, 1) + if not dvar: + bb.error("PKGD not defined") + return + + kernelver = bb.data.getVar('KERNEL_VERSION', d, 1) + kerneldir = bb.data.getVar('STAGING_KERNEL_DIR', d, 1) + kernelver_stripped = kernelver + m = re.match('^(.*-hh.*)[\.\+].*$', kernelver) + if m: + kernelver_stripped = m.group(1) + path = bb.data.getVar("PATH", d, 1) + host_prefix = bb.data.getVar("HOST_PREFIX", d, 1) or "" + major_version = bb.data.getVar('KERNEL_MAJOR_VERSION', d, 1) + + cmd = "PATH=\"%s\" %sdepmod-%s -n -a -r -b %s -F %s/System.map-%s %s" % (path, host_prefix, major_version, dvar, kerneldir, kernelver, kernelver_stripped) + f = os.popen(cmd, 'r') + + deps = {} + pattern0 = "^(.*\.k?o):..*$" + pattern1 = "^(.*\.k?o):\s*(.*\.k?o)\s*$" + pattern2 = "^(.*\.k?o):\s*(.*\.k?o)\s*\\\$" + pattern3 = "^\t(.*\.k?o)\s*\\\$" + pattern4 = "^\t(.*\.k?o)\s*$" + + line = f.readline() + while line: + if not re.match(pattern0, line): + line = f.readline() + continue + m1 = re.match(pattern1, line) + if m1: + deps[m1.group(1)] = m1.group(2).split() + else: + m2 = re.match(pattern2, line) + if m2: + deps[m2.group(1)] = m2.group(2).split() + line = f.readline() + m3 = re.match(pattern3, line) + while m3: + deps[m2.group(1)].extend(m3.group(1).split()) + line = f.readline() + m3 = re.match(pattern3, line) + m4 = re.match(pattern4, line) + deps[m2.group(1)].extend(m4.group(1).split()) + line = f.readline() + f.close() + return deps + + def get_dependencies(file, pattern, format): + file = file.replace(bb.data.getVar('PKGD', d, 1) or '', '', 1) + + if module_deps.has_key(file): + import re + dependencies = [] + for i in module_deps[file]: + m = re.match(pattern, os.path.basename(i)) + if not m: + continue + on = legitimize_package_name(m.group(1)) + dependency_pkg = format % on + dependencies.append(dependency_pkg) + return dependencies + return [] + + def frob_metadata(file, pkg, pattern, format, basename): + import re + vals = extract_modinfo(file) + + dvar = bb.data.getVar('PKGD', d, 1) + + # If autoloading is requested, output /etc/modutils/<name> and append + # appropriate modprobe commands to the postinst + autoload = bb.data.getVar('module_autoload_%s' % basename, d, 1) + if not autoload: + # Also, try canonical name with dashes + autoload = bb.data.getVar('module_autoload_%s' % basename.replace('_', '-'), d, 1) + if autoload: + name = '%s/etc/modutils/%s' % (dvar, basename) + f = open(name, 'w') + for m in autoload.split(): + f.write('%s\n' % m) + f.close() + postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) + if not postinst: + bb.fatal("pkg_postinst_%s not defined" % pkg) + postinst += bb.data.getVar('autoload_postinst_fragment', d, 1) % autoload + bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) + + # Write out any modconf fragment + modconf = bb.data.getVar('module_conf_%s' % basename, d, 1) + if modconf: + if bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1) == "2.6": + name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) + else: + name = '%s/etc/modutils/%s.conf' % (dvar, basename) + f = open(name, 'w') + f.write("%s\n" % modconf) + f.close() + + files = bb.data.getVar('FILES_%s' % pkg, d, 1) + files = "%s /etc/modutils/%s /etc/modutils/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename, basename) + bb.data.setVar('FILES_%s' % pkg, files, d) + + if vals.has_key("description"): + old_desc = bb.data.getVar('DESCRIPTION_' + pkg, d, 1) or "" + bb.data.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"], d) + + rdepends_str = bb.data.getVar('RDEPENDS_' + pkg, d, 1) + if rdepends_str: + rdepends = rdepends_str.split() + else: + rdepends = [] + rdepends.extend(get_dependencies(file, pattern, format)) + bb.data.setVar('RDEPENDS_' + pkg, ' '.join(rdepends), d) + + module_deps = parse_depmod() + module_regex = '^(.*)\.k?o$' + module_pattern = 'kernel-module-%s' + + postinst = bb.data.getVar('pkg_postinst_modules', d, 1) + postrm = bb.data.getVar('pkg_postrm_modules', d, 1) + + maybe_update_modules = "update-modules " + if bb.data.getVar("ONLINE_PACKAGE_MANAGEMENT", d) == "none": + maybe_update_modules = "" + + do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') + do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') + 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='%skernel-%s' % (maybe_update_modules, bb.data.getVar("KERNEL_VERSION", d, 1))) + + import re + metapkg = bb.data.getVar("PN", d, 1) + bb.data.setVar('ALLOW_EMPTY_' + metapkg, "1", d) + bb.data.setVar('FILES_' + metapkg, "", d) + blacklist = [ metapkg, metapkg + '-doc', metapkg + '-dev', metapkg + '-dbg', metapkg + '-locale', metapkg + '-static' ] + depchains = (d.getVar("DEPCHAIN_POST", True) or "").split() + for l in module_deps.values(): + for i in l: + pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1)) + blacklist.append(pkg) + metapkg_rrecommends = [] + packages = bb.data.getVar('PACKAGES', d, 1).split() + for pkg in packages[1:]: + if not pkg in blacklist and not pkg in metapkg_rrecommends and not any(pkg.endswith(post) for post in depchains): + metapkg_rrecommends.append(pkg) + bb.data.setVar('RRECOMMENDS_' + metapkg, ' '.join(metapkg_rrecommends), d) + bb.data.setVar('DESCRIPTION_' + metapkg, metapkg + ' modules meta package', d) +} + +pkg_postinst_modules () {if [ -n "$D" ]; then
- exit 1
+ ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_VERSION} ${KERNEL_VERSION} else
depmod -a ${KERNEL_VERSION}
update-modules || true
fi
}classes/module.bbclass +8
-2-pkg_postrm_append () { - update-modules || true +pkg_postrm_modules () { +update-modules || true +} + +autoload_postinst_fragment() { +if [ x"$D" = "x" ]; then + modprobe %s || true +fi}
EXPORT_FUNCTIONS
do_compiledo_install-FILES_${PN} = "/etc
/lib/modules"
--
1.6.6.1_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Quoted 7 lines · Khem Raj
Quoted 1 line
+ cmd = "PATH=\"%s\" %sobjcopy -j .modinfo -O binary %s %s"
% (
bb.data.getVar("PATH", d, 1),bb.data.getVar("HOST_PREFIX", d, 1)or "", file, tmpfile)Quoted 1 line
+
os.system(cmd)may be we can get rid of os.system and use subprocess popen or something
We have convenience wrappers around subprocess both in utils.bbclass and in oe.process -- probably easiest to use one of those.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics