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