Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | pkg_postinst_modules () { |
| 2 | if [ -z "$D" ]; then |
| 3 | depmod -a ${KERNEL_VERSION} |
| 4 | else |
| 5 | # image.bbclass will call depmodwrapper after everything is installed, |
| 6 | # no need to do it here as well |
| 7 | : |
| 8 | fi |
| 9 | } |
| 10 | |
| 11 | pkg_postrm_modules () { |
| 12 | if [ -z "$D" ]; then |
| 13 | depmod -a ${KERNEL_VERSION} |
| 14 | else |
| 15 | depmodwrapper -a -b $D ${KERNEL_VERSION} |
| 16 | fi |
| 17 | } |
| 18 | |
| 19 | autoload_postinst_fragment() { |
| 20 | if [ x"$D" = "x" ]; then |
| 21 | modprobe %s || true |
| 22 | fi |
| 23 | } |
| 24 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | PACKAGE_WRITE_DEPS += "kmod-native depmodwrapper-cross" |
| 26 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | do_install_append() { |
| 28 | install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/ |
| 29 | } |
| 30 | |
| 31 | PACKAGESPLITFUNCS_prepend = "split_kernel_module_packages " |
| 32 | |
| 33 | KERNEL_MODULES_META_PACKAGE ?= "kernel-modules" |
| 34 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 35 | KERNEL_MODULE_PACKAGE_PREFIX ?= "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | KERNEL_MODULE_PACKAGE_SUFFIX ?= "-${KERNEL_VERSION}" |
| 37 | KERNEL_MODULE_PROVIDE_VIRTUAL ?= "1" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | python split_kernel_module_packages () { |
| 40 | import re |
| 41 | |
| 42 | modinfoexp = re.compile("([^=]+)=(.*)") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | |
| 44 | def extract_modinfo(file): |
| 45 | import tempfile, subprocess |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 46 | tempfile.tempdir = d.getVar("WORKDIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | tf = tempfile.mkstemp() |
| 48 | tmpfile = tf[1] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX") or "", file, tmpfile) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 50 | subprocess.check_call(cmd, shell=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | f = open(tmpfile) |
| 52 | l = f.read().split("\000") |
| 53 | f.close() |
| 54 | os.close(tf[0]) |
| 55 | os.unlink(tmpfile) |
| 56 | vals = {} |
| 57 | for i in l: |
| 58 | m = modinfoexp.match(i) |
| 59 | if not m: |
| 60 | continue |
| 61 | vals[m.group(1)] = m.group(2) |
| 62 | return vals |
| 63 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | def frob_metadata(file, pkg, pattern, format, basename): |
| 65 | vals = extract_modinfo(file) |
| 66 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 67 | dvar = d.getVar('PKGD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | |
| 69 | # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append |
| 70 | # appropriate modprobe commands to the postinst |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 71 | autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split() |
| 72 | autoload = d.getVar('module_autoload_%s' % basename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | if autoload and autoload == basename: |
| 74 | bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename) |
| 75 | if autoload and basename not in autoloadlist: |
| 76 | bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename)) |
| 77 | if basename in autoloadlist: |
| 78 | name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename) |
| 79 | f = open(name, 'w') |
| 80 | if autoload: |
| 81 | for m in autoload.split(): |
| 82 | f.write('%s\n' % m) |
| 83 | else: |
| 84 | f.write('%s\n' % basename) |
| 85 | f.close() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 86 | postinst = d.getVar('pkg_postinst_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | if not postinst: |
| 88 | bb.fatal("pkg_postinst_%s not defined" % pkg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 89 | postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | d.setVar('pkg_postinst_%s' % pkg, postinst) |
| 91 | |
| 92 | # Write out any modconf fragment |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 93 | modconflist = (d.getVar("KERNEL_MODULE_PROBECONF") or "").split() |
| 94 | modconf = d.getVar('module_conf_%s' % basename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | if modconf and basename in modconflist: |
| 96 | name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) |
| 97 | f = open(name, 'w') |
| 98 | f.write("%s\n" % modconf) |
| 99 | f.close() |
| 100 | elif modconf: |
| 101 | bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename)) |
| 102 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 103 | files = d.getVar('FILES_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename) |
| 105 | d.setVar('FILES_%s' % pkg, files) |
| 106 | |
| 107 | if "description" in vals: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 108 | old_desc = d.getVar('DESCRIPTION_' + pkg) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"]) |
| 110 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 111 | rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 112 | modinfo_deps = [] |
| 113 | if "depends" in vals and vals["depends"] != "": |
| 114 | for dep in vals["depends"].split(","): |
| 115 | on = legitimize_package_name(dep) |
| 116 | dependency_pkg = format % on |
| 117 | modinfo_deps.append(dependency_pkg) |
| 118 | for dep in modinfo_deps: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | if not dep in rdepends: |
| 120 | rdepends[dep] = [] |
| 121 | d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False)) |
| 122 | |
| 123 | # Avoid automatic -dev recommendations for modules ending with -dev. |
| 124 | d.setVarFlag('RRECOMMENDS_' + pkg, 'nodeprrecs', 1) |
| 125 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 126 | # Provide virtual package without postfix |
| 127 | providevirt = d.getVar('KERNEL_MODULE_PROVIDE_VIRTUAL') |
| 128 | if providevirt == "1": |
| 129 | postfix = format.split('%s')[1] |
| 130 | d.setVar('RPROVIDES_' + pkg, pkg.replace(postfix, '')) |
| 131 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | module_regex = '^(.*)\.k?o$' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 133 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 134 | module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX') |
| 135 | module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX') |
| 136 | module_pattern = module_pattern_prefix + 'kernel-module-%s' + module_pattern_suffix |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | postinst = d.getVar('pkg_postinst_modules') |
| 139 | postrm = d.getVar('pkg_postrm_modules') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 141 | 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='kernel-%s' % (d.getVar("KERNEL_VERSION"))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 142 | if modules: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 143 | metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | d.appendVar('RDEPENDS_' + metapkg, ' '+' '.join(modules)) |
| 145 | |
| 146 | # If modules-load.d and modprobe.d are empty at this point, remove them to |
| 147 | # avoid warnings. removedirs only raises an OSError if an empty |
| 148 | # directory cannot be removed. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 149 | dvar = d.getVar('PKGD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]: |
| 151 | if len(os.listdir(dir)) == 0: |
| 152 | os.rmdir(dir) |
| 153 | } |
| 154 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 155 | do_package[vardeps] += '${@" ".join(map(lambda s: "module_conf_" + s, (d.getVar("KERNEL_MODULE_PROBECONF") or "").split()))}' |