diff options
Diffstat (limited to 'yocto-poky/meta/classes/image.bbclass')
-rw-r--r-- | yocto-poky/meta/classes/image.bbclass | 586 |
1 files changed, 301 insertions, 285 deletions
diff --git a/yocto-poky/meta/classes/image.bbclass b/yocto-poky/meta/classes/image.bbclass index d2f8105f1..8bfd24193 100644 --- a/yocto-poky/meta/classes/image.bbclass +++ b/yocto-poky/meta/classes/image.bbclass @@ -1,6 +1,9 @@ inherit rootfs_${IMAGE_PKGTYPE} -inherit populate_sdk_ext +# Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk +# in the non-Linux SDK_OS case, such as mingw32 +SDKEXTCLASS ?= "${@['populate_sdk', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS", True)]}" +inherit ${SDKEXTCLASS} TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}" TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}" @@ -30,6 +33,10 @@ IMAGE_GEN_DEBUGFS ?= "0" # rootfs bootstrap install ROOTFS_BOOTSTRAP_INSTALL = "${@bb.utils.contains("IMAGE_FEATURES", "package-management", "", "${ROOTFS_PKGMANAGE_BOOTSTRAP}",d)}" +# These packages will be removed from a read-only rootfs after all other +# packages have been installed +ROOTFS_RO_UNNEEDED = "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}" + # packages to install from features FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}" FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}" @@ -94,43 +101,25 @@ do_rootfs[depends] += " \ " do_rootfs[recrdeptask] += "do_packagedata" -def command_variables(d): - return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND', - 'IMAGE_PREPROCESS_COMMAND','ROOTFS_POSTPROCESS_COMMAND','POPULATE_SDK_POST_HOST_COMMAND','POPULATE_SDK_POST_TARGET_COMMAND','SDK_POSTPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS', - 'RPM_POSTPROCESS_COMMANDS'] +def rootfs_command_variables(d): + return ['ROOTFS_POSTPROCESS_COMMAND','ROOTFS_PREPROCESS_COMMAND','ROOTFS_POSTINSTALL_COMMAND','ROOTFS_POSTUNINSTALL_COMMAND','OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','IMAGE_POSTPROCESS_COMMAND', + 'IMAGE_PREPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS','DEB_PREPROCESS_COMMANDS','DEB_POSTPROCESS_COMMANDS'] python () { - variables = command_variables(d) + variables = rootfs_command_variables(d) + sdk_command_variables(d) for var in variables: if d.getVar(var, False): d.setVarFlag(var, 'func', '1') } -def fstype_variables(d): - import oe.image - - image = oe.image.Image(d) - alltypes, fstype_groups, cimages = image._get_image_types() - fstype_vars = set() - for fstype_group in fstype_groups: - for fstype in fstype_group: - fstype_vars.add('IMAGE_CMD_' + fstype) - if fstype in cimages: - for ctype in cimages[fstype]: - fstype_vars.add('COMPRESS_CMD_' + ctype) - - return sorted(fstype_vars) - def rootfs_variables(d): from oe.rootfs import variable_depends variables = ['IMAGE_DEVICE_TABLES','BUILD_IMAGES_FROM_FEEDS','IMAGE_TYPES_MASKED','IMAGE_ROOTFS_ALIGNMENT','IMAGE_OVERHEAD_FACTOR','IMAGE_ROOTFS_SIZE','IMAGE_ROOTFS_EXTRA_SPACE', - 'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','RM_OLD_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS','SDK_OS', - 'SDK_OUTPUT','SDKPATHNATIVE','SDKTARGETSYSROOT','SDK_DIR','SDK_VENDOR','SDKIMAGE_INSTALL_COMPLEMENTARY','SDK_PACKAGE_ARCHS','SDK_OUTPUT','SDKTARGETSYSROOT','MULTILIBRE_ALLOW_REP', - 'MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS','PACKAGE_ARCHS', - 'PACKAGE_CLASSES','TARGET_VENDOR','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS', - 'COMPRESSIONTYPES', 'IMAGE_GEN_DEBUGFS'] - variables.extend(fstype_variables(d)) - variables.extend(command_variables(d)) + 'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','RM_OLD_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS', + 'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS', + 'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS', + 'COMPRESSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED'] + variables.extend(rootfs_command_variables(d)) variables.extend(variable_depends(d)) return " ".join(variables) @@ -183,7 +172,7 @@ python () { initramfs_image = d.getVar('INITRAMFS_IMAGE', True) or "" if initramfs_image != "": d.appendVarFlag('do_build', 'depends', " %s:do_bundle_initramfs" % d.getVar('PN', True)) - d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_rootfs" % initramfs_image) + d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_image_complete" % initramfs_image) } IMAGE_CLASSES += "image_types" @@ -191,32 +180,6 @@ inherit ${IMAGE_CLASSES} IMAGE_POSTPROCESS_COMMAND ?= "" -# Zap the root password if debug-tweaks feature is not enabled -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password ; ",d)}' - -# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is enabled -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}' - -# Enable postinst logging if debug-tweaks is enabled -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}' - -# Create /etc/timestamp during image construction to give a reasonably sane default time setting -ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; " - -# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}' - -# Write manifest -IMAGE_MANIFEST = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.manifest" -ROOTFS_POSTUNINSTALL_COMMAND =+ "write_image_manifest ; " -# Set default postinst log file -POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log" -# Set default target for systemd images -SYSTEMD_DEFAULT_TARGET ?= '${@bb.utils.contains("IMAGE_FEATURES", "x11-base", "graphical.target", "multi-user.target", d)}' -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; ", "", d)}' - -ROOTFS_POSTPROCESS_COMMAND += 'empty_var_volatile;' - # some default locales IMAGE_LINGUAS ?= "de-de fr-fr en-gb" @@ -226,80 +189,16 @@ LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IM # aren't yet available. PSEUDO_PASSWD = "${IMAGE_ROOTFS}:${STAGING_DIR_NATIVE}" -do_rootfs[dirs] = "${TOPDIR}" -do_rootfs[lockfiles] += "${IMAGE_ROOTFS}.lock" -do_rootfs[cleandirs] += "${S}" - -# Must call real_do_rootfs() from inside here, rather than as a separate -# task, so that we have a single fakeroot context for the whole process. -do_rootfs[umask] = "022" - -# A hook function to support read-only-rootfs IMAGE_FEATURES -read_only_rootfs_hook () { - # Tweak the mount option and fs_passno for rootfs in fstab - sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab - - # If we're using openssh and the /etc/ssh directory has no pre-generated keys, - # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly - # and the keys under /var/run/ssh. - if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then - if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then - echo "SYSCONFDIR=/etc/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh - echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh - else - echo "SYSCONFDIR=/var/run/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh - echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh - fi - fi - - # Also tweak the key location for dropbear in the same way. - if [ -d ${IMAGE_ROOTFS}/etc/dropbear ]; then - if [ -e ${IMAGE_ROOTFS}/etc/dropbear/dropbear_rsa_host_key ]; then - echo "DROPBEAR_RSAKEY_DIR=/etc/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear - else - echo "DROPBEAR_RSAKEY_DIR=/var/lib/dropbear" >> ${IMAGE_ROOTFS}/etc/default/dropbear - fi - fi - - - if ${@bb.utils.contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then - # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes - if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then - sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS - fi - # Run populate-volatile.sh at rootfs time to set up basic files - # and directories to support read-only rootfs. - if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then - ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh - fi - fi - - if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then - # Update user database files so that services don't fail for a read-only systemd system - for conffile in ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd.conf ${IMAGE_ROOTFS}/usr/lib/sysusers.d/systemd-remote.conf; do - [ -e $conffile ] || continue - grep -v "^#" $conffile | sed -e '/^$/d' | while read type name id comment; do - if [ "$type" = "u" ]; then - useradd_params="" - [ "$id" != "-" ] && useradd_params="$useradd_params --uid $id" - [ "$comment" != "-" ] && useradd_params="$useradd_params --comment $comment" - useradd_params="$useradd_params --system $name" - eval useradd --root ${IMAGE_ROOTFS} $useradd_params || true - elif [ "$type" = "g" ]; then - groupadd_params="" - [ "$id" != "-" ] && groupadd_params="$groupadd_params --gid $id" - groupadd_params="$groupadd_params --system $name" - eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true - fi - done - done - fi -} +inherit rootfs-postcommands PACKAGE_EXCLUDE ??= "" PACKAGE_EXCLUDE[type] = "list" -python rootfs_process_ignore() { +fakeroot python do_rootfs () { + from oe.rootfs import create_rootfs + from oe.manifest import create_manifest + + # Handle package exclusions excl_pkgs = d.getVar("PACKAGE_EXCLUDE", True).split() inst_pkgs = d.getVar("PACKAGE_INSTALL", True).split() inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY", True).split() @@ -318,193 +217,311 @@ python rootfs_process_ignore() { d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs)) d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs)) -} -do_rootfs[prefuncs] += "rootfs_process_ignore" -# We have to delay the runtime_mapping_rename until just before rootfs runs -# otherwise, the multilib renaming could step in and squash any fixups that -# may have occurred. -python rootfs_runtime_mapping() { + # Ensure we handle package name remapping + # We have to delay the runtime_mapping_rename until just before rootfs runs + # otherwise, the multilib renaming could step in and squash any fixups that + # may have occurred. pn = d.getVar('PN', True) runtime_mapping_rename("PACKAGE_INSTALL", pn, d) runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d) runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d) -} -do_rootfs[prefuncs] += "rootfs_runtime_mapping" -fakeroot python do_rootfs () { - from oe.rootfs import create_rootfs - from oe.image import create_image - from oe.manifest import create_manifest - - # generate the initial manifest + # Generate the initial manifest create_manifest(d) - # generate rootfs + # Generate rootfs create_rootfs(d) - - # generate final images - create_image(d) } +do_rootfs[dirs] = "${TOPDIR}" +do_rootfs[cleandirs] += "${S}" +do_rootfs[umask] = "022" +addtask rootfs before do_build -insert_feed_uris () { - - echo "Building feeds for [${DISTRO}].." - - for line in ${FEED_URIS} - do - # strip leading and trailing spaces/tabs, then split into name and uri - line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`" - feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`" - feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`" - - echo "Added $feed_name feed with URL $feed_uri" - - # insert new feed-sources - echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf - done -} +fakeroot python do_image () { + from oe.utils import execute_pre_post_process -MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|" -MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py" -MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib" + pre_process_cmds = d.getVar("IMAGE_PREPROCESS_COMMAND", True) -# This function is intended to disallow empty root password if 'debug-tweaks' is not in IMAGE_FEATURES. -zap_empty_root_password () { - if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then - sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow - fi - if [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then - sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd - fi -} - -# allow dropbear/openssh to accept root logins and logins from accounts with an empty password string -ssh_allow_empty_password () { - if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then - sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config - sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config - fi - - if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then - if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then - if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear ; then - sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear - fi - else - printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear - fi - fi - - if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then - sed -i 's/nullok_secure/nullok/' ${IMAGE_ROOTFS}${sysconfdir}/pam.d/* - fi + execute_pre_post_process(d, pre_process_cmds) } +do_image[dirs] = "${TOPDIR}" +do_image[umask] = "022" +addtask do_image after do_rootfs before do_build -# Disable DNS lookups, the SSH_DISABLE_DNS_LOOKUP can be overridden to allow -# distros to choose not to take this change -SSH_DISABLE_DNS_LOOKUP ?= " ssh_disable_dns_lookup ; " -ROOTFS_POSTPROCESS_COMMAND_append_qemuall = "${SSH_DISABLE_DNS_LOOKUP}" -ssh_disable_dns_lookup () { - if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then - sed -i -e 's:#UseDNS yes:UseDNS no:' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config - fi -} +fakeroot python do_image_complete () { + from oe.utils import execute_pre_post_process -# Enable postinst logging if debug-tweaks is enabled -postinst_enable_logging () { - mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default - echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst - echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst -} + post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND", True) -# Modify systemd default target -set_systemd_default_target () { - if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ]; then - ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target - fi + execute_pre_post_process(d, post_process_cmds) } +do_image_complete[dirs] = "${TOPDIR}" +do_image_complete[umask] = "022" +addtask do_image_complete after do_image before do_build -# If /var/volatile is not empty, we have seen problems where programs such as the -# journal make assumptions based on the contents of /var/volatile. The journal -# would then write to /var/volatile before it was mounted, thus hiding the -# items previously written. # -# This change is to attempt to fix those types of issues in a way that doesn't -# affect users that may not be using /var/volatile. -empty_var_volatile () { - if [ -e ${IMAGE_ROOTFS}/etc/fstab ]; then - match=`awk '$1 !~ "#" && $2 ~ /\/var\/volatile/{print $2}' ${IMAGE_ROOTFS}/etc/fstab 2> /dev/null` - if [ -n "$match" ]; then - find ${IMAGE_ROOTFS}/var/volatile -mindepth 1 -delete - fi - fi -} - -# Turn any symbolic /sbin/init link into a file -remove_init_link () { - if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then - LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init` - rm ${IMAGE_ROOTFS}/sbin/init - cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init - fi -} - -make_zimage_symlink_relative () { - if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then - (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done) - fi -} - -python write_image_manifest () { - from oe.rootfs import image_list_installed_packages - with open(d.getVar('IMAGE_MANIFEST', True), 'w+') as image_manifest: - image_manifest.write(image_list_installed_packages(d, 'ver')) - image_manifest.write("\n") +# Write environment variables used by wic +# to tmp/sysroots/<machine>/imgdata/<image>.env +# +python do_rootfs_wicenv () { + wicvars = d.getVar('WICVARS', True) + if not wicvars: + return + + stdir = d.getVar('STAGING_DIR_TARGET', True) + outdir = os.path.join(stdir, 'imgdata') + bb.utils.mkdirhier(outdir) + basename = d.getVar('IMAGE_BASENAME', True) + with open(os.path.join(outdir, basename) + '.env', 'w') as envf: + for var in wicvars.split(): + value = d.getVar(var, True) + if value: + envf.write('%s="%s"\n' % (var, value.strip())) } - -# Can be use to create /etc/timestamp during image construction to give a reasonably -# sane default time setting -rootfs_update_timestamp () { - date -u +%4Y%2m%2d%2H%2M%2S >${IMAGE_ROOTFS}/etc/timestamp +addtask do_rootfs_wicenv after do_image before do_image_wic +do_rootfs_wicenv[vardeps] += "${WICVARS}" +do_rootfs_wicenv[prefuncs] = 'set_image_size' + +def setup_debugfs_variables(d): + d.appendVar('IMAGE_ROOTFS', '-dbg') + d.appendVar('IMAGE_LINK_NAME', '-dbg') + d.appendVar('IMAGE_NAME','-dbg') + debugfs_image_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS', True) + if debugfs_image_fstypes: + d.setVar('IMAGE_FSTYPES', debugfs_image_fstypes) + +python setup_debugfs () { + setup_debugfs_variables(d) } -# Prevent X from being started -rootfs_no_x_startup () { - if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then - chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm - fi +python () { + vardeps = set() + ctypes = d.getVar('COMPRESSIONTYPES', True).split() + old_overrides = d.getVar('OVERRIDES', 0) + + def _image_base_type(type): + basetype = type + for ctype in ctypes: + if type.endswith("." + ctype): + basetype = type[:-len("." + ctype)] + break + + if basetype != type: + # New base type itself might be generated by a conversion command. + basetype = _image_base_type(basetype) + + return basetype + + basetypes = {} + alltypes = d.getVar('IMAGE_FSTYPES', True).split() + typedeps = {} + + if d.getVar('IMAGE_GEN_DEBUGFS', True) == "1": + debugfs_fstypes = d.getVar('IMAGE_FSTYPES_DEBUGFS', True).split() + for t in debugfs_fstypes: + alltypes.append("debugfs_" + t) + + def _add_type(t): + baset = _image_base_type(t) + input_t = t + if baset not in basetypes: + basetypes[baset]= [] + if t not in basetypes[baset]: + basetypes[baset].append(t) + debug = "" + if t.startswith("debugfs_"): + t = t[8:] + debug = "debugfs_" + deps = (d.getVar('IMAGE_TYPEDEP_' + t, True) or "").split() + vardeps.add('IMAGE_TYPEDEP_' + t) + if baset not in typedeps: + typedeps[baset] = set() + deps = [debug + dep for dep in deps] + for dep in deps: + if dep not in alltypes: + alltypes.append(dep) + _add_type(dep) + basedep = _image_base_type(dep) + typedeps[baset].add(basedep) + + if baset != input_t: + _add_type(baset) + + for t in alltypes[:]: + _add_type(t) + + d.appendVarFlag('do_image', 'vardeps', ' '.join(vardeps)) + + maskedtypes = (d.getVar('IMAGE_TYPES_MASKED', True) or "").split() + + for t in basetypes: + vardeps = set() + cmds = [] + subimages = [] + realt = t + + if t in maskedtypes: + continue + + localdata = bb.data.createCopy(d) + debug = "" + if t.startswith("debugfs_"): + setup_debugfs_variables(localdata) + debug = "setup_debugfs " + realt = t[8:] + localdata.setVar('OVERRIDES', '%s:%s' % (realt, old_overrides)) + bb.data.update_data(localdata) + localdata.setVar('type', realt) + # Delete DATETIME so we don't expand any references to it now + # This means the task's hash can be stable rather than having hardcoded + # date/time values. It will get expanded at execution time. + # Similarly TMPDIR since otherwise we see QA stamp comparision problems + localdata.delVar('DATETIME') + localdata.delVar('TMPDIR') + + image_cmd = localdata.getVar("IMAGE_CMD", True) + vardeps.add('IMAGE_CMD_' + realt) + if image_cmd: + cmds.append("\t" + image_cmd) + else: + bb.fatal("No IMAGE_CMD defined for IMAGE_FSTYPES entry '%s' - possibly invalid type name or missing support class" % t) + cmds.append(localdata.expand("\tcd ${DEPLOY_DIR_IMAGE}")) + + rm_tmp_images = set() + def gen_conversion_cmds(bt): + for ctype in ctypes: + if bt.endswith("." + ctype): + type = bt[0:-len(ctype) - 1] + if type.startswith("debugfs_"): + type = type[8:] + # Create input image first. + gen_conversion_cmds(type) + localdata.setVar('type', type) + cmds.append("\t" + localdata.getVar("COMPRESS_CMD_" + ctype, True)) + vardeps.add('COMPRESS_CMD_' + ctype) + subimages.append(type + "." + ctype) + if type not in alltypes: + rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) + + for bt in basetypes[t]: + gen_conversion_cmds(bt) + + localdata.setVar('type', realt) + if t not in alltypes: + rm_tmp_images.add(localdata.expand("${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}")) + else: + subimages.append(realt) + + # Clean up after applying all conversion commands. Some of them might + # use the same input, therefore we cannot delete sooner without applying + # some complex dependency analysis. + for image in rm_tmp_images: + cmds.append("\trm " + image) + + after = 'do_image' + for dep in typedeps[t]: + after += ' do_image_%s' % dep.replace("-", "_").replace(".", "_") + + t = t.replace("-", "_").replace(".", "_") + + d.setVar('do_image_%s' % t, '\n'.join(cmds)) + d.setVarFlag('do_image_%s' % t, 'func', '1') + d.setVarFlag('do_image_%s' % t, 'fakeroot', '1') + d.setVarFlag('do_image_%s' % t, 'prefuncs', debug + 'set_image_size') + d.setVarFlag('do_image_%s' % t, 'postfuncs', 'create_symlinks') + d.setVarFlag('do_image_%s' % t, 'subimages', ' '.join(subimages)) + d.appendVarFlag('do_image_%s' % t, 'vardeps', ' '.join(vardeps)) + d.appendVarFlag('do_image_%s' % t, 'vardepsexclude', 'DATETIME') + + bb.debug(2, "Adding type %s before %s, after %s" % (t, 'do_image_complete', after)) + bb.build.addtask('do_image_%s' % t, 'do_image_complete', after, d) } -rootfs_trim_schemas () { - for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas - do - # Need this in case no files exist - if [ -e $schema ]; then - oe-trim-schemas $schema > $schema.new - mv $schema.new $schema - fi - done +# +# Compute the rootfs size +# +def get_rootfs_size(d): + import subprocess + + rootfs_alignment = int(d.getVar('IMAGE_ROOTFS_ALIGNMENT', True)) + overhead_factor = float(d.getVar('IMAGE_OVERHEAD_FACTOR', True)) + rootfs_req_size = int(d.getVar('IMAGE_ROOTFS_SIZE', True)) + rootfs_extra_space = eval(d.getVar('IMAGE_ROOTFS_EXTRA_SPACE', True)) + rootfs_maxsize = d.getVar('IMAGE_ROOTFS_MAXSIZE', True) + image_fstypes = d.getVar('IMAGE_FSTYPES', True) or '' + initramfs_fstypes = d.getVar('INITRAMFS_FSTYPES', True) or '' + initramfs_maxsize = d.getVar('INITRAMFS_MAXSIZE', True) + + output = subprocess.check_output(['du', '-ks', + d.getVar('IMAGE_ROOTFS', True)]) + size_kb = int(output.split()[0]) + base_size = size_kb * overhead_factor + base_size = max(base_size, rootfs_req_size) + rootfs_extra_space + + if base_size != int(base_size): + base_size = int(base_size + 1) + else: + base_size = int(base_size) + + base_size += rootfs_alignment - 1 + base_size -= base_size % rootfs_alignment + + # Check the rootfs size against IMAGE_ROOTFS_MAXSIZE (if set) + if rootfs_maxsize: + rootfs_maxsize_int = int(rootfs_maxsize) + if base_size > rootfs_maxsize_int: + bb.fatal("The rootfs size %d(K) overrides IMAGE_ROOTFS_MAXSIZE: %d(K)" % \ + (base_size, rootfs_maxsize_int)) + + # Check the initramfs size against INITRAMFS_MAXSIZE (if set) + if image_fstypes == initramfs_fstypes != '' and initramfs_maxsize: + initramfs_maxsize_int = int(initramfs_maxsize) + if base_size > initramfs_maxsize_int: + bb.error("The initramfs size %d(K) overrides INITRAMFS_MAXSIZE: %d(K)" % \ + (base_size, initramfs_maxsize_int)) + bb.error("You can set INITRAMFS_MAXSIZE a larger value. Usually, it should") + bb.fatal("be less than 1/2 of ram size, or you may fail to boot it.\n") + return base_size + +python set_image_size () { + rootfs_size = get_rootfs_size(d) + d.setVar('ROOTFS_SIZE', str(rootfs_size)) + d.setVarFlag('ROOTFS_SIZE', 'export', '1') } -rootfs_check_host_user_contaminated () { - contaminated="${WORKDIR}/host-user-contaminated.txt" - HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)" - HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)" - - find "${IMAGE_ROOTFS}" -wholename "${IMAGE_ROOTFS}/home" -prune \ - -user "$HOST_USER_UID" -o -group "$HOST_USER_GID" >"$contaminated" - - if [ -s "$contaminated" ]; then - echo "WARNING: Paths in the rootfs are owned by the same user or group as the user running bitbake. See the logfile for the specific paths." - cat "$contaminated" | sed "s,^, ," - fi +# +# Create symlinks to the newly created image +# +python create_symlinks() { + + deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True) + img_name = d.getVar('IMAGE_NAME', True) + link_name = d.getVar('IMAGE_LINK_NAME', True) + manifest_name = d.getVar('IMAGE_MANIFEST', True) + taskname = d.getVar("BB_CURRENTTASK", True) + subimages = (d.getVarFlag("do_" + taskname, 'subimages', False) or "").split() + imgsuffix = d.getVarFlag("do_" + taskname, 'imgsuffix', True) or d.expand("${IMAGE_NAME_SUFFIX}.") + os.chdir(deploy_dir) + + if not link_name: + return + for type in subimages: + if os.path.exists(img_name + imgsuffix + type): + dst = deploy_dir + "/" + link_name + "." + type + src = img_name + imgsuffix + type + bb.note("Creating symlink: %s -> %s" % (dst, src)) + if os.path.islink(dst): + if d.getVar('RM_OLD_IMAGE', True) == "1" and \ + os.path.exists(os.path.realpath(dst)): + os.remove(os.path.realpath(dst)) + os.remove(dst) + os.symlink(src, dst) } -# Make any absolute links in a sysroot relative -rootfs_sysroot_relativelinks () { - sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT} -} +MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|" +MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py" +MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib" do_fetch[noexec] = "1" do_unpack[noexec] = "1" @@ -520,7 +537,6 @@ do_package_write_ipk[noexec] = "1" do_package_write_deb[noexec] = "1" do_package_write_rpm[noexec] = "1" -addtask rootfs before do_build # Allow the kernel to be repacked with the initramfs and boot image file as a single file do_bundle_initramfs[depends] += "virtual/kernel:do_bundle_initramfs" do_bundle_initramfs[nostamp] = "1" @@ -528,4 +544,4 @@ do_bundle_initramfs[noexec] = "1" do_bundle_initramfs () { : } -addtask bundle_initramfs after do_rootfs +addtask bundle_initramfs after do_image_complete |