Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1 | pkg_postinst:modules () { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 11 | pkg_postrm:modules () { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 27 | do_install:append() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/ |
| 29 | } |
| 30 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 31 | PACKAGESPLITFUNCS:prepend = "split_kernel_module_packages " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 33 | KERNEL_MODULES_META_PACKAGE ?= "${@ d.getVar("KERNEL_PACKAGE_NAME") or "kernel" }-modules" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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") |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 47 | compressed = re.match( r'.*\.([xg])z$', file) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | tf = tempfile.mkstemp() |
| 49 | tmpfile = tf[1] |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 50 | if compressed: |
| 51 | tmpkofile = tmpfile + ".ko" |
| 52 | if compressed.group(1) == 'g': |
| 53 | cmd = "gunzip -dc %s > %s" % (file, tmpkofile) |
| 54 | subprocess.check_call(cmd, shell=True) |
| 55 | elif compressed.group(1) == 'x': |
| 56 | cmd = "xz -dc %s > %s" % (file, tmpkofile) |
| 57 | subprocess.check_call(cmd, shell=True) |
| 58 | else: |
| 59 | msg = "Cannot decompress '%s'" % file |
| 60 | raise msg |
| 61 | cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX") or "", tmpkofile, tmpfile) |
| 62 | else: |
| 63 | 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] | 64 | subprocess.check_call(cmd, shell=True) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 65 | # errors='replace': Some old kernel versions contain invalid utf-8 characters in mod descriptions (like 0xf6, 'รถ') |
| 66 | f = open(tmpfile, errors='replace') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | l = f.read().split("\000") |
| 68 | f.close() |
| 69 | os.close(tf[0]) |
| 70 | os.unlink(tmpfile) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 71 | if compressed: |
| 72 | os.unlink(tmpkofile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | vals = {} |
| 74 | for i in l: |
| 75 | m = modinfoexp.match(i) |
| 76 | if not m: |
| 77 | continue |
| 78 | vals[m.group(1)] = m.group(2) |
| 79 | return vals |
| 80 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | def frob_metadata(file, pkg, pattern, format, basename): |
| 82 | vals = extract_modinfo(file) |
| 83 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 84 | dvar = d.getVar('PKGD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | |
| 86 | # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append |
| 87 | # appropriate modprobe commands to the postinst |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split() |
| 89 | autoload = d.getVar('module_autoload_%s' % basename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | if autoload and autoload == basename: |
| 91 | bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename) |
| 92 | if autoload and basename not in autoloadlist: |
| 93 | bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename)) |
| 94 | if basename in autoloadlist: |
| 95 | name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename) |
| 96 | f = open(name, 'w') |
| 97 | if autoload: |
| 98 | for m in autoload.split(): |
| 99 | f.write('%s\n' % m) |
| 100 | else: |
| 101 | f.write('%s\n' % basename) |
| 102 | f.close() |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 103 | postinst = d.getVar('pkg_postinst:%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | if not postinst: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 105 | bb.fatal("pkg_postinst:%s not defined" % pkg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 107 | d.setVar('pkg_postinst:%s' % pkg, postinst) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | |
| 109 | # Write out any modconf fragment |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 110 | modconflist = (d.getVar("KERNEL_MODULE_PROBECONF") or "").split() |
| 111 | modconf = d.getVar('module_conf_%s' % basename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | if modconf and basename in modconflist: |
| 113 | name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) |
| 114 | f = open(name, 'w') |
| 115 | f.write("%s\n" % modconf) |
| 116 | f.close() |
| 117 | elif modconf: |
| 118 | bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename)) |
| 119 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 120 | files = d.getVar('FILES:%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 122 | d.setVar('FILES:%s' % pkg, files) |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 123 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 124 | conffiles = d.getVar('CONFFILES:%s' % pkg) |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 125 | conffiles = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (conffiles, basename, basename) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 126 | d.setVar('CONFFILES:%s' % pkg, conffiles) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | |
| 128 | if "description" in vals: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 129 | old_desc = d.getVar('DESCRIPTION:' + pkg) or "" |
| 130 | d.setVar('DESCRIPTION:' + pkg, old_desc + "; " + vals["description"]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 132 | rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS:' + pkg) or "") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 133 | modinfo_deps = [] |
| 134 | if "depends" in vals and vals["depends"] != "": |
| 135 | for dep in vals["depends"].split(","): |
| 136 | on = legitimize_package_name(dep) |
| 137 | dependency_pkg = format % on |
| 138 | modinfo_deps.append(dependency_pkg) |
| 139 | for dep in modinfo_deps: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | if not dep in rdepends: |
| 141 | rdepends[dep] = [] |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 142 | d.setVar('RDEPENDS:' + pkg, bb.utils.join_deps(rdepends, commasep=False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | |
| 144 | # Avoid automatic -dev recommendations for modules ending with -dev. |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 145 | d.setVarFlag('RRECOMMENDS:' + pkg, 'nodeprrecs', 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 146 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 147 | # Provide virtual package without postfix |
| 148 | providevirt = d.getVar('KERNEL_MODULE_PROVIDE_VIRTUAL') |
| 149 | if providevirt == "1": |
| 150 | postfix = format.split('%s')[1] |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 151 | d.setVar('RPROVIDES:' + pkg, pkg.replace(postfix, '')) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 152 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 153 | kernel_package_name = d.getVar("KERNEL_PACKAGE_NAME") or "kernel" |
| 154 | kernel_version = d.getVar("KERNEL_VERSION") |
| 155 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 156 | module_regex = r'^(.*)\.k?o(?:\.[xg]z)?$' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 157 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 158 | module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX') |
| 159 | module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 160 | module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 162 | postinst = d.getVar('pkg_postinst:modules') |
| 163 | postrm = d.getVar('pkg_postrm:modules') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 165 | 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)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | if modules: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 167 | metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE') |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 168 | d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | |
| 170 | # If modules-load.d and modprobe.d are empty at this point, remove them to |
| 171 | # avoid warnings. removedirs only raises an OSError if an empty |
| 172 | # directory cannot be removed. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 173 | dvar = d.getVar('PKGD') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]: |
| 175 | if len(os.listdir(dir)) == 0: |
| 176 | os.rmdir(dir) |
| 177 | } |
| 178 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 179 | do_package[vardeps] += '${@" ".join(map(lambda s: "module_conf_" + s, (d.getVar("KERNEL_MODULE_PROBECONF") or "").split()))}' |