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