summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorlbonn <lbonn@users.noreply.github.com>2020-06-03 11:28:17 +0200
committerGitHub <noreply@github.com>2020-06-03 11:28:17 +0200
commit1739961a0a52c10e2839a99ff67f619128bff921 (patch)
treeaf3b9483bf425e940c377bc9075fcc8e317fb871 /classes
parentb3bc79b0319dcf720fb5a54852d9152f7642a61d (diff)
parent9dcbb6e9afe3a328ec76aa98ffe64445edf35655 (diff)
downloadmeta-updater-1739961a0a52c10e2839a99ff67f619128bff921.tar.gz
Merge pull request #732 from advancedtelematic/feat/zeus/2020.7
2020.7 on zeus
Diffstat (limited to 'classes')
-rw-r--r--classes/image_types_ostree.bbclass60
-rw-r--r--classes/image_types_ota.bbclass30
-rw-r--r--classes/sota_sanity.bbclass23
3 files changed, 67 insertions, 46 deletions
diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass
index 533d338..8d68b5a 100644
--- a/classes/image_types_ostree.bbclass
+++ b/classes/image_types_ostree.bbclass
@@ -19,14 +19,24 @@ CONVERSIONTYPES_append = " tar"
19 19
20REQUIRED_DISTRO_FEATURES = "usrmerge" 20REQUIRED_DISTRO_FEATURES = "usrmerge"
21TAR_IMAGE_ROOTFS_task-image-ostree = "${OSTREE_ROOTFS}" 21TAR_IMAGE_ROOTFS_task-image-ostree = "${OSTREE_ROOTFS}"
22
23python prepare_ostree_rootfs() {
24 import oe.path
25 import shutil
26
27 ostree_rootfs = d.getVar("OSTREE_ROOTFS")
28 if os.path.lexists(ostree_rootfs):
29 bb.utils.remove(ostree_rootfs, True)
30
31 # Copy required as we change permissions on some files.
32 image_rootfs = d.getVar("IMAGE_ROOTFS")
33 oe.path.copyhardlinktree(image_rootfs, ostree_rootfs)
34}
35
22do_image_ostree[dirs] = "${OSTREE_ROOTFS}" 36do_image_ostree[dirs] = "${OSTREE_ROOTFS}"
23do_image_ostree[cleandirs] = "${OSTREE_ROOTFS}" 37do_image_ostree[prefuncs] += "prepare_ostree_rootfs"
24do_image_ostree[depends] = "coreutils-native:do_populate_sysroot virtual/kernel:do_deploy ${INITRAMFS_IMAGE}:do_image_complete" 38do_image_ostree[depends] = "coreutils-native:do_populate_sysroot virtual/kernel:do_deploy ${INITRAMFS_IMAGE}:do_image_complete"
25IMAGE_CMD_ostree () { 39IMAGE_CMD_ostree () {
26 cp -a ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS}
27 chmod a+rx ${OSTREE_ROOTFS}
28 sync
29
30 for d in var/*; do 40 for d in var/*; do
31 if [ "${d}" != "var/local" ]; then 41 if [ "${d}" != "var/local" ]; then
32 rm -rf ${d} 42 rm -rf ${d}
@@ -37,9 +47,6 @@ IMAGE_CMD_ostree () {
37 mkdir sysroot 47 mkdir sysroot
38 ln -sf sysroot/ostree ostree 48 ln -sf sysroot/ostree ostree
39 49
40 rm -rf tmp/*
41 ln -sf sysroot/tmp tmp
42
43 mkdir -p usr/rootdirs 50 mkdir -p usr/rootdirs
44 51
45 mv etc usr/ 52 mv etc usr/
@@ -48,13 +55,11 @@ IMAGE_CMD_ostree () {
48 mkdir -p usr/etc/tmpfiles.d 55 mkdir -p usr/etc/tmpfiles.d
49 tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf 56 tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf
50 echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} 57 echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf}
51 echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf}
52 else 58 else
53 mkdir -p usr/etc/init.d 59 mkdir -p usr/etc/init.d
54 tmpfiles_conf=usr/etc/init.d/tmpfiles.sh 60 tmpfiles_conf=usr/etc/init.d/tmpfiles.sh
55 echo '#!/bin/sh' > ${tmpfiles_conf} 61 echo '#!/bin/sh' > ${tmpfiles_conf}
56 echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} 62 echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf}
57 echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf}
58 63
59 ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh 64 ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh
60 fi 65 fi
@@ -63,13 +68,11 @@ IMAGE_CMD_ostree () {
63 mkdir -p usr/share/sota/ 68 mkdir -p usr/share/sota/
64 echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname 69 echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname
65 70
66 # Preserve data in /home to be later copied to /sysroot/home by sysroot 71 # home directories get copied from the OE root later to the final sysroot
67 # generating procedure 72 # Create a symlink to var/rootdirs/home to make sure the OSTree deployment
68 mkdir -p usr/homedirs 73 # redirects /home to /var/rootdirs/home.
69 if [ -d "home" ] && [ ! -L "home" ]; then 74 rm -rf home/
70 mv home usr/homedirs/home 75 ln -sf var/rootdirs/home home
71 ln -sf var/rootdirs/home home
72 fi
73 76
74 # Move persistent directories to /var 77 # Move persistent directories to /var
75 dirs="opt mnt media srv" 78 dirs="opt mnt media srv"
@@ -137,7 +140,7 @@ IMAGE_CMD_ostree () {
137 checksum=$(sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " ") 140 checksum=$(sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " ")
138 touch boot/initramfs-${checksum} 141 touch boot/initramfs-${checksum}
139 else 142 else
140 if [ "${OSTREE_DEPLOY_DEVICETREE}" = "1" ] && [ -n "${KERNEL_DEVICETREE}" ]; then 143 if [ ${@ oe.types.boolean('${OSTREE_DEPLOY_DEVICETREE}')} = True ] && [ -n "${KERNEL_DEVICETREE}" ]; then
141 checksum=$(cat ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.${INITRAMFS_FSTYPES} ${KERNEL_DEVICETREE} | sha256sum | cut -f 1 -d " ") 144 checksum=$(cat ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.${INITRAMFS_FSTYPES} ${KERNEL_DEVICETREE} | sha256sum | cut -f 1 -d " ")
142 for DTS_FILE in ${KERNEL_DEVICETREE}; do 145 for DTS_FILE in ${KERNEL_DEVICETREE}; do
143 DTS_FILE_BASENAME=$(basename ${DTS_FILE}) 146 DTS_FILE_BASENAME=$(basename ${DTS_FILE})
@@ -164,25 +167,20 @@ IMAGE_CMD_ostreecommit () {
164 fi 167 fi
165 168
166 # Commit the result 169 # Commit the result
167 ostree --repo=${OSTREE_REPO} commit \ 170 ostree_target_hash=$(ostree --repo=${OSTREE_REPO} commit \
168 --tree=dir=${OSTREE_ROOTFS} \ 171 --tree=dir=${OSTREE_ROOTFS} \
169 --skip-if-unchanged \ 172 --skip-if-unchanged \
170 --branch=${OSTREE_BRANCHNAME} \ 173 --branch=${OSTREE_BRANCHNAME} \
171 --subject="${OSTREE_COMMIT_SUBJECT}" \ 174 --subject="${OSTREE_COMMIT_SUBJECT}" \
172 --body="${OSTREE_COMMIT_BODY}" \ 175 --body="${OSTREE_COMMIT_BODY}" \
173 --add-metadata-string=version="${OSTREE_COMMIT_VERSION}" \ 176 --add-metadata-string=version="${OSTREE_COMMIT_VERSION}" \
174 --bind-ref="${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}" 177 ${EXTRA_OSTREE_COMMIT})
175 178
176 if [ "${OSTREE_UPDATE_SUMMARY}" = "1" ]; then 179 echo $ostree_target_hash > ${WORKDIR}/ostree_manifest
180
181 if [ ${@ oe.types.boolean('${OSTREE_UPDATE_SUMMARY}')} = True ]; then
177 ostree --repo=${OSTREE_REPO} summary -u 182 ostree --repo=${OSTREE_REPO} summary -u
178 fi 183 fi
179
180 # To enable simultaneous bitbaking of two images with the same branch name,
181 # create a new ref in the repo using the basename of the image. (This first
182 # requires deleting it if it already exists.) Fixes OTA-2211.
183 ostree --repo=${OSTREE_REPO} refs --delete ${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}
184 ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME})
185 ostree --repo=${OSTREE_REPO} refs --create=${OSTREE_BRANCHNAME}-${IMAGE_BASENAME} ${ostree_target_hash}
186} 184}
187 185
188IMAGE_TYPEDEP_ostreepush = "ostreecommit" 186IMAGE_TYPEDEP_ostreepush = "ostreecommit"
@@ -197,7 +195,7 @@ IMAGE_CMD_ostreepush () {
197 195
198 if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then 196 if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then
199 if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then 197 if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then
200 garage-push -vv --repo=${OSTREE_REPO} \ 198 garage-push --loglevel 0 --repo=${OSTREE_REPO} \
201 --ref=${OSTREE_BRANCHNAME} \ 199 --ref=${OSTREE_BRANCHNAME} \
202 --credentials=${SOTA_PACKED_CREDENTIALS} \ 200 --credentials=${SOTA_PACKED_CREDENTIALS} \
203 --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt \ 201 --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt \
@@ -232,7 +230,7 @@ IMAGE_CMD_garagesign () {
232 --home-dir ${GARAGE_SIGN_REPO} \ 230 --home-dir ${GARAGE_SIGN_REPO} \
233 --credentials ${SOTA_PACKED_CREDENTIALS} 231 --credentials ${SOTA_PACKED_CREDENTIALS}
234 232
235 ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}) 233 ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest)
236 234
237 # Use OSTree target hash as version if none was provided by the user 235 # Use OSTree target hash as version if none was provided by the user
238 target_version=${ostree_target_hash} 236 target_version=${ostree_target_hash}
@@ -308,7 +306,7 @@ IMAGE_CMD_garagecheck () {
308 # if credentials are issued by a server that doesn't support offline signing, exit silently 306 # if credentials are issued by a server that doesn't support offline signing, exit silently
309 unzip -p ${SOTA_PACKED_CREDENTIALS} root.json targets.pub targets.sec tufrepo.url 2>&1 >/dev/null || exit 0 307 unzip -p ${SOTA_PACKED_CREDENTIALS} root.json targets.pub targets.sec tufrepo.url 2>&1 >/dev/null || exit 0
310 308
311 ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}) 309 ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest)
312 310
313 garage-check --ref=${ostree_target_hash} \ 311 garage-check --ref=${ostree_target_hash} \
314 --credentials=${SOTA_PACKED_CREDENTIALS} \ 312 --credentials=${SOTA_PACKED_CREDENTIALS} \
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass
index 2cc8913..a8a19b5 100644
--- a/classes/image_types_ota.bbclass
+++ b/classes/image_types_ota.bbclass
@@ -45,14 +45,17 @@ do_image_ota[cleandirs] = "${OTA_SYSROOT}"
45do_image_ota[depends] = "${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER') == 'grub' else ''} \ 45do_image_ota[depends] = "${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER') == 'grub' else ''} \
46 ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER') == 'u-boot' else ''}" 46 ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER') == 'u-boot' else ''}"
47IMAGE_CMD_ota () { 47IMAGE_CMD_ota () {
48 export OSTREE_BOOT_PARTITION=${OSTREE_BOOT_PARTITION} 48 ostree admin --sysroot=${OTA_SYSROOT} init-fs --modern ${OTA_SYSROOT}
49
50 ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT}
51 ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} 49 ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME}
50
51 # Preparation required to steer ostree bootloader detection
52 mkdir -p ${OTA_SYSROOT}/boot/loader.0 52 mkdir -p ${OTA_SYSROOT}/boot/loader.0
53 ln -s loader.0 ${OTA_SYSROOT}/boot/loader 53 ln -s loader.0 ${OTA_SYSROOT}/boot/loader
54 54
55 if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then 55 if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then
56 # Used by ostree-grub-generator called by the ostree binary
57 export OSTREE_BOOT_PARTITION=${OSTREE_BOOT_PARTITION}
58
56 mkdir -p ${OTA_SYSROOT}/boot/grub2 59 mkdir -p ${OTA_SYSROOT}/boot/grub2
57 ln -s ../loader/grub.cfg ${OTA_SYSROOT}/boot/grub2/grub.cfg 60 ln -s ../loader/grub.cfg ${OTA_SYSROOT}/boot/grub2/grub.cfg
58 elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then 61 elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then
@@ -61,15 +64,25 @@ IMAGE_CMD_ota () {
61 bbfatal "Invalid bootloader: ${OSTREE_BOOTLOADER}" 64 bbfatal "Invalid bootloader: ${OSTREE_BOOTLOADER}"
62 fi 65 fi
63 66
64 ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}-${IMAGE_BASENAME}) 67 ostree_target_hash=$(cat ${WORKDIR}/ostree_manifest)
65 68
69 # Use OSTree hash to avoid any potential race conditions between
70 # multiple builds accessing the same ${OSTREE_REPO}.
66 ostree --repo=${OTA_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} 71 ostree --repo=${OTA_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash}
67 kargs_list="" 72 kargs_list=""
68 for arg in ${OSTREE_KERNEL_ARGS}; do 73 for arg in ${OSTREE_KERNEL_ARGS}; do
69 kargs_list="${kargs_list} --karg-append=$arg" 74 kargs_list="${kargs_list} --karg-append=$arg"
70 done 75 done
71 76
72 ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} 77 # Create the same reference on the device we use in the archive OSTree
78 # repo in ${OSTREE_REPO}. This reference will show up when showing the
79 # deployment on the device:
80 # ostree admin status
81 # If a remote with the name ${OSTREE_OSNAME} is configured, this also
82 # will allow to use:
83 # ostree admin upgrade
84 ostree --repo=${OTA_SYSROOT}/ostree/repo refs --create=${OSTREE_OSNAME}:${OSTREE_BRANCHNAME} ${ostree_target_hash}
85 ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${OSTREE_OSNAME}:${OSTREE_BRANCHNAME}
73 86
74 cp -a ${IMAGE_ROOTFS}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true 87 cp -a ${IMAGE_ROOTFS}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true
75 # Create /var/sota if it doesn't exist yet 88 # Create /var/sota if it doesn't exist yet
@@ -77,8 +90,11 @@ IMAGE_CMD_ota () {
77 # Ensure the permissions are correctly set 90 # Ensure the permissions are correctly set
78 chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota 91 chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota
79 92
80 cp -a ${OSTREE_ROOTFS}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true 93 cp -a ${IMAGE_ROOTFS}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true
81 cp -a ${OSTREE_ROOTFS}/usr/homedirs/home ${OTA_SYSROOT}/ || true 94
95 mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/rootdirs
96 cp -a ${IMAGE_ROOTFS}/home ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/rootdirs/home || true
97
82 # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) 98 # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local)
83 install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local 99 install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local
84 # Set package version for the first deployment 100 # Set package version for the first deployment
diff --git a/classes/sota_sanity.bbclass b/classes/sota_sanity.bbclass
index 74973eb..02ca2e7 100644
--- a/classes/sota_sanity.bbclass
+++ b/classes/sota_sanity.bbclass
@@ -1,5 +1,12 @@
1# Sanity check the sota setup for common misconfigurations 1# Sanity check the sota setup for common misconfigurations
2 2
3def sota_check_boolean_variable(var, d):
4 try:
5 oe.types.boolean(d.getVar(var))
6 except:
7 return False
8 return True
9
3def sota_check_overrides(status, d): 10def sota_check_overrides(status, d):
4 for var in (d.getVar('SOTA_OVERRIDES_BLACKLIST') or "").split(): 11 for var in (d.getVar('SOTA_OVERRIDES_BLACKLIST') or "").split():
5 if var in d.getVar('OVERRIDES').split(':'): 12 if var in d.getVar('OVERRIDES').split(':'):
@@ -47,14 +54,14 @@ def sota_check_variables_validity(status, d):
47 path = os.path.abspath(credentials) 54 path = os.path.abspath(credentials)
48 if not os.path.exists(path): 55 if not os.path.exists(path):
49 status.addresult("SOTA_PACKED_CREDENTIALS is not set correctly. The zipped credentials file does not exist.\n") 56 status.addresult("SOTA_PACKED_CREDENTIALS is not set correctly. The zipped credentials file does not exist.\n")
50 if d.getVar("OSTREE_UPDATE_SUMMARY") and d.getVar("OSTREE_UPDATE_SUMMARY") not in ("0", "1", ""): 57 if not sota_check_boolean_variable("OSTREE_UPDATE_SUMMARY", d):
51 status.addresult("OSTREE_UPDATE_SUMMARY should be set to 0 or 1.\n") 58 status.addresult("OSTREE_UPDATE_SUMMARY (=%s) should be set to yes/y/true/t/1 or no/n/false/f/0.\n" % d.getVar("OSTREE_UPDATE_SUMMARY"))
52 if d.getVar("OSTREE_DEPLOY_DEVICETREE") and d.getVar("OSTREE_DEPLOY_DEVICETREE") not in ("0", "1", ""): 59 if not sota_check_boolean_variable("OSTREE_DEPLOY_DEVICETREE", d):
53 status.addresult("OSTREE_DEPLOY_DEVICETREE should be set to 0 or 1.\n") 60 status.addresult("OSTREE_DEPLOY_DEVICETREE (=%s) should be set to yes/y/true/t/1 or no/n/false/f/0.\n" % d.getVar("OSTREE_DEPLOY_DEVICETREE"))
54 if d.getVar("GARAGE_SIGN_AUTOVERSION") and d.getVar("GARAGE_SIGN_AUTOVERSION") not in ("0", "1", ""): 61 if not sota_check_boolean_variable("GARAGE_SIGN_AUTOVERSION", d):
55 status.addresult("GARAGE_SIGN_AUTOVERSION should be set to 0 or 1.\n") 62 status.addresult("GARAGE_SIGN_AUTOVERSION (=%s) should be set to yes/y/true/t/1 or no/n/false/f/0.\n" % d.getVar("GARAGE_SIGN_AUTOVERSION"))
56 if d.getVar("SOTA_DEPLOY_CREDENTIALS") and d.getVar("SOTA_DEPLOY_CREDENTIALS") not in ("0", "1", ""): 63 if not sota_check_boolean_variable("SOTA_DEPLOY_CREDENTIALS", d):
57 status.addresult("SOTA_DEPLOY_CREDENTIALS should be set to 0 or 1.\n") 64 status.addresult("SOTA_DEPLOY_CREDENTIALS (=%s) should be set to yes/y/true/t/1 or no/n/false/f/0.\n" % d.getVar("SOTA_DEPLOY_CREDENTIALS"))
58 65
59def sota_raise_sanity_error(msg, d): 66def sota_raise_sanity_error(msg, d):
60 if d.getVar("SANITY_USE_EVENTS") == "1": 67 if d.getVar("SANITY_USE_EVENTS") == "1":