From a14950444f22e7aaed1cce3c061c860572cf262f Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Mon, 29 Mar 2021 19:09:53 +0200 Subject: classes: Rebase override_image_types_{ota,ostree} - override_image_types_ostree.inc is no longer required; - override_image_types_ota.inc is mostly superseded by upstream, except the creation of /boot/grub as a symlink to /boot/loader (note that /boot/grub2 is a real dir with /boot/grub2/grub.cfg being a symlink to /boot/loader/grub.cfg - it would be quite complicated to override the whole IMAGE_CMD_ota just to keep symlinking the parent dir instead of grub.cfg directly); /boot/grub should be a symlink so that /boot/grub/grubenv also points to /boot/loader/grubenv); fold its contents into enea-nfv-access-host-common.inc as it doesn't override a class anymore Note: Previously, OSTree did not follow symlinks, so the symlink /boot/grub2/grub.cfg was being overwritten with a real file, this is no longer an issue. Change-Id: I38ec2b3a791ef7068b97caa49010eee62b7f4aee Signed-off-by: Alexandru Avadanii Signed-off-by: Adrian Dudau --- classes/override_image_types_ostree.inc | 155 -------------------------------- classes/override_image_types_ota.inc | 99 -------------------- images/enea-nfv-access-host-common.inc | 10 +++ 3 files changed, 10 insertions(+), 254 deletions(-) delete mode 100644 classes/override_image_types_ostree.inc delete mode 100644 classes/override_image_types_ota.inc diff --git a/classes/override_image_types_ostree.inc b/classes/override_image_types_ostree.inc deleted file mode 100644 index 011e27e..0000000 --- a/classes/override_image_types_ostree.inc +++ /dev/null @@ -1,155 +0,0 @@ -# overrides meta-updater/classes/image_types_ostree.bbclass -# - add do_image_ostree flags: -# - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean -# - subimages, imgsuffix: to use automatic link creation -# - override of IMAGE_CMD_ostree -# - use the added flags -# - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE - -OSTREE_ROOTFS="${WORKDIR}/ostree-root" -do_image_ostree[dirs] = "${OSTREE_ROOTFS}" -do_image_ostree[cleandirs] = "${OSTREE_ROOTFS}" -do_image_ostree[subimages] = "rootfs.ostree.tar.bz2" -do_image_ostree[imgsuffix] = "." -export OSTREE_ROOTFS - -IMAGE_CMD_ostree () { - if [ -z "$OSTREE_REPO" ]; then - bbfatal "OSTREE_REPO should be set in your local.conf" - fi - - if [ -z "$OSTREE_BRANCHNAME" ]; then - bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" - fi - - cp -a ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS} - chmod a+rx ${OSTREE_ROOTFS} - sync - - for d in var/*; do - if [ "${d}" != "var/local" ]; then - rm -rf ${d} - fi - done - - # Create sysroot directory to which physical sysroot will be mounted - mkdir sysroot - ln -sf sysroot/ostree ostree - - rm -rf tmp/* - ln -sf sysroot/tmp tmp - - mkdir -p usr/rootdirs - - mv etc usr/ - # Implement UsrMove - dirs="bin sbin lib" - - for dir in ${dirs} ; do - if [ -d ${dir} ] && [ ! -L ${dir} ] ; then - mv ${dir} usr/rootdirs/ - rm -rf ${dir} - ln -sf usr/rootdirs/${dir} ${dir} - fi - done - - if [ -n "$SYSTEMD_USED" ]; then - mkdir -p usr/etc/tmpfiles.d - tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf - echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} - echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} - else - mkdir -p usr/etc/init.d - tmpfiles_conf=usr/etc/init.d/tmpfiles.sh - echo '#!/bin/sh' > ${tmpfiles_conf} - echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} - echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} - - ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh - fi - - # Preserve OSTREE_BRANCHNAME for future information - mkdir -p usr/share/sota/ - echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname - - # Preserve data in /home to be later copied to /sysroot/home by sysroot - # generating procedure - mkdir -p usr/homedirs - if [ -d "home" ] && [ ! -L "home" ]; then - mv home usr/homedirs/home - ln -sf var/rootdirs/home home - fi - - # Move persistent directories to /var - dirs="opt mnt media srv" - - for dir in ${dirs}; do - if [ -d ${dir} ] && [ ! -L ${dir} ]; then - if [ "$(ls -A $dir)" ]; then - bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" - fi - - if [ -n "$SYSTEMD_USED" ]; then - echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} - else - echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} - fi - rm -rf ${dir} - ln -sf var/rootdirs/${dir} ${dir} - fi - done - - if [ -d root ] && [ ! -L root ]; then - if [ "$(ls -A root)" ]; then - bberror "Data in /root directory is not preserved by OSTree." - exit 1 - fi - - if [ -n "$SYSTEMD_USED" ]; then - echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} - else - echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} - fi - - rm -rf root - ln -sf var/roothome root - fi - - if [ -n "${SOTA_SECONDARY_ECUS}" ]; then - mkdir -p var/sota/ecus - cp ${SOTA_SECONDARY_ECUS} var/sota/ecus - fi - - # Creating boot directories is required for "ostree admin deploy" - - mkdir -p boot/loader.0 - mkdir -p boot/loader.1 - ln -sf loader.0 boot/loader - - checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` - - # Copy kernel and initramfs and their signature files - cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} - cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL}.p7b boot/vmlinuz-${checksum}.p7b - cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} - cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT}.p7b boot/initramfs-${checksum}.p7b - - # Copy image manifest - cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest - - # Create a tarball that can be then commited to OSTree repo - OSTREE_TAR=${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 - tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . - sync - - if ! ostree --repo=${OSTREE_REPO} refs 2>&1 > /dev/null; then - ostree --repo=${OSTREE_REPO} init --mode=archive-z2 - fi - - # Commit the result - ostree --repo=${OSTREE_REPO} commit \ - --tree=dir=${OSTREE_ROOTFS} \ - --skip-if-unchanged \ - --branch=${OSTREE_BRANCHNAME} \ - --subject="Commit-id: ${IMAGE_NAME}" -} diff --git a/classes/override_image_types_ota.inc b/classes/override_image_types_ota.inc deleted file mode 100644 index da920c1..0000000 --- a/classes/override_image_types_ota.inc +++ /dev/null @@ -1,99 +0,0 @@ -# overrides meta-updater/classes/image_types_ota.bbclass -# - add do_image_otaimg flags: -# - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean -# - override of IMAGE_CMD_otaimg -# - use the added flags -# - avoid untar-ing the ostree image, and use OSTREE_ROOTFS -# - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE - -OSTREE_REPO = "${WORKDIR}/ostree-repo" -PHYS_SYSROOT = "${WORKDIR}/ota-sysroot" - -do_image_otaimg[dirs] = "${PHYS_SYSROOT}" -do_image_otaimg[cleandirs] = "${PHYS_SYSROOT}" - -IMAGE_CMD_otaimg () { - if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then - if [ -z "$OSTREE_REPO" ]; then - bbfatal "OSTREE_REPO should be set in your local.conf" - fi - - if [ -z "$OSTREE_OSNAME" ]; then - bbfatal "OSTREE_OSNAME should be set in your local.conf" - fi - - if [ -z "$OSTREE_BRANCHNAME" ]; then - bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" - fi - - ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} - ostree admin --sysroot=${PHYS_SYSROOT} os-init ${OSTREE_OSNAME} - - mkdir -p ${PHYS_SYSROOT}/boot/loader.0 - ln -s loader.0 ${PHYS_SYSROOT}/boot/loader - - if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then - ln -s loader ${PHYS_SYSROOT}/boot/grub - ln -s loader ${PHYS_SYSROOT}/boot/grub2 - touch ${PHYS_SYSROOT}/boot/grub/grub.cfg - elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then - touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt - else - bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" - fi; - - ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) - - ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} - export OSTREE_BOOT_PARTITION="/boot" - kargs_list="" - for arg in ${OSTREE_KERNEL_ARGS}; do - kargs_list="${kargs_list} --karg-append=$arg" - done - - ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} - - cp -a ${IMAGE_ROOTFS}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true - # Create /var/sota if it doesn't exist yet - mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota - # Ensure the permissions are correctly set - chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota - - cp -a ${OSTREE_ROOTFS}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true - cp -a ${OSTREE_ROOTFS}/usr/homedirs/home ${PHYS_SYSROOT}/ || true - # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) - install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local - # Set package version for the first deployment - target_version=${ostree_target_hash} - if [ -n "${GARAGE_TARGET_VERSION}" ]; then - target_version=${GARAGE_TARGET_VERSION} - elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then - target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version") - fi - mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import - echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions - - # Calculate image type - OTA_ROOTFS_SIZE=$(calculate_size `du -ks ${PHYS_SYSROOT} | cut -f 1` "${IMAGE_OVERHEAD_FACTOR}" "${IMAGE_ROOTFS_SIZE}" "${IMAGE_ROOTFS_MAXSIZE}" `expr ${IMAGE_ROOTFS_EXTRA_SPACE}` "${IMAGE_ROOTFS_ALIGNMENT}") - - if [ $OTA_ROOTFS_SIZE -lt 0 ]; then - exit -1 - fi - eval local COUNT=\"0\" - eval local MIN_COUNT=\"60\" - if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then - eval COUNT=\"$MIN_COUNT\" - fi - - # create image - dd if=/dev/zero of=${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg seek=${OTA_ROOTFS_SIZE} count=${COUNT} bs=1024 - mkfs.ext4 -O ^64bit ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg -L otaroot -d ${PHYS_SYSROOT} - rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg - ln -s ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg - # for forward compatibility - rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4 - ln -s ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4 - fi -} - -IMAGE_TYPEDEP_otaimg = "ostree" diff --git a/images/enea-nfv-access-host-common.inc b/images/enea-nfv-access-host-common.inc index b3f110a..82e9792 100644 --- a/images/enea-nfv-access-host-common.inc +++ b/images/enea-nfv-access-host-common.inc @@ -59,3 +59,13 @@ IMAGE_CMD_ostree_prepend () { mv var/lib/dpkg/* usr/dpkg/lib/dpkg/ fi } + +IMAGE_CMD_ota_prepend () { + if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then + # Upstream bbclass creates /boot/grub2, complement it with /boot/grub + # Note: /boot/grub2 is a dir with /boot/grub2/grub.cfg -> ../loader/grub.cfg symlink + # while /boot/grub -> loader is a symlink to also account for /boot/grub/grubenv + mkdir -p ${OTA_SYSROOT}/boot + ln -s loader ${OTA_SYSROOT}/boot/grub + fi +} -- cgit v1.2.3-54-g00ecf