diff options
Diffstat (limited to 'meta/classes/image.bbclass')
-rw-r--r-- | meta/classes/image.bbclass | 674 |
1 files changed, 0 insertions, 674 deletions
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass deleted file mode 100644 index 41fc329178..0000000000 --- a/meta/classes/image.bbclass +++ /dev/null | |||
@@ -1,674 +0,0 @@ | |||
1 | |||
2 | IMAGE_CLASSES ??= "" | ||
3 | |||
4 | # rootfs bootstrap install | ||
5 | # warning - image-container resets this | ||
6 | ROOTFS_BOOTSTRAP_INSTALL = "run-postinsts" | ||
7 | |||
8 | # Handle inherits of any of the image classes we need | ||
9 | IMGCLASSES = "rootfs_${IMAGE_PKGTYPE} image_types ${IMAGE_CLASSES}" | ||
10 | # Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk_base | ||
11 | # in the non-Linux SDK_OS case, such as mingw32 | ||
12 | IMGCLASSES += "${@['populate_sdk_base', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS")]}" | ||
13 | IMGCLASSES += "${@bb.utils.contains_any('IMAGE_FSTYPES', 'live iso hddimg', 'image-live', '', d)}" | ||
14 | IMGCLASSES += "${@bb.utils.contains('IMAGE_FSTYPES', 'container', 'image-container', '', d)}" | ||
15 | IMGCLASSES += "image_types_wic" | ||
16 | IMGCLASSES += "rootfs-postcommands" | ||
17 | IMGCLASSES += "image-postinst-intercepts" | ||
18 | inherit ${IMGCLASSES} | ||
19 | |||
20 | TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}" | ||
21 | TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}" | ||
22 | POPULATE_SDK_POST_TARGET_COMMAND += "rootfs_sysroot_relativelinks; " | ||
23 | |||
24 | LICENSE ?= "MIT" | ||
25 | PACKAGES = "" | ||
26 | DEPENDS += "${@' '.join(["%s-qemuwrapper-cross" % m for m in d.getVar("MULTILIB_VARIANTS").split()])} qemuwrapper-cross depmodwrapper-cross cross-localedef-native" | ||
27 | RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL} ${IMAGE_INSTALL_DEBUGFS}" | ||
28 | RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}" | ||
29 | PATH_prepend = "${@":".join(all_multilib_tune_values(d, 'STAGING_BINDIR_CROSS').split())}:" | ||
30 | |||
31 | INHIBIT_DEFAULT_DEPS = "1" | ||
32 | |||
33 | # IMAGE_FEATURES may contain any available package group | ||
34 | IMAGE_FEATURES ?= "" | ||
35 | IMAGE_FEATURES[type] = "list" | ||
36 | IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs read-only-rootfs-delayed-postinsts stateless-rootfs empty-root-password allow-empty-password allow-root-login post-install-logging" | ||
37 | |||
38 | # Generate companion debugfs? | ||
39 | IMAGE_GEN_DEBUGFS ?= "0" | ||
40 | |||
41 | # These pacackages will be installed as additional into debug rootfs | ||
42 | IMAGE_INSTALL_DEBUGFS ?= "" | ||
43 | |||
44 | # These packages will be removed from a read-only rootfs after all other | ||
45 | # packages have been installed | ||
46 | ROOTFS_RO_UNNEEDED ??= "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}" | ||
47 | |||
48 | # packages to install from features | ||
49 | FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}" | ||
50 | FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}" | ||
51 | FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}" | ||
52 | FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}" | ||
53 | |||
54 | # Define some very basic feature package groups | ||
55 | FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}" | ||
56 | SPLASH ?= "psplash" | ||
57 | FEATURE_PACKAGES_splash = "${SPLASH}" | ||
58 | |||
59 | IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}' | ||
60 | |||
61 | def check_image_features(d): | ||
62 | valid_features = (d.getVarFlag('IMAGE_FEATURES', 'validitems') or "").split() | ||
63 | valid_features += d.getVarFlags('COMPLEMENTARY_GLOB').keys() | ||
64 | for var in d: | ||
65 | if var.startswith("FEATURE_PACKAGES_"): | ||
66 | valid_features.append(var[17:]) | ||
67 | valid_features.sort() | ||
68 | |||
69 | features = set(oe.data.typed_value('IMAGE_FEATURES', d)) | ||
70 | for feature in features: | ||
71 | if feature not in valid_features: | ||
72 | if bb.utils.contains('EXTRA_IMAGE_FEATURES', feature, True, False, d): | ||
73 | raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES (added via EXTRA_IMAGE_FEATURES) is not a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features))) | ||
74 | else: | ||
75 | raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES is not a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features))) | ||
76 | |||
77 | IMAGE_INSTALL ?= "" | ||
78 | IMAGE_INSTALL[type] = "list" | ||
79 | export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}" | ||
80 | PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}" | ||
81 | |||
82 | IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-image-complete" | ||
83 | |||
84 | # Images are generally built explicitly, do not need to be part of world. | ||
85 | EXCLUDE_FROM_WORLD = "1" | ||
86 | |||
87 | USE_DEVFS ?= "1" | ||
88 | USE_DEPMOD ?= "1" | ||
89 | |||
90 | PID = "${@os.getpid()}" | ||
91 | |||
92 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
93 | |||
94 | LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot" | ||
95 | LDCONFIGDEPEND_libc-musl = "" | ||
96 | |||
97 | # This is needed to have depmod data in PKGDATA_DIR, | ||
98 | # but if you're building small initramfs image | ||
99 | # e.g. to include it in your kernel, you probably | ||
100 | # don't want this dependency, which is causing dependency loop | ||
101 | KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata" | ||
102 | |||
103 | do_rootfs[depends] += " \ | ||
104 | makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \ | ||
105 | virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \ | ||
106 | ${KERNELDEPMODDEPEND} \ | ||
107 | " | ||
108 | do_rootfs[recrdeptask] += "do_packagedata" | ||
109 | |||
110 | def rootfs_command_variables(d): | ||
111 | return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','ROOTFS_POSTUNINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND', | ||
112 | 'IMAGE_PREPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS','DEB_PREPROCESS_COMMANDS','DEB_POSTPROCESS_COMMANDS'] | ||
113 | |||
114 | python () { | ||
115 | variables = rootfs_command_variables(d) + sdk_command_variables(d) | ||
116 | for var in variables: | ||
117 | if d.getVar(var, False): | ||
118 | d.setVarFlag(var, 'func', '1') | ||
119 | } | ||
120 | |||
121 | def rootfs_variables(d): | ||
122 | from oe.rootfs import variable_depends | ||
123 | variables = ['IMAGE_DEVICE_TABLE','IMAGE_DEVICE_TABLES','BUILD_IMAGES_FROM_FEEDS','IMAGE_TYPES_MASKED','IMAGE_ROOTFS_ALIGNMENT','IMAGE_OVERHEAD_FACTOR','IMAGE_ROOTFS_SIZE','IMAGE_ROOTFS_EXTRA_SPACE', | ||
124 | 'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS', 'IMAGE_LINGUAS_COMPLEMENTARY', 'IMAGE_LOCALES_ARCHIVE', | ||
125 | 'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS', | ||
126 | 'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS', | ||
127 | 'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY', 'REPRODUCIBLE_TIMESTAMP_ROOTFS', 'IMAGE_INSTALL_DEBUGFS'] | ||
128 | variables.extend(rootfs_command_variables(d)) | ||
129 | variables.extend(variable_depends(d)) | ||
130 | return " ".join(variables) | ||
131 | |||
132 | do_rootfs[vardeps] += "${@rootfs_variables(d)}" | ||
133 | |||
134 | do_build[depends] += "virtual/kernel:do_deploy" | ||
135 | |||
136 | |||
137 | python () { | ||
138 | def extraimage_getdepends(task): | ||
139 | deps = "" | ||
140 | for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split(): | ||
141 | deps += " %s:%s" % (dep, task) | ||
142 | return deps | ||
143 | |||
144 | d.appendVarFlag('do_image_complete', 'depends', extraimage_getdepends('do_populate_sysroot')) | ||
145 | |||
146 | deps = " " + imagetypes_getdepends(d) | ||
147 | d.appendVarFlag('do_rootfs', 'depends', deps) | ||
148 | |||
149 | #process IMAGE_FEATURES, we must do this before runtime_mapping_rename | ||
150 | #Check for replaces image features | ||
151 | features = set(oe.data.typed_value('IMAGE_FEATURES', d)) | ||
152 | remain_features = features.copy() | ||
153 | for feature in features: | ||
154 | replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature) or "").split()) | ||
155 | remain_features -= replaces | ||
156 | |||
157 | #Check for conflict image features | ||
158 | for feature in remain_features: | ||
159 | conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature) or "").split()) | ||
160 | temp = conflicts & remain_features | ||
161 | if temp: | ||
162 | bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN'), feature, ' '.join(list(temp)))) | ||
163 | |||
164 | d.setVar('IMAGE_FEATURES', ' '.join(sorted(list(remain_features)))) | ||
165 | |||
166 | check_image_features(d) | ||
167 | } | ||
168 | |||
169 | IMAGE_POSTPROCESS_COMMAND ?= "" | ||
170 | |||
171 | # some default locales | ||
172 | IMAGE_LINGUAS ?= "de-de fr-fr en-gb" | ||
173 | |||
174 | LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IMAGE_LINGUAS').split()))}" | ||
175 | |||
176 | # per default create a locale archive | ||
177 | IMAGE_LOCALES_ARCHIVE ?= '1' | ||
178 | |||
179 | # Prefer image, but use the fallback files for lookups if the image ones | ||
180 | # aren't yet available. | ||
181 | PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}" | ||
182 | |||
183 | PSEUDO_IGNORE_PATHS .= ",${WORKDIR}/intercept_scripts,${WORKDIR}/oe-rootfs-repo,${WORKDIR}/sstate-build-image_complete" | ||
184 | |||
185 | PACKAGE_EXCLUDE ??= "" | ||
186 | PACKAGE_EXCLUDE[type] = "list" | ||
187 | |||
188 | fakeroot python do_rootfs () { | ||
189 | from oe.rootfs import create_rootfs | ||
190 | from oe.manifest import create_manifest | ||
191 | import logging | ||
192 | |||
193 | logger = d.getVar('BB_TASK_LOGGER', False) | ||
194 | if logger: | ||
195 | logcatcher = bb.utils.LogCatcher() | ||
196 | logger.addHandler(logcatcher) | ||
197 | else: | ||
198 | logcatcher = None | ||
199 | |||
200 | # NOTE: if you add, remove or significantly refactor the stages of this | ||
201 | # process then you should recalculate the weightings here. This is quite | ||
202 | # easy to do - just change the MultiStageProgressReporter line temporarily | ||
203 | # to pass debug=True as the last parameter and you'll get a printout of | ||
204 | # the weightings as well as a map to the lines where next_stage() was | ||
205 | # called. Of course this isn't critical, but it helps to keep the progress | ||
206 | # reporting accurate. | ||
207 | stage_weights = [1, 203, 354, 186, 65, 4228, 1, 353, 49, 330, 382, 23, 1] | ||
208 | progress_reporter = bb.progress.MultiStageProgressReporter(d, stage_weights) | ||
209 | progress_reporter.next_stage() | ||
210 | |||
211 | # Handle package exclusions | ||
212 | excl_pkgs = d.getVar("PACKAGE_EXCLUDE").split() | ||
213 | inst_pkgs = d.getVar("PACKAGE_INSTALL").split() | ||
214 | inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY").split() | ||
215 | |||
216 | d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs)) | ||
217 | d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs)) | ||
218 | |||
219 | for pkg in excl_pkgs: | ||
220 | if pkg in inst_pkgs: | ||
221 | bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL (%s). It will be removed from the list." % (pkg, d.getVar('PN'), inst_pkgs)) | ||
222 | inst_pkgs.remove(pkg) | ||
223 | |||
224 | if pkg in inst_attempt_pkgs: | ||
225 | bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL_ATTEMPTONLY (%s). It will be removed from the list." % (pkg, d.getVar('PN'), inst_pkgs)) | ||
226 | inst_attempt_pkgs.remove(pkg) | ||
227 | |||
228 | d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs)) | ||
229 | d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs)) | ||
230 | |||
231 | # Ensure we handle package name remapping | ||
232 | # We have to delay the runtime_mapping_rename until just before rootfs runs | ||
233 | # otherwise, the multilib renaming could step in and squash any fixups that | ||
234 | # may have occurred. | ||
235 | pn = d.getVar('PN') | ||
236 | runtime_mapping_rename("PACKAGE_INSTALL", pn, d) | ||
237 | runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d) | ||
238 | runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d) | ||
239 | |||
240 | # Generate the initial manifest | ||
241 | create_manifest(d) | ||
242 | |||
243 | progress_reporter.next_stage() | ||
244 | |||
245 | # generate rootfs | ||
246 | d.setVarFlag('REPRODUCIBLE_TIMESTAMP_ROOTFS', 'export', '1') | ||
247 | create_rootfs(d, progress_reporter=progress_reporter, logcatcher=logcatcher) | ||
248 | |||
249 | progress_reporter.finish() | ||
250 | } | ||
251 | do_rootfs[dirs] = "${TOPDIR}" | ||
252 | do_rootfs[cleandirs] += "${S} ${IMGDEPLOYDIR}" | ||
253 | do_rootfs[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}" | ||
254 | addtask rootfs after do_prepare_recipe_sysroot | ||
255 | |||
256 | fakeroot python do_image () { | ||
257 | from oe.utils import execute_pre_post_process | ||
258 | |||
259 | d.setVarFlag('REPRODUCIBLE_TIMESTAMP_ROOTFS', 'export', '1') | ||
260 | pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND") | ||
261 | |||
262 | execute_pre_post_process(d, pre_process_cmds) | ||
263 | } | ||
264 | do_image[dirs] = "${TOPDIR}" | ||
265 | addtask do_image after do_rootfs | ||
266 | |||
267 | fakeroot python do_image_complete () { | ||
268 | from oe.utils import execute_pre_post_process | ||
269 | |||
270 | post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND") | ||
271 | |||
272 | execute_pre_post_process(d, post_process_cmds) | ||
273 | } | ||
274 | do_image_complete[dirs] = "${TOPDIR}" | ||
275 | SSTATETASKS += "do_image_complete" | ||
276 | SSTATE_SKIP_CREATION_task-image-complete = '1' | ||
277 | do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}" | ||
278 | do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}" | ||
279 | do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}" | ||
280 | addtask do_image_complete after do_image before do_build | ||
281 | python do_image_complete_setscene () { | ||
282 | sstate_setscene(d) | ||
283 | } | ||
284 | addtask do_image_complete_setscene | ||
285 | |||
286 | # Add image-level QA/sanity checks to IMAGE_QA_COMMANDS | ||
287 | # | ||
288 | # IMAGE_QA_COMMANDS += " \ | ||
289 | # image_check_everything_ok \ | ||
290 | # " | ||
291 | # This task runs all functions in IMAGE_QA_COMMANDS after the rootfs | ||
292 | # construction has completed in order to validate the resulting image. | ||
293 | # | ||
294 | # The functions should use ${IMAGE_ROOTFS} to find the unpacked rootfs | ||
295 | # directory, which if QA passes will be the basis for the images. | ||
296 | fakeroot python do_image_qa () { | ||
297 | from oe.utils import ImageQAFailed | ||
298 | |||
299 | qa_cmds = (d.getVar('IMAGE_QA_COMMANDS') or '').split() | ||
300 | qamsg = "" | ||
301 | |||
302 | for cmd in qa_cmds: | ||
303 | try: | ||
304 | bb.build.exec_func(cmd, d) | ||
305 | except oe.utils.ImageQAFailed as e: | ||
306 | qamsg = qamsg + '\tImage QA function %s failed: %s\n' % (e.name, e.description) | ||
307 | except Exception as e: | ||
308 | qamsg = qamsg + '\tImage QA function %s failed\n' % cmd | ||
309 | |||
310 | if qamsg: | ||
311 | imgname = d.getVar('IMAGE_NAME') | ||
312 | bb.fatal("QA errors found whilst validating image: %s\n%s" % (imgname, qamsg)) | ||
313 | } | ||
314 | addtask do_image_qa after do_rootfs before do_image | ||
315 | |||
316 | SSTATETASKS += "do_image_qa" | ||
317 | SSTATE_SKIP_CREATION_task-image-qa = '1' | ||
318 | do_image_qa[sstate-inputdirs] = "" | ||
319 | do_image_qa[sstate-outputdirs] = "" | ||
320 | python do_image_qa_setscene () { | ||
321 | sstate_setscene(d) | ||
322 | } | ||
323 | addtask do_image_qa_setscene | ||
324 | |||
325 | def setup_debugfs_variables(d): | ||
326 | d.appendVar('IMAGE_ROOTFS', '-dbg') | ||
327 | if d.getVar('IMAGE_LINK_NAME'): | ||
328 | d.appendVar('IMAGE_LINK_NAME', '-dbg') | ||
329 | d.appendVar('IMAGE_NAME','-dbg') | ||
330 | d.setVar('IMAGE_BUILDING_DEBUGFS', 'true') | ||
331 | debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS') | ||
332 | if debugfs_image_fstypes: | ||
333 | d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes) | ||
334 | |||
335 | python setup_debugfs () { | ||
336 | setup_debugfs_variables(d) | ||
337 | } | ||
338 | |||
339 | python () { | ||
340 | vardeps = set() | ||
341 | # We allow CONVERSIONTYPES to have duplicates. That avoids breaking | ||
342 | # derived distros when OE-core or some other layer independently adds | ||
343 | # the same type. There is still only one command for each type, but | ||
344 | # presumably the commands will do the same when the type is the same, | ||
345 | # even when added in different places. | ||
346 | # | ||
347 | # Without de-duplication, gen_conversion_cmds() below | ||
348 | # would create the same compression command multiple times. | ||
349 | ctypes = set(d.getVar('CONVERSIONTYPES').split()) | ||
350 | old_overrides = d.getVar('OVERRIDES', False) | ||
351 | |||
352 | def _image_base_type(type): | ||
353 | basetype = type | ||
354 | for ctype in ctypes: | ||
355 | if type.endswith("." + ctype): | ||
356 | basetype = type[:-len("." + ctype)] | ||
357 | break | ||
358 | |||
359 | if basetype != type: | ||
360 | # New base type itself might be generated by a conversion command. | ||
361 | basetype = _image_base_type(basetype) | ||
362 | |||
363 | return basetype | ||
364 | |||
365 | basetypes = {} | ||
366 | alltypes = d.getVar('IMAGE_FSTYPES').split() | ||
367 | typedeps = {} | ||
368 | |||
369 | if d.getVar('IMAGE_GEN_DEBUGFS') == "1": | ||
370 | debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS').split() | ||
371 | for t in debugfs_fstypes: | ||
372 | alltypes.append("debugfs_" + t) | ||
373 | |||
374 | def _add_type(t): | ||
375 | baset = _image_base_type(t) | ||
376 | input_t = t | ||
377 | if baset not in basetypes: | ||
378 | basetypes[baset]= [] | ||
379 | if t not in basetypes[baset]: | ||
380 | basetypes[baset].append(t) | ||
381 | debug = "" | ||
382 | if t.startswith("debugfs_"): | ||
383 | t = t[8:] | ||
384 | debug = "debugfs_" | ||
385 | deps = (d.getVar('IMAGE_TYPEDEP_' + t) or "").split() | ||
386 | vardeps.add('IMAGE_TYPEDEP_' + t) | ||
387 | if baset not in typedeps: | ||
388 | typedeps[baset] = set() | ||
389 | deps = [debug + dep for dep in deps] | ||
390 | for dep in deps: | ||
391 | if dep not in alltypes: | ||
392 | alltypes.append(dep) | ||
393 | _add_type(dep) | ||
394 | basedep = _image_base_type(dep) | ||
395 | typedeps[baset].add(basedep) | ||
396 | |||
397 | if baset != input_t: | ||
398 | _add_type(baset) | ||
399 | |||
400 | for t in alltypes[:]: | ||
401 | _add_type(t) | ||
402 | |||
403 | d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps)) | ||
404 | |||
405 | maskedtypes = (d.getVar('IMAGE_TYPES_MASKED') or "").split() | ||
406 | maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")] | ||
407 | |||
408 | for t in basetypes: | ||
409 | vardeps = set() | ||
410 | cmds = [] | ||
411 | subimages = [] | ||
412 | realt = t | ||
413 | |||
414 | if t in maskedtypes: | ||
415 | continue | ||
416 | |||
417 | localdata = bb.data.createCopy(d) | ||
418 | debug = "" | ||
419 | if t.startswith("debugfs_"): | ||
420 | setup_debugfs_variables(localdata) | ||
421 | debug = "setup_debugfs " | ||
422 | realt = t[8:] | ||
423 | localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides)) | ||
424 | localdata.setVar('type', realt) | ||
425 | # Delete DATETIME so we don't expand any references to it now | ||
426 | # This means the task's hash can be stable rather than having hardcoded | ||
427 | # date/time values. It will get expanded at execution time. | ||
428 | # Similarly TMPDIR since otherwise we see QA stamp comparision problems | ||
429 | # Expand PV else it can trigger get_srcrev which can fail due to these variables being unset | ||
430 | localdata.setVar('PV', d.getVar('PV')) | ||
431 | localdata.delVar('DATETIME') | ||
432 | localdata.delVar('DATE') | ||
433 | localdata.delVar('TMPDIR') | ||
434 | vardepsexclude = (d.getVarFlag('IMAGE_CMD_' + realt, 'vardepsexclude', True) or '').split() | ||
435 | for dep in vardepsexclude: | ||
436 | localdata.delVar(dep) | ||
437 | |||
438 | image_cmd = localdata.getVar("IMAGE_CMD") | ||
439 | vardeps.add('IMAGE_CMD_' + realt) | ||
440 | if image_cmd: | ||
441 | cmds.append("\t" + image_cmd) | ||
442 | else: | ||
443 | bb.fatal("No IMAGE_CMD defined for IMAGE_FSTYPES entry '%s' - possibly invalid type name or missing support class" % t) | ||
444 | cmds.append(localdata.expand("\tcd ${IMGDEPLOYDIR}")) | ||
445 | |||
446 | # Since a copy of IMAGE_CMD_xxx will be inlined within do_image_xxx, | ||
447 | # prevent a redundant copy of IMAGE_CMD_xxx being emitted as a function. | ||
448 | d.delVarFlag('IMAGE_CMD_' + realt, 'func') | ||
449 | |||
450 | rm_tmp_images = set() | ||
451 | def gen_conversion_cmds(bt): | ||
452 | for ctype in sorted(ctypes): | ||
453 | if bt.endswith("." + ctype): | ||
454 | type = bt[0:-len(ctype) - 1] | ||
455 | if type.startswith("debugfs_"): | ||
456 | type = type[8:] | ||
457 | # Create input image first. | ||
458 | gen_conversion_cmds(type) | ||
459 | localdata.setVar('type', type) | ||
460 | cmd = "\t" + (localdata.getVar("CONVERSION_CMD_" + ctype) or localdata.getVar("COMPRESS_CMD_" + ctype)) | ||
461 | if cmd not in cmds: | ||
462 | cmds.append(cmd) | ||
463 | vardeps.add('CONVERSION_CMD_' + ctype) | ||
464 | vardeps.add('COMPRESS_CMD_' + ctype) | ||
465 | subimage = type + "." + ctype | ||
466 | if subimage not in subimages: | ||
467 | subimages.append(subimage) | ||
468 | if type not in alltypes: | ||
469 | rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) | ||
470 | |||
471 | for bt in basetypes[t]: | ||
472 | gen_conversion_cmds(bt) | ||
473 | |||
474 | localdata.setVar('type', realt) | ||
475 | if t not in alltypes: | ||
476 | rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) | ||
477 | else: | ||
478 | subimages.append(realt) | ||
479 | |||
480 | # Clean up after applying all conversion commands. Some of them might | ||
481 | # use the same input, therefore we cannot delete sooner without applying | ||
482 | # some complex dependency analysis. | ||
483 | for image in sorted(rm_tmp_images): | ||
484 | cmds.append("\trm " + image) | ||
485 | |||
486 | after = 'do_image' | ||
487 | for dep in typedeps[t]: | ||
488 | after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_") | ||
489 | |||
490 | task = "do_image_%s" % t.replace("-", "_").replace(".", "_") | ||
491 | |||
492 | d.setVar(task, '\n'.join(cmds)) | ||
493 | d.setVarFlag(task, 'func', '1') | ||
494 | d.setVarFlag(task, 'fakeroot', '1') | ||
495 | |||
496 | d.appendVarFlag(task, 'prefuncs', ' ' + debug + ' set_image_size') | ||
497 | d.prependVarFlag(task, 'postfuncs', 'create_symlinks ') | ||
498 | d.appendVarFlag(task, 'subimages', ' ' + ' '.join(subimages)) | ||
499 | d.appendVarFlag(task, 'vardeps', ' ' + ' '.join(vardeps)) | ||
500 | d.appendVarFlag(task, 'vardepsexclude', ' DATETIME DATE ' + ' '.join(vardepsexclude)) | ||
501 | |||
502 | bb.debug(2, "Adding task %s before %s, after %s" % (task, 'do_image_complete', after)) | ||
503 | bb.build.addtask(task, 'do_image_complete', after, d) | ||
504 | } | ||
505 | |||
506 | # | ||
507 | # Compute the rootfs size | ||
508 | # | ||
509 | def get_rootfs_size(d): | ||
510 | import subprocess | ||
511 | |||
512 | rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT')) | ||
513 | overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR')) | ||
514 | rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE')) | ||
515 | rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE')) | ||
516 | rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE') | ||
517 | image_fstypes = d.getVar('IMAGE_FSTYPES') or '' | ||
518 | initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES') or '' | ||
519 | initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE') | ||
520 | |||
521 | output = subprocess.check_output(['du', '-ks', | ||
522 | d.getVar('IMAGE_ROOTFS')]) | ||
523 | size_kb = int(output.split()[0]) | ||
524 | |||
525 | base_size = size_kb * overhead_factor | ||
526 | bb.debug(1, '%f = %d * %f' % (base_size, size_kb, overhead_factor)) | ||
527 | base_size2 = max(base_size, rootfs_req_size) + rootfs_extra_space | ||
528 | bb.debug(1, '%f = max(%f, %d)[%f] + %d' % (base_size2, base_size, rootfs_req_size, max(base_size, rootfs_req_size), rootfs_extra_space)) | ||
529 | |||
530 | base_size = base_size2 | ||
531 | if base_size != int(base_size): | ||
532 | base_size = int(base_size + 1) | ||
533 | else: | ||
534 | base_size = int(base_size) | ||
535 | bb.debug(1, '%f = int(%f)' % (base_size, base_size2)) | ||
536 | |||
537 | base_size_saved = base_size | ||
538 | base_size += rootfs_alignment - 1 | ||
539 | base_size -= base_size % rootfs_alignment | ||
540 | bb.debug(1, '%d = aligned(%d)' % (base_size, base_size_saved)) | ||
541 | |||
542 | # Do not check image size of the debugfs image. This is not supposed | ||
543 | # to be deployed, etc. so it doesn't make sense to limit the size | ||
544 | # of the debug. | ||
545 | if (d.getVar('IMAGE_BUILDING_DEBUGFS') or "") == "true": | ||
546 | bb.debug(1, 'returning debugfs size %d' % (base_size)) | ||
547 | return base_size | ||
548 | |||
549 | # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set) | ||
550 | if rootfs_maxsize: | ||
551 | rootfs_maxsize_int = int(rootfs_maxsize) | ||
552 | if base_size > rootfs_maxsize_int: | ||
553 | bb.fatal("The rootfs size %d(K) exceeds IMAGE_ROOTFS_MAXSIZE: %d(K)" % \ | ||
554 | (base_size, rootfs_maxsize_int)) | ||
555 | |||
556 | # Check the initramfs size against INITRAMFS_MAXSIZE (if set) | ||
557 | if image_fstypes == initramfs_fstypes != '' and initramfs_maxsize: | ||
558 | initramfs_maxsize_int = int(initramfs_maxsize) | ||
559 | if base_size > initramfs_maxsize_int: | ||
560 | bb.error("The initramfs size %d(K) exceeds INITRAMFS_MAXSIZE: %d(K)" % \ | ||
561 | (base_size, initramfs_maxsize_int)) | ||
562 | bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should") | ||
563 | bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n") | ||
564 | |||
565 | bb.debug(1, 'returning %d' % (base_size)) | ||
566 | return base_size | ||
567 | |||
568 | python set_image_size () { | ||
569 | rootfs_size = get_rootfs_size(d) | ||
570 | d.setVar('ROOTFS_SIZE', str(rootfs_size)) | ||
571 | d.setVarFlag('ROOTFS_SIZE', 'export', '1') | ||
572 | } | ||
573 | |||
574 | # | ||
575 | # Create symlinks to the newly created image | ||
576 | # | ||
577 | python create_symlinks() { | ||
578 | |||
579 | deploy_dir = d.getVar('IMGDEPLOYDIR') | ||
580 | img_name = d.getVar('IMAGE_NAME') | ||
581 | link_name = d.getVar('IMAGE_LINK_NAME') | ||
582 | manifest_name = d.getVar('IMAGE_MANIFEST') | ||
583 | taskname = d.getVar("BB_CURRENTTASK") | ||
584 | subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split() | ||
585 | imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix') or d.expand("${IMAGE_NAME_SUFFIX}.") | ||
586 | |||
587 | if not link_name: | ||
588 | return | ||
589 | for type in subimages: | ||
590 | dst = os.path.join(deploy_dir, link_name + "." + type) | ||
591 | src = img_name + imgsuffix + type | ||
592 | if os.path.exists(os.path.join(deploy_dir, src)): | ||
593 | bb.note("Creating symlink: %s -> %s" % (dst, src)) | ||
594 | if os.path.islink(dst): | ||
595 | os.remove(dst) | ||
596 | os.symlink(src, dst) | ||
597 | else: | ||
598 | bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src)) | ||
599 | } | ||
600 | |||
601 | MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|" | ||
602 | MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py" | ||
603 | MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib" | ||
604 | |||
605 | do_fetch[noexec] = "1" | ||
606 | do_unpack[noexec] = "1" | ||
607 | do_patch[noexec] = "1" | ||
608 | do_configure[noexec] = "1" | ||
609 | do_compile[noexec] = "1" | ||
610 | do_install[noexec] = "1" | ||
611 | deltask do_populate_lic | ||
612 | deltask do_populate_sysroot | ||
613 | do_package[noexec] = "1" | ||
614 | deltask do_package_qa | ||
615 | do_packagedata[noexec] = "1" | ||
616 | deltask do_package_write_ipk | ||
617 | deltask do_package_write_deb | ||
618 | deltask do_package_write_rpm | ||
619 | |||
620 | # Prepare the root links to point to the /usr counterparts. | ||
621 | create_merged_usr_symlinks() { | ||
622 | root="$1" | ||
623 | install -d $root${base_bindir} $root${base_sbindir} $root${base_libdir} | ||
624 | lnr $root${base_bindir} $root/bin | ||
625 | lnr $root${base_sbindir} $root/sbin | ||
626 | lnr $root${base_libdir} $root/${baselib} | ||
627 | |||
628 | if [ "${nonarch_base_libdir}" != "${base_libdir}" ]; then | ||
629 | install -d $root${nonarch_base_libdir} | ||
630 | lnr $root${nonarch_base_libdir} $root/lib | ||
631 | fi | ||
632 | |||
633 | # create base links for multilibs | ||
634 | multi_libdirs="${@d.getVar('MULTILIB_VARIANTS')}" | ||
635 | for d in $multi_libdirs; do | ||
636 | install -d $root${exec_prefix}/$d | ||
637 | lnr $root${exec_prefix}/$d $root/$d | ||
638 | done | ||
639 | } | ||
640 | |||
641 | create_merged_usr_symlinks_rootfs() { | ||
642 | create_merged_usr_symlinks ${IMAGE_ROOTFS} | ||
643 | } | ||
644 | |||
645 | create_merged_usr_symlinks_sdk() { | ||
646 | create_merged_usr_symlinks ${SDK_OUTPUT}${SDKTARGETSYSROOT} | ||
647 | } | ||
648 | |||
649 | ROOTFS_PREPROCESS_COMMAND += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', 'create_merged_usr_symlinks_rootfs; ', '',d)}" | ||
650 | POPULATE_SDK_PRE_TARGET_COMMAND += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', 'create_merged_usr_symlinks_sdk; ', '',d)}" | ||
651 | |||
652 | reproducible_final_image_task () { | ||
653 | if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then | ||
654 | if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then | ||
655 | REPRODUCIBLE_TIMESTAMP_ROOTFS=`git -C "${COREBASE}" log -1 --pretty=%ct 2>/dev/null` || true | ||
656 | if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then | ||
657 | REPRODUCIBLE_TIMESTAMP_ROOTFS=`stat -c%Y ${@bb.utils.which(d.getVar("BBPATH"), "conf/bitbake.conf")}` | ||
658 | fi | ||
659 | fi | ||
660 | # Set mtime of all files to a reproducible value | ||
661 | bbnote "reproducible_final_image_task: mtime set to $REPRODUCIBLE_TIMESTAMP_ROOTFS" | ||
662 | find ${IMAGE_ROOTFS} -exec touch -h --date=@$REPRODUCIBLE_TIMESTAMP_ROOTFS {} \; | ||
663 | fi | ||
664 | } | ||
665 | |||
666 | systemd_preset_all () { | ||
667 | if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then | ||
668 | systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all | ||
669 | fi | ||
670 | } | ||
671 | |||
672 | IMAGE_PREPROCESS_COMMAND_append = " ${@ 'systemd_preset_all;' if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else ''} reproducible_final_image_task; " | ||
673 | |||
674 | CVE_PRODUCT = "" | ||