diff options
author | Ming Liu <liu.ming50@gmail.com> | 2018-11-20 09:03:25 +0100 |
---|---|---|
committer | Ming Liu <liu.ming50@gmail.com> | 2018-11-24 14:24:26 +0100 |
commit | e97975d6113ca1ffa6cbe9b005bd518bd146fd9c (patch) | |
tree | 0c1df1f626bfd3d1819661dda5fb6ff7c4877210 /classes/image_types_ota.bbclass | |
parent | f4cf0698a88631af150782dce9b3dafcb0dbc5d5 (diff) | |
download | meta-updater-e97975d6113ca1ffa6cbe9b005bd518bd146fd9c.tar.gz |
image_types_ostree/ota.bbclass: refactor ostree task
There are several flaws with ostree tasks, as follows:
- ${IMAGE_NAME}.rootfs.ostree.tar.bz2 is generated, but it's not being
used during ostree commit, so it should be removed if it's just a
intermittent artifact. Or if we intend to deploy this tar.bz2 file,
it should be tracked by sstate cache, that is to day, it should be
generated in ${IMGDEPLOYDIR} rather than in ${DEPLOY_DIR_IMAGE}.
- There are quite a few redundant code like mktemp/cd/rm a directory,
which can be replaced by setting 'dirs', 'cleandirs' varflags.
- There are some redundant variable check logic in image_types_ostree
and image_types_ota bbclass.
To fix the above, we make the following changes:
- Introduce a new conversion image type 'tar', it could convert ostree
and ota to ostree.tar, ota.tar, hence we can drop the code generating
ostree.tar.bz2 in image_types_ostree.bbclass, and also drop the
do_image_ota-tar task. To let this conversion type take effect, the
otasetup task needs to be changed to ota.
- Introduce BUILD_OSTREE_TARBALL variable, when being set to 1, a
ostree.tar.bz2 tarball would be built, BUILD_OSTREE_TARBALL defaults
to be 1, to be consistent with original behavior.
- Replace 'ota-tar ota-tar.xz' with ota.tar.xz in IMAGE_FSTYPES.
- Add a sanity check bbclass sota_sanity.bbclass, to ensure ostree or
ota is not in OVERRIDES, this is to prevent potential naming
pollution with other meta layers, and also check the required
variables are not empty. This sota_sanity.bbclass is a common class
that could be extended easily in furture, and one of its most
advantages is that all the check are done in bb.event.SanityCheck
event handler, so the end users could get the error message at very
beginning of the recipe parsing time.
Signed-off-by: Ming Liu <liu.ming50@gmail.com>
Diffstat (limited to 'classes/image_types_ota.bbclass')
-rw-r--r-- | classes/image_types_ota.bbclass | 60 |
1 files changed, 11 insertions, 49 deletions
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 79de909..09f1095 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass | |||
@@ -1,15 +1,9 @@ | |||
1 | # Image to use with u-boot as BIOS and OSTree deployment system | 1 | # Image to use with u-boot as BIOS and OSTree deployment system |
2 | 2 | ||
3 | #inherit image_types | ||
4 | |||
5 | # Boot filesystem size in MiB | 3 | # Boot filesystem size in MiB |
6 | # OSTree updates may require some space on boot file system for | 4 | # OSTree updates may require some space on boot file system for |
7 | # boot scripts, kernel and initramfs images | 5 | # boot scripts, kernel and initramfs images |
8 | # | 6 | # |
9 | |||
10 | |||
11 | do_image_ota_ext4[depends] += "e2fsprogs-native:do_populate_sysroot" | ||
12 | |||
13 | calculate_size () { | 7 | calculate_size () { |
14 | BASE=$1 | 8 | BASE=$1 |
15 | SCALE=$2 | 9 | SCALE=$2 |
@@ -44,26 +38,13 @@ calculate_size () { | |||
44 | } | 38 | } |
45 | 39 | ||
46 | OTA_SYSROOT = "${WORKDIR}/ota-sysroot" | 40 | OTA_SYSROOT = "${WORKDIR}/ota-sysroot" |
47 | 41 | OTA_IMAGE_ROOTFS_task-image-ota = "${OTA_SYSROOT}" | |
48 | ## Common OTA image setup | 42 | IMAGE_TYPEDEP_ota = "ostreecommit" |
49 | fakeroot do_otasetup () { | 43 | do_image_ota[dirs] = "${OTA_SYSROOT}" |
50 | 44 | do_image_ota[cleandirs] = "${OTA_SYSROOT}" | |
51 | if [ -z "$OSTREE_REPO" ]; then | 45 | do_image_ota[depends] = "${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ |
52 | bbfatal "OSTREE_REPO should be set in your local.conf" | 46 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" |
53 | fi | 47 | IMAGE_CMD_ota () { |
54 | |||
55 | if [ -z "$OSTREE_OSNAME" ]; then | ||
56 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | ||
57 | fi | ||
58 | |||
59 | if [ -z "$OSTREE_BRANCHNAME" ]; then | ||
60 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | ||
61 | fi | ||
62 | |||
63 | # HaX! Since we are using a peristent directory, we need to be sure to clean it on run. | ||
64 | mkdir -p ${OTA_SYSROOT} | ||
65 | rm -rf ${OTA_SYSROOT}/* | ||
66 | |||
67 | ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT} | 48 | ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT} |
68 | ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} | 49 | ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} |
69 | mkdir -p ${OTA_SYSROOT}/boot/loader.0 | 50 | mkdir -p ${OTA_SYSROOT}/boot/loader.0 |
@@ -88,19 +69,14 @@ fakeroot do_otasetup () { | |||
88 | 69 | ||
89 | ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} | 70 | ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} |
90 | 71 | ||
91 | # Copy deployment /home and /var/sota to sysroot | ||
92 | HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX` | ||
93 | |||
94 | tar --xattrs --xattrs-include='*' -C ${HOME_TMP} -xf ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 ./usr/homedirs ./var/local || true | ||
95 | |||
96 | cp -a ${IMAGE_ROOTFS}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | 72 | cp -a ${IMAGE_ROOTFS}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true |
97 | # Create /var/sota if it doesn't exist yet | 73 | # Create /var/sota if it doesn't exist yet |
98 | mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | 74 | mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota |
99 | # Ensure the permissions are correctly set | 75 | # Ensure the permissions are correctly set |
100 | chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | 76 | chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota |
101 | 77 | ||
102 | mv ${HOME_TMP}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | 78 | cp -a ${OSTREE_ROOTFS}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true |
103 | mv ${HOME_TMP}/usr/homedirs/home ${OTA_SYSROOT}/ || true | 79 | cp -a ${OSTREE_ROOTFS}/usr/homedirs/home ${OTA_SYSROOT}/ || true |
104 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | 80 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) |
105 | install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | 81 | install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local |
106 | # Set package version for the first deployment | 82 | # Set package version for the first deployment |
@@ -112,10 +88,10 @@ fakeroot do_otasetup () { | |||
112 | fi | 88 | fi |
113 | mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import | 89 | mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import |
114 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions | 90 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions |
115 | echo "All done. Cleaning up dir: ${HOME_TMP}" | ||
116 | rm -rf ${HOME_TMP} | ||
117 | } | 91 | } |
118 | 92 | ||
93 | IMAGE_TYPEDEP_ota-ext4 = "ota" | ||
94 | do_image_ota_ext4[depends] = "e2fsprogs-native:do_populate_sysroot" | ||
119 | IMAGE_CMD_ota-ext4 () { | 95 | IMAGE_CMD_ota-ext4 () { |
120 | # Calculate image type | 96 | # Calculate image type |
121 | OTA_ROOTFS_SIZE=$(calculate_size `du -ks $OTA_SYSROOT | cut -f 1` "${IMAGE_OVERHEAD_FACTOR}" "${IMAGE_ROOTFS_SIZE}" "${IMAGE_ROOTFS_MAXSIZE}" `expr ${IMAGE_ROOTFS_EXTRA_SPACE}` "${IMAGE_ROOTFS_ALIGNMENT}") | 97 | OTA_ROOTFS_SIZE=$(calculate_size `du -ks $OTA_SYSROOT | cut -f 1` "${IMAGE_OVERHEAD_FACTOR}" "${IMAGE_ROOTFS_SIZE}" "${IMAGE_ROOTFS_MAXSIZE}" `expr ${IMAGE_ROOTFS_EXTRA_SPACE}` "${IMAGE_ROOTFS_ALIGNMENT}") |
@@ -133,17 +109,3 @@ IMAGE_CMD_ota-ext4 () { | |||
133 | dd if=/dev/zero of=${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ota-ext4 seek=${OTA_ROOTFS_SIZE} count=$COUNT bs=1024 | 109 | dd if=/dev/zero of=${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ota-ext4 seek=${OTA_ROOTFS_SIZE} count=$COUNT bs=1024 |
134 | mkfs.ext4 -O ^64bit ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ota-ext4 -L otaroot -d ${OTA_SYSROOT} | 110 | mkfs.ext4 -O ^64bit ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ota-ext4 -L otaroot -d ${OTA_SYSROOT} |
135 | } | 111 | } |
136 | |||
137 | IMAGE_CMD_ota-tar () { | ||
138 | tar -cf ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.ota-tar -C ${OTA_SYSROOT} . | ||
139 | } | ||
140 | |||
141 | do_otasetup[doc] = "Sets up the base ota rootfs used for subsequent image generation" | ||
142 | do_otasetup[depends] += "virtual/fakeroot-native:do_populate_sysroot \ | ||
143 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ | ||
144 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" | ||
145 | |||
146 | addtask do_otasetup after do_image_ostree before do_image_ota_ext4 do_image_ota_tar | ||
147 | |||
148 | IMAGE_TYPEDEP_ota-ext4 = "ostree" | ||
149 | IMAGE_TYPEDEP_ota-tar = "ostree" | ||