blob: 4bcfb87c9c9674c07bb0afaf6ba3cabf5e38a947 [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012LICENSE = "MIT"
13PACKAGES = ""
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
20TESTIMAGECLASS = "${@base_conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
21inherit ${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
36ROOTFS_RO_UNNEEDED = "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
37
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"
88LDCONFIGDEPEND_libc-uclibc = ""
89LDCONFIGDEPEND_libc-musl = ""
90
91# This is needed to have depmod data in PKGDATA_DIR,
92# but if you're building small initramfs image
93# e.g. to include it in your kernel, you probably
94# don't want this dependency, which is causing dependency loop
95KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"
96
97do_rootfs[depends] += " \
98 makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \
99 virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \
100 ${KERNELDEPMODDEPEND} \
101"
102do_rootfs[recrdeptask] += "do_packagedata"
103
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500104def rootfs_command_variables(d):
105 return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','ROOTFS_POSTUNINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND',
106 'IMAGE_PREPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS','DEB_PREPROCESS_COMMANDS','DEB_POSTPROCESS_COMMANDS']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107
108python () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500109 variables = rootfs_command_variables(d) + sdk_command_variables(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 for var in variables:
111 if d.getVar(var, False):
112 d.setVarFlag(var, 'func', '1')
113}
114
115def rootfs_variables(d):
116 from oe.rootfs import variable_depends
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600117 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',
118 '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 -0500119 'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS',
120 'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600121 'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY']
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500122 variables.extend(rootfs_command_variables(d))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123 variables.extend(variable_depends(d))
124 return " ".join(variables)
125
126do_rootfs[vardeps] += "${@rootfs_variables(d)}"
127
128do_build[depends] += "virtual/kernel:do_deploy"
129
130def build_live(d):
131 if bb.utils.contains("IMAGE_FSTYPES", "live", "live", "0", d) == "0": # live is not set but hob might set iso or hddimg
132 d.setVar('NOISO', bb.utils.contains('IMAGE_FSTYPES', "iso", "0", "1", d))
133 d.setVar('NOHDD', bb.utils.contains('IMAGE_FSTYPES', "hddimg", "0", "1", d))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500134 if d.getVar('NOISO') == "0" or d.getVar('NOHDD') == "0":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 return "image-live"
136 return ""
137 return "image-live"
138
139IMAGE_TYPE_live = "${@build_live(d)}"
140inherit ${IMAGE_TYPE_live}
141
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500142IMAGE_TYPE_vm = '${@bb.utils.contains_any("IMAGE_FSTYPES", ["vmdk", "vdi", "qcow2", "hdddirect"], "image-vm", "", d)}'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143inherit ${IMAGE_TYPE_vm}
144
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500145IMAGE_TYPE_container = '${@bb.utils.contains("IMAGE_FSTYPES", "container", "image-container", "", d)}'
146inherit ${IMAGE_TYPE_container}
147
148IMAGE_TYPE_wic = "image_types_wic"
149inherit ${IMAGE_TYPE_wic}
150
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151python () {
152 deps = " " + imagetypes_getdepends(d)
153 d.appendVarFlag('do_rootfs', 'depends', deps)
154
155 deps = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500156 for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 deps += " %s:do_populate_sysroot" % dep
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 d.appendVarFlag('do_image_complete', 'depends', deps)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159
160 #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 Bishop6e60e8b2018-02-01 10:27:11 -0500257 create_rootfs(d, progress_reporter=progress_reporter, logcatcher=logcatcher)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600258
259 progress_reporter.finish()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500260}
261do_rootfs[dirs] = "${TOPDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600262do_rootfs[cleandirs] += "${S} ${IMGDEPLOYDIR}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500263do_rootfs[umask] = "022"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500264addtask rootfs before do_build after do_prepare_recipe_sysroot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500266fakeroot python do_image () {
267 from oe.utils import execute_pre_post_process
268
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500269 pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500270
271 execute_pre_post_process(d, pre_process_cmds)
272}
273do_image[dirs] = "${TOPDIR}"
274do_image[umask] = "022"
275addtask do_image after do_rootfs before do_build
276
277fakeroot python do_image_complete () {
278 from oe.utils import execute_pre_post_process
279
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500281
282 execute_pre_post_process(d, post_process_cmds)
283}
284do_image_complete[dirs] = "${TOPDIR}"
285do_image_complete[umask] = "022"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600286SSTATETASKS += "do_image_complete"
287SSTATE_SKIP_CREATION_task-image-complete = '1'
288do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
289do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
290do_image_complete[stamp-extra-info] = "${MACHINE}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500291addtask do_image_complete after do_image before do_build
292
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600293# Add image-level QA/sanity checks to IMAGE_QA_COMMANDS
294#
295# IMAGE_QA_COMMANDS += " \
296# image_check_everything_ok \
297# "
298# This task runs all functions in IMAGE_QA_COMMANDS after the image
299# construction has completed in order to validate the resulting image.
300fakeroot python do_image_qa () {
301 from oe.utils import ImageQAFailed
302
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 qa_cmds = (d.getVar('IMAGE_QA_COMMANDS') or '').split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600304 qamsg = ""
305
306 for cmd in qa_cmds:
307 try:
308 bb.build.exec_func(cmd, d)
309 except oe.utils.ImageQAFailed as e:
310 qamsg = qamsg + '\tImage QA function %s failed: %s\n' % (e.name, e.description)
311 except bb.build.FuncFailed as e:
312 qamsg = qamsg + '\tImage QA function %s failed' % e.name
313 if e.logfile:
314 qamsg = qamsg + ' (log file is located at %s)' % e.logfile
315 qamsg = qamsg + '\n'
316
317 if qamsg:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500318 imgname = d.getVar('IMAGE_NAME')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319 bb.fatal("QA errors found whilst validating image: %s\n%s" % (imgname, qamsg))
320}
321addtask do_image_qa after do_image_complete before do_build
322
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500323def setup_debugfs_variables(d):
324 d.appendVar('IMAGE_ROOTFS', '-dbg')
325 d.appendVar('IMAGE_LINK_NAME', '-dbg')
326 d.appendVar('IMAGE_NAME','-dbg')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600327 d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500328 debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500329 if debugfs_image_fstypes:
330 d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
331
332python setup_debugfs () {
333 setup_debugfs_variables(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500334}
335
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500336python () {
337 vardeps = set()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600338 # We allow CONVERSIONTYPES to have duplicates. That avoids breaking
339 # derived distros when OE-core or some other layer independently adds
340 # the same type. There is still only one command for each type, but
341 # presumably the commands will do the same when the type is the same,
342 # even when added in different places.
343 #
344 # Without de-duplication, gen_conversion_cmds() below
345 # would create the same compression command multiple times.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500346 ctypes = set(d.getVar('CONVERSIONTYPES').split())
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600347 old_overrides = d.getVar('OVERRIDES', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500348
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500349 def _image_base_type(type):
350 basetype = type
351 for ctype in ctypes:
352 if type.endswith("." + ctype):
353 basetype = type[:-len("." + ctype)]
354 break
355
356 if basetype != type:
357 # New base type itself might be generated by a conversion command.
358 basetype = _image_base_type(basetype)
359
360 return basetype
361
362 basetypes = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500363 alltypes = d.getVar('IMAGE_FSTYPES').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500364 typedeps = {}
365
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500366 if d.getVar('IMAGE_GEN_DEBUGFS') == "1":
367 debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500368 for t in debugfs_fstypes:
369 alltypes.append("debugfs_" + t)
370
371 def _add_type(t):
372 baset = _image_base_type(t)
373 input_t = t
374 if baset not in basetypes:
375 basetypes[baset]= []
376 if t not in basetypes[baset]:
377 basetypes[baset].append(t)
378 debug = ""
379 if t.startswith("debugfs_"):
380 t = t[8:]
381 debug = "debugfs_"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500382 deps = (d.getVar('IMAGE_TYPEDEP_' + t) or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500383 vardeps.add('IMAGE_TYPEDEP_' + t)
384 if baset not in typedeps:
385 typedeps[baset] = set()
386 deps = [debug + dep for dep in deps]
387 for dep in deps:
388 if dep not in alltypes:
389 alltypes.append(dep)
390 _add_type(dep)
391 basedep = _image_base_type(dep)
392 typedeps[baset].add(basedep)
393
394 if baset != input_t:
395 _add_type(baset)
396
397 for t in alltypes[:]:
398 _add_type(t)
399
400 d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps))
401
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500402 maskedtypes = (d.getVar('IMAGE_TYPES_MASKED') or "").split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600403 maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500404
405 for t in basetypes:
406 vardeps = set()
407 cmds = []
408 subimages = []
409 realt = t
410
411 if t in maskedtypes:
412 continue
413
414 localdata = bb.data.createCopy(d)
415 debug = ""
416 if t.startswith("debugfs_"):
417 setup_debugfs_variables(localdata)
418 debug = "setup_debugfs "
419 realt = t[8:]
420 localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500421 localdata.setVar('type', realt)
422 # Delete DATETIME so we don't expand any references to it now
423 # This means the task's hash can be stable rather than having hardcoded
424 # date/time values. It will get expanded at execution time.
425 # Similarly TMPDIR since otherwise we see QA stamp comparision problems
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500426 # Expand PV else it can trigger get_srcrev which can fail due to these variables being unset
427 localdata.setVar('PV', d.getVar('PV'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500428 localdata.delVar('DATETIME')
429 localdata.delVar('TMPDIR')
430
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500431 image_cmd = localdata.getVar("IMAGE_CMD")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500432 vardeps.add('IMAGE_CMD_' + realt)
433 if image_cmd:
434 cmds.append("\t" + image_cmd)
435 else:
436 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 -0600437 cmds.append(localdata.expand("\tcd ${IMGDEPLOYDIR}"))
438
439 # Since a copy of IMAGE_CMD_xxx will be inlined within do_image_xxx,
440 # prevent a redundant copy of IMAGE_CMD_xxx being emitted as a function.
441 d.delVarFlag('IMAGE_CMD_' + realt, 'func')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500442
443 rm_tmp_images = set()
444 def gen_conversion_cmds(bt):
Gerson Fernando Budke3c4c45d2017-09-19 14:15:36 -0300445 for ctype in sorted(ctypes):
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500446 if bt.endswith("." + ctype):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500447 type = bt[0:-len(ctype) - 1]
448 if type.startswith("debugfs_"):
449 type = type[8:]
450 # Create input image first.
451 gen_conversion_cmds(type)
452 localdata.setVar('type', type)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500453 cmd = "\t" + (localdata.getVar("CONVERSION_CMD_" + ctype) or localdata.getVar("COMPRESS_CMD_" + ctype))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600454 if cmd not in cmds:
455 cmds.append(cmd)
456 vardeps.add('CONVERSION_CMD_' + ctype)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500457 vardeps.add('COMPRESS_CMD_' + ctype)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600458 subimage = type + "." + ctype
459 if subimage not in subimages:
460 subimages.append(subimage)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500461 if type not in alltypes:
462 rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
463
464 for bt in basetypes[t]:
465 gen_conversion_cmds(bt)
466
467 localdata.setVar('type', realt)
468 if t not in alltypes:
469 rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
470 else:
471 subimages.append(realt)
472
473 # Clean up after applying all conversion commands. Some of them might
474 # use the same input, therefore we cannot delete sooner without applying
475 # some complex dependency analysis.
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500476 for image in sorted(rm_tmp_images):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500477 cmds.append("\trm " + image)
478
479 after = 'do_image'
480 for dep in typedeps[t]:
481 after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_")
482
483 t = t.replace("-", "_").replace(".", "_")
484
485 d.setVar('do_image_%s' % t, '\n'.join(cmds))
486 d.setVarFlag('do_image_%s' % t, 'func', '1')
487 d.setVarFlag('do_image_%s' % t, 'fakeroot', '1')
488 d.setVarFlag('do_image_%s' % t, 'prefuncs', debug + 'set_image_size')
489 d.setVarFlag('do_image_%s' % t, 'postfuncs', 'create_symlinks')
490 d.setVarFlag('do_image_%s' % t, 'subimages', ' '.join(subimages))
491 d.appendVarFlag('do_image_%s' % t, 'vardeps', ' '.join(vardeps))
492 d.appendVarFlag('do_image_%s' % t, 'vardepsexclude', 'DATETIME')
493
494 bb.debug(2, "Adding type %s before %s, after %s" % (t, 'do_image_complete', after))
495 bb.build.addtask('do_image_%s' % t, 'do_image_complete', after, d)
496}
497
498#
499# Compute the rootfs size
500#
501def get_rootfs_size(d):
502 import subprocess
503
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500504 rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT'))
505 overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR'))
506 rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE'))
507 rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE'))
508 rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE')
509 image_fstypes = d.getVar('IMAGE_FSTYPES') or ''
510 initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES') or ''
511 initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500512
513 output = subprocess.check_output(['du', '-ks',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500514 d.getVar('IMAGE_ROOTFS')])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500515 size_kb = int(output.split()[0])
516 base_size = size_kb * overhead_factor
517 base_size = max(base_size, rootfs_req_size) + rootfs_extra_space
518
519 if base_size != int(base_size):
520 base_size = int(base_size + 1)
521 else:
522 base_size = int(base_size)
523
524 base_size += rootfs_alignment - 1
525 base_size -= base_size % rootfs_alignment
526
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600527 # Do not check image size of the debugfs image. This is not supposed
528 # to be deployed, etc. so it doesn't make sense to limit the size
529 # of the debug.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500530 if (d.getVar('IMAGE_BUILDING_DEBUGFS') or "") == "true":
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600531 return base_size
532
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500533 # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set)
534 if rootfs_maxsize:
535 rootfs_maxsize_int = int(rootfs_maxsize)
536 if base_size > rootfs_maxsize_int:
537 bb.fatal("The rootfs size %d(K) overrides IMAGE_ROOTFS_MAXSIZE: %d(K)" % \
538 (base_size, rootfs_maxsize_int))
539
540 # Check the initramfs size against INITRAMFS_MAXSIZE (if set)
541 if image_fstypes == initramfs_fstypes != '' and initramfs_maxsize:
542 initramfs_maxsize_int = int(initramfs_maxsize)
543 if base_size > initramfs_maxsize_int:
544 bb.error("The initramfs size %d(K) overrides INITRAMFS_MAXSIZE: %d(K)" % \
545 (base_size, initramfs_maxsize_int))
546 bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should")
547 bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n")
548 return base_size
549
550python set_image_size () {
551 rootfs_size = get_rootfs_size(d)
552 d.setVar('ROOTFS_SIZE', str(rootfs_size))
553 d.setVarFlag('ROOTFS_SIZE', 'export', '1')
554}
555
556#
557# Create symlinks to the newly created image
558#
559python create_symlinks() {
560
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500561 deploy_dir = d.getVar('IMGDEPLOYDIR')
562 img_name = d.getVar('IMAGE_NAME')
563 link_name = d.getVar('IMAGE_LINK_NAME')
564 manifest_name = d.getVar('IMAGE_MANIFEST')
565 taskname = d.getVar("BB_CURRENTTASK")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500566 subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500567 imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix') or d.expand("${IMAGE_NAME_SUFFIX}.")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500568
569 if not link_name:
570 return
571 for type in subimages:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600572 dst = os.path.join(deploy_dir, link_name + "." + type)
573 src = img_name + imgsuffix + type
574 if os.path.exists(os.path.join(deploy_dir, src)):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500575 bb.note("Creating symlink: %s -> %s" % (dst, src))
576 if os.path.islink(dst):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500577 os.remove(dst)
578 os.symlink(src, dst)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600579 else:
580 bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500581}
582
583MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
584MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
585MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
586
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500587do_fetch[noexec] = "1"
588do_unpack[noexec] = "1"
589do_patch[noexec] = "1"
590do_configure[noexec] = "1"
591do_compile[noexec] = "1"
592do_install[noexec] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500593deltask do_populate_sysroot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500594do_package[noexec] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500595deltask do_package_qa
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500596do_packagedata[noexec] = "1"
597do_package_write_ipk[noexec] = "1"
598do_package_write_deb[noexec] = "1"
599do_package_write_rpm[noexec] = "1"
600