Upgrade to pyro
[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_base
4 # in the non-Linux SDK_OS case, such as mingw32
5 SDKEXTCLASS ?= "${@['populate_sdk_base', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS")]}"
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 LICENSE = "MIT"
13 PACKAGES = ""
14 DEPENDS += "${MLPREFIX}qemuwrapper-cross depmodwrapper-cross"
15 RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL}"
16 RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"
17
18 INHIBIT_DEFAULT_DEPS = "1"
19
20 TESTIMAGECLASS = "${@base_conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
21 inherit ${TESTIMAGECLASS}
22
23 # IMAGE_FEATURES may contain any available package group
24 IMAGE_FEATURES ?= ""
25 IMAGE_FEATURES[type] = "list"
26 IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs empty-root-password allow-empty-password post-install-logging"
27
28 # Generate companion debugfs?
29 IMAGE_GEN_DEBUGFS ?= "0"
30
31 # rootfs bootstrap install
32 ROOTFS_BOOTSTRAP_INSTALL = "run-postinsts"
33
34 # These packages will be removed from a read-only rootfs after all other
35 # packages have been installed
36 ROOTFS_RO_UNNEEDED = "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
37
38 # packages to install from features
39 FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
40 FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
41 FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
42 FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}"
43
44 # Define some very basic feature package groups
45 FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
46 SPLASH ?= "psplash"
47 FEATURE_PACKAGES_splash = "${SPLASH}"
48
49 IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'
50
51 def check_image_features(d):
52     valid_features = (d.getVarFlag('IMAGE_FEATURES', 'validitems') or "").split()
53     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
70 IMAGE_INSTALL ?= ""
71 IMAGE_INSTALL[type] = "list"
72 export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
73 PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"
74
75 IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-image-complete"
76
77 # Images are generally built explicitly, do not need to be part of world.
78 EXCLUDE_FROM_WORLD = "1"
79
80 USE_DEVFS ?= "1"
81 USE_DEPMOD ?= "1"
82
83 PID = "${@os.getpid()}"
84
85 PACKAGE_ARCH = "${MACHINE_ARCH}"
86
87 LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
88 LDCONFIGDEPEND_libc-uclibc = ""
89 LDCONFIGDEPEND_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
95 KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"
96
97 do_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 "
102 do_rootfs[recrdeptask] += "do_packagedata"
103
104 def 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']
107
108 python () {
109     variables = rootfs_command_variables(d) + sdk_command_variables(d)
110     for var in variables:
111         if d.getVar(var, False):
112             d.setVarFlag(var, 'func', '1')
113 }
114
115 def rootfs_variables(d):
116     from oe.rootfs import variable_depends
117     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',
119                  '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',
121                  'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY']
122     variables.extend(rootfs_command_variables(d))
123     variables.extend(variable_depends(d))
124     return " ".join(variables)
125
126 do_rootfs[vardeps] += "${@rootfs_variables(d)}"
127
128 do_build[depends] += "virtual/kernel:do_deploy"
129
130 def 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))
134         if d.getVar('NOISO') == "0" or d.getVar('NOHDD') == "0":
135             return "image-live"
136         return ""
137     return "image-live"
138
139 IMAGE_TYPE_live = "${@build_live(d)}"
140 inherit ${IMAGE_TYPE_live}
141
142 IMAGE_TYPE_vm = '${@bb.utils.contains_any("IMAGE_FSTYPES", ["vmdk", "vmdk.xz", "vdi", "qcow2", "hdddirect"], "image-vm", "", d)}'
143
144 inherit ${IMAGE_TYPE_vm}
145
146 IMAGE_TYPE_container = '${@bb.utils.contains("IMAGE_FSTYPES", "container", "image-container", "", d)}'
147 inherit ${IMAGE_TYPE_container}
148
149 def build_uboot(d):
150     if 'u-boot' in (d.getVar('IMAGE_FSTYPES') or ''):
151         return "image_types_uboot"
152     else:
153         return ""
154
155 IMAGE_TYPE_uboot = "${@build_uboot(d)}"
156 inherit ${IMAGE_TYPE_uboot}
157
158 IMAGE_TYPE_wic = "image_types_wic"
159 inherit ${IMAGE_TYPE_wic}
160
161 python () {
162     deps = " " + imagetypes_getdepends(d)
163     d.appendVarFlag('do_rootfs', 'depends', deps)
164
165     deps = ""
166     for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
167         deps += " %s:do_populate_sysroot" % dep
168     d.appendVarFlag('do_image_complete', 'depends', deps)
169
170     #process IMAGE_FEATURES, we must do this before runtime_mapping_rename
171     #Check for replaces image features
172     features = set(oe.data.typed_value('IMAGE_FEATURES', d))
173     remain_features = features.copy()
174     for feature in features:
175         replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature) or "").split())
176         remain_features -= replaces
177
178     #Check for conflict image features
179     for feature in remain_features:
180         conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature) or "").split())
181         temp = conflicts & remain_features
182         if temp:
183             bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN'), feature, ' '.join(list(temp))))
184
185     d.setVar('IMAGE_FEATURES', ' '.join(sorted(list(remain_features))))
186
187     check_image_features(d)
188     initramfs_image = d.getVar('INITRAMFS_IMAGE') or ""
189     if initramfs_image != "":
190         d.appendVarFlag('do_build', 'depends', " %s:do_bundle_initramfs" %  d.getVar('PN'))
191         d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_image_complete" % initramfs_image)
192 }
193
194 IMAGE_CLASSES += "image_types"
195 inherit ${IMAGE_CLASSES}
196
197 IMAGE_POSTPROCESS_COMMAND ?= ""
198
199 # some default locales
200 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
201
202 LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IMAGE_LINGUAS').split()))}"
203
204 # Prefer image, but use the fallback files for lookups if the image ones
205 # aren't yet available.
206 PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}"
207
208 inherit rootfs-postcommands
209
210 PACKAGE_EXCLUDE ??= ""
211 PACKAGE_EXCLUDE[type] = "list"
212
213 fakeroot python do_rootfs () {
214     from oe.rootfs import create_rootfs
215     from oe.manifest import create_manifest
216     import logging
217
218     logger = d.getVar('BB_TASK_LOGGER', False)
219     if logger:
220         logcatcher = bb.utils.LogCatcher()
221         logger.addHandler(logcatcher)
222     else:
223         logcatcher = None
224
225     # NOTE: if you add, remove or significantly refactor the stages of this
226     # process then you should recalculate the weightings here. This is quite
227     # easy to do - just change the MultiStageProgressReporter line temporarily
228     # to pass debug=True as the last parameter and you'll get a printout of
229     # the weightings as well as a map to the lines where next_stage() was
230     # called. Of course this isn't critical, but it helps to keep the progress
231     # reporting accurate.
232     stage_weights = [1, 203, 354, 186, 65, 4228, 1, 353, 49, 330, 382, 23, 1]
233     progress_reporter = bb.progress.MultiStageProgressReporter(d, stage_weights)
234     progress_reporter.next_stage()
235
236     # Handle package exclusions
237     excl_pkgs = d.getVar("PACKAGE_EXCLUDE").split()
238     inst_pkgs = d.getVar("PACKAGE_INSTALL").split()
239     inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY").split()
240
241     d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
242     d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))
243
244     for pkg in excl_pkgs:
245         if pkg in inst_pkgs:
246             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))
247             inst_pkgs.remove(pkg)
248
249         if pkg in inst_attempt_pkgs:
250             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))
251             inst_attempt_pkgs.remove(pkg)
252
253     d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
254     d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
255
256     # Ensure we handle package name remapping
257     # We have to delay the runtime_mapping_rename until just before rootfs runs
258     # otherwise, the multilib renaming could step in and squash any fixups that
259     # may have occurred.
260     pn = d.getVar('PN')
261     runtime_mapping_rename("PACKAGE_INSTALL", pn, d)
262     runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d)
263     runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d)
264
265     # Generate the initial manifest
266     create_manifest(d)
267
268     progress_reporter.next_stage()
269
270     # generate rootfs
271     create_rootfs(d, progress_reporter=progress_reporter, logcatcher=logcatcher)
272
273     progress_reporter.finish()
274 }
275 do_rootfs[dirs] = "${TOPDIR}"
276 do_rootfs[cleandirs] += "${S} ${IMGDEPLOYDIR}"
277 do_rootfs[umask] = "022"
278 addtask rootfs before do_build after do_prepare_recipe_sysroot
279
280 fakeroot python do_image () {
281     from oe.utils import execute_pre_post_process
282
283     pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND")
284
285     execute_pre_post_process(d, pre_process_cmds)
286 }
287 do_image[dirs] = "${TOPDIR}"
288 do_image[umask] = "022"
289 addtask do_image after do_rootfs before do_build
290
291 fakeroot python do_image_complete () {
292     from oe.utils import execute_pre_post_process
293
294     post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND")
295
296     execute_pre_post_process(d, post_process_cmds)
297 }
298 do_image_complete[dirs] = "${TOPDIR}"
299 do_image_complete[umask] = "022"
300 SSTATETASKS += "do_image_complete"
301 SSTATE_SKIP_CREATION_task-image-complete = '1'
302 do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
303 do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
304 do_image_complete[stamp-extra-info] = "${MACHINE}"
305 addtask do_image_complete after do_image before do_build
306
307 # Add image-level QA/sanity checks to IMAGE_QA_COMMANDS
308 #
309 # IMAGE_QA_COMMANDS += " \
310 #     image_check_everything_ok \
311 # "
312 # This task runs all functions in IMAGE_QA_COMMANDS after the image
313 # construction has completed in order to validate the resulting image.
314 fakeroot python do_image_qa () {
315     from oe.utils import ImageQAFailed
316
317     qa_cmds = (d.getVar('IMAGE_QA_COMMANDS') or '').split()
318     qamsg = ""
319
320     for cmd in qa_cmds:
321         try:
322             bb.build.exec_func(cmd, d)
323         except oe.utils.ImageQAFailed as e:
324             qamsg = qamsg + '\tImage QA function %s failed: %s\n' % (e.name, e.description)
325         except bb.build.FuncFailed as e:
326             qamsg = qamsg + '\tImage QA function %s failed' % e.name
327             if e.logfile:
328                 qamsg = qamsg + ' (log file is located at %s)' % e.logfile
329             qamsg = qamsg + '\n'
330
331     if qamsg:
332         imgname = d.getVar('IMAGE_NAME')
333         bb.fatal("QA errors found whilst validating image: %s\n%s" % (imgname, qamsg))
334 }
335 addtask do_image_qa after do_image_complete before do_build
336
337 def setup_debugfs_variables(d):
338     d.appendVar('IMAGE_ROOTFS', '-dbg')
339     d.appendVar('IMAGE_LINK_NAME', '-dbg')
340     d.appendVar('IMAGE_NAME','-dbg')
341     d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
342     debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS')
343     if debugfs_image_fstypes:
344         d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
345
346 python setup_debugfs () {
347     setup_debugfs_variables(d)
348 }
349
350 python () {
351     vardeps = set()
352     # We allow CONVERSIONTYPES to have duplicates. That avoids breaking
353     # derived distros when OE-core or some other layer independently adds
354     # the same type. There is still only one command for each type, but
355     # presumably the commands will do the same when the type is the same,
356     # even when added in different places.
357     #
358     # Without de-duplication, gen_conversion_cmds() below
359     # would create the same compression command multiple times.
360     ctypes = set(d.getVar('CONVERSIONTYPES').split())
361     old_overrides = d.getVar('OVERRIDES', False)
362
363     def _image_base_type(type):
364         basetype = type
365         for ctype in ctypes:
366             if type.endswith("." + ctype):
367                 basetype = type[:-len("." + ctype)]
368                 break
369
370         if basetype != type:
371             # New base type itself might be generated by a conversion command.
372             basetype = _image_base_type(basetype)
373
374         return basetype
375
376     basetypes = {}
377     alltypes = d.getVar('IMAGE_FSTYPES').split()
378     typedeps = {}
379
380     if d.getVar('IMAGE_GEN_DEBUGFS') == "1":
381         debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS').split()
382         for t in debugfs_fstypes:
383             alltypes.append("debugfs_" + t)
384
385     def _add_type(t):
386         baset = _image_base_type(t)
387         input_t = t
388         if baset not in basetypes:
389             basetypes[baset]= []
390         if t not in basetypes[baset]:
391             basetypes[baset].append(t)
392         debug = ""
393         if t.startswith("debugfs_"):
394             t = t[8:]
395             debug = "debugfs_"
396         deps = (d.getVar('IMAGE_TYPEDEP_' + t) or "").split()
397         vardeps.add('IMAGE_TYPEDEP_' + t)
398         if baset not in typedeps:
399             typedeps[baset] = set()
400         deps = [debug + dep for dep in deps]
401         for dep in deps:
402             if dep not in alltypes:
403                 alltypes.append(dep)
404             _add_type(dep)
405             basedep = _image_base_type(dep)
406             typedeps[baset].add(basedep)
407
408         if baset != input_t:
409             _add_type(baset)
410
411     for t in alltypes[:]:
412         _add_type(t)
413
414     d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps))
415
416     maskedtypes = (d.getVar('IMAGE_TYPES_MASKED') or "").split()
417     maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")]
418
419     for t in basetypes:
420         vardeps = set()
421         cmds = []
422         subimages = []
423         realt = t
424
425         if t in maskedtypes:
426             continue
427
428         localdata = bb.data.createCopy(d)
429         debug = ""
430         if t.startswith("debugfs_"):
431             setup_debugfs_variables(localdata)
432             debug = "setup_debugfs "
433             realt = t[8:]
434         localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides))
435         localdata.setVar('type', realt)
436         # Delete DATETIME so we don't expand any references to it now
437         # This means the task's hash can be stable rather than having hardcoded
438         # date/time values. It will get expanded at execution time.
439         # Similarly TMPDIR since otherwise we see QA stamp comparision problems
440         localdata.delVar('DATETIME')
441         localdata.delVar('TMPDIR')
442
443         image_cmd = localdata.getVar("IMAGE_CMD")
444         vardeps.add('IMAGE_CMD_' + realt)
445         if image_cmd:
446             cmds.append("\t" + image_cmd)
447         else:
448             bb.fatal("No IMAGE_CMD defined for IMAGE_FSTYPES entry '%s' - possibly invalid type name or missing support class" % t)
449         cmds.append(localdata.expand("\tcd ${IMGDEPLOYDIR}"))
450
451         # Since a copy of IMAGE_CMD_xxx will be inlined within do_image_xxx,
452         # prevent a redundant copy of IMAGE_CMD_xxx being emitted as a function.
453         d.delVarFlag('IMAGE_CMD_' + realt, 'func')
454
455         rm_tmp_images = set()
456         def gen_conversion_cmds(bt):
457             for ctype in ctypes:
458                 if bt[bt.find('.') + 1:] == ctype:
459                     type = bt[0:-len(ctype) - 1]
460                     if type.startswith("debugfs_"):
461                         type = type[8:]
462                     # Create input image first.
463                     gen_conversion_cmds(type)
464                     localdata.setVar('type', type)
465                     cmd = "\t" + (localdata.getVar("CONVERSION_CMD_" + ctype) or localdata.getVar("COMPRESS_CMD_" + ctype))
466                     if cmd not in cmds:
467                         cmds.append(cmd)
468                     vardeps.add('CONVERSION_CMD_' + ctype)
469                     vardeps.add('COMPRESS_CMD_' + ctype)
470                     subimage = type + "." + ctype
471                     if subimage not in subimages:
472                         subimages.append(subimage)
473                     if type not in alltypes:
474                         rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
475
476         for bt in basetypes[t]:
477             gen_conversion_cmds(bt)
478
479         localdata.setVar('type', realt)
480         if t not in alltypes:
481             rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
482         else:
483             subimages.append(realt)
484
485         # Clean up after applying all conversion commands. Some of them might
486         # use the same input, therefore we cannot delete sooner without applying
487         # some complex dependency analysis.
488         for image in rm_tmp_images:
489             cmds.append("\trm " + image)
490
491         after = 'do_image'
492         for dep in typedeps[t]:
493             after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_")
494
495         t = t.replace("-", "_").replace(".", "_")
496
497         d.setVar('do_image_%s' % t, '\n'.join(cmds))
498         d.setVarFlag('do_image_%s' % t, 'func', '1')
499         d.setVarFlag('do_image_%s' % t, 'fakeroot', '1')
500         d.setVarFlag('do_image_%s' % t, 'prefuncs', debug + 'set_image_size')
501         d.setVarFlag('do_image_%s' % t, 'postfuncs', 'create_symlinks')
502         d.setVarFlag('do_image_%s' % t, 'subimages', ' '.join(subimages))
503         d.appendVarFlag('do_image_%s' % t, 'vardeps', ' '.join(vardeps))
504         d.appendVarFlag('do_image_%s' % t, 'vardepsexclude', 'DATETIME')
505
506         bb.debug(2, "Adding type %s before %s, after %s" % (t, 'do_image_complete', after))
507         bb.build.addtask('do_image_%s' % t, 'do_image_complete', after, d)
508 }
509
510 #
511 # Compute the rootfs size
512 #
513 def get_rootfs_size(d):
514     import subprocess
515
516     rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT'))
517     overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR'))
518     rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE'))
519     rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE'))
520     rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE')
521     image_fstypes = d.getVar('IMAGE_FSTYPES') or ''
522     initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES') or ''
523     initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE')
524
525     output = subprocess.check_output(['du', '-ks',
526                                       d.getVar('IMAGE_ROOTFS')])
527     size_kb = int(output.split()[0])
528     base_size = size_kb * overhead_factor
529     base_size = max(base_size, rootfs_req_size) + rootfs_extra_space
530
531     if base_size != int(base_size):
532         base_size = int(base_size + 1)
533     else:
534         base_size = int(base_size)
535
536     base_size += rootfs_alignment - 1
537     base_size -= base_size % rootfs_alignment
538
539     # Do not check image size of the debugfs image. This is not supposed
540     # to be deployed, etc. so it doesn't make sense to limit the size
541     # of the debug.
542     if (d.getVar('IMAGE_BUILDING_DEBUGFS') or "") == "true":
543         return base_size
544
545     # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set)
546     if rootfs_maxsize:
547         rootfs_maxsize_int = int(rootfs_maxsize)
548         if base_size > rootfs_maxsize_int:
549             bb.fatal("The rootfs size %d(K) overrides IMAGE_ROOTFS_MAXSIZE: %d(K)" % \
550                 (base_size, rootfs_maxsize_int))
551
552     # Check the initramfs size against INITRAMFS_MAXSIZE (if set)
553     if image_fstypes == initramfs_fstypes != ''  and initramfs_maxsize:
554         initramfs_maxsize_int = int(initramfs_maxsize)
555         if base_size > initramfs_maxsize_int:
556             bb.error("The initramfs size %d(K) overrides INITRAMFS_MAXSIZE: %d(K)" % \
557                 (base_size, initramfs_maxsize_int))
558             bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should")
559             bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n")
560     return base_size
561
562 python set_image_size () {
563         rootfs_size = get_rootfs_size(d)
564         d.setVar('ROOTFS_SIZE', str(rootfs_size))
565         d.setVarFlag('ROOTFS_SIZE', 'export', '1')
566 }
567
568 #
569 # Create symlinks to the newly created image
570 #
571 python create_symlinks() {
572
573     deploy_dir = d.getVar('IMGDEPLOYDIR')
574     img_name = d.getVar('IMAGE_NAME')
575     link_name = d.getVar('IMAGE_LINK_NAME')
576     manifest_name = d.getVar('IMAGE_MANIFEST')
577     taskname = d.getVar("BB_CURRENTTASK")
578     subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split()
579     imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix') or d.expand("${IMAGE_NAME_SUFFIX}.")
580
581     if not link_name:
582         return
583     for type in subimages:
584         dst = os.path.join(deploy_dir, link_name + "." + type)
585         src = img_name + imgsuffix + type
586         if os.path.exists(os.path.join(deploy_dir, src)):
587             bb.note("Creating symlink: %s -> %s" % (dst, src))
588             if os.path.islink(dst):
589                 os.remove(dst)
590             os.symlink(src, dst)
591         else:
592             bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src))
593 }
594
595 MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
596 MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
597 MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
598
599 do_fetch[noexec] = "1"
600 do_unpack[noexec] = "1"
601 do_patch[noexec] = "1"
602 do_configure[noexec] = "1"
603 do_compile[noexec] = "1"
604 do_install[noexec] = "1"
605 deltask do_populate_sysroot
606 do_package[noexec] = "1"
607 deltask do_package_qa
608 do_packagedata[noexec] = "1"
609 do_package_write_ipk[noexec] = "1"
610 do_package_write_deb[noexec] = "1"
611 do_package_write_rpm[noexec] = "1"
612
613 # Allow the kernel to be repacked with the initramfs and boot image file as a single file
614 do_bundle_initramfs[depends] += "virtual/kernel:do_bundle_initramfs"
615 do_bundle_initramfs[nostamp] = "1"
616 do_bundle_initramfs[noexec] = "1"
617 do_bundle_initramfs () {
618         :
619 }
620 addtask bundle_initramfs after do_image_complete