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