blob: 2247b305da89442d9872a525486223fef512afc4 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit rootfs_${IMAGE_PKGTYPE}
2
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003# Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk_base
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05004# in the non-Linux SDK_OS case, such as mingw32
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005SDKEXTCLASS ?= "${@['populate_sdk_base', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS")]}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006inherit ${SDKEXTCLASS}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}"
9TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}"
10POPULATE_SDK_POST_TARGET_COMMAND += "rootfs_sysroot_relativelinks; "
11
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012LICENSE ?= "MIT"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013PACKAGES = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014DEPENDS += "${MLPREFIX}qemuwrapper-cross depmodwrapper-cross"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL}"
16RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"
17
18INHIBIT_DEFAULT_DEPS = "1"
19
Brad Bishop316dfdd2018-06-25 12:45:53 -040020TESTIMAGECLASS = "${@oe.utils.conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021inherit ${TESTIMAGECLASS}
22
23# IMAGE_FEATURES may contain any available package group
24IMAGE_FEATURES ?= ""
25IMAGE_FEATURES[type] = "list"
26IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs empty-root-password allow-empty-password post-install-logging"
27
28# Generate companion debugfs?
29IMAGE_GEN_DEBUGFS ?= "0"
30
31# rootfs bootstrap install
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032ROOTFS_BOOTSTRAP_INSTALL = "run-postinsts"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050034# These packages will be removed from a read-only rootfs after all other
35# packages have been installed
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036ROOTFS_RO_UNNEEDED ??= "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050037
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038# packages to install from features
39FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
40FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
41FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
42FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}"
43
44# Define some very basic feature package groups
45FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
46SPLASH ?= "psplash"
47FEATURE_PACKAGES_splash = "${SPLASH}"
48
49IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'
50
51def check_image_features(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 valid_features = (d.getVarFlag('IMAGE_FEATURES', 'validitems') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 valid_features += d.getVarFlags('COMPLEMENTARY_GLOB').keys()
54 for var in d:
55 if var.startswith("PACKAGE_GROUP_"):
56 bb.warn("PACKAGE_GROUP is deprecated, please use FEATURE_PACKAGES instead")
57 valid_features.append(var[14:])
58 elif var.startswith("FEATURE_PACKAGES_"):
59 valid_features.append(var[17:])
60 valid_features.sort()
61
62 features = set(oe.data.typed_value('IMAGE_FEATURES', d))
63 for feature in features:
64 if feature not in valid_features:
65 if bb.utils.contains('EXTRA_IMAGE_FEATURES', feature, True, False, d):
66 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)))
67 else:
68 raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES is not a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features)))
69
70IMAGE_INSTALL ?= ""
71IMAGE_INSTALL[type] = "list"
72export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
73PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"
74
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-image-complete"
76
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077# Images are generally built explicitly, do not need to be part of world.
78EXCLUDE_FROM_WORLD = "1"
79
80USE_DEVFS ?= "1"
81USE_DEPMOD ?= "1"
82
83PID = "${@os.getpid()}"
84
85PACKAGE_ARCH = "${MACHINE_ARCH}"
86
87LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088LDCONFIGDEPEND_libc-musl = ""
89
90# This is needed to have depmod data in PKGDATA_DIR,
91# but if you're building small initramfs image
92# e.g. to include it in your kernel, you probably
93# don't want this dependency, which is causing dependency loop
94KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"
95
96do_rootfs[depends] += " \
97 makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \
98 virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \
99 ${KERNELDEPMODDEPEND} \
100"
101do_rootfs[recrdeptask] += "do_packagedata"
102
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500103def rootfs_command_variables(d):
104 return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','ROOTFS_POSTUNINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND',
105 'IMAGE_PREPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS','DEB_PREPROCESS_COMMANDS','DEB_POSTPROCESS_COMMANDS']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500106
107python () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500108 variables = rootfs_command_variables(d) + sdk_command_variables(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 for var in variables:
110 if d.getVar(var, False):
111 d.setVarFlag(var, 'func', '1')
112}
113
114def rootfs_variables(d):
115 from oe.rootfs import variable_depends
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600116 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',
117 'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500118 'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS',
119 'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500120 'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY', 'REPRODUCIBLE_TIMESTAMP_ROOTFS']
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500121 variables.extend(rootfs_command_variables(d))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 variables.extend(variable_depends(d))
123 return " ".join(variables)
124
125do_rootfs[vardeps] += "${@rootfs_variables(d)}"
126
127do_build[depends] += "virtual/kernel:do_deploy"
128
129def build_live(d):
130 if bb.utils.contains("IMAGE_FSTYPES", "live", "live", "0", d) == "0": # live is not set but hob might set iso or hddimg
131 d.setVar('NOISO', bb.utils.contains('IMAGE_FSTYPES', "iso", "0", "1", d))
132 d.setVar('NOHDD', bb.utils.contains('IMAGE_FSTYPES', "hddimg", "0", "1", d))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 if d.getVar('NOISO') == "0" or d.getVar('NOHDD') == "0":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 return "image-live"
135 return ""
136 return "image-live"
137
138IMAGE_TYPE_live = "${@build_live(d)}"
139inherit ${IMAGE_TYPE_live}
140
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500141IMAGE_TYPE_container = '${@bb.utils.contains("IMAGE_FSTYPES", "container", "image-container", "", d)}'
142inherit ${IMAGE_TYPE_container}
143
144IMAGE_TYPE_wic = "image_types_wic"
145inherit ${IMAGE_TYPE_wic}
146
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147python () {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148 def extraimage_getdepends(task):
149 deps = ""
150 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
151 deps += " %s:%s" % (dep, task)
152 return deps
153
154 d.appendVarFlag('do_image', 'depends', extraimage_getdepends('do_populate_lic'))
155 d.appendVarFlag('do_image_complete', 'depends', extraimage_getdepends('do_populate_sysroot'))
156
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 deps = " " + imagetypes_getdepends(d)
158 d.appendVarFlag('do_rootfs', 'depends', deps)
159
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 #process IMAGE_FEATURES, we must do this before runtime_mapping_rename
161 #Check for replaces image features
162 features = set(oe.data.typed_value('IMAGE_FEATURES', d))
163 remain_features = features.copy()
164 for feature in features:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500165 replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature) or "").split())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166 remain_features -= replaces
167
168 #Check for conflict image features
169 for feature in remain_features:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500170 conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature) or "").split())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171 temp = conflicts & remain_features
172 if temp:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500173 bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN'), feature, ' '.join(list(temp))))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600175 d.setVar('IMAGE_FEATURES', ' '.join(sorted(list(remain_features))))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
177 check_image_features(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178}
179
180IMAGE_CLASSES += "image_types"
181inherit ${IMAGE_CLASSES}
182
183IMAGE_POSTPROCESS_COMMAND ?= ""
184
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500185# some default locales
186IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
187
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500188LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IMAGE_LINGUAS').split()))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189
190# Prefer image, but use the fallback files for lookups if the image ones
191# aren't yet available.
192PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}"
193
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500194inherit rootfs-postcommands
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500195
196PACKAGE_EXCLUDE ??= ""
197PACKAGE_EXCLUDE[type] = "list"
198
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500199fakeroot python do_rootfs () {
200 from oe.rootfs import create_rootfs
201 from oe.manifest import create_manifest
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500202 import logging
203
204 logger = d.getVar('BB_TASK_LOGGER', False)
205 if logger:
206 logcatcher = bb.utils.LogCatcher()
207 logger.addHandler(logcatcher)
208 else:
209 logcatcher = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500210
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600211 # NOTE: if you add, remove or significantly refactor the stages of this
212 # process then you should recalculate the weightings here. This is quite
213 # easy to do - just change the MultiStageProgressReporter line temporarily
214 # to pass debug=True as the last parameter and you'll get a printout of
215 # the weightings as well as a map to the lines where next_stage() was
216 # called. Of course this isn't critical, but it helps to keep the progress
217 # reporting accurate.
218 stage_weights = [1, 203, 354, 186, 65, 4228, 1, 353, 49, 330, 382, 23, 1]
219 progress_reporter = bb.progress.MultiStageProgressReporter(d, stage_weights)
220 progress_reporter.next_stage()
221
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222 # Handle package exclusions
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 excl_pkgs = d.getVar("PACKAGE_EXCLUDE").split()
224 inst_pkgs = d.getVar("PACKAGE_INSTALL").split()
225 inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
227 d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
228 d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))
229
230 for pkg in excl_pkgs:
231 if pkg in inst_pkgs:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500232 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))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233 inst_pkgs.remove(pkg)
234
235 if pkg in inst_attempt_pkgs:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500236 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))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237 inst_attempt_pkgs.remove(pkg)
238
239 d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
240 d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500242 # Ensure we handle package name remapping
243 # We have to delay the runtime_mapping_rename until just before rootfs runs
244 # otherwise, the multilib renaming could step in and squash any fixups that
245 # may have occurred.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500246 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 runtime_mapping_rename("PACKAGE_INSTALL", pn, d)
248 runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d)
249 runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500251 # Generate the initial manifest
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252 create_manifest(d)
253
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600254 progress_reporter.next_stage()
255
256 # generate rootfs
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500257 d.setVarFlag('REPRODUCIBLE_TIMESTAMP_ROOTFS', 'export', '1')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500258 create_rootfs(d, progress_reporter=progress_reporter, logcatcher=logcatcher)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600259
260 progress_reporter.finish()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500261}
262do_rootfs[dirs] = "${TOPDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600263do_rootfs[cleandirs] += "${S} ${IMGDEPLOYDIR}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264do_rootfs[umask] = "022"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500265addtask rootfs after do_prepare_recipe_sysroot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500267fakeroot python do_image () {
268 from oe.utils import execute_pre_post_process
269
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500270 d.setVarFlag('REPRODUCIBLE_TIMESTAMP_ROOTFS', 'export', '1')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500271 pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500272
273 execute_pre_post_process(d, pre_process_cmds)
274}
275do_image[dirs] = "${TOPDIR}"
276do_image[umask] = "022"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500277addtask do_image after do_rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500278
279fakeroot python do_image_complete () {
280 from oe.utils import execute_pre_post_process
281
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500282 post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500283
284 execute_pre_post_process(d, post_process_cmds)
285}
286do_image_complete[dirs] = "${TOPDIR}"
287do_image_complete[umask] = "022"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600288SSTATETASKS += "do_image_complete"
289SSTATE_SKIP_CREATION_task-image-complete = '1'
290do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
291do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400292do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500293addtask do_image_complete after do_image before do_build
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500294python do_image_complete_setscene () {
295 sstate_setscene(d)
296}
297addtask do_image_complete_setscene
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500298
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600299# Add image-level QA/sanity checks to IMAGE_QA_COMMANDS
300#
301# IMAGE_QA_COMMANDS += " \
302# image_check_everything_ok \
303# "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500304# This task runs all functions in IMAGE_QA_COMMANDS after the rootfs
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600305# construction has completed in order to validate the resulting image.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500306#
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.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600309fakeroot python do_image_qa () {
310 from oe.utils import ImageQAFailed
311
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500312 qa_cmds = (d.getVar('IMAGE_QA_COMMANDS') or '').split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600313 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 bb.build.FuncFailed as e:
321 qamsg = qamsg + '\tImage QA function %s failed' % e.name
322 if e.logfile:
323 qamsg = qamsg + ' (log file is located at %s)' % e.logfile
324 qamsg = qamsg + '\n'
325
326 if qamsg:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327 imgname = d.getVar('IMAGE_NAME')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600328 bb.fatal("QA errors found whilst validating image: %s\n%s" % (imgname, qamsg))
329}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500330addtask do_image_qa after do_rootfs before do_image
331
332SSTATETASKS += "do_image_qa"
333SSTATE_SKIP_CREATION_task-image-qa = '1'
334do_image_qa[sstate-inputdirs] = ""
335do_image_qa[sstate-outputdirs] = ""
336python do_image_qa_setscene () {
337 sstate_setscene(d)
338}
339addtask do_image_qa_setscene
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600340
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500341def setup_debugfs_variables(d):
342 d.appendVar('IMAGE_ROOTFS', '-dbg')
343 d.appendVar('IMAGE_LINK_NAME', '-dbg')
344 d.appendVar('IMAGE_NAME','-dbg')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600345 d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500346 debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500347 if debugfs_image_fstypes:
348 d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
349
350python setup_debugfs () {
351 setup_debugfs_variables(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352}
353
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500354python () {
355 vardeps = set()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600356 # We allow CONVERSIONTYPES to have duplicates. That avoids breaking
357 # derived distros when OE-core or some other layer independently adds
358 # the same type. There is still only one command for each type, but
359 # presumably the commands will do the same when the type is the same,
360 # even when added in different places.
361 #
362 # Without de-duplication, gen_conversion_cmds() below
363 # would create the same compression command multiple times.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500364 ctypes = set(d.getVar('CONVERSIONTYPES').split())
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600365 old_overrides = d.getVar('OVERRIDES', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500366
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500367 def _image_base_type(type):
368 basetype = type
369 for ctype in ctypes:
370 if type.endswith("." + ctype):
371 basetype = type[:-len("." + ctype)]
372 break
373
374 if basetype != type:
375 # New base type itself might be generated by a conversion command.
376 basetype = _image_base_type(basetype)
377
378 return basetype
379
380 basetypes = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500381 alltypes = d.getVar('IMAGE_FSTYPES').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500382 typedeps = {}
383
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500384 if d.getVar('IMAGE_GEN_DEBUGFS') == "1":
385 debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500386 for t in debugfs_fstypes:
387 alltypes.append("debugfs_" + t)
388
389 def _add_type(t):
390 baset = _image_base_type(t)
391 input_t = t
392 if baset not in basetypes:
393 basetypes[baset]= []
394 if t not in basetypes[baset]:
395 basetypes[baset].append(t)
396 debug = ""
397 if t.startswith("debugfs_"):
398 t = t[8:]
399 debug = "debugfs_"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500400 deps = (d.getVar('IMAGE_TYPEDEP_' + t) or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500401 vardeps.add('IMAGE_TYPEDEP_' + t)
402 if baset not in typedeps:
403 typedeps[baset] = set()
404 deps = [debug + dep for dep in deps]
405 for dep in deps:
406 if dep not in alltypes:
407 alltypes.append(dep)
408 _add_type(dep)
409 basedep = _image_base_type(dep)
410 typedeps[baset].add(basedep)
411
412 if baset != input_t:
413 _add_type(baset)
414
415 for t in alltypes[:]:
416 _add_type(t)
417
418 d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps))
419
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500420 maskedtypes = (d.getVar('IMAGE_TYPES_MASKED') or "").split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600421 maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500422
423 for t in basetypes:
424 vardeps = set()
425 cmds = []
426 subimages = []
427 realt = t
428
429 if t in maskedtypes:
430 continue
431
432 localdata = bb.data.createCopy(d)
433 debug = ""
434 if t.startswith("debugfs_"):
435 setup_debugfs_variables(localdata)
436 debug = "setup_debugfs "
437 realt = t[8:]
438 localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500439 localdata.setVar('type', realt)
440 # Delete DATETIME so we don't expand any references to it now
441 # This means the task's hash can be stable rather than having hardcoded
442 # date/time values. It will get expanded at execution time.
443 # Similarly TMPDIR since otherwise we see QA stamp comparision problems
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500444 # Expand PV else it can trigger get_srcrev which can fail due to these variables being unset
445 localdata.setVar('PV', d.getVar('PV'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500446 localdata.delVar('DATETIME')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500447 localdata.delVar('DATE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500448 localdata.delVar('TMPDIR')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500449 vardepsexclude = (d.getVarFlag('IMAGE_CMD_' + realt, 'vardepsexclude', True) or '').split()
450 for dep in vardepsexclude:
451 localdata.delVar(dep)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500452
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500453 image_cmd = localdata.getVar("IMAGE_CMD")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500454 vardeps.add('IMAGE_CMD_' + realt)
455 if image_cmd:
456 cmds.append("\t" + image_cmd)
457 else:
458 bb.fatal("No IMAGE_CMD defined for IMAGE_FSTYPES entry '%s' - possibly invalid type name or missing support class" % t)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600459 cmds.append(localdata.expand("\tcd ${IMGDEPLOYDIR}"))
460
461 # Since a copy of IMAGE_CMD_xxx will be inlined within do_image_xxx,
462 # prevent a redundant copy of IMAGE_CMD_xxx being emitted as a function.
463 d.delVarFlag('IMAGE_CMD_' + realt, 'func')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500464
465 rm_tmp_images = set()
466 def gen_conversion_cmds(bt):
Gerson Fernando Budke3c4c45d2017-09-19 14:15:36 -0300467 for ctype in sorted(ctypes):
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500468 if bt.endswith("." + ctype):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500469 type = bt[0:-len(ctype) - 1]
470 if type.startswith("debugfs_"):
471 type = type[8:]
472 # Create input image first.
473 gen_conversion_cmds(type)
474 localdata.setVar('type', type)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500475 cmd = "\t" + (localdata.getVar("CONVERSION_CMD_" + ctype) or localdata.getVar("COMPRESS_CMD_" + ctype))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600476 if cmd not in cmds:
477 cmds.append(cmd)
478 vardeps.add('CONVERSION_CMD_' + ctype)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500479 vardeps.add('COMPRESS_CMD_' + ctype)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600480 subimage = type + "." + ctype
481 if subimage not in subimages:
482 subimages.append(subimage)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500483 if type not in alltypes:
484 rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
485
486 for bt in basetypes[t]:
487 gen_conversion_cmds(bt)
488
489 localdata.setVar('type', realt)
490 if t not in alltypes:
491 rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
492 else:
493 subimages.append(realt)
494
495 # Clean up after applying all conversion commands. Some of them might
496 # use the same input, therefore we cannot delete sooner without applying
497 # some complex dependency analysis.
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500498 for image in sorted(rm_tmp_images):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500499 cmds.append("\trm " + image)
500
501 after = 'do_image'
502 for dep in typedeps[t]:
503 after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_")
504
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500505 task = "do_image_%s" % t.replace("-", "_").replace(".", "_")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500506
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500507 d.setVar(task, '\n'.join(cmds))
508 d.setVarFlag(task, 'func', '1')
509 d.setVarFlag(task, 'fakeroot', '1')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500510
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500511 d.appendVarFlag(task, 'prefuncs', ' ' + debug + ' set_image_size')
512 d.prependVarFlag(task, 'postfuncs', ' create_symlinks')
513 d.appendVarFlag(task, 'subimages', ' ' + ' '.join(subimages))
514 d.appendVarFlag(task, 'vardeps', ' ' + ' '.join(vardeps))
515 d.appendVarFlag(task, 'vardepsexclude', 'DATETIME DATE ' + ' '.join(vardepsexclude))
516
517 bb.debug(2, "Adding task %s before %s, after %s" % (task, 'do_image_complete', after))
518 bb.build.addtask(task, 'do_image_complete', after, d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500519}
520
521#
522# Compute the rootfs size
523#
524def get_rootfs_size(d):
525 import subprocess
526
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527 rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT'))
528 overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR'))
529 rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE'))
530 rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE'))
531 rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE')
532 image_fstypes = d.getVar('IMAGE_FSTYPES') or ''
533 initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES') or ''
534 initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500535
536 output = subprocess.check_output(['du', '-ks',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 d.getVar('IMAGE_ROOTFS')])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500538 size_kb = int(output.split()[0])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500539
Brad Bishop316dfdd2018-06-25 12:45:53 -0400540 base_size = size_kb * overhead_factor
541 bb.debug(1, '%f = %d * %f' % (base_size, size_kb, overhead_factor))
542 base_size2 = max(base_size, rootfs_req_size) + rootfs_extra_space
543 bb.debug(1, '%f = max(%f, %d)[%f] + %d' % (base_size2, base_size, rootfs_req_size, max(base_size, rootfs_req_size), overhead_factor))
544
545 base_size = base_size2
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500546 if base_size != int(base_size):
547 base_size = int(base_size + 1)
548 else:
549 base_size = int(base_size)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400550 bb.debug(1, '%f = int(%f)' % (base_size, base_size2))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500551
Brad Bishop316dfdd2018-06-25 12:45:53 -0400552 base_size_saved = base_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500553 base_size += rootfs_alignment - 1
554 base_size -= base_size % rootfs_alignment
Brad Bishop316dfdd2018-06-25 12:45:53 -0400555 bb.debug(1, '%d = aligned(%d)' % (base_size, base_size_saved))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500556
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600557 # Do not check image size of the debugfs image. This is not supposed
558 # to be deployed, etc. so it doesn't make sense to limit the size
559 # of the debug.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500560 if (d.getVar('IMAGE_BUILDING_DEBUGFS') or "") == "true":
Brad Bishop316dfdd2018-06-25 12:45:53 -0400561 bb.debug(1, 'returning debugfs size %d' % (base_size))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600562 return base_size
563
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500564 # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set)
565 if rootfs_maxsize:
566 rootfs_maxsize_int = int(rootfs_maxsize)
567 if base_size > rootfs_maxsize_int:
568 bb.fatal("The rootfs size %d(K) overrides IMAGE_ROOTFS_MAXSIZE: %d(K)" % \
569 (base_size, rootfs_maxsize_int))
570
571 # Check the initramfs size against INITRAMFS_MAXSIZE (if set)
572 if image_fstypes == initramfs_fstypes != '' and initramfs_maxsize:
573 initramfs_maxsize_int = int(initramfs_maxsize)
574 if base_size > initramfs_maxsize_int:
575 bb.error("The initramfs size %d(K) overrides INITRAMFS_MAXSIZE: %d(K)" % \
576 (base_size, initramfs_maxsize_int))
577 bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should")
578 bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400579
580 bb.debug(1, 'returning %d' % (base_size))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500581 return base_size
582
583python set_image_size () {
584 rootfs_size = get_rootfs_size(d)
585 d.setVar('ROOTFS_SIZE', str(rootfs_size))
586 d.setVarFlag('ROOTFS_SIZE', 'export', '1')
587}
588
589#
590# Create symlinks to the newly created image
591#
592python create_symlinks() {
593
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500594 deploy_dir = d.getVar('IMGDEPLOYDIR')
595 img_name = d.getVar('IMAGE_NAME')
596 link_name = d.getVar('IMAGE_LINK_NAME')
597 manifest_name = d.getVar('IMAGE_MANIFEST')
598 taskname = d.getVar("BB_CURRENTTASK")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500599 subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500600 imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix') or d.expand("${IMAGE_NAME_SUFFIX}.")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500601
602 if not link_name:
603 return
604 for type in subimages:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600605 dst = os.path.join(deploy_dir, link_name + "." + type)
606 src = img_name + imgsuffix + type
607 if os.path.exists(os.path.join(deploy_dir, src)):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500608 bb.note("Creating symlink: %s -> %s" % (dst, src))
609 if os.path.islink(dst):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500610 os.remove(dst)
611 os.symlink(src, dst)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600612 else:
613 bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500614}
615
616MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
617MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
618MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
619
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500620do_fetch[noexec] = "1"
621do_unpack[noexec] = "1"
622do_patch[noexec] = "1"
623do_configure[noexec] = "1"
624do_compile[noexec] = "1"
625do_install[noexec] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500626deltask do_populate_sysroot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627do_package[noexec] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500628deltask do_package_qa
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500629do_packagedata[noexec] = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400630deltask do_package_write_ipk
631deltask do_package_write_deb
632deltask do_package_write_rpm
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500633
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500634# Prepare the root links to point to the /usr counterparts.
635create_merged_usr_symlinks() {
636 root="$1"
637 install -d $root${base_bindir} $root${base_sbindir} $root${base_libdir}
638 lnr $root${base_bindir} $root/bin
639 lnr $root${base_sbindir} $root/sbin
640 lnr $root${base_libdir} $root/${baselib}
641
642 if [ "${nonarch_base_libdir}" != "${base_libdir}" ]; then
643 install -d $root${nonarch_base_libdir}
644 lnr $root${nonarch_base_libdir} $root/lib
645 fi
646
647 # create base links for multilibs
648 multi_libdirs="${@d.getVar('MULTILIB_VARIANTS')}"
649 for d in $multi_libdirs; do
650 install -d $root${exec_prefix}/$d
651 lnr $root${exec_prefix}/$d $root/$d
652 done
653}
654
655create_merged_usr_symlinks_rootfs() {
656 create_merged_usr_symlinks ${IMAGE_ROOTFS}
657}
658
659create_merged_usr_symlinks_sdk() {
660 create_merged_usr_symlinks ${SDK_OUTPUT}${SDKTARGETSYSROOT}
661}
662
663ROOTFS_PREPROCESS_COMMAND += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', 'create_merged_usr_symlinks_rootfs; ', '',d)}"
664POPULATE_SDK_PRE_TARGET_COMMAND += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', 'create_merged_usr_symlinks_sdk; ', '',d)}"
665
666reproducible_final_image_task () {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400667 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500668 if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
669 REPRODUCIBLE_TIMESTAMP_ROOTFS=`git log -1 --pretty=%ct`
670 fi
671 # Set mtime of all files to a reproducible value
672 bbnote "reproducible_final_image_task: mtime set to $REPRODUCIBLE_TIMESTAMP_ROOTFS"
673 find ${IMAGE_ROOTFS} -exec touch -h --date=@$REPRODUCIBLE_TIMESTAMP_ROOTFS {} \;
674 fi
675}
676IMAGE_PREPROCESS_COMMAND_append = " reproducible_final_image_task; "
Brad Bishop316dfdd2018-06-25 12:45:53 -0400677
678CVE_PRODUCT = ""