diff options
Diffstat (limited to 'meta/classes/kernel-module-split.bbclass')
-rw-r--r-- | meta/classes/kernel-module-split.bbclass | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/meta/classes/kernel-module-split.bbclass b/meta/classes/kernel-module-split.bbclass new file mode 100644 index 0000000000..aa0c499b79 --- /dev/null +++ b/meta/classes/kernel-module-split.bbclass | |||
@@ -0,0 +1,185 @@ | |||
1 | pkg_postinst_modules () { | ||
2 | if [ -z "$D" ]; then | ||
3 | depmod -a ${KERNEL_VERSION} | ||
4 | else | ||
5 | depmodwrapper -a -b $D ${KERNEL_VERSION} | ||
6 | fi | ||
7 | } | ||
8 | |||
9 | pkg_postrm_modules () { | ||
10 | if [ -z "$D" ]; then | ||
11 | depmod -a ${KERNEL_VERSION} | ||
12 | else | ||
13 | depmodwrapper -a -b $D ${KERNEL_VERSION} | ||
14 | fi | ||
15 | } | ||
16 | |||
17 | autoload_postinst_fragment() { | ||
18 | if [ x"$D" = "x" ]; then | ||
19 | modprobe %s || true | ||
20 | fi | ||
21 | } | ||
22 | |||
23 | do_install_append() { | ||
24 | install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/ | ||
25 | } | ||
26 | |||
27 | PACKAGESPLITFUNCS_prepend = "split_kernel_module_packages " | ||
28 | |||
29 | KERNEL_MODULES_META_PACKAGE ?= "kernel-modules" | ||
30 | |||
31 | python split_kernel_module_packages () { | ||
32 | import re | ||
33 | |||
34 | modinfoexp = re.compile("([^=]+)=(.*)") | ||
35 | kerverrexp = re.compile('^(.*-hh.*)[\.\+].*$') | ||
36 | depmodpat0 = re.compile("^(.*\.k?o):..*$") | ||
37 | depmodpat1 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*$") | ||
38 | depmodpat2 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*\\\$") | ||
39 | depmodpat3 = re.compile("^\t(.*\.k?o)\s*\\\$") | ||
40 | depmodpat4 = re.compile("^\t(.*\.k?o)\s*$") | ||
41 | |||
42 | def extract_modinfo(file): | ||
43 | import tempfile, subprocess | ||
44 | tempfile.tempdir = d.getVar("WORKDIR", True) | ||
45 | tf = tempfile.mkstemp() | ||
46 | tmpfile = tf[1] | ||
47 | cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX", True) or "", file, tmpfile) | ||
48 | subprocess.call(cmd, shell=True) | ||
49 | f = open(tmpfile) | ||
50 | l = f.read().split("\000") | ||
51 | f.close() | ||
52 | os.close(tf[0]) | ||
53 | os.unlink(tmpfile) | ||
54 | vals = {} | ||
55 | for i in l: | ||
56 | m = modinfoexp.match(i) | ||
57 | if not m: | ||
58 | continue | ||
59 | vals[m.group(1)] = m.group(2) | ||
60 | return vals | ||
61 | |||
62 | def parse_depmod(): | ||
63 | |||
64 | dvar = d.getVar('PKGD', True) | ||
65 | |||
66 | kernelver = d.getVar('KERNEL_VERSION', True) | ||
67 | kernelver_stripped = kernelver | ||
68 | m = kerverrexp.match(kernelver) | ||
69 | if m: | ||
70 | kernelver_stripped = m.group(1) | ||
71 | staging_kernel_dir = d.getVar("STAGING_KERNEL_DIR", True) | ||
72 | system_map_file = "%s/boot/System.map-%s" % (dvar, kernelver) | ||
73 | if not os.path.exists(system_map_file): | ||
74 | system_map_file = "%s/System.map-%s" % (staging_kernel_dir, kernelver) | ||
75 | if not os.path.exists(system_map_file): | ||
76 | bb.fatal("System.map-%s does not exist in '%s/boot' nor STAGING_KERNEL_DIR '%s'" % (kernelver, dvar, staging_kernel_dir)) | ||
77 | |||
78 | cmd = "depmod -n -a -b %s -F %s %s" % (dvar, system_map_file, kernelver_stripped) | ||
79 | f = os.popen(cmd, 'r') | ||
80 | |||
81 | deps = {} | ||
82 | line = f.readline() | ||
83 | while line: | ||
84 | if not depmodpat0.match(line): | ||
85 | line = f.readline() | ||
86 | continue | ||
87 | m1 = depmodpat1.match(line) | ||
88 | if m1: | ||
89 | deps[m1.group(1)] = m1.group(2).split() | ||
90 | else: | ||
91 | m2 = depmodpat2.match(line) | ||
92 | if m2: | ||
93 | deps[m2.group(1)] = m2.group(2).split() | ||
94 | line = f.readline() | ||
95 | m3 = depmodpat3.match(line) | ||
96 | while m3: | ||
97 | deps[m2.group(1)].extend(m3.group(1).split()) | ||
98 | line = f.readline() | ||
99 | m3 = depmodpat3.match(line) | ||
100 | m4 = depmodpat4.match(line) | ||
101 | deps[m2.group(1)].extend(m4.group(1).split()) | ||
102 | line = f.readline() | ||
103 | f.close() | ||
104 | return deps | ||
105 | |||
106 | def get_dependencies(file, pattern, format): | ||
107 | # file no longer includes PKGD | ||
108 | file = file.replace(d.getVar('PKGD', True) or '', '', 1) | ||
109 | # instead is prefixed with /lib/modules/${KERNEL_VERSION} | ||
110 | file = file.replace("/lib/modules/%s/" % d.getVar('KERNEL_VERSION', True) or '', '', 1) | ||
111 | |||
112 | if module_deps.has_key(file): | ||
113 | dependencies = [] | ||
114 | for i in module_deps[file]: | ||
115 | m = re.match(pattern, os.path.basename(i)) | ||
116 | if not m: | ||
117 | continue | ||
118 | on = legitimize_package_name(m.group(1)) | ||
119 | dependency_pkg = format % on | ||
120 | dependencies.append(dependency_pkg) | ||
121 | return dependencies | ||
122 | return [] | ||
123 | |||
124 | def frob_metadata(file, pkg, pattern, format, basename): | ||
125 | vals = extract_modinfo(file) | ||
126 | |||
127 | dvar = d.getVar('PKGD', True) | ||
128 | |||
129 | # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append | ||
130 | # appropriate modprobe commands to the postinst | ||
131 | autoload = d.getVar('module_autoload_%s' % basename, True) | ||
132 | if autoload: | ||
133 | name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename) | ||
134 | f = open(name, 'w') | ||
135 | for m in autoload.split(): | ||
136 | f.write('%s\n' % m) | ||
137 | f.close() | ||
138 | postinst = d.getVar('pkg_postinst_%s' % pkg, True) | ||
139 | if not postinst: | ||
140 | bb.fatal("pkg_postinst_%s not defined" % pkg) | ||
141 | postinst += d.getVar('autoload_postinst_fragment', True) % autoload | ||
142 | d.setVar('pkg_postinst_%s' % pkg, postinst) | ||
143 | |||
144 | # Write out any modconf fragment | ||
145 | modconf = d.getVar('module_conf_%s' % basename, True) | ||
146 | if modconf: | ||
147 | name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) | ||
148 | f = open(name, 'w') | ||
149 | f.write("%s\n" % modconf) | ||
150 | f.close() | ||
151 | |||
152 | files = d.getVar('FILES_%s' % pkg, True) | ||
153 | files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename) | ||
154 | d.setVar('FILES_%s' % pkg, files) | ||
155 | |||
156 | if vals.has_key("description"): | ||
157 | old_desc = d.getVar('DESCRIPTION_' + pkg, True) or "" | ||
158 | d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"]) | ||
159 | |||
160 | rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or "") | ||
161 | for dep in get_dependencies(file, pattern, format): | ||
162 | if not dep in rdepends: | ||
163 | rdepends[dep] = [] | ||
164 | d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False)) | ||
165 | |||
166 | module_deps = parse_depmod() | ||
167 | module_regex = '^(.*)\.k?o$' | ||
168 | module_pattern = 'kernel-module-%s' | ||
169 | |||
170 | postinst = d.getVar('pkg_postinst_modules', True) | ||
171 | postrm = d.getVar('pkg_postrm_modules', True) | ||
172 | |||
173 | 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))) | ||
174 | if modules: | ||
175 | metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE', True) | ||
176 | d.appendVar('RDEPENDS_' + metapkg, ' '.join(modules)) | ||
177 | |||
178 | # If modules-load.d and modprobe.d are empty at this point, remove them to | ||
179 | # avoid warnings. removedirs only raises an OSError if an empty | ||
180 | # directory cannot be removed. | ||
181 | dvar = d.getVar('PKGD', True) | ||
182 | for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]: | ||
183 | if len(os.listdir(dir)) == 0: | ||
184 | os.rmdir(dir) | ||
185 | } | ||