Fix kernel-devsrc package failing during install
[AGL/meta-agl.git] / meta-agl-bsp / classes / image.bbclass
1 inherit rootfs_${IMAGE_PKGTYPE}
2
3 # Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk
4 # in the non-Linux SDK_OS case, such as mingw32
5 SDKEXTCLASS ?= "${@['populate_sdk', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS", True)]}"
6 inherit ${SDKEXTCLASS}
7
8 TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}"
9 TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}"
10 POPULATE_SDK_POST_TARGET_COMMAND += "rootfs_sysroot_relativelinks; "
11
12 inherit gzipnative
13
14 LICENSE = "MIT"
15 PACKAGES = ""
16 DEPENDS += "${MLPREFIX}qemuwrapper-cross ${MLPREFIX}depmodwrapper-cross"
17 RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL}"
18 RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"
19
20 INHIBIT_DEFAULT_DEPS = "1"
21
22 TESTIMAGECLASS = "${@base_conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
23 inherit ${TESTIMAGECLASS}
24
25 # IMAGE_FEATURES may contain any available package group
26 IMAGE_FEATURES ?= ""
27 IMAGE_FEATURES[type] = "list"
28 IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs empty-root-password allow-empty-password post-install-logging"
29
30 # Generate companion debugfs?
31 IMAGE_GEN_DEBUGFS ?= "0"
32
33 # rootfs bootstrap install
34 ROOTFS_BOOTSTRAP_INSTALL = "${@bb.utils.contains("IMAGE_FEATURES", "package-management", "", "${ROOTFS_PKGMANAGE_BOOTSTRAP}",d)}"
35
36 # These packages will be removed from a read-only rootfs after all other
37 # packages have been installed
38 ROOTFS_RO_UNNEEDED = "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
39
40 # packages to install from features
41 FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
42 FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
43 FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
44 FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}"
45
46 # Define some very basic feature package groups
47 FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
48 SPLASH ?= "psplash"
49 FEATURE_PACKAGES_splash = "${SPLASH}"
50
51 IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'
52
53 def 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
72 IMAGE_INSTALL ?= ""
73 IMAGE_INSTALL[type] = "list"
74 export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
75 PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"
76
77 IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-image-complete"
78
79 # Images are generally built explicitly, do not need to be part of world.
80 EXCLUDE_FROM_WORLD = "1"
81
82 USE_DEVFS ?= "1"
83 USE_DEPMOD ?= "1"
84
85 PID = "${@os.getpid()}"
86
87 PACKAGE_ARCH = "${MACHINE_ARCH}"
88
89 LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
90 LDCONFIGDEPEND_libc-uclibc = ""
91 LDCONFIGDEPEND_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
97 KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"
98
99 do_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 "
104 do_rootfs[recrdeptask] += "do_packagedata"
105
106 def 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']
109
110 python () {
111     variables = rootfs_command_variables(d) + sdk_command_variables(d)
112     for var in variables:
113         if d.getVar(var, False):
114             d.setVarFlag(var, 'func', '1')
115 }
116
117 def rootfs_variables(d):
118     from oe.rootfs import variable_depends
119     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',
121                  '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',
123                  'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY']
124     variables.extend(rootfs_command_variables(d))
125     variables.extend(variable_depends(d))
126     return " ".join(variables)
127
128 do_rootfs[vardeps] += "${@rootfs_variables(d)}"
129
130 do_build[depends] += "virtual/kernel:do_deploy"
131
132 def 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
141 IMAGE_TYPE_live = "${@build_live(d)}"
142 inherit ${IMAGE_TYPE_live}
143
144 IMAGE_TYPE_vm = '${@bb.utils.contains_any("IMAGE_FSTYPES", ["vmdk", "vmdk.xz", "vdi", "qcow2", "hdddirect"], "image-vm", "", d)}'
145 inherit ${IMAGE_TYPE_vm}
146
147 python () {
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
171     d.setVar('IMAGE_FEATURES', ' '.join(sorted(list(remain_features))))
172
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))
177         d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_image_complete" % initramfs_image)
178 }
179
180 IMAGE_CLASSES += "image_types"
181 inherit ${IMAGE_CLASSES}
182
183 IMAGE_POSTPROCESS_COMMAND ?= ""
184
185 # some default locales
186 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
187
188 LINGUAS_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.
192 PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}"
193
194 inherit rootfs-postcommands
195
196 PACKAGE_EXCLUDE ??= ""
197 PACKAGE_EXCLUDE[type] = "list"
198
199 fakeroot python do_rootfs () {
200     from oe.rootfs import create_rootfs
201     from oe.manifest import create_manifest
202
203     # 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
214     # Handle package exclusions
215     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))
233
234     # 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.
238     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)
242
243     # Generate the initial manifest
244     create_manifest(d)
245
246     progress_reporter.next_stage()
247
248     # generate rootfs
249     create_rootfs(d, progress_reporter=progress_reporter)
250
251     progress_reporter.finish()
252 }
253 do_rootfs[dirs] = "${TOPDIR}"
254 do_rootfs[cleandirs] += "${S} ${IMGDEPLOYDIR}"
255 do_rootfs[umask] = "022"
256 addtask rootfs before do_build
257
258 fakeroot 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 }
265 do_image[dirs] = "${TOPDIR}"
266 do_image[umask] = "022"
267 addtask do_image after do_rootfs before do_build
268
269 fakeroot 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 }
276 do_image_complete[dirs] = "${TOPDIR}"
277 do_image_complete[umask] = "022"
278 SSTATETASKS += "do_image_complete"
279 SSTATE_SKIP_CREATION_task-image-complete = '1'
280 do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
281 do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
282 do_image_complete[stamp-extra-info] = "${MACHINE}"
283 addtask do_image_complete after do_image before do_build
284
285 # 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.
292 fakeroot 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 }
313 addtask do_image_qa after do_image_complete before do_build
314
315 #
316 # Write environment variables used by wic
317 # to tmp/sysroots/<machine>/imgdata/<image>.env
318 #
319 python 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 }
334 addtask do_rootfs_wicenv after do_image before do_image_wic
335 do_rootfs_wicenv[vardeps] += "${WICVARS}"
336 do_rootfs_wicenv[prefuncs] = 'set_image_size'
337
338 def setup_debugfs_variables(d):
339     d.appendVar('IMAGE_ROOTFS', '-dbg')
340     d.appendVar('IMAGE_LINK_NAME', '-dbg')
341     d.appendVar('IMAGE_NAME','-dbg')
342     d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
343     debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS', True)
344     if debugfs_image_fstypes:
345         d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
346
347 python setup_debugfs () {
348     setup_debugfs_variables(d)
349 }
350
351 python () {
352     vardeps = set()
353     # 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)
363
364     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()
418     maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")]
419
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)
451         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')
456
457         rm_tmp_images = set()
458         def gen_conversion_cmds(bt):
459             for ctype in ctypes:
460                 if bt[bt.find('.') + 1:] == ctype:
461                     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)
467                     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)
471                     vardeps.add('COMPRESS_CMD_' + ctype)
472                     subimage = type + "." + ctype
473                     if subimage not in subimages:
474                         subimages.append(subimage)
475                     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 #
515 def 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
541     # 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
547     # 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
564 python 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 #
573 python create_symlinks() {
574
575     deploy_dir = d.getVar('IMGDEPLOYDIR', True)
576     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}.")
582
583     if not link_name:
584         return
585     for type in subimages:
586         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)):
589             bb.note("Creating symlink: %s -> %s" % (dst, src))
590             if os.path.islink(dst):
591                 os.remove(dst)
592             os.symlink(src, dst)
593         else:
594             bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src))
595 }
596
597 MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
598 MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
599 MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
600
601 do_fetch[noexec] = "1"
602 do_unpack[noexec] = "1"
603 do_patch[noexec] = "1"
604 do_configure[noexec] = "1"
605 do_compile[noexec] = "1"
606 do_install[noexec] = "1"
607 do_populate_sysroot[noexec] = "1"
608 do_package[noexec] = "1"
609 do_package_qa[noexec] = "1"
610 do_packagedata[noexec] = "1"
611 do_package_write_ipk[noexec] = "1"
612 do_package_write_deb[noexec] = "1"
613 do_package_write_rpm[noexec] = "1"
614
615 # Allow the kernel to be repacked with the initramfs and boot image file as a single file
616 do_bundle_initramfs[depends] += "virtual/kernel:do_bundle_initramfs"
617 do_bundle_initramfs[nostamp] = "1"
618 do_bundle_initramfs[noexec] = "1"
619 do_bundle_initramfs () {
620         :
621 }
622 addtask bundle_initramfs after do_image_complete