image.bbclass 25 KB

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