diff options
| author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2021-03-29 19:09:53 +0200 |
|---|---|---|
| committer | Adrian Dudau <adrian.dudau@enea.com> | 2021-04-09 13:20:11 +0200 |
| commit | a14950444f22e7aaed1cce3c061c860572cf262f (patch) | |
| tree | 1a41f9445d57e84551294fb11a09ac10b2bd7e1c /classes | |
| parent | 17dae722fbab32bd477a650b3f6b412b7dc7b20f (diff) | |
| download | meta-el-nfv-access-a14950444f22e7aaed1cce3c061c860572cf262f.tar.gz | |
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 <Alexandru.Avadanii@enea.com>
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/override_image_types_ostree.inc | 155 | ||||
| -rw-r--r-- | classes/override_image_types_ota.inc | 99 |
2 files changed, 0 insertions, 254 deletions
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 @@ | |||
| 1 | # overrides meta-updater/classes/image_types_ostree.bbclass | ||
| 2 | # - add do_image_ostree flags: | ||
| 3 | # - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean | ||
| 4 | # - subimages, imgsuffix: to use automatic link creation | ||
| 5 | # - override of IMAGE_CMD_ostree | ||
| 6 | # - use the added flags | ||
| 7 | # - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE | ||
| 8 | |||
| 9 | OSTREE_ROOTFS="${WORKDIR}/ostree-root" | ||
| 10 | do_image_ostree[dirs] = "${OSTREE_ROOTFS}" | ||
| 11 | do_image_ostree[cleandirs] = "${OSTREE_ROOTFS}" | ||
| 12 | do_image_ostree[subimages] = "rootfs.ostree.tar.bz2" | ||
| 13 | do_image_ostree[imgsuffix] = "." | ||
| 14 | export OSTREE_ROOTFS | ||
| 15 | |||
| 16 | IMAGE_CMD_ostree () { | ||
| 17 | if [ -z "$OSTREE_REPO" ]; then | ||
| 18 | bbfatal "OSTREE_REPO should be set in your local.conf" | ||
| 19 | fi | ||
| 20 | |||
| 21 | if [ -z "$OSTREE_BRANCHNAME" ]; then | ||
| 22 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | ||
| 23 | fi | ||
| 24 | |||
| 25 | cp -a ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS} | ||
| 26 | chmod a+rx ${OSTREE_ROOTFS} | ||
| 27 | sync | ||
| 28 | |||
| 29 | for d in var/*; do | ||
| 30 | if [ "${d}" != "var/local" ]; then | ||
| 31 | rm -rf ${d} | ||
| 32 | fi | ||
| 33 | done | ||
| 34 | |||
| 35 | # Create sysroot directory to which physical sysroot will be mounted | ||
| 36 | mkdir sysroot | ||
| 37 | ln -sf sysroot/ostree ostree | ||
| 38 | |||
| 39 | rm -rf tmp/* | ||
| 40 | ln -sf sysroot/tmp tmp | ||
| 41 | |||
| 42 | mkdir -p usr/rootdirs | ||
| 43 | |||
| 44 | mv etc usr/ | ||
| 45 | # Implement UsrMove | ||
| 46 | dirs="bin sbin lib" | ||
| 47 | |||
| 48 | for dir in ${dirs} ; do | ||
| 49 | if [ -d ${dir} ] && [ ! -L ${dir} ] ; then | ||
| 50 | mv ${dir} usr/rootdirs/ | ||
| 51 | rm -rf ${dir} | ||
| 52 | ln -sf usr/rootdirs/${dir} ${dir} | ||
| 53 | fi | ||
| 54 | done | ||
| 55 | |||
| 56 | if [ -n "$SYSTEMD_USED" ]; then | ||
| 57 | mkdir -p usr/etc/tmpfiles.d | ||
| 58 | tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf | ||
| 59 | echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} | ||
| 60 | echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} | ||
| 61 | else | ||
| 62 | mkdir -p usr/etc/init.d | ||
| 63 | tmpfiles_conf=usr/etc/init.d/tmpfiles.sh | ||
| 64 | echo '#!/bin/sh' > ${tmpfiles_conf} | ||
| 65 | echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} | ||
| 66 | echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} | ||
| 67 | |||
| 68 | ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh | ||
| 69 | fi | ||
| 70 | |||
| 71 | # Preserve OSTREE_BRANCHNAME for future information | ||
| 72 | mkdir -p usr/share/sota/ | ||
| 73 | echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname | ||
| 74 | |||
| 75 | # Preserve data in /home to be later copied to /sysroot/home by sysroot | ||
| 76 | # generating procedure | ||
| 77 | mkdir -p usr/homedirs | ||
| 78 | if [ -d "home" ] && [ ! -L "home" ]; then | ||
| 79 | mv home usr/homedirs/home | ||
| 80 | ln -sf var/rootdirs/home home | ||
| 81 | fi | ||
| 82 | |||
| 83 | # Move persistent directories to /var | ||
| 84 | dirs="opt mnt media srv" | ||
| 85 | |||
| 86 | for dir in ${dirs}; do | ||
| 87 | if [ -d ${dir} ] && [ ! -L ${dir} ]; then | ||
| 88 | if [ "$(ls -A $dir)" ]; then | ||
| 89 | bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" | ||
| 90 | fi | ||
| 91 | |||
| 92 | if [ -n "$SYSTEMD_USED" ]; then | ||
| 93 | echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} | ||
| 94 | else | ||
| 95 | echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} | ||
| 96 | fi | ||
| 97 | rm -rf ${dir} | ||
| 98 | ln -sf var/rootdirs/${dir} ${dir} | ||
| 99 | fi | ||
| 100 | done | ||
| 101 | |||
| 102 | if [ -d root ] && [ ! -L root ]; then | ||
| 103 | if [ "$(ls -A root)" ]; then | ||
| 104 | bberror "Data in /root directory is not preserved by OSTree." | ||
| 105 | exit 1 | ||
| 106 | fi | ||
| 107 | |||
| 108 | if [ -n "$SYSTEMD_USED" ]; then | ||
| 109 | echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} | ||
| 110 | else | ||
| 111 | echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} | ||
| 112 | fi | ||
| 113 | |||
| 114 | rm -rf root | ||
| 115 | ln -sf var/roothome root | ||
| 116 | fi | ||
| 117 | |||
| 118 | if [ -n "${SOTA_SECONDARY_ECUS}" ]; then | ||
| 119 | mkdir -p var/sota/ecus | ||
| 120 | cp ${SOTA_SECONDARY_ECUS} var/sota/ecus | ||
| 121 | fi | ||
| 122 | |||
| 123 | # Creating boot directories is required for "ostree admin deploy" | ||
| 124 | |||
| 125 | mkdir -p boot/loader.0 | ||
| 126 | mkdir -p boot/loader.1 | ||
| 127 | ln -sf loader.0 boot/loader | ||
| 128 | |||
| 129 | checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` | ||
| 130 | |||
| 131 | # Copy kernel and initramfs and their signature files | ||
| 132 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} | ||
| 133 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL}.p7b boot/vmlinuz-${checksum}.p7b | ||
| 134 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} | ||
| 135 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT}.p7b boot/initramfs-${checksum}.p7b | ||
| 136 | |||
| 137 | # Copy image manifest | ||
| 138 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest | ||
| 139 | |||
| 140 | # Create a tarball that can be then commited to OSTree repo | ||
| 141 | OSTREE_TAR=${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 | ||
| 142 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . | ||
| 143 | sync | ||
| 144 | |||
| 145 | if ! ostree --repo=${OSTREE_REPO} refs 2>&1 > /dev/null; then | ||
| 146 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 | ||
| 147 | fi | ||
| 148 | |||
| 149 | # Commit the result | ||
| 150 | ostree --repo=${OSTREE_REPO} commit \ | ||
| 151 | --tree=dir=${OSTREE_ROOTFS} \ | ||
| 152 | --skip-if-unchanged \ | ||
| 153 | --branch=${OSTREE_BRANCHNAME} \ | ||
| 154 | --subject="Commit-id: ${IMAGE_NAME}" | ||
| 155 | } | ||
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 @@ | |||
| 1 | # overrides meta-updater/classes/image_types_ota.bbclass | ||
| 2 | # - add do_image_otaimg flags: | ||
| 3 | # - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean | ||
| 4 | # - override of IMAGE_CMD_otaimg | ||
| 5 | # - use the added flags | ||
| 6 | # - avoid untar-ing the ostree image, and use OSTREE_ROOTFS | ||
| 7 | # - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE | ||
| 8 | |||
| 9 | OSTREE_REPO = "${WORKDIR}/ostree-repo" | ||
| 10 | PHYS_SYSROOT = "${WORKDIR}/ota-sysroot" | ||
| 11 | |||
| 12 | do_image_otaimg[dirs] = "${PHYS_SYSROOT}" | ||
| 13 | do_image_otaimg[cleandirs] = "${PHYS_SYSROOT}" | ||
| 14 | |||
| 15 | IMAGE_CMD_otaimg () { | ||
| 16 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then | ||
| 17 | if [ -z "$OSTREE_REPO" ]; then | ||
| 18 | bbfatal "OSTREE_REPO should be set in your local.conf" | ||
| 19 | fi | ||
| 20 | |||
| 21 | if [ -z "$OSTREE_OSNAME" ]; then | ||
| 22 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | ||
| 23 | fi | ||
| 24 | |||
| 25 | if [ -z "$OSTREE_BRANCHNAME" ]; then | ||
| 26 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | ||
| 27 | fi | ||
| 28 | |||
| 29 | ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} | ||
| 30 | ostree admin --sysroot=${PHYS_SYSROOT} os-init ${OSTREE_OSNAME} | ||
| 31 | |||
| 32 | mkdir -p ${PHYS_SYSROOT}/boot/loader.0 | ||
| 33 | ln -s loader.0 ${PHYS_SYSROOT}/boot/loader | ||
| 34 | |||
| 35 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then | ||
| 36 | ln -s loader ${PHYS_SYSROOT}/boot/grub | ||
| 37 | ln -s loader ${PHYS_SYSROOT}/boot/grub2 | ||
| 38 | touch ${PHYS_SYSROOT}/boot/grub/grub.cfg | ||
| 39 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then | ||
| 40 | touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt | ||
| 41 | else | ||
| 42 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" | ||
| 43 | fi; | ||
| 44 | |||
| 45 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
| 46 | |||
| 47 | ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} | ||
| 48 | export OSTREE_BOOT_PARTITION="/boot" | ||
| 49 | kargs_list="" | ||
| 50 | for arg in ${OSTREE_KERNEL_ARGS}; do | ||
| 51 | kargs_list="${kargs_list} --karg-append=$arg" | ||
| 52 | done | ||
| 53 | |||
| 54 | ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} | ||
| 55 | |||
| 56 | cp -a ${IMAGE_ROOTFS}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
| 57 | # Create /var/sota if it doesn't exist yet | ||
| 58 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
| 59 | # Ensure the permissions are correctly set | ||
| 60 | chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
| 61 | |||
| 62 | cp -a ${OSTREE_ROOTFS}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
| 63 | cp -a ${OSTREE_ROOTFS}/usr/homedirs/home ${PHYS_SYSROOT}/ || true | ||
| 64 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | ||
| 65 | install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | ||
| 66 | # Set package version for the first deployment | ||
| 67 | target_version=${ostree_target_hash} | ||
| 68 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
| 69 | target_version=${GARAGE_TARGET_VERSION} | ||
| 70 | elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then | ||
| 71 | target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version") | ||
| 72 | fi | ||
| 73 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import | ||
| 74 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions | ||
| 75 | |||
| 76 | # Calculate image type | ||
| 77 | 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}") | ||
| 78 | |||
| 79 | if [ $OTA_ROOTFS_SIZE -lt 0 ]; then | ||
| 80 | exit -1 | ||
| 81 | fi | ||
| 82 | eval local COUNT=\"0\" | ||
| 83 | eval local MIN_COUNT=\"60\" | ||
| 84 | if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then | ||
| 85 | eval COUNT=\"$MIN_COUNT\" | ||
| 86 | fi | ||
| 87 | |||
| 88 | # create image | ||
| 89 | dd if=/dev/zero of=${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg seek=${OTA_ROOTFS_SIZE} count=${COUNT} bs=1024 | ||
| 90 | mkfs.ext4 -O ^64bit ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg -L otaroot -d ${PHYS_SYSROOT} | ||
| 91 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | ||
| 92 | ln -s ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | ||
| 93 | # for forward compatibility | ||
| 94 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4 | ||
| 95 | ln -s ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4 | ||
| 96 | fi | ||
| 97 | } | ||
| 98 | |||
| 99 | IMAGE_TYPEDEP_otaimg = "ostree" | ||
