diff options
author | Ben Clouser <ben.clouser@toradex.com> | 2018-06-29 17:43:39 -0700 |
---|---|---|
committer | Ben Clouser <ben.clouser@toradex.com> | 2018-06-29 17:43:39 -0700 |
commit | 850801c59cbe49e841650489508ae78fbe5a9e82 (patch) | |
tree | acb5becb49e6926988d05c820c6c9e74aab86a54 /classes | |
parent | cd97b4cd1e680b22afe62ebea2d8701b2f357098 (diff) | |
download | meta-updater-850801c59cbe49e841650489508ae78fbe5a9e82.tar.gz |
Adding support for creating an otaimg.tar file in addition to the ext4 image
Diffstat (limited to 'classes')
-rw-r--r-- | classes/image_types_ota.bbclass | 192 | ||||
-rw-r--r-- | classes/sota.bbclass | 7 |
2 files changed, 121 insertions, 78 deletions
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 9581971..99a2b63 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass | |||
@@ -7,7 +7,11 @@ | |||
7 | # boot scripts, kernel and initramfs images | 7 | # boot scripts, kernel and initramfs images |
8 | # | 8 | # |
9 | 9 | ||
10 | do_image_otaimg[depends] += "e2fsprogs-native:do_populate_sysroot \ | 10 | do_image_ota_ext4[depends] += "e2fsprogs-native:do_populate_sysroot \ |
11 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ | ||
12 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" | ||
13 | |||
14 | do_image_ota_tar[depends] += "e2fsprogs-native:do_populate_sysroot \ | ||
11 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ | 15 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ |
12 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" | 16 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" |
13 | 17 | ||
@@ -51,92 +55,128 @@ export OSTREE_BOOTLOADER | |||
51 | 55 | ||
52 | export GARAGE_TARGET_NAME | 56 | export GARAGE_TARGET_NAME |
53 | 57 | ||
54 | IMAGE_CMD_otaimg () { | 58 | export OTA_SYSROOT="${WORKDIR}/ota-sysroot" |
55 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then | ||
56 | if [ -z "$OSTREE_REPO" ]; then | ||
57 | bbfatal "OSTREE_REPO should be set in your local.conf" | ||
58 | fi | ||
59 | 59 | ||
60 | if [ -z "$OSTREE_OSNAME" ]; then | 60 | ## Common OTA image setup |
61 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | 61 | fakeroot do_otasetup () { |
62 | fi | 62 | |
63 | 63 | if [ -z "$OSTREE_REPO" ]; then | |
64 | if [ -z "$OSTREE_BRANCHNAME" ]; then | 64 | bbfatal "OSTREE_REPO should be set in your local.conf" |
65 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | 65 | fi |
66 | fi | ||
67 | 66 | ||
67 | if [ -z "$OSTREE_OSNAME" ]; then | ||
68 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | ||
69 | fi | ||
68 | 70 | ||
69 | PHYS_SYSROOT=`mktemp -d ${WORKDIR}/ota-sysroot-XXXXX` | 71 | if [ -z "$OSTREE_BRANCHNAME" ]; then |
70 | 72 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | |
71 | ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} | 73 | fi |
72 | ostree admin --sysroot=${PHYS_SYSROOT} os-init ${OSTREE_OSNAME} | ||
73 | |||
74 | mkdir -p ${PHYS_SYSROOT}/boot/loader.0 | ||
75 | ln -s loader.0 ${PHYS_SYSROOT}/boot/loader | ||
76 | |||
77 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then | ||
78 | mkdir -p ${PHYS_SYSROOT}/boot/grub2 | ||
79 | ln -s ../loader/grub.cfg ${PHYS_SYSROOT}/boot/grub2/grub.cfg | ||
80 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then | ||
81 | touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt | ||
82 | else | ||
83 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" | ||
84 | fi; | ||
85 | |||
86 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
87 | |||
88 | ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} | ||
89 | export OSTREE_BOOT_PARTITION="/boot" | ||
90 | kargs_list="" | ||
91 | for arg in ${OSTREE_KERNEL_ARGS}; do | ||
92 | kargs_list="${kargs_list} --karg-append=$arg" | ||
93 | done | ||
94 | |||
95 | ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} | ||
96 | |||
97 | # Copy deployment /home and /var/sota to sysroot | ||
98 | 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 | ||
100 | mv ${HOME_TMP}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
101 | mv ${HOME_TMP}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
102 | # Create /var/sota if it doesn't exist yet | ||
103 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota || true | ||
104 | # Ensure the permissions are correctly set | ||
105 | chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
106 | mv ${HOME_TMP}/usr/homedirs/home ${PHYS_SYSROOT}/ || true | ||
107 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | ||
108 | install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | ||
109 | # Set package version for the first deployment | ||
110 | target_version=${ostree_target_hash} | ||
111 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
112 | target_version=${GARAGE_TARGET_VERSION} | ||
113 | fi | ||
114 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/installed_versions | ||
115 | 74 | ||
116 | rm -rf ${HOME_TMP} | 75 | # HaX! Since we are using a peristent directory, we need to be sure to clean it on run. |
76 | mkdir -p ${OTA_SYSROOT} | ||
77 | rm -rf ${OTA_SYSROOT}/* | ||
78 | |||
79 | ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT} | ||
80 | ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} | ||
81 | mkdir -p ${OTA_SYSROOT}/boot/loader.0 | ||
82 | ln -s loader.0 ${OTA_SYSROOT}/boot/loader | ||
83 | |||
84 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then | ||
85 | mkdir -p ${OTA_SYSROOT}/boot/grub2 | ||
86 | ln -s ../loader/grub.cfg ${OTA_SYSROOT}/boot/grub2/grub.cfg | ||
87 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then | ||
88 | touch ${OTA_SYSROOT}/boot/loader/uEnv.txt | ||
89 | else | ||
90 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" | ||
91 | fi; | ||
92 | |||
93 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
94 | |||
95 | ostree --repo=${OTA_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} | ||
96 | export OSTREE_BOOT_PARTITION="/boot" | ||
97 | kargs_list="" | ||
98 | for arg in ${OSTREE_KERNEL_ARGS}; do | ||
99 | kargs_list="${kargs_list} --karg-append=$arg" | ||
100 | done | ||
101 | |||
102 | ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} | ||
103 | |||
104 | # Copy deployment /home and /var/sota to sysroot | ||
105 | HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX` | ||
106 | |||
107 | 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 | ||
108 | mv ${HOME_TMP}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
109 | mv ${HOME_TMP}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
110 | # Create /var/sota if it doesn't exist yet | ||
111 | mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota || true | ||
112 | # Ensure the permissions are correctly set | ||
113 | chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
114 | mv ${HOME_TMP}/usr/homedirs/home ${OTA_SYSROOT}/ || true | ||
115 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | ||
116 | install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | ||
117 | # Set package version for the first deployment | ||
118 | target_version=${ostree_target_hash} | ||
119 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
120 | target_version=${GARAGE_TARGET_VERSION} | ||
121 | fi | ||
122 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/installed_versions | ||
123 | echo "All done. Cleaning up dir: ${HOME_TMP}" | ||
124 | rm -rf ${HOME_TMP} | ||
125 | } | ||
117 | 126 | ||
118 | # Calculate image type | 127 | ## Specific image creation |
119 | 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}") | 128 | create_ota () { |
129 | FS_TYPE=${1} | ||
130 | # Calculate image type | ||
131 | 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}") | ||
120 | 132 | ||
121 | if [ $OTA_ROOTFS_SIZE -lt 0 ]; then | 133 | if [ $OTA_ROOTFS_SIZE -lt 0 ]; then |
122 | exit -1 | 134 | exit -1 |
123 | fi | 135 | fi |
124 | eval local COUNT=\"0\" | 136 | eval local COUNT=\"0\" |
125 | eval local MIN_COUNT=\"60\" | 137 | eval local MIN_COUNT=\"60\" |
126 | if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then | 138 | if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then |
127 | eval COUNT=\"$MIN_COUNT\" | 139 | eval COUNT=\"$MIN_COUNT\" |
128 | fi | 140 | fi |
129 | 141 | ||
130 | # create image | 142 | # create image |
143 | if [ "${FS_TYPE}" = "ext4" ]; then | ||
131 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg | 144 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg |
132 | sync | 145 | sync |
133 | dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=$OTA_ROOTFS_SIZE count=$COUNT bs=1024 | 146 | dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=${OTA_ROOTFS_SIZE} count=$COUNT bs=1024 |
134 | mkfs.ext4 -O ^64bit ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg -L otaroot -d ${PHYS_SYSROOT} | 147 | mkfs.ext4 -O ^64bit ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg -L otaroot -d ${OTA_SYSROOT} |
135 | rm -rf ${PHYS_SYSROOT} | ||
136 | |||
137 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | 148 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg |
138 | ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | 149 | ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg |
150 | elif [ "${FS_TYPE}" = "tar" ]; then | ||
151 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar | ||
152 | tar -cf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar -C ${OTA_SYSROOT} . | ||
153 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar | ||
154 | ln -s ${IMAGE_NAME}.otaimg.tar ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar | ||
155 | else | ||
156 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg* | ||
157 | bbfatal "create_ota Function called with unknown or unspecified FS_TYPE of ${FS_TYPE}. Failing!" | ||
158 | fi | ||
159 | } | ||
160 | |||
161 | IMAGE_CMD_ota-ext4 () { | ||
162 | |||
163 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'ota-ext4', 'true', 'false', d)}; then | ||
164 | # create ext4 | ||
165 | create_ota "ext4" | ||
139 | fi | 166 | fi |
140 | } | 167 | } |
141 | 168 | ||
142 | IMAGE_TYPEDEP_otaimg = "ostree" | 169 | IMAGE_CMD_ota-tar () { |
170 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'ota-tar', 'true', 'false', d)}; then | ||
171 | # create tarball | ||
172 | create_ota "tar" | ||
173 | fi | ||
174 | } | ||
175 | |||
176 | do_otasetup[doc] = "Sets up the base ota rootfs used for subsequent image generation" | ||
177 | do_otasetup[depends] += "virtual/fakeroot-native:do_populate_sysroot" | ||
178 | |||
179 | addtask do_otasetup after do_image_ostree before do_image_ota_ext4 do_image_ota_tar | ||
180 | |||
181 | IMAGE_TYPEDEP_ota-ext4 = "ostree" | ||
182 | IMAGE_TYPEDEP_ota-tar = "ostree" | ||
diff --git a/classes/sota.bbclass b/classes/sota.bbclass index e1c5ecd..f86a589 100644 --- a/classes/sota.bbclass +++ b/classes/sota.bbclass | |||
@@ -1,6 +1,7 @@ | |||
1 | export BUILD_OTA_TARBALL | ||
1 | python __anonymous() { | 2 | python __anonymous() { |
2 | if bb.utils.contains('DISTRO_FEATURES', 'sota', True, False, d): | 3 | if bb.utils.contains('DISTRO_FEATURES', 'sota', True, False, d): |
3 | d.appendVarFlag("do_image_wic", "depends", " %s:do_image_otaimg" % d.getVar("IMAGE_BASENAME", True)) | 4 | d.appendVarFlag("do_image_wic", "depends", " %s:do_image_ota_ext4" % d.getVar("IMAGE_BASENAME", True)) |
4 | } | 5 | } |
5 | 6 | ||
6 | OVERRIDES .= "${@bb.utils.contains('DISTRO_FEATURES', 'sota', ':sota', '', d)}" | 7 | OVERRIDES .= "${@bb.utils.contains('DISTRO_FEATURES', 'sota', ':sota', '', d)}" |
@@ -11,7 +12,9 @@ SOTA_CLIENT ??= "aktualizr" | |||
11 | SOTA_CLIENT_PROV ??= "aktualizr-auto-prov" | 12 | SOTA_CLIENT_PROV ??= "aktualizr-auto-prov" |
12 | IMAGE_INSTALL_append_sota = " ostree os-release ${SOTA_CLIENT} ${SOTA_CLIENT_PROV}" | 13 | IMAGE_INSTALL_append_sota = " ostree os-release ${SOTA_CLIENT} ${SOTA_CLIENT_PROV}" |
13 | IMAGE_CLASSES += " image_types_ostree image_types_ota" | 14 | IMAGE_CLASSES += " image_types_ostree image_types_ota" |
14 | IMAGE_FSTYPES += "${@bb.utils.contains('DISTRO_FEATURES', 'sota', 'ostreepush garagesign garagecheck otaimg wic', ' ', d)}" | 15 | |
16 | IMAGE_FSTYPES += "${@bb.utils.contains('DISTRO_FEATURES', 'sota', 'ostreepush garagesign garagecheck ota-ext4 wic', ' ', d)}" | ||
17 | IMAGE_FSTYPES += "${@bb.utils.contains('BUILD_OTA_TARBALL', '1', 'ota-tar', ' ', d)}" | ||
15 | 18 | ||
16 | PACKAGECONFIG_append_pn-curl = " ssl" | 19 | PACKAGECONFIG_append_pn-curl = " ssl" |
17 | PACKAGECONFIG_remove_pn-curl = "gnutls" | 20 | PACKAGECONFIG_remove_pn-curl = "gnutls" |