blob: 6111f6d266044b02fdeea85a03271d1c3ab337ca [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit rootfs_${IMAGE_PKGTYPE}
2
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003# Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk
4# in the non-Linux SDK_OS case, such as mingw32
5SDKEXTCLASS ?= "${@['populate_sdk', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS", True)]}"
6inherit ${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
12inherit gzipnative
13
14LICENSE = "MIT"
15PACKAGES = ""
16DEPENDS += "${MLPREFIX}qemuwrapper-cross ${MLPREFIX}depmodwrapper-cross"
17RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL}"
18RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"
19
20INHIBIT_DEFAULT_DEPS = "1"
21
22TESTIMAGECLASS = "${@base_conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
23inherit ${TESTIMAGECLASS}
24
25# IMAGE_FEATURES may contain any available package group
26IMAGE_FEATURES ?= ""
27IMAGE_FEATURES[type] = "list"
28IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs empty-root-password allow-empty-password post-install-logging"
29
30# Generate companion debugfs?
31IMAGE_GEN_DEBUGFS ?= "0"
32
33# rootfs bootstrap install
34ROOTFS_BOOTSTRAP_INSTALL = "${@bb.utils.contains("IMAGE_FEATURES", "package-management", "", "${ROOTFS_PKGMANAGE_BOOTSTRAP}",d)}"
35
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036# These packages will be removed from a read-only rootfs after all other
37# packages have been installed
38ROOTFS_RO_UNNEEDED = "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
39
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040# packages to install from features
41FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
42FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
43FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
44FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}"
45
46# Define some very basic feature package groups
47FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
48SPLASH ?= "psplash"
49FEATURE_PACKAGES_splash = "${SPLASH}"
50
51IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'
52
53def check_image_features(d):
54 valid_features = (d.getVarFlag('IMAGE_FEATURES', 'validitems', True) or "").split()
55 valid_features += d.getVarFlags('COMPLEMENTARY_GLOB').keys()
56 for var in d:
57 if var.startswith("PACKAGE_GROUP_"):
58 bb.warn("PACKAGE_GROUP is deprecated, please use FEATURE_PACKAGES instead")
59 valid_features.append(var[14:])
60 elif var.startswith("FEATURE_PACKAGES_"):
61 valid_features.append(var[17:])
62 valid_features.sort()
63
64 features = set(oe.data.typed_value('IMAGE_FEATURES', d))
65 for feature in features:
66 if feature not in valid_features:
67 if bb.utils.contains('EXTRA_IMAGE_FEATURES', feature, True, False, d):
68 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)))
69 else:
70 raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES is not a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features)))
71
72IMAGE_INSTALL ?= ""
73IMAGE_INSTALL[type] = "list"
74export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
75PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"
76
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-image-complete"
78
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079# Images are generally built explicitly, do not need to be part of world.
80EXCLUDE_FROM_WORLD = "1"
81
82USE_DEVFS ?= "1"
83USE_DEPMOD ?= "1"
84
85PID = "${@os.getpid()}"
86
87PACKAGE_ARCH = "${MACHINE_ARCH}"
88
89LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
90LDCONFIGDEPEND_libc-uclibc = ""
91LDCONFIGDEPEND_libc-musl = ""
92
93# This is needed to have depmod data in PKGDATA_DIR,
94# but if you're building small initramfs image
95# e.g. to include it in your kernel, you probably
96# don't want this dependency, which is causing dependency loop
97KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"
98
99do_rootfs[depends] += " \
100 makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \
101 virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \
102 ${KERNELDEPMODDEPEND} \
103"
104do_rootfs[recrdeptask] += "do_packagedata"
105
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500106def rootfs_command_variables(d):
107 return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','ROOTFS_POSTUNINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND',
108 'IMAGE_PREPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS','DEB_PREPROCESS_COMMANDS','DEB_POSTPROCESS_COMMANDS']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109
110python () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500111 variables = rootfs_command_variables(d) + sdk_command_variables(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 for var in variables:
113 if d.getVar(var, False):
114 d.setVarFlag(var, 'func', '1')
115}
116
117def rootfs_variables(d):
118 from oe.rootfs import variable_depends
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600119 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',
120 '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 -0500121 'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS',
122 '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 -0600123 'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY']
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500124 variables.extend(rootfs_command_variables(d))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 variables.extend(variable_depends(d))
126 return " ".join(variables)
127
128do_rootfs[vardeps] += "${@rootfs_variables(d)}"
129
130do_build[depends] += "virtual/kernel:do_deploy"
131
132def build_live(d):
133 if bb.utils.contains("IMAGE_FSTYPES", "live", "live", "0", d) == "0": # live is not set but hob might set iso or hddimg
134 d.setVar('NOISO', bb.utils.contains('IMAGE_FSTYPES', "iso", "0", "1", d))
135 d.setVar('NOHDD', bb.utils.contains('IMAGE_FSTYPES', "hddimg", "0", "1", d))
136 if d.getVar('NOISO', True) == "0" or d.getVar('NOHDD', True) == "0":
137 return "image-live"
138 return ""
139 return "image-live"
140
141IMAGE_TYPE_live = "${@build_live(d)}"
142inherit ${IMAGE_TYPE_live}
143
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500144IMAGE_TYPE_vm = '${@bb.utils.contains_any("IMAGE_FSTYPES", ["vmdk", "vdi", "qcow2", "hdddirect"], "image-vm", "", d)}'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145inherit ${IMAGE_TYPE_vm}
146
147python () {
148 deps = " " + imagetypes_getdepends(d)
149 d.appendVarFlag('do_rootfs', 'depends', deps)
150
151 deps = ""
152 for dep in (d.getVar('EXTRA_IMAGEDEPENDS', True) or "").split():
153 deps += " %s:do_populate_sysroot" % dep
154 d.appendVarFlag('do_build', 'depends', deps)
155
156 #process IMAGE_FEATURES, we must do this before runtime_mapping_rename
157 #Check for replaces image features
158 features = set(oe.data.typed_value('IMAGE_FEATURES', d))
159 remain_features = features.copy()
160 for feature in features:
161 replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature, True) or "").split())
162 remain_features -= replaces
163
164 #Check for conflict image features
165 for feature in remain_features:
166 conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature, True) or "").split())
167 temp = conflicts & remain_features
168 if temp:
169 bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN', True), feature, ' '.join(list(temp))))
170
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600171 d.setVar('IMAGE_FEATURES', ' '.join(sorted(list(remain_features))))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172
173 check_image_features(d)
174 initramfs_image = d.getVar('INITRAMFS_IMAGE', True) or ""
175 if initramfs_image != "":
176 d.appendVarFlag('do_build', 'depends', " %s:do_bundle_initramfs" % d.getVar('PN', True))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500177 d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_image_complete" % initramfs_image)
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
188LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IMAGE_LINGUAS', True).split()))}"
189
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
202
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600203 # NOTE: if you add, remove or significantly refactor the stages of this
204 # process then you should recalculate the weightings here. This is quite
205 # easy to do - just change the MultiStageProgressReporter line temporarily
206 # to pass debug=True as the last parameter and you'll get a printout of
207 # the weightings as well as a map to the lines where next_stage() was
208 # called. Of course this isn't critical, but it helps to keep the progress
209 # reporting accurate.
210 stage_weights = [1, 203, 354, 186, 65, 4228, 1, 353, 49, 330, 382, 23, 1]
211 progress_reporter = bb.progress.MultiStageProgressReporter(d, stage_weights)
212 progress_reporter.next_stage()
213
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500214 # Handle package exclusions
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 excl_pkgs = d.getVar("PACKAGE_EXCLUDE", True).split()
216 inst_pkgs = d.getVar("PACKAGE_INSTALL", True).split()
217 inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY", True).split()
218
219 d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
220 d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))
221
222 for pkg in excl_pkgs:
223 if pkg in inst_pkgs:
224 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', True), inst_pkgs))
225 inst_pkgs.remove(pkg)
226
227 if pkg in inst_attempt_pkgs:
228 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', True), inst_pkgs))
229 inst_attempt_pkgs.remove(pkg)
230
231 d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
232 d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500234 # Ensure we handle package name remapping
235 # We have to delay the runtime_mapping_rename until just before rootfs runs
236 # otherwise, the multilib renaming could step in and squash any fixups that
237 # may have occurred.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 pn = d.getVar('PN', True)
239 runtime_mapping_rename("PACKAGE_INSTALL", pn, d)
240 runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d)
241 runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500242
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243 # Generate the initial manifest
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 create_manifest(d)
245
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600246 progress_reporter.next_stage()
247
248 # generate rootfs
249 create_rootfs(d, progress_reporter=progress_reporter)
250
251 progress_reporter.finish()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500252}
253do_rootfs[dirs] = "${TOPDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600254do_rootfs[cleandirs] += "${S} ${IMGDEPLOYDIR}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500255do_rootfs[umask] = "022"
256addtask rootfs before do_build
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500258fakeroot python do_image () {
259 from oe.utils import execute_pre_post_process
260
261 pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND", True)
262
263 execute_pre_post_process(d, pre_process_cmds)
264}
265do_image[dirs] = "${TOPDIR}"
266do_image[umask] = "022"
267addtask do_image after do_rootfs before do_build
268
269fakeroot python do_image_complete () {
270 from oe.utils import execute_pre_post_process
271
272 post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND", True)
273
274 execute_pre_post_process(d, post_process_cmds)
275}
276do_image_complete[dirs] = "${TOPDIR}"
277do_image_complete[umask] = "022"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600278SSTATETASKS += "do_image_complete"
279SSTATE_SKIP_CREATION_task-image-complete = '1'
280do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
281do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
282do_image_complete[stamp-extra-info] = "${MACHINE}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500283addtask do_image_complete after do_image before do_build
284
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600285# Add image-level QA/sanity checks to IMAGE_QA_COMMANDS
286#
287# IMAGE_QA_COMMANDS += " \
288# image_check_everything_ok \
289# "
290# This task runs all functions in IMAGE_QA_COMMANDS after the image
291# construction has completed in order to validate the resulting image.
292fakeroot python do_image_qa () {
293 from oe.utils import ImageQAFailed
294
295 qa_cmds = (d.getVar('IMAGE_QA_COMMANDS', True) or '').split()
296 qamsg = ""
297
298 for cmd in qa_cmds:
299 try:
300 bb.build.exec_func(cmd, d)
301 except oe.utils.ImageQAFailed as e:
302 qamsg = qamsg + '\tImage QA function %s failed: %s\n' % (e.name, e.description)
303 except bb.build.FuncFailed as e:
304 qamsg = qamsg + '\tImage QA function %s failed' % e.name
305 if e.logfile:
306 qamsg = qamsg + ' (log file is located at %s)' % e.logfile
307 qamsg = qamsg + '\n'
308
309 if qamsg:
310 imgname = d.getVar('IMAGE_NAME', True)
311 bb.fatal("QA errors found whilst validating image: %s\n%s" % (imgname, qamsg))
312}
313addtask do_image_qa after do_image_complete before do_build
314
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500315#
316# Write environment variables used by wic
317# to tmp/sysroots/<machine>/imgdata/<image>.env
318#
319python do_rootfs_wicenv () {
320 wicvars = d.getVar('WICVARS', True)
321 if not wicvars:
322 return
323
324 stdir = d.getVar('STAGING_DIR_TARGET', True)
325 outdir = os.path.join(stdir, 'imgdata')
326 bb.utils.mkdirhier(outdir)
327 basename = d.getVar('IMAGE_BASENAME', True)
328 with open(os.path.join(outdir, basename) + '.env', 'w') as envf:
329 for var in wicvars.split():
330 value = d.getVar(var, True)
331 if value:
332 envf.write('%s="%s"\n' % (var, value.strip()))
333}
334addtask do_rootfs_wicenv after do_image before do_image_wic
335do_rootfs_wicenv[vardeps] += "${WICVARS}"
336do_rootfs_wicenv[prefuncs] = 'set_image_size'
337
338def setup_debugfs_variables(d):
339 d.appendVar('IMAGE_ROOTFS', '-dbg')
340 d.appendVar('IMAGE_LINK_NAME', '-dbg')
341 d.appendVar('IMAGE_NAME','-dbg')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600342 d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500343 debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS', True)
344 if debugfs_image_fstypes:
345 d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
346
347python setup_debugfs () {
348 setup_debugfs_variables(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500349}
350
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500351python () {
352 vardeps = set()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600353 # We allow CONVERSIONTYPES to have duplicates. That avoids breaking
354 # derived distros when OE-core or some other layer independently adds
355 # the same type. There is still only one command for each type, but
356 # presumably the commands will do the same when the type is the same,
357 # even when added in different places.
358 #
359 # Without de-duplication, gen_conversion_cmds() below
360 # would create the same compression command multiple times.
361 ctypes = set(d.getVar('CONVERSIONTYPES', True).split())
362 old_overrides = d.getVar('OVERRIDES', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500364 def _image_base_type(type):
365 basetype = type
366 for ctype in ctypes:
367 if type.endswith("." + ctype):
368 basetype = type[:-len("." + ctype)]
369 break
370
371 if basetype != type:
372 # New base type itself might be generated by a conversion command.
373 basetype = _image_base_type(basetype)
374
375 return basetype
376
377 basetypes = {}
378 alltypes = d.getVar('IMAGE_FSTYPES', True).split()
379 typedeps = {}
380
381 if d.getVar('IMAGE_GEN_DEBUGFS', True) == "1":
382 debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS', True).split()
383 for t in debugfs_fstypes:
384 alltypes.append("debugfs_" + t)
385
386 def _add_type(t):
387 baset = _image_base_type(t)
388 input_t = t
389 if baset not in basetypes:
390 basetypes[baset]= []
391 if t not in basetypes[baset]:
392 basetypes[baset].append(t)
393 debug = ""
394 if t.startswith("debugfs_"):
395 t = t[8:]
396 debug = "debugfs_"
397 deps = (d.getVar('IMAGE_TYPEDEP_' + t, True) or "").split()
398 vardeps.add('IMAGE_TYPEDEP_' + t)
399 if baset not in typedeps:
400 typedeps[baset] = set()
401 deps = [debug + dep for dep in deps]
402 for dep in deps:
403 if dep not in alltypes:
404 alltypes.append(dep)
405 _add_type(dep)
406 basedep = _image_base_type(dep)
407 typedeps[baset].add(basedep)
408
409 if baset != input_t:
410 _add_type(baset)
411
412 for t in alltypes[:]:
413 _add_type(t)
414
415 d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps))
416
417 maskedtypes = (d.getVar('IMAGE_TYPES_MASKED', True) or "").split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600418 maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500419
420 for t in basetypes:
421 vardeps = set()
422 cmds = []
423 subimages = []
424 realt = t
425
426 if t in maskedtypes:
427 continue
428
429 localdata = bb.data.createCopy(d)
430 debug = ""
431 if t.startswith("debugfs_"):
432 setup_debugfs_variables(localdata)
433 debug = "setup_debugfs "
434 realt = t[8:]
435 localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides))
436 bb.data.update_data(localdata)
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 localdata.delVar('DATETIME')
443 localdata.delVar('TMPDIR')
444
445 image_cmd = localdata.getVar("IMAGE_CMD", True)
446 vardeps.add('IMAGE_CMD_' + realt)
447 if image_cmd:
448 cmds.append("\t" + image_cmd)
449 else:
450 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 -0600451 cmds.append(localdata.expand("\tcd ${IMGDEPLOYDIR}"))
452
453 # Since a copy of IMAGE_CMD_xxx will be inlined within do_image_xxx,
454 # prevent a redundant copy of IMAGE_CMD_xxx being emitted as a function.
455 d.delVarFlag('IMAGE_CMD_' + realt, 'func')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500456
457 rm_tmp_images = set()
458 def gen_conversion_cmds(bt):
459 for ctype in ctypes:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600460 if bt[bt.find('.') + 1:] == ctype:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500461 type = bt[0:-len(ctype) - 1]
462 if type.startswith("debugfs_"):
463 type = type[8:]
464 # Create input image first.
465 gen_conversion_cmds(type)
466 localdata.setVar('type', type)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600467 cmd = "\t" + (localdata.getVar("CONVERSION_CMD_" + ctype, True) or localdata.getVar("COMPRESS_CMD_" + ctype, True))
468 if cmd not in cmds:
469 cmds.append(cmd)
470 vardeps.add('CONVERSION_CMD_' + ctype)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500471 vardeps.add('COMPRESS_CMD_' + ctype)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600472 subimage = type + "." + ctype
473 if subimage not in subimages:
474 subimages.append(subimage)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500475 if type not in alltypes:
476 rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
477
478 for bt in basetypes[t]:
479 gen_conversion_cmds(bt)
480
481 localdata.setVar('type', realt)
482 if t not in alltypes:
483 rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
484 else:
485 subimages.append(realt)
486
487 # Clean up after applying all conversion commands. Some of them might
488 # use the same input, therefore we cannot delete sooner without applying
489 # some complex dependency analysis.
490 for image in rm_tmp_images:
491 cmds.append("\trm " + image)
492
493 after = 'do_image'
494 for dep in typedeps[t]:
495 after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_")
496
497 t = t.replace("-", "_").replace(".", "_")
498
499 d.setVar('do_image_%s' % t, '\n'.join(cmds))
500 d.setVarFlag('do_image_%s' % t, 'func', '1')
501 d.setVarFlag('do_image_%s' % t, 'fakeroot', '1')
502 d.setVarFlag('do_image_%s' % t, 'prefuncs', debug + 'set_image_size')
503 d.setVarFlag('do_image_%s' % t, 'postfuncs', 'create_symlinks')
504 d.setVarFlag('do_image_%s' % t, 'subimages', ' '.join(subimages))
505 d.appendVarFlag('do_image_%s' % t, 'vardeps', ' '.join(vardeps))
506 d.appendVarFlag('do_image_%s' % t, 'vardepsexclude', 'DATETIME')
507
508 bb.debug(2, "Adding type %s before %s, after %s" % (t, 'do_image_complete', after))
509 bb.build.addtask('do_image_%s' % t, 'do_image_complete', after, d)
510}
511
512#
513# Compute the rootfs size
514#
515def get_rootfs_size(d):
516 import subprocess
517
518 rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT', True))
519 overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR', True))
520 rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE', True))
521 rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE', True))
522 rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE', True)
523 image_fstypes = d.getVar('IMAGE_FSTYPES', True) or ''
524 initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES', True) or ''
525 initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE', True)
526
527 output = subprocess.check_output(['du', '-ks',
528 d.getVar('IMAGE_ROOTFS', True)])
529 size_kb = int(output.split()[0])
530 base_size = size_kb * overhead_factor
531 base_size = max(base_size, rootfs_req_size) + rootfs_extra_space
532
533 if base_size != int(base_size):
534 base_size = int(base_size + 1)
535 else:
536 base_size = int(base_size)
537
538 base_size += rootfs_alignment - 1
539 base_size -= base_size % rootfs_alignment
540
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600541 # Do not check image size of the debugfs image. This is not supposed
542 # to be deployed, etc. so it doesn't make sense to limit the size
543 # of the debug.
544 if (d.getVar('IMAGE_BUILDING_DEBUGFS', True) or "") == "true":
545 return base_size
546
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500547 # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set)
548 if rootfs_maxsize:
549 rootfs_maxsize_int = int(rootfs_maxsize)
550 if base_size > rootfs_maxsize_int:
551 bb.fatal("The rootfs size %d(K) overrides IMAGE_ROOTFS_MAXSIZE: %d(K)" % \
552 (base_size, rootfs_maxsize_int))
553
554 # Check the initramfs size against INITRAMFS_MAXSIZE (if set)
555 if image_fstypes == initramfs_fstypes != '' and initramfs_maxsize:
556 initramfs_maxsize_int = int(initramfs_maxsize)
557 if base_size > initramfs_maxsize_int:
558 bb.error("The initramfs size %d(K) overrides INITRAMFS_MAXSIZE: %d(K)" % \
559 (base_size, initramfs_maxsize_int))
560 bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should")
561 bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n")
562 return base_size
563
564python set_image_size () {
565 rootfs_size = get_rootfs_size(d)
566 d.setVar('ROOTFS_SIZE', str(rootfs_size))
567 d.setVarFlag('ROOTFS_SIZE', 'export', '1')
568}
569
570#
571# Create symlinks to the newly created image
572#
573python create_symlinks() {
574
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600575 deploy_dir = d.getVar('IMGDEPLOYDIR', True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500576 img_name = d.getVar('IMAGE_NAME', True)
577 link_name = d.getVar('IMAGE_LINK_NAME', True)
578 manifest_name = d.getVar('IMAGE_MANIFEST', True)
579 taskname = d.getVar("BB_CURRENTTASK", True)
580 subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split()
581 imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix', True) or d.expand("${IMAGE_NAME_SUFFIX}.")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500582
583 if not link_name:
584 return
585 for type in subimages:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600586 dst = os.path.join(deploy_dir, link_name + "." + type)
587 src = img_name + imgsuffix + type
588 if os.path.exists(os.path.join(deploy_dir, src)):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500589 bb.note("Creating symlink: %s -> %s" % (dst, src))
590 if os.path.islink(dst):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500591 os.remove(dst)
592 os.symlink(src, dst)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600593 else:
594 bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500595}
596
597MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
598MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
599MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
600
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500601do_fetch[noexec] = "1"
602do_unpack[noexec] = "1"
603do_patch[noexec] = "1"
604do_configure[noexec] = "1"
605do_compile[noexec] = "1"
606do_install[noexec] = "1"
607do_populate_sysroot[noexec] = "1"
608do_package[noexec] = "1"
609do_package_qa[noexec] = "1"
610do_packagedata[noexec] = "1"
611do_package_write_ipk[noexec] = "1"
612do_package_write_deb[noexec] = "1"
613do_package_write_rpm[noexec] = "1"
614
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615# Allow the kernel to be repacked with the initramfs and boot image file as a single file
616do_bundle_initramfs[depends] += "virtual/kernel:do_bundle_initramfs"
617do_bundle_initramfs[nostamp] = "1"
618do_bundle_initramfs[noexec] = "1"
619do_bundle_initramfs () {
620 :
621}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500622addtask bundle_initramfs after do_image_complete