diff options
author | Leon Anavi <leon.anavi@konsulko.com> | 2019-01-02 19:01:34 +0200 |
---|---|---|
committer | Leon Anavi <leon.anavi@konsulko.com> | 2019-01-02 19:01:34 +0200 |
commit | dad9579e2c1333f3a72ff9a98e06705a61e546c1 (patch) | |
tree | ce222efcaa82f48924dd0facc82c6fabcb46fdbf | |
parent | f937a223136ec2e1f7699dd6621539aca950d633 (diff) | |
download | meta-updater-dad9579e2c1333f3a72ff9a98e06705a61e546c1.tar.gz |
classes: Backporting classes from Sumo
Backport SOTA specific classes needed for latest version of
Aktualizr from branch Sumo to Morty.
Signed-off-by: Leon Anavi <leon.anavi@konsulko.com>
-rw-r--r-- | classes/image_repo_manifest.bbclass | 23 | ||||
-rw-r--r-- | classes/image_types_ostree.bbclass | 411 | ||||
-rw-r--r-- | classes/image_types_ota.bbclass | 41 | ||||
-rw-r--r-- | classes/sota.bbclass | 30 |
4 files changed, 313 insertions, 192 deletions
diff --git a/classes/image_repo_manifest.bbclass b/classes/image_repo_manifest.bbclass new file mode 100644 index 0000000..c2e7056 --- /dev/null +++ b/classes/image_repo_manifest.bbclass | |||
@@ -0,0 +1,23 @@ | |||
1 | # Writes the repo manifest to the target filesystem in /etc/manifest.xml | ||
2 | # | ||
3 | # Author: Phil Wise <phil@advancedtelematic.com> | ||
4 | # Usage: add "inherit image_repo_manifest" to your image file | ||
5 | # To reproduce a build, copy the /etc/manifest.xml to .repo/manifests/yourname.xml | ||
6 | # then run: | ||
7 | # repo init -m yourname.xml | ||
8 | # repo sync | ||
9 | # For more information, see: | ||
10 | # https://web.archive.org/web/20161224194009/https://wiki.cyanogenmod.org/w/Doc:_Using_manifests | ||
11 | |||
12 | HOSTTOOLS_NONFATAL += " repo " | ||
13 | |||
14 | # Write build information to target filesystem | ||
15 | buildinfo_manifest () { | ||
16 | if [ $(which repo) ]; then | ||
17 | repo manifest --revision-as-HEAD -o ${IMAGE_ROOTFS}${sysconfdir}/manifest.xml || bbwarn "Android repo tool failed to run; manifest not copied" | ||
18 | else | ||
19 | bbwarn "Android repo tool not found; manifest not copied." | ||
20 | fi | ||
21 | } | ||
22 | |||
23 | IMAGE_PREPROCESS_COMMAND += "buildinfo_manifest;" | ||
diff --git a/classes/image_types_ostree.bbclass b/classes/image_types_ostree.bbclass index 29f267d..0acc786 100644 --- a/classes/image_types_ostree.bbclass +++ b/classes/image_types_ostree.bbclass | |||
@@ -1,207 +1,274 @@ | |||
1 | # OSTree deployment | 1 | # OSTree deployment |
2 | 2 | ||
3 | inherit image | 3 | do_image_ostree[depends] += "ostree-native:do_populate_sysroot \ |
4 | 4 | openssl-native:do_populate_sysroot \ | |
5 | IMAGE_DEPENDS_ostree = "ostree-native:do_populate_sysroot \ | 5 | coreutils-native:do_populate_sysroot \ |
6 | openssl-native:do_populate_sysroot \ | 6 | unzip-native:do_populate_sysroot \ |
7 | zip-native:do_populate_sysroot \ | 7 | virtual/kernel:do_deploy \ |
8 | virtual/kernel:do_deploy \ | 8 | ${OSTREE_INITRAMFS_IMAGE}:do_image_complete" |
9 | ${OSTREE_INITRAMFS_IMAGE}:do_image_complete" | 9 | do_image_ostree[lockfiles] += "${OSTREE_REPO}/ostree.lock" |
10 | 10 | ||
11 | export OSTREE_REPO | 11 | export OSTREE_REPO |
12 | export OSTREE_BRANCHNAME | 12 | export OSTREE_BRANCHNAME |
13 | export GARAGE_TARGET_NAME | ||
13 | 14 | ||
14 | RAMDISK_EXT ?= ".ext4.gz" | 15 | RAMDISK_EXT ?= ".${OSTREE_INITRAMFS_FSTYPES}" |
15 | RAMDISK_EXT_arm ?= ".ext4.gz.u-boot" | ||
16 | 16 | ||
17 | OSTREE_KERNEL ??= "${KERNEL_IMAGETYPE}" | 17 | OSTREE_KERNEL ??= "${KERNEL_IMAGETYPE}" |
18 | 18 | ||
19 | export SYSTEMD_USED = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', '', d)}" | 19 | OSTREE_COMMIT_SUBJECT ??= "Commit-id: ${IMAGE_NAME}" |
20 | OSTREE_COMMIT_BODY ??= "" | ||
21 | OSTREE_UPDATE_SUMMARY ??= "0" | ||
22 | |||
23 | export SYSTEMD_USED = "${@oe.utils.ifelse(d.getVar('VIRTUAL-RUNTIME_init_manager', True) == 'systemd', 'true', '')}" | ||
20 | 24 | ||
21 | IMAGE_CMD_ostree () { | 25 | IMAGE_CMD_ostree () { |
22 | if [ -z "$OSTREE_REPO" ]; then | 26 | if [ -z "$OSTREE_REPO" ]; then |
23 | bbfatal "OSTREE_REPO should be set in your local.conf" | 27 | bbfatal "OSTREE_REPO should be set in your local.conf" |
24 | fi | ||
25 | |||
26 | if [ -z "$OSTREE_BRANCHNAME" ]; then | ||
27 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | ||
28 | fi | ||
29 | |||
30 | OSTREE_ROOTFS=`mktemp -du ${WORKDIR}/ostree-root-XXXXX` | ||
31 | cp -a ${IMAGE_ROOTFS} ${OSTREE_ROOTFS} | ||
32 | chmod a+rx ${OSTREE_ROOTFS} | ||
33 | sync | ||
34 | |||
35 | cd ${OSTREE_ROOTFS} | ||
36 | |||
37 | # Create sysroot directory to which physical sysroot will be mounted | ||
38 | mkdir sysroot | ||
39 | ln -sf sysroot/ostree ostree | ||
40 | |||
41 | rm -rf tmp/* | ||
42 | ln -sf sysroot/tmp tmp | ||
43 | |||
44 | mkdir -p usr/rootdirs | ||
45 | |||
46 | mv etc usr/ | ||
47 | # Implement UsrMove | ||
48 | dirs="bin sbin lib" | ||
49 | |||
50 | for dir in ${dirs} ; do | ||
51 | if [ -d ${dir} ] && [ ! -L ${dir} ] ; then | ||
52 | mv ${dir} usr/rootdirs/ | ||
53 | rm -rf ${dir} | ||
54 | ln -sf usr/rootdirs/${dir} ${dir} | ||
55 | fi | ||
56 | done | ||
57 | |||
58 | if [ -n "$SYSTEMD_USED" ]; then | ||
59 | mkdir -p usr/etc/tmpfiles.d | ||
60 | tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf | ||
61 | echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} | ||
62 | echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} | ||
63 | else | ||
64 | mkdir -p usr/etc/init.d | ||
65 | tmpfiles_conf=usr/etc/init.d/tmpfiles.sh | ||
66 | echo '#!/bin/sh' > ${tmpfiles_conf} | ||
67 | echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} | ||
68 | echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} | ||
69 | |||
70 | ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh | ||
71 | fi | ||
72 | |||
73 | # Preserve OSTREE_BRANCHNAME for future information | ||
74 | mkdir -p usr/share/sota/ | ||
75 | echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname | ||
76 | |||
77 | # Preserve data in /home to be later copied to /sysroot/home by | ||
78 | # sysroot generating procedure | ||
79 | mkdir -p usr/homedirs | ||
80 | if [ -d "home" ] && [ ! -L "home" ]; then | ||
81 | mv home usr/homedirs/home | ||
82 | ln -sf var/rootdirs/home home | ||
83 | fi | ||
84 | |||
85 | # Move cron jobs if exist | ||
86 | if [ -d "var/spool/cron" ] && [ "$(ls -A var/spool/cron)" ] && | ||
87 | [ -d "usr/share/cronie-spool" ] ; then | ||
88 | mv var/spool/cron/* usr/share/cronie-spool/ | ||
89 | fi | 28 | fi |
90 | 29 | ||
91 | # Move persistent directories to /var | 30 | if [ -z "$OSTREE_BRANCHNAME" ]; then |
92 | dirs="opt mnt media srv" | 31 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" |
93 | |||
94 | for dir in ${dirs}; do | ||
95 | if [ -d ${dir} ] && [ ! -L ${dir} ]; then | ||
96 | if [ "$(ls -A $dir)" ]; then | ||
97 | bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" | ||
98 | fi | ||
99 | |||
100 | if [ -n "$SYSTEMD_USED" ]; then | ||
101 | echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} | ||
102 | else | ||
103 | echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} | ||
104 | fi | ||
105 | rm -rf ${dir} | ||
106 | ln -sf var/rootdirs/${dir} ${dir} | ||
107 | fi | ||
108 | done | ||
109 | |||
110 | if [ -d root ] && [ ! -L root ]; then | ||
111 | if [ "$(ls -A root)" ]; then | ||
112 | bberror "Data in /root directory is not preserved by OSTree." | ||
113 | fi | ||
114 | |||
115 | if [ -n "$SYSTEMD_USED" ]; then | ||
116 | echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} | ||
117 | else | ||
118 | echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} | ||
119 | fi | ||
120 | |||
121 | rm -rf root | ||
122 | ln -sf var/roothome root | ||
123 | fi | ||
124 | |||
125 | mkdir -p var/sota | ||
126 | |||
127 | if [ -n "${SOTA_AUTOPROVISION_CREDENTIALS}" ]; then | ||
128 | bbwarn "SOTA_AUTOPROVISION_CREDENTIALS are ignored. Please use SOTA_PACKED_CREDENTIALS" | ||
129 | fi | 32 | fi |
130 | if [ -n "${SOTA_AUTOPROVISION_URL}" ]; then | 33 | |
131 | bbwarn "SOTA_AUTOPROVISION_URL is ignored. Please use SOTA_PACKED_CREDENTIALS" | 34 | OSTREE_ROOTFS=`mktemp -du ${WORKDIR}/ostree-root-XXXXX` |
35 | cp -a ${IMAGE_ROOTFS} ${OSTREE_ROOTFS} | ||
36 | chmod a+rx ${OSTREE_ROOTFS} | ||
37 | sync | ||
38 | |||
39 | cd ${OSTREE_ROOTFS} | ||
40 | |||
41 | for d in var/*; do | ||
42 | if [ "${d}" != "var/local" ]; then | ||
43 | rm -rf ${d} | ||
44 | fi | ||
45 | done | ||
46 | |||
47 | # Create sysroot directory to which physical sysroot will be mounted | ||
48 | mkdir sysroot | ||
49 | ln -sf sysroot/ostree ostree | ||
50 | |||
51 | rm -rf tmp/* | ||
52 | ln -sf sysroot/tmp tmp | ||
53 | |||
54 | mkdir -p usr/rootdirs | ||
55 | |||
56 | mv etc usr/ | ||
57 | # Implement UsrMove | ||
58 | dirs="bin sbin lib" | ||
59 | |||
60 | for dir in ${dirs} ; do | ||
61 | if [ -d ${dir} ] && [ ! -L ${dir} ] ; then | ||
62 | mv ${dir} usr/rootdirs/ | ||
63 | rm -rf ${dir} | ||
64 | ln -sf usr/rootdirs/${dir} ${dir} | ||
65 | fi | ||
66 | done | ||
67 | |||
68 | if [ -n "$SYSTEMD_USED" ]; then | ||
69 | mkdir -p usr/etc/tmpfiles.d | ||
70 | tmpfiles_conf=usr/etc/tmpfiles.d/00ostree-tmpfiles.conf | ||
71 | echo "d /var/rootdirs 0755 root root -" >>${tmpfiles_conf} | ||
72 | echo "L /var/rootdirs/home - - - - /sysroot/home" >>${tmpfiles_conf} | ||
73 | else | ||
74 | mkdir -p usr/etc/init.d | ||
75 | tmpfiles_conf=usr/etc/init.d/tmpfiles.sh | ||
76 | echo '#!/bin/sh' > ${tmpfiles_conf} | ||
77 | echo "mkdir -p /var/rootdirs; chmod 755 /var/rootdirs" >> ${tmpfiles_conf} | ||
78 | echo "ln -sf /sysroot/home /var/rootdirs/home" >> ${tmpfiles_conf} | ||
79 | |||
80 | ln -s ../init.d/tmpfiles.sh usr/etc/rcS.d/S20tmpfiles.sh | ||
132 | fi | 81 | fi |
133 | if [ -n "${SOTA_AUTOPROVISION_URL_FILE}" ]; then | 82 | |
134 | bbwarn "SOTA_AUTOPROVISION_URL_FILE is ignored. Please use SOTA_PACKED_CREDENTIALS" | 83 | # Preserve OSTREE_BRANCHNAME for future information |
84 | mkdir -p usr/share/sota/ | ||
85 | echo -n "${OSTREE_BRANCHNAME}" > usr/share/sota/branchname | ||
86 | |||
87 | # Preserve data in /home to be later copied to /sysroot/home by sysroot | ||
88 | # generating procedure | ||
89 | mkdir -p usr/homedirs | ||
90 | if [ -d "home" ] && [ ! -L "home" ]; then | ||
91 | mv home usr/homedirs/home | ||
92 | ln -sf var/rootdirs/home home | ||
135 | fi | 93 | fi |
136 | if [ -n "${OSTREE_PUSH_CREDENTIALS}" ]; then | 94 | |
137 | bbwarn "OSTREE_PUSH_CREDENTIALS is ignored. Please use SOTA_PACKED_CREDENTIALS" | 95 | # Move persistent directories to /var |
96 | dirs="opt mnt media srv" | ||
97 | |||
98 | for dir in ${dirs}; do | ||
99 | if [ -d ${dir} ] && [ ! -L ${dir} ]; then | ||
100 | if [ "$(ls -A $dir)" ]; then | ||
101 | bbwarn "Data in /$dir directory is not preserved by OSTree. Consider moving it under /usr" | ||
102 | fi | ||
103 | |||
104 | if [ -n "$SYSTEMD_USED" ]; then | ||
105 | echo "d /var/rootdirs/${dir} 0755 root root -" >>${tmpfiles_conf} | ||
106 | else | ||
107 | echo "mkdir -p /var/rootdirs/${dir}; chown 755 /var/rootdirs/${dir}" >>${tmpfiles_conf} | ||
108 | fi | ||
109 | rm -rf ${dir} | ||
110 | ln -sf var/rootdirs/${dir} ${dir} | ||
111 | fi | ||
112 | done | ||
113 | |||
114 | if [ -d root ] && [ ! -L root ]; then | ||
115 | if [ "$(ls -A root)" ]; then | ||
116 | bberror "Data in /root directory is not preserved by OSTree." | ||
117 | exit 1 | ||
118 | fi | ||
119 | |||
120 | if [ -n "$SYSTEMD_USED" ]; then | ||
121 | echo "d /var/roothome 0755 root root -" >>${tmpfiles_conf} | ||
122 | else | ||
123 | echo "mkdir -p /var/roothome; chown 755 /var/roothome" >>${tmpfiles_conf} | ||
124 | fi | ||
125 | |||
126 | rm -rf root | ||
127 | ln -sf var/roothome root | ||
138 | fi | 128 | fi |
139 | 129 | ||
140 | # deploy SOTA credentials | 130 | # Creating boot directories is required for "ostree admin deploy" |
141 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then | ||
142 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then | ||
143 | cp ${SOTA_PACKED_CREDENTIALS} var/sota/sota_provisioning_credentials.zip | ||
144 | # Device should not be able to push data to treehub | ||
145 | zip -d var/sota/sota_provisioning_credentials.zip treehub.json | ||
146 | fi | ||
147 | fi | ||
148 | 131 | ||
149 | if [ -n "${SOTA_SECONDARY_ECUS}" ]; then | 132 | mkdir -p boot/loader.0 |
150 | cp ${SOTA_SECONDARY_ECUS} var/sota/ecus | 133 | mkdir -p boot/loader.1 |
151 | fi | 134 | ln -sf boot/loader.0 boot/loader |
152 | 135 | ||
153 | # Creating boot directories is required for "ostree admin deploy" | 136 | checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` |
154 | 137 | ||
155 | mkdir -p boot/loader.0 | 138 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} |
156 | mkdir -p boot/loader.1 | 139 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} |
157 | ln -sf boot/loader.0 boot/loader | ||
158 | 140 | ||
159 | checksum=`sha256sum ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} | cut -f 1 -d " "` | 141 | # Copy image manifest |
142 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest | ||
160 | 143 | ||
161 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_KERNEL} boot/vmlinuz-${checksum} | 144 | cd ${WORKDIR} |
162 | cp ${DEPLOY_DIR_IMAGE}/${OSTREE_INITRAMFS_IMAGE}-${MACHINE}${RAMDISK_EXT} boot/initramfs-${checksum} | ||
163 | 145 | ||
164 | # Copy image manifest | 146 | # Create a tarball that can be then commited to OSTree repo |
165 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest | 147 | OSTREE_TAR=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 |
148 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . | ||
149 | sync | ||
166 | 150 | ||
167 | cd ${WORKDIR} | 151 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 |
152 | ln -s ${IMAGE_NAME}.rootfs.ostree.tar.bz2 ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | ||
168 | 153 | ||
169 | # Create a tarball that can be then commited to OSTree repo | 154 | if ! ostree --repo=${OSTREE_REPO} refs 2>&1 > /dev/null; then |
170 | OSTREE_TAR=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 | 155 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 |
171 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . | 156 | fi |
172 | sync | ||
173 | 157 | ||
174 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | 158 | # Commit the result |
175 | ln -s ${IMAGE_NAME}.rootfs.ostree.tar.bz2 ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | 159 | ostree --repo=${OSTREE_REPO} commit \ |
176 | 160 | --tree=dir=${OSTREE_ROOTFS} \ | |
177 | if [ ! -d ${OSTREE_REPO} ]; then | 161 | --skip-if-unchanged \ |
178 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 | 162 | --branch=${OSTREE_BRANCHNAME} \ |
179 | fi | 163 | --subject="${OSTREE_COMMIT_SUBJECT}" \ |
164 | --body="${OSTREE_COMMIT_BODY}" | ||
180 | 165 | ||
181 | # Commit the result | 166 | if [ "${OSTREE_UPDATE_SUMMARY}" = "1" ]; then |
182 | ostree --repo=${OSTREE_REPO} commit \ | 167 | ostree --repo=${OSTREE_REPO} summary -u |
183 | --tree=dir=${OSTREE_ROOTFS} \ | 168 | fi |
184 | --skip-if-unchanged \ | ||
185 | --branch=${OSTREE_BRANCHNAME} \ | ||
186 | --subject="Commit-id: ${IMAGE_NAME}" | ||
187 | 169 | ||
188 | rm -rf ${OSTREE_ROOTFS} | 170 | rm -rf ${OSTREE_ROOTFS} |
189 | } | 171 | } |
190 | 172 | ||
191 | IMAGE_TYPEDEP_ostreepush = "ostree" | 173 | IMAGE_TYPEDEP_ostreepush = "ostree" |
192 | IMAGE_DEPENDS_ostreepush = "sota-tools-native:do_populate_sysroot" | 174 | do_image_ostreepush[depends] += "aktualizr-native:do_populate_sysroot ca-certificates-native:do_populate_sysroot" |
193 | IMAGE_CMD_ostreepush () { | 175 | IMAGE_CMD_ostreepush () { |
194 | # Print warnings if credetials are not set or if the file has not been found. | 176 | # Print warnings if credetials are not set or if the file has not been found. |
195 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then | 177 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then |
196 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then | 178 | if [ -e ${SOTA_PACKED_CREDENTIALS} ]; then |
197 | garage-push --repo=${OSTREE_REPO} \ | 179 | garage-push --repo=${OSTREE_REPO} \ |
198 | --ref=${OSTREE_BRANCHNAME} \ | 180 | --ref=${OSTREE_BRANCHNAME} \ |
199 | --credentials=${SOTA_PACKED_CREDENTIALS} \ | 181 | --credentials=${SOTA_PACKED_CREDENTIALS} \ |
200 | --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt | 182 | --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt |
201 | else | ||
202 | bbwarn "SOTA_PACKED_CREDENTIALS file does not exist." | ||
203 | fi | ||
204 | else | 183 | else |
205 | bbwarn "SOTA_PACKED_CREDENTIALS not set. Please add SOTA_PACKED_CREDENTIALS." | 184 | bbwarn "SOTA_PACKED_CREDENTIALS file does not exist." |
206 | fi | 185 | fi |
186 | else | ||
187 | bbwarn "SOTA_PACKED_CREDENTIALS not set. Please add SOTA_PACKED_CREDENTIALS." | ||
188 | fi | ||
189 | } | ||
190 | |||
191 | IMAGE_TYPEDEP_garagesign = "ostreepush" | ||
192 | do_image_garagesign[depends] += "aktualizr-native:do_populate_sysroot" | ||
193 | IMAGE_CMD_garagesign () { | ||
194 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then | ||
195 | # if credentials are issued by a server that doesn't support offline signing, exit silently | ||
196 | unzip -p ${SOTA_PACKED_CREDENTIALS} root.json targets.pub targets.sec tufrepo.url 2>&1 >/dev/null || exit 0 | ||
197 | |||
198 | java_version=$( java -version 2>&1 | awk -F '"' '/version/ {print $2}' ) | ||
199 | if [ "${java_version}" = "" ]; then | ||
200 | bberror "Java is required for synchronization with update backend, but is not installed on the host machine" | ||
201 | exit 1 | ||
202 | elif [ "${java_version}" \< "1.8" ]; then | ||
203 | bberror "Java version >= 8 is required for synchronization with update backend" | ||
204 | exit 1 | ||
205 | fi | ||
206 | |||
207 | rm -rf ${GARAGE_SIGN_REPO} | ||
208 | garage-sign init --repo tufrepo \ | ||
209 | --home-dir ${GARAGE_SIGN_REPO} \ | ||
210 | --credentials ${SOTA_PACKED_CREDENTIALS} | ||
211 | |||
212 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
213 | |||
214 | # Use OSTree target hash as version if none was provided by the user | ||
215 | target_version=${ostree_target_hash} | ||
216 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
217 | target_version=${GARAGE_TARGET_VERSION} | ||
218 | bbwarn "Target version is overriden with GARAGE_TARGET_VERSION variable. It is a dangerous operation, make sure you've read the respective secion in meta-updater/README.adoc" | ||
219 | elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then | ||
220 | target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version") | ||
221 | bbwarn "Target version is overriden with target_version file. It is a dangerous operation, make sure you've read the respective secion in meta-updater/README.adoc" | ||
222 | fi | ||
223 | |||
224 | # Push may fail due to race condition when multiple build machines try to push simultaneously | ||
225 | # in which case targets.json should be pulled again and the whole procedure repeated | ||
226 | push_success=0 | ||
227 | for push_retries in $( seq 3 ); do | ||
228 | garage-sign targets pull --repo tufrepo \ | ||
229 | --home-dir ${GARAGE_SIGN_REPO} | ||
230 | garage-sign targets add --repo tufrepo \ | ||
231 | --home-dir ${GARAGE_SIGN_REPO} \ | ||
232 | --name ${GARAGE_TARGET_NAME} \ | ||
233 | --format OSTREE \ | ||
234 | --version ${target_version} \ | ||
235 | --length 0 \ | ||
236 | --url "${GARAGE_TARGET_URL}" \ | ||
237 | --sha256 ${ostree_target_hash} \ | ||
238 | --hardwareids ${SOTA_HARDWARE_ID} | ||
239 | garage-sign targets sign --repo tufrepo \ | ||
240 | --home-dir ${GARAGE_SIGN_REPO} \ | ||
241 | --key-name=targets | ||
242 | errcode=0 | ||
243 | garage-sign targets push --repo tufrepo \ | ||
244 | --home-dir ${GARAGE_SIGN_REPO} || errcode=$? | ||
245 | if [ "$errcode" -eq "0" ]; then | ||
246 | push_success=1 | ||
247 | break | ||
248 | else | ||
249 | bbwarn "Push to garage repository has failed, retrying" | ||
250 | fi | ||
251 | done | ||
252 | rm -rf ${GARAGE_SIGN_REPO} | ||
253 | |||
254 | if [ "$push_success" -ne "1" ]; then | ||
255 | bberror "Couldn't push to garage repository" | ||
256 | exit 1 | ||
257 | fi | ||
258 | fi | ||
259 | } | ||
260 | |||
261 | IMAGE_TYPEDEP_garagecheck = "ostreepush garagesign" | ||
262 | do_image_garagecheck[depends] += "aktualizr-native:do_populate_sysroot" | ||
263 | IMAGE_CMD_garagecheck () { | ||
264 | if [ -n "${SOTA_PACKED_CREDENTIALS}" ]; then | ||
265 | # if credentials are issued by a server that doesn't support offline signing, exit silently | ||
266 | unzip -p ${SOTA_PACKED_CREDENTIALS} root.json targets.pub targets.sec tufrepo.url 2>&1 >/dev/null || exit 0 | ||
267 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
268 | |||
269 | garage-check --ref=${ostree_target_hash} \ | ||
270 | --credentials=${SOTA_PACKED_CREDENTIALS} \ | ||
271 | --cacert=${STAGING_ETCDIR_NATIVE}/ssl/certs/ca-certificates.crt | ||
272 | fi | ||
207 | } | 273 | } |
274 | # vim:set ts=4 sw=4 sts=4 expandtab: | ||
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 09c30ff..df3bc7c 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass | |||
@@ -7,11 +7,7 @@ | |||
7 | # boot scripts, kernel and initramfs images | 7 | # boot scripts, kernel and initramfs images |
8 | # | 8 | # |
9 | 9 | ||
10 | inherit image | 10 | do_image_otaimg[depends] += "e2fsprogs-native:do_populate_sysroot \ |
11 | |||
12 | OSTREE_BOOTLOADER ??= 'u-boot' | ||
13 | |||
14 | IMAGE_DEPENDS_otaimg = "e2fsprogs-native:do_populate_sysroot \ | ||
15 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ | 11 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ |
16 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" | 12 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" |
17 | 13 | ||
@@ -32,7 +28,7 @@ calculate_size () { | |||
32 | fi | 28 | fi |
33 | 29 | ||
34 | if [ "$SIZE" -lt "$MIN" ]; then | 30 | if [ "$SIZE" -lt "$MIN" ]; then |
35 | $SIZE=$MIN | 31 | SIZE=$MIN |
36 | fi | 32 | fi |
37 | 33 | ||
38 | SIZE=`expr $SIZE \+ $EXTRA` | 34 | SIZE=`expr $SIZE \+ $EXTRA` |
@@ -53,6 +49,8 @@ export OSTREE_BRANCHNAME | |||
53 | export OSTREE_REPO | 49 | export OSTREE_REPO |
54 | export OSTREE_BOOTLOADER | 50 | export OSTREE_BOOTLOADER |
55 | 51 | ||
52 | export GARAGE_TARGET_NAME | ||
53 | |||
56 | IMAGE_CMD_otaimg () { | 54 | IMAGE_CMD_otaimg () { |
57 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then | 55 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then |
58 | if [ -z "$OSTREE_REPO" ]; then | 56 | if [ -z "$OSTREE_REPO" ]; then |
@@ -67,7 +65,6 @@ IMAGE_CMD_otaimg () { | |||
67 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | 65 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" |
68 | fi | 66 | fi |
69 | 67 | ||
70 | |||
71 | PHYS_SYSROOT=`mktemp -d ${WORKDIR}/ota-sysroot-XXXXX` | 68 | PHYS_SYSROOT=`mktemp -d ${WORKDIR}/ota-sysroot-XXXXX` |
72 | 69 | ||
73 | ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} | 70 | ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} |
@@ -78,32 +75,48 @@ IMAGE_CMD_otaimg () { | |||
78 | 75 | ||
79 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then | 76 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then |
80 | mkdir -p ${PHYS_SYSROOT}/boot/grub2 | 77 | mkdir -p ${PHYS_SYSROOT}/boot/grub2 |
81 | touch ${PHYS_SYSROOT}/boot/grub2/grub.cfg | 78 | ln -s ../loader/grub.cfg ${PHYS_SYSROOT}/boot/grub2/grub.cfg |
82 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then | 79 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then |
83 | touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt | 80 | touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt |
84 | else | 81 | else |
85 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" | 82 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" |
86 | fi; | 83 | fi; |
87 | 84 | ||
88 | ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${OSTREE_BRANCHNAME} | 85 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) |
86 | |||
87 | ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} | ||
89 | export OSTREE_BOOT_PARTITION="/boot" | 88 | export OSTREE_BOOT_PARTITION="/boot" |
90 | kargs_list="" | 89 | kargs_list="" |
91 | for arg in ${OSTREE_KERNEL_ARGS}; do | 90 | for arg in ${OSTREE_KERNEL_ARGS}; do |
92 | kargs_list="${kargs_list} --karg-append=$arg" | 91 | kargs_list="${kargs_list} --karg-append=$arg" |
93 | done | 92 | done |
94 | 93 | ||
95 | ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${OSTREE_BRANCHNAME} | 94 | ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} |
96 | 95 | ||
97 | # Copy deployment /home and /var/sota to sysroot | 96 | # Copy deployment /home and /var/sota to sysroot |
98 | HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX` | 97 | HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX` |
99 | tar --xattrs --xattrs-include='*' -C ${HOME_TMP} -xf ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 ./usr/homedirs ./var/sota ./var/local || true | 98 | tar --xattrs --xattrs-include='*' -C ${HOME_TMP} -xf ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 ./usr/homedirs ./var/local || true |
100 | mv ${HOME_TMP}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | 99 | |
101 | mv ${HOME_TMP}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | 100 | cp -a ${IMAGE_ROOTFS}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true |
102 | # Create /var/sota if it doesn't exist yet | 101 | # Create /var/sota if it doesn't exist yet |
103 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota || true | 102 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota |
103 | # Ensure the permissions are correctly set | ||
104 | chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
105 | |||
106 | mv ${HOME_TMP}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
104 | mv ${HOME_TMP}/usr/homedirs/home ${PHYS_SYSROOT}/ || true | 107 | mv ${HOME_TMP}/usr/homedirs/home ${PHYS_SYSROOT}/ || true |
105 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | 108 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) |
106 | install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | 109 | install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local |
110 | # Set package version for the first deployment | ||
111 | target_version=${ostree_target_hash} | ||
112 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
113 | target_version=${GARAGE_TARGET_VERSION} | ||
114 | elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then | ||
115 | target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version") | ||
116 | fi | ||
117 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import | ||
118 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions | ||
119 | |||
107 | rm -rf ${HOME_TMP} | 120 | rm -rf ${HOME_TMP} |
108 | 121 | ||
109 | # Calculate image type | 122 | # Calculate image type |
diff --git a/classes/sota.bbclass b/classes/sota.bbclass index 5073e29..070fe72 100644 --- a/classes/sota.bbclass +++ b/classes/sota.bbclass | |||
@@ -5,25 +5,41 @@ python __anonymous() { | |||
5 | 5 | ||
6 | OVERRIDES .= "${@bb.utils.contains('DISTRO_FEATURES', 'sota', ':sota', '', d)}" | 6 | OVERRIDES .= "${@bb.utils.contains('DISTRO_FEATURES', 'sota', ':sota', '', d)}" |
7 | 7 | ||
8 | HOSTTOOLS_NONFATAL += "java" | ||
9 | |||
8 | SOTA_CLIENT ??= "aktualizr" | 10 | SOTA_CLIENT ??= "aktualizr" |
9 | IMAGE_INSTALL_append_sota = " ostree os-release ${SOTA_CLIENT}" | 11 | SOTA_CLIENT_PROV ??= "aktualizr-auto-prov" |
12 | SOTA_DEPLOY_CREDENTIALS ?= "1" | ||
13 | SOTA_HARDWARE_ID ??= "${MACHINE}" | ||
14 | |||
15 | IMAGE_INSTALL_append_sota = " ostree os-release ${SOTA_CLIENT} ${SOTA_CLIENT_PROV}" | ||
10 | IMAGE_CLASSES += " image_types_ostree image_types_ota" | 16 | IMAGE_CLASSES += " image_types_ostree image_types_ota" |
11 | IMAGE_FSTYPES += "${@bb.utils.contains('DISTRO_FEATURES', 'sota', 'ostreepush otaimg wic', ' ', d)}" | 17 | IMAGE_FSTYPES += "${@bb.utils.contains('DISTRO_FEATURES', 'sota', 'ostreepush garagesign garagecheck otaimg wic', ' ', d)}" |
18 | |||
19 | PACKAGECONFIG_append_pn-curl = " ssl" | ||
20 | PACKAGECONFIG_remove_pn-curl = "gnutls" | ||
12 | 21 | ||
13 | WKS_FILE_sota ?= "sdimage-sota.wks" | 22 | WKS_FILE_sota ?= "sdimage-sota.wks" |
14 | 23 | ||
15 | EXTRA_IMAGEDEPENDS_append_sota = " parted-native mtools-native dosfstools-native" | 24 | EXTRA_IMAGEDEPENDS_append_sota = " parted-native mtools-native dosfstools-native" |
16 | 25 | ||
26 | OSTREE_INITRAMFS_FSTYPES ??= 'ext4.gz' | ||
27 | |||
17 | # Please redefine OSTREE_REPO in order to have a persistent OSTree repo | 28 | # Please redefine OSTREE_REPO in order to have a persistent OSTree repo |
18 | OSTREE_REPO ?= "${DEPLOY_DIR_IMAGE}/ostree_repo" | 29 | OSTREE_REPO ?= "${DEPLOY_DIR_IMAGE}/ostree_repo" |
19 | # For UPTANE operation, OSTREE_BRANCHNAME must start with "${MACHINE}-" | 30 | OSTREE_BRANCHNAME ?= "${SOTA_HARDWARE_ID}" |
20 | OSTREE_BRANCHNAME ?= "${MACHINE}-ota" | ||
21 | OSTREE_OSNAME ?= "poky" | 31 | OSTREE_OSNAME ?= "poky" |
22 | OSTREE_INITRAMFS_IMAGE ?= "initramfs-ostree-image" | 32 | OSTREE_INITRAMFS_IMAGE ?= "initramfs-ostree-image" |
33 | OSTREE_BOOTLOADER ??= 'u-boot' | ||
34 | |||
35 | GARAGE_SIGN_REPO ?= "${DEPLOY_DIR_IMAGE}/garage_sign_repo" | ||
36 | GARAGE_SIGN_KEYNAME ?= "garage-key" | ||
37 | GARAGE_TARGET_NAME ?= "${OSTREE_BRANCHNAME}" | ||
38 | GARAGE_TARGET_VERSION ?= "" | ||
39 | GARAGE_TARGET_URL ?= "https://example.com/" | ||
23 | 40 | ||
24 | SOTA_MACHINE ??="none" | 41 | SOTA_MACHINE ??="none" |
25 | SOTA_MACHINE_raspberrypi2 ?= "raspberrypi" | 42 | SOTA_MACHINE_rpi ?= "raspberrypi" |
26 | SOTA_MACHINE_raspberrypi3 ?= "raspberrypi" | ||
27 | SOTA_MACHINE_porter ?= "porter" | 43 | SOTA_MACHINE_porter ?= "porter" |
28 | SOTA_MACHINE_m3ulcb = "m3ulcb" | 44 | SOTA_MACHINE_m3ulcb = "m3ulcb" |
29 | SOTA_MACHINE_intel-corei7-64 ?= "minnowboard" | 45 | SOTA_MACHINE_intel-corei7-64 ?= "minnowboard" |
@@ -31,3 +47,5 @@ SOTA_MACHINE_qemux86-64 ?= "qemux86-64" | |||
31 | SOTA_MACHINE_am335x-evm ?= "am335x-evm-wifi" | 47 | SOTA_MACHINE_am335x-evm ?= "am335x-evm-wifi" |
32 | 48 | ||
33 | inherit sota_${SOTA_MACHINE} | 49 | inherit sota_${SOTA_MACHINE} |
50 | |||
51 | inherit image_repo_manifest | ||