image.bbclass 27 KB

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