image.bbclass 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. IMAGE_CLASSES ??= ""
  5. # rootfs bootstrap install
  6. # warning - image-container resets this
  7. ROOTFS_BOOTSTRAP_INSTALL = "run-postinsts"
  8. # Handle inherits of any of the image classes we need
  9. IMGCLASSES = "rootfs_${IMAGE_PKGTYPE} image_types ${IMAGE_CLASSES}"
  10. # Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk_base
  11. # in the non-Linux SDK_OS case, such as mingw32
  12. IMGCLASSES += "${@['populate_sdk_base', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS")]}"
  13. IMGCLASSES += "${@bb.utils.contains_any('IMAGE_FSTYPES', 'live iso hddimg', 'image-live', '', d)}"
  14. IMGCLASSES += "${@bb.utils.contains('IMAGE_FSTYPES', 'container', 'image-container', '', d)}"
  15. IMGCLASSES += "image_types_wic"
  16. IMGCLASSES += "rootfs-postcommands"
  17. IMGCLASSES += "image-postinst-intercepts"
  18. IMGCLASSES += "overlayfs-etc"
  19. inherit ${IMGCLASSES}
  20. TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}"
  21. TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}"
  22. POPULATE_SDK_POST_TARGET_COMMAND += "rootfs_sysroot_relativelinks; "
  23. LICENSE ?= "MIT"
  24. PACKAGES = ""
  25. DEPENDS += "${@' '.join(["%s-qemuwrapper-cross" % m for m in d.getVar("MULTILIB_VARIANTS").split()])} qemuwrapper-cross depmodwrapper-cross cross-localedef-native"
  26. RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL} ${IMAGE_INSTALL_DEBUGFS}"
  27. RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"
  28. PATH:prepend = "${@":".join(all_multilib_tune_values(d, 'STAGING_BINDIR_CROSS').split())}:"
  29. INHIBIT_DEFAULT_DEPS = "1"
  30. # IMAGE_FEATURES may contain any available package group
  31. IMAGE_FEATURES ?= ""
  32. IMAGE_FEATURES[type] = "list"
  33. IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs read-only-rootfs-delayed-postinsts stateless-rootfs empty-root-password allow-empty-password allow-root-login post-install-logging overlayfs-etc"
  34. # Generate companion debugfs?
  35. IMAGE_GEN_DEBUGFS ?= "0"
  36. # These packages will be installed as additional into debug rootfs
  37. IMAGE_INSTALL_DEBUGFS ?= ""
  38. # These packages will be removed from a read-only rootfs after all other
  39. # packages have been installed
  40. ROOTFS_RO_UNNEEDED ??= "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
  41. # packages to install from features
  42. FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
  43. FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
  44. FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
  45. FEATURE_INSTALL_OPTIONAL[vardepvalue] = "${FEATURE_INSTALL_OPTIONAL}"
  46. # Define some very basic feature package groups
  47. FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
  48. SPLASH ?= "${@bb.utils.contains("MACHINE_FEATURES", "screen", "psplash", "", d)}"
  49. FEATURE_PACKAGES_splash = "${SPLASH}"
  50. IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'
  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("FEATURE_PACKAGES_"):
  56. valid_features.append(var[17:])
  57. valid_features.sort()
  58. features = set(oe.data.typed_value('IMAGE_FEATURES', d))
  59. for feature in features:
  60. if feature not in valid_features:
  61. if bb.utils.contains('EXTRA_IMAGE_FEATURES', feature, True, False, d):
  62. 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)))
  63. else:
  64. raise bb.parse.SkipRecipe("'%s' in IMAGE_FEATURES is not a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features)))
  65. IMAGE_INSTALL ?= ""
  66. IMAGE_INSTALL[type] = "list"
  67. export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
  68. PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"
  69. IMGDEPLOYDIR = "${WORKDIR}/deploy-${PN}-image-complete"
  70. # Images are generally built explicitly, do not need to be part of world.
  71. EXCLUDE_FROM_WORLD = "1"
  72. USE_DEVFS ?= "1"
  73. USE_DEPMOD ?= "1"
  74. PID = "${@os.getpid()}"
  75. PACKAGE_ARCH = "${MACHINE_ARCH}"
  76. LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
  77. LDCONFIGDEPEND:libc-musl = ""
  78. # This is needed to have depmod data in PKGDATA_DIR,
  79. # but if you're building small initramfs image
  80. # e.g. to include it in your kernel, you probably
  81. # don't want this dependency, which is causing dependency loop
  82. KERNELDEPMODDEPEND ?= "virtual/kernel:do_packagedata"
  83. do_rootfs[depends] += " \
  84. makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND} \
  85. virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot \
  86. ${KERNELDEPMODDEPEND} \
  87. "
  88. do_rootfs[recrdeptask] += "do_packagedata"
  89. def rootfs_command_variables(d):
  90. return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','ROOTFS_POSTUNINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND',
  91. 'IMAGE_PREPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS','DEB_PREPROCESS_COMMANDS','DEB_POSTPROCESS_COMMANDS']
  92. python () {
  93. variables = rootfs_command_variables(d)
  94. for var in variables:
  95. if d.getVar(var, False):
  96. d.setVarFlag(var, 'func', '1')
  97. }
  98. def rootfs_variables(d):
  99. from oe.rootfs import variable_depends
  100. 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',
  101. 'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS', 'IMAGE_LINGUAS_COMPLEMENTARY', 'IMAGE_LOCALES_ARCHIVE',
  102. 'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS',
  103. 'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS',
  104. 'CONVERSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED', 'IMGDEPLOYDIR', 'PACKAGE_EXCLUDE_COMPLEMENTARY', 'REPRODUCIBLE_TIMESTAMP_ROOTFS', 'IMAGE_INSTALL_DEBUGFS']
  105. variables.extend(rootfs_command_variables(d))
  106. variables.extend(variable_depends(d))
  107. return " ".join(variables)
  108. do_rootfs[vardeps] += "${@rootfs_variables(d)}"
  109. # This is needed to have kernel image in DEPLOY_DIR.
  110. # This follows many common usecases and user expectations.
  111. # But if you are building an image which doesn't need the kernel image at all,
  112. # you can unset this variable manually.
  113. KERNEL_DEPLOY_DEPEND ?= "virtual/kernel:do_deploy"
  114. do_build[depends] += "${KERNEL_DEPLOY_DEPEND}"
  115. python () {
  116. def extraimage_getdepends(task):
  117. deps = ""
  118. for dep in (d.getVar('EXTRA_IMAGEDEPENDS') or "").split():
  119. if ":" in dep:
  120. deps += " %s " % (dep)
  121. else:
  122. deps += " %s:%s" % (dep, task)
  123. return deps
  124. d.appendVarFlag('do_image_complete', 'depends', extraimage_getdepends('do_populate_sysroot'))
  125. deps = " " + imagetypes_getdepends(d)
  126. d.appendVarFlag('do_rootfs', 'depends', deps)
  127. #process IMAGE_FEATURES, we must do this before runtime_mapping_rename
  128. #Check for replaces image features
  129. features = set(oe.data.typed_value('IMAGE_FEATURES', d))
  130. remain_features = features.copy()
  131. for feature in features:
  132. replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature) or "").split())
  133. remain_features -= replaces
  134. #Check for conflict image features
  135. for feature in remain_features:
  136. conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature) or "").split())
  137. temp = conflicts & remain_features
  138. if temp:
  139. bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN'), feature, ' '.join(list(temp))))
  140. d.setVar('IMAGE_FEATURES', ' '.join(sorted(list(remain_features))))
  141. check_image_features(d)
  142. }
  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').split()))}"
  147. # per default create a locale archive
  148. IMAGE_LOCALES_ARCHIVE ?= '1'
  149. # Prefer image, but use the fallback files for lookups if the image ones
  150. # aren't yet available.
  151. PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}"
  152. PSEUDO_IGNORE_PATHS .= ",${WORKDIR}/intercept_scripts,${WORKDIR}/oe-rootfs-repo,${WORKDIR}/sstate-build-image_complete"
  153. PACKAGE_EXCLUDE ??= ""
  154. PACKAGE_EXCLUDE[type] = "list"
  155. fakeroot python do_rootfs () {
  156. from oe.rootfs import create_rootfs
  157. from oe.manifest import create_manifest
  158. import logging
  159. logger = d.getVar('BB_TASK_LOGGER', False)
  160. if logger:
  161. logcatcher = bb.utils.LogCatcher()
  162. logger.addHandler(logcatcher)
  163. else:
  164. logcatcher = None
  165. # NOTE: if you add, remove or significantly refactor the stages of this
  166. # process then you should recalculate the weightings here. This is quite
  167. # easy to do - just change the MultiStageProgressReporter line temporarily
  168. # to pass debug=True as the last parameter and you'll get a printout of
  169. # the weightings as well as a map to the lines where next_stage() was
  170. # called. Of course this isn't critical, but it helps to keep the progress
  171. # reporting accurate.
  172. stage_weights = [1, 203, 354, 186, 65, 4228, 1, 353, 49, 330, 382, 23, 1]
  173. progress_reporter = bb.progress.MultiStageProgressReporter(d, stage_weights)
  174. progress_reporter.next_stage()
  175. # Handle package exclusions
  176. excl_pkgs = d.getVar("PACKAGE_EXCLUDE").split()
  177. inst_pkgs = d.getVar("PACKAGE_INSTALL").split()
  178. inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY").split()
  179. d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
  180. d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))
  181. for pkg in excl_pkgs:
  182. if pkg in inst_pkgs:
  183. 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))
  184. inst_pkgs.remove(pkg)
  185. if pkg in inst_attempt_pkgs:
  186. 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))
  187. inst_attempt_pkgs.remove(pkg)
  188. d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
  189. d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
  190. # Ensure we handle package name remapping
  191. # We have to delay the runtime_mapping_rename until just before rootfs runs
  192. # otherwise, the multilib renaming could step in and squash any fixups that
  193. # may have occurred.
  194. pn = d.getVar('PN')
  195. runtime_mapping_rename("PACKAGE_INSTALL", pn, d)
  196. runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d)
  197. runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d)
  198. # Generate the initial manifest
  199. create_manifest(d)
  200. progress_reporter.next_stage()
  201. # generate rootfs
  202. d.setVarFlag('REPRODUCIBLE_TIMESTAMP_ROOTFS', 'export', '1')
  203. create_rootfs(d, progress_reporter=progress_reporter, logcatcher=logcatcher)
  204. progress_reporter.finish()
  205. }
  206. do_rootfs[dirs] = "${TOPDIR}"
  207. do_rootfs[cleandirs] += "${IMAGE_ROOTFS} ${IMGDEPLOYDIR} ${S}"
  208. do_rootfs[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}"
  209. addtask rootfs after do_prepare_recipe_sysroot
  210. fakeroot python do_image () {
  211. from oe.utils import execute_pre_post_process
  212. d.setVarFlag('REPRODUCIBLE_TIMESTAMP_ROOTFS', 'export', '1')
  213. pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND")
  214. execute_pre_post_process(d, pre_process_cmds)
  215. }
  216. do_image[dirs] = "${TOPDIR}"
  217. addtask do_image after do_rootfs
  218. fakeroot python do_image_complete () {
  219. from oe.utils import execute_pre_post_process
  220. post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND")
  221. execute_pre_post_process(d, post_process_cmds)
  222. }
  223. do_image_complete[dirs] = "${TOPDIR}"
  224. SSTATETASKS += "do_image_complete"
  225. SSTATE_SKIP_CREATION:task-image-complete = '1'
  226. do_image_complete[sstate-inputdirs] = "${IMGDEPLOYDIR}"
  227. do_image_complete[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
  228. do_image_complete[stamp-extra-info] = "${MACHINE_ARCH}"
  229. addtask do_image_complete after do_image before do_build
  230. python do_image_complete_setscene () {
  231. sstate_setscene(d)
  232. }
  233. addtask do_image_complete_setscene
  234. # Add image-level QA/sanity checks to IMAGE_QA_COMMANDS
  235. #
  236. # IMAGE_QA_COMMANDS += " \
  237. # image_check_everything_ok \
  238. # "
  239. # This task runs all functions in IMAGE_QA_COMMANDS after the rootfs
  240. # construction has completed in order to validate the resulting image.
  241. #
  242. # The functions should use ${IMAGE_ROOTFS} to find the unpacked rootfs
  243. # directory, which if QA passes will be the basis for the images.
  244. fakeroot python do_image_qa () {
  245. from oe.utils import ImageQAFailed
  246. qa_cmds = (d.getVar('IMAGE_QA_COMMANDS') or '').split()
  247. qamsg = ""
  248. for cmd in qa_cmds:
  249. try:
  250. bb.build.exec_func(cmd, d)
  251. except oe.utils.ImageQAFailed as e:
  252. qamsg = qamsg + '\tImage QA function %s failed: %s\n' % (e.name, e.description)
  253. except Exception as e:
  254. qamsg = qamsg + '\tImage QA function %s failed\n' % cmd
  255. if qamsg:
  256. imgname = d.getVar('IMAGE_NAME')
  257. bb.fatal("QA errors found whilst validating image: %s\n%s" % (imgname, qamsg))
  258. }
  259. addtask do_image_qa after do_rootfs before do_image
  260. SSTATETASKS += "do_image_qa"
  261. SSTATE_SKIP_CREATION:task-image-qa = '1'
  262. do_image_qa[sstate-inputdirs] = ""
  263. do_image_qa[sstate-outputdirs] = ""
  264. python do_image_qa_setscene () {
  265. sstate_setscene(d)
  266. }
  267. addtask do_image_qa_setscene
  268. def setup_debugfs_variables(d):
  269. d.appendVar('IMAGE_ROOTFS', '-dbg')
  270. if d.getVar('IMAGE_LINK_NAME'):
  271. d.appendVar('IMAGE_LINK_NAME', '-dbg')
  272. d.appendVar('IMAGE_NAME','-dbg')
  273. d.setVar('IMAGE_BUILDING_DEBUGFS', 'true')
  274. debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS')
  275. if debugfs_image_fstypes:
  276. d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes)
  277. python setup_debugfs () {
  278. setup_debugfs_variables(d)
  279. }
  280. python () {
  281. vardeps = set()
  282. # We allow CONVERSIONTYPES to have duplicates. That avoids breaking
  283. # derived distros when OE-core or some other layer independently adds
  284. # the same type. There is still only one command for each type, but
  285. # presumably the commands will do the same when the type is the same,
  286. # even when added in different places.
  287. #
  288. # Without de-duplication, gen_conversion_cmds() below
  289. # would create the same compression command multiple times.
  290. ctypes = set(d.getVar('CONVERSIONTYPES').split())
  291. old_overrides = d.getVar('OVERRIDES', False)
  292. def _image_base_type(type):
  293. basetype = type
  294. for ctype in ctypes:
  295. if type.endswith("." + ctype):
  296. basetype = type[:-len("." + ctype)]
  297. break
  298. if basetype != type:
  299. # New base type itself might be generated by a conversion command.
  300. basetype = _image_base_type(basetype)
  301. return basetype
  302. basetypes = {}
  303. alltypes = d.getVar('IMAGE_FSTYPES').split()
  304. typedeps = {}
  305. if d.getVar('IMAGE_GEN_DEBUGFS') == "1":
  306. debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS').split()
  307. for t in debugfs_fstypes:
  308. alltypes.append("debugfs_" + t)
  309. def _add_type(t):
  310. baset = _image_base_type(t)
  311. input_t = t
  312. if baset not in basetypes:
  313. basetypes[baset]= []
  314. if t not in basetypes[baset]:
  315. basetypes[baset].append(t)
  316. debug = ""
  317. if t.startswith("debugfs_"):
  318. t = t[8:]
  319. debug = "debugfs_"
  320. deps = (d.getVar('IMAGE_TYPEDEP:' + t) or "").split()
  321. vardeps.add('IMAGE_TYPEDEP:' + t)
  322. if baset not in typedeps:
  323. typedeps[baset] = set()
  324. deps = [debug + dep for dep in deps]
  325. for dep in deps:
  326. if dep not in alltypes:
  327. alltypes.append(dep)
  328. _add_type(dep)
  329. basedep = _image_base_type(dep)
  330. typedeps[baset].add(basedep)
  331. if baset != input_t:
  332. _add_type(baset)
  333. for t in alltypes[:]:
  334. _add_type(t)
  335. d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps))
  336. maskedtypes = (d.getVar('IMAGE_TYPES_MASKED') or "").split()
  337. maskedtypes = [dbg + t for t in maskedtypes for dbg in ("", "debugfs_")]
  338. for t in basetypes:
  339. vardeps = set()
  340. cmds = []
  341. subimages = []
  342. realt = t
  343. if t in maskedtypes:
  344. continue
  345. localdata = bb.data.createCopy(d)
  346. debug = ""
  347. if t.startswith("debugfs_"):
  348. setup_debugfs_variables(localdata)
  349. debug = "setup_debugfs "
  350. realt = t[8:]
  351. localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides))
  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. # Expand PV else it can trigger get_srcrev which can fail due to these variables being unset
  358. localdata.setVar('PV', d.getVar('PV'))
  359. localdata.delVar('DATETIME')
  360. localdata.delVar('DATE')
  361. localdata.delVar('TMPDIR')
  362. localdata.delVar('IMAGE_VERSION_SUFFIX')
  363. vardepsexclude = (d.getVarFlag('IMAGE_CMD:' + realt, 'vardepsexclude', True) or '').split()
  364. for dep in vardepsexclude:
  365. localdata.delVar(dep)
  366. image_cmd = localdata.getVar("IMAGE_CMD")
  367. vardeps.add('IMAGE_CMD:' + realt)
  368. if image_cmd:
  369. cmds.append("\t" + image_cmd)
  370. else:
  371. bb.fatal("No IMAGE_CMD defined for IMAGE_FSTYPES entry '%s' - possibly invalid type name or missing support class" % t)
  372. cmds.append(localdata.expand("\tcd ${IMGDEPLOYDIR}"))
  373. # Since a copy of IMAGE_CMD:xxx will be inlined within do_image_xxx,
  374. # prevent a redundant copy of IMAGE_CMD:xxx being emitted as a function.
  375. d.delVarFlag('IMAGE_CMD:' + realt, 'func')
  376. rm_tmp_images = set()
  377. def gen_conversion_cmds(bt):
  378. for ctype in sorted(ctypes):
  379. if bt.endswith("." + ctype):
  380. type = bt[0:-len(ctype) - 1]
  381. if type.startswith("debugfs_"):
  382. type = type[8:]
  383. # Create input image first.
  384. gen_conversion_cmds(type)
  385. localdata.setVar('type', type)
  386. cmd = "\t" + localdata.getVar("CONVERSION_CMD:" + ctype)
  387. if cmd not in cmds:
  388. cmds.append(cmd)
  389. vardeps.add('CONVERSION_CMD:' + ctype)
  390. subimage = type + "." + ctype
  391. if subimage not in subimages:
  392. subimages.append(subimage)
  393. if type not in alltypes:
  394. rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
  395. for bt in basetypes[t]:
  396. gen_conversion_cmds(bt)
  397. localdata.setVar('type', realt)
  398. if t not in alltypes:
  399. rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}"))
  400. else:
  401. subimages.append(realt)
  402. # Clean up after applying all conversion commands. Some of them might
  403. # use the same input, therefore we cannot delete sooner without applying
  404. # some complex dependency analysis.
  405. for image in sorted(rm_tmp_images):
  406. cmds.append("\trm " + image)
  407. after = 'do_image'
  408. for dep in typedeps[t]:
  409. after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_")
  410. task = "do_image_%s" % t.replace("-", "_").replace(".", "_")
  411. d.setVar(task, '\n'.join(cmds))
  412. d.setVarFlag(task, 'func', '1')
  413. d.setVarFlag(task, 'fakeroot', '1')
  414. d.appendVarFlag(task, 'prefuncs', ' ' + debug + ' set_image_size')
  415. d.prependVarFlag(task, 'postfuncs', 'create_symlinks ')
  416. d.appendVarFlag(task, 'subimages', ' ' + ' '.join(subimages))
  417. d.appendVarFlag(task, 'vardeps', ' ' + ' '.join(vardeps))
  418. d.appendVarFlag(task, 'vardepsexclude', ' DATETIME DATE ' + ' '.join(vardepsexclude))
  419. bb.debug(2, "Adding task %s before %s, after %s" % (task, 'do_image_complete', after))
  420. bb.build.addtask(task, 'do_image_complete', after, d)
  421. }
  422. #
  423. # Compute the rootfs size
  424. #
  425. def get_rootfs_size(d):
  426. import subprocess, oe.utils
  427. rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT'))
  428. overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR'))
  429. rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE'))
  430. rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE'))
  431. rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE')
  432. image_fstypes = d.getVar('IMAGE_FSTYPES') or ''
  433. initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES') or ''
  434. initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE')
  435. size_kb = oe.utils.directory_size(d.getVar("IMAGE_ROOTFS")) / 1024
  436. base_size = size_kb * overhead_factor
  437. bb.debug(1, '%f = %d * %f' % (base_size, size_kb, overhead_factor))
  438. base_size2 = max(base_size, rootfs_req_size) + rootfs_extra_space
  439. bb.debug(1, '%f = max(%f, %d)[%f] + %d' % (base_size2, base_size, rootfs_req_size, max(base_size, rootfs_req_size), rootfs_extra_space))
  440. base_size = base_size2
  441. if base_size != int(base_size):
  442. base_size = int(base_size + 1)
  443. else:
  444. base_size = int(base_size)
  445. bb.debug(1, '%f = int(%f)' % (base_size, base_size2))
  446. base_size_saved = base_size
  447. base_size += rootfs_alignment - 1
  448. base_size -= base_size % rootfs_alignment
  449. bb.debug(1, '%d = aligned(%d)' % (base_size, base_size_saved))
  450. # Do not check image size of the debugfs image. This is not supposed
  451. # to be deployed, etc. so it doesn't make sense to limit the size
  452. # of the debug.
  453. if (d.getVar('IMAGE_BUILDING_DEBUGFS') or "") == "true":
  454. bb.debug(1, 'returning debugfs size %d' % (base_size))
  455. return base_size
  456. # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set)
  457. if rootfs_maxsize:
  458. rootfs_maxsize_int = int(rootfs_maxsize)
  459. if base_size > rootfs_maxsize_int:
  460. bb.fatal("The rootfs size %d(K) exceeds IMAGE_ROOTFS_MAXSIZE: %d(K)" % \
  461. (base_size, rootfs_maxsize_int))
  462. # Check the initramfs size against INITRAMFS_MAXSIZE (if set)
  463. if image_fstypes == initramfs_fstypes != '' and initramfs_maxsize:
  464. initramfs_maxsize_int = int(initramfs_maxsize)
  465. if base_size > initramfs_maxsize_int:
  466. bb.error("The initramfs size %d(K) exceeds INITRAMFS_MAXSIZE: %d(K)" % \
  467. (base_size, initramfs_maxsize_int))
  468. bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should")
  469. bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n")
  470. bb.debug(1, 'returning %d' % (base_size))
  471. return base_size
  472. python set_image_size () {
  473. rootfs_size = get_rootfs_size(d)
  474. d.setVar('ROOTFS_SIZE', str(rootfs_size))
  475. d.setVarFlag('ROOTFS_SIZE', 'export', '1')
  476. }
  477. #
  478. # Create symlinks to the newly created image
  479. #
  480. python create_symlinks() {
  481. deploy_dir = d.getVar('IMGDEPLOYDIR')
  482. img_name = d.getVar('IMAGE_NAME')
  483. link_name = d.getVar('IMAGE_LINK_NAME')
  484. manifest_name = d.getVar('IMAGE_MANIFEST')
  485. taskname = d.getVar("BB_CURRENTTASK")
  486. subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split()
  487. imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix') or d.expand("${IMAGE_NAME_SUFFIX}.")
  488. if not link_name:
  489. return
  490. for type in subimages:
  491. dst = os.path.join(deploy_dir, link_name + "." + type)
  492. src = img_name + imgsuffix + type
  493. if os.path.exists(os.path.join(deploy_dir, src)):
  494. bb.note("Creating symlink: %s -> %s" % (dst, src))
  495. if os.path.islink(dst):
  496. os.remove(dst)
  497. os.symlink(src, dst)
  498. else:
  499. bb.note("Skipping symlink, source does not exist: %s -> %s" % (dst, src))
  500. }
  501. MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
  502. MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
  503. MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
  504. do_fetch[noexec] = "1"
  505. do_unpack[noexec] = "1"
  506. do_patch[noexec] = "1"
  507. do_configure[noexec] = "1"
  508. do_compile[noexec] = "1"
  509. do_install[noexec] = "1"
  510. deltask do_populate_lic
  511. deltask do_populate_sysroot
  512. do_package[noexec] = "1"
  513. deltask do_package_qa
  514. deltask do_packagedata
  515. deltask do_package_write_ipk
  516. deltask do_package_write_deb
  517. deltask do_package_write_rpm
  518. # Prepare the root links to point to the /usr counterparts.
  519. create_merged_usr_symlinks() {
  520. root="$1"
  521. install -d $root${base_bindir} $root${base_sbindir} $root${base_libdir}
  522. ln -rs $root${base_bindir} $root/bin
  523. ln -rs $root${base_sbindir} $root/sbin
  524. ln -rs $root${base_libdir} $root/${baselib}
  525. if [ "${nonarch_base_libdir}" != "${base_libdir}" ]; then
  526. install -d $root${nonarch_base_libdir}
  527. ln -rs $root${nonarch_base_libdir} $root/lib
  528. fi
  529. # create base links for multilibs
  530. multi_libdirs="${@d.getVar('MULTILIB_VARIANTS')}"
  531. for d in $multi_libdirs; do
  532. install -d $root${exec_prefix}/$d
  533. ln -rs $root${exec_prefix}/$d $root/$d
  534. done
  535. }
  536. create_merged_usr_symlinks_rootfs() {
  537. create_merged_usr_symlinks ${IMAGE_ROOTFS}
  538. }
  539. create_merged_usr_symlinks_sdk() {
  540. create_merged_usr_symlinks ${SDK_OUTPUT}${SDKTARGETSYSROOT}
  541. }
  542. ROOTFS_PREPROCESS_COMMAND += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', 'create_merged_usr_symlinks_rootfs; ', '',d)}"
  543. POPULATE_SDK_PRE_TARGET_COMMAND += "${@bb.utils.contains('DISTRO_FEATURES', 'usrmerge', 'create_merged_usr_symlinks_sdk; ', '',d)}"
  544. reproducible_final_image_task () {
  545. if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
  546. REPRODUCIBLE_TIMESTAMP_ROOTFS=`git -C "${COREBASE}" log -1 --pretty=%ct 2>/dev/null` || true
  547. if [ "$REPRODUCIBLE_TIMESTAMP_ROOTFS" = "" ]; then
  548. REPRODUCIBLE_TIMESTAMP_ROOTFS=`stat -c%Y ${@bb.utils.which(d.getVar("BBPATH"), "conf/bitbake.conf")}`
  549. fi
  550. fi
  551. # Set mtime of all files to a reproducible value
  552. bbnote "reproducible_final_image_task: mtime set to $REPRODUCIBLE_TIMESTAMP_ROOTFS"
  553. find ${IMAGE_ROOTFS} -print0 | xargs -0 touch -h --date=@$REPRODUCIBLE_TIMESTAMP_ROOTFS
  554. }
  555. systemd_preset_all () {
  556. if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then
  557. systemctl --root="${IMAGE_ROOTFS}" --preset-mode=enable-only preset-all
  558. fi
  559. }
  560. IMAGE_PREPROCESS_COMMAND:append = " ${@ 'systemd_preset_all;' if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else ''} reproducible_final_image_task; "
  561. CVE_PRODUCT = ""