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 | |
| 25 | do_install_append() { |
| 26 | install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/ |
| 27 | } |
| 28 | |
| 29 | PACKAGESPLITFUNCS_prepend = "split_kernel_module_packages " |
| 30 | |
| 31 | KERNEL_MODULES_META_PACKAGE ?= "kernel-modules" |
| 32 | |
| 33 | python split_kernel_module_packages () { |
| 34 | import re |
| 35 | |
| 36 | modinfoexp = re.compile("([^=]+)=(.*)") |
| 37 | kerverrexp = re.compile('^(.*-hh.*)[\.\+].*$') |
| 38 | depmodpat0 = re.compile("^(.*\.k?o):..*$") |
| 39 | depmodpat1 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*$") |
| 40 | depmodpat2 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*\\\$") |
| 41 | depmodpat3 = re.compile("^\t(.*\.k?o)\s*\\\$") |
| 42 | depmodpat4 = re.compile("^\t(.*\.k?o)\s*$") |
| 43 | |
| 44 | def extract_modinfo(file): |
| 45 | import tempfile, subprocess |
| 46 | tempfile.tempdir = d.getVar("WORKDIR", True) |
| 47 | tf = tempfile.mkstemp() |
| 48 | tmpfile = tf[1] |
| 49 | cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX", True) or "", file, tmpfile) |
| 50 | subprocess.call(cmd, shell=True) |
| 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 | |
| 64 | def parse_depmod(): |
| 65 | |
| 66 | dvar = d.getVar('PKGD', True) |
| 67 | |
| 68 | kernelver = d.getVar('KERNEL_VERSION', True) |
| 69 | kernelver_stripped = kernelver |
| 70 | m = kerverrexp.match(kernelver) |
| 71 | if m: |
| 72 | kernelver_stripped = m.group(1) |
| 73 | staging_kernel_dir = d.getVar("STAGING_KERNEL_BUILDDIR", True) |
| 74 | system_map_file = "%s/boot/System.map-%s" % (dvar, kernelver) |
| 75 | if not os.path.exists(system_map_file): |
| 76 | system_map_file = "%s/System.map-%s" % (staging_kernel_dir, kernelver) |
| 77 | if not os.path.exists(system_map_file): |
| 78 | bb.fatal("System.map-%s does not exist in '%s/boot' nor STAGING_KERNEL_BUILDDIR '%s'" % (kernelver, dvar, staging_kernel_dir)) |
| 79 | |
| 80 | cmd = "depmod -n -a -b %s -F %s %s" % (dvar, system_map_file, kernelver_stripped) |
| 81 | f = os.popen(cmd, 'r') |
| 82 | |
| 83 | deps = {} |
| 84 | line = f.readline() |
| 85 | while line: |
| 86 | if not depmodpat0.match(line): |
| 87 | line = f.readline() |
| 88 | continue |
| 89 | m1 = depmodpat1.match(line) |
| 90 | if m1: |
| 91 | deps[m1.group(1)] = m1.group(2).split() |
| 92 | else: |
| 93 | m2 = depmodpat2.match(line) |
| 94 | if m2: |
| 95 | deps[m2.group(1)] = m2.group(2).split() |
| 96 | line = f.readline() |
| 97 | m3 = depmodpat3.match(line) |
| 98 | while m3: |
| 99 | deps[m2.group(1)].extend(m3.group(1).split()) |
| 100 | line = f.readline() |
| 101 | m3 = depmodpat3.match(line) |
| 102 | m4 = depmodpat4.match(line) |
| 103 | deps[m2.group(1)].extend(m4.group(1).split()) |
| 104 | line = f.readline() |
| 105 | f.close() |
| 106 | return deps |
| 107 | |
| 108 | def get_dependencies(file, pattern, format): |
| 109 | # file no longer includes PKGD |
| 110 | file = file.replace(d.getVar('PKGD', True) or '', '', 1) |
| 111 | # instead is prefixed with /lib/modules/${KERNEL_VERSION} |
| 112 | file = file.replace("/lib/modules/%s/" % d.getVar('KERNEL_VERSION', True) or '', '', 1) |
| 113 | |
| 114 | if file in module_deps: |
| 115 | dependencies = [] |
| 116 | for i in module_deps[file]: |
| 117 | m = re.match(pattern, os.path.basename(i)) |
| 118 | if not m: |
| 119 | continue |
| 120 | on = legitimize_package_name(m.group(1)) |
| 121 | dependency_pkg = format % on |
| 122 | dependencies.append(dependency_pkg) |
| 123 | return dependencies |
| 124 | return [] |
| 125 | |
| 126 | def frob_metadata(file, pkg, pattern, format, basename): |
| 127 | vals = extract_modinfo(file) |
| 128 | |
| 129 | dvar = d.getVar('PKGD', True) |
| 130 | |
| 131 | # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append |
| 132 | # appropriate modprobe commands to the postinst |
| 133 | autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD", True) or "").split() |
| 134 | autoload = d.getVar('module_autoload_%s' % basename, True) |
| 135 | if autoload and autoload == basename: |
| 136 | bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename) |
| 137 | if autoload and basename not in autoloadlist: |
| 138 | bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename)) |
| 139 | if basename in autoloadlist: |
| 140 | name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename) |
| 141 | f = open(name, 'w') |
| 142 | if autoload: |
| 143 | for m in autoload.split(): |
| 144 | f.write('%s\n' % m) |
| 145 | else: |
| 146 | f.write('%s\n' % basename) |
| 147 | f.close() |
| 148 | postinst = d.getVar('pkg_postinst_%s' % pkg, True) |
| 149 | if not postinst: |
| 150 | bb.fatal("pkg_postinst_%s not defined" % pkg) |
| 151 | postinst += d.getVar('autoload_postinst_fragment', True) % (autoload or basename) |
| 152 | d.setVar('pkg_postinst_%s' % pkg, postinst) |
| 153 | |
| 154 | # Write out any modconf fragment |
| 155 | modconflist = (d.getVar("KERNEL_MODULE_PROBECONF", True) or "").split() |
| 156 | modconf = d.getVar('module_conf_%s' % basename, True) |
| 157 | if modconf and basename in modconflist: |
| 158 | name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) |
| 159 | f = open(name, 'w') |
| 160 | f.write("%s\n" % modconf) |
| 161 | f.close() |
| 162 | elif modconf: |
| 163 | bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename)) |
| 164 | |
| 165 | files = d.getVar('FILES_%s' % pkg, True) |
| 166 | files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename) |
| 167 | d.setVar('FILES_%s' % pkg, files) |
| 168 | |
| 169 | if "description" in vals: |
| 170 | old_desc = d.getVar('DESCRIPTION_' + pkg, True) or "" |
| 171 | d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"]) |
| 172 | |
| 173 | rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or "") |
| 174 | for dep in get_dependencies(file, pattern, format): |
| 175 | if not dep in rdepends: |
| 176 | rdepends[dep] = [] |
| 177 | d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False)) |
| 178 | |
| 179 | # Avoid automatic -dev recommendations for modules ending with -dev. |
| 180 | d.setVarFlag('RRECOMMENDS_' + pkg, 'nodeprrecs', 1) |
| 181 | |
| 182 | module_deps = parse_depmod() |
| 183 | module_regex = '^(.*)\.k?o$' |
| 184 | module_pattern = 'kernel-module-%s' |
| 185 | |
| 186 | postinst = d.getVar('pkg_postinst_modules', True) |
| 187 | postrm = d.getVar('pkg_postrm_modules', True) |
| 188 | |
| 189 | modules = 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))) |
| 190 | if modules: |
| 191 | metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE', True) |
| 192 | d.appendVar('RDEPENDS_' + metapkg, ' '+' '.join(modules)) |
| 193 | |
| 194 | # If modules-load.d and modprobe.d are empty at this point, remove them to |
| 195 | # avoid warnings. removedirs only raises an OSError if an empty |
| 196 | # directory cannot be removed. |
| 197 | dvar = d.getVar('PKGD', True) |
| 198 | for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]: |
| 199 | if len(os.listdir(dir)) == 0: |
| 200 | os.rmdir(dir) |
| 201 | } |
| 202 | |
| 203 | do_package[vardeps] += '${@" ".join(map(lambda s: "module_conf_" + s, (d.getVar("KERNEL_MODULE_PROBECONF", True) or "").split()))}' |