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