diff options
author | cajun-rat <philip.wise@here.com> | 2018-08-08 10:28:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-08 10:28:10 +0200 |
commit | 661f27ff1a47b2e0df06c5600443697ab6cab780 (patch) | |
tree | 404d9d422b9158c5a8e27f75f45c22461bc66324 | |
parent | 85c02be3156f025facb614de83e6e7735d6ad5de (diff) | |
parent | fef98227e6ff5c97593697fe6c382ddd3ee8dfa8 (diff) | |
download | meta-updater-661f27ff1a47b2e0df06c5600443697ab6cab780.tar.gz |
Merge pull request #352 from bclouser/master
Support for creating an otaimg.tar file in addition to the ext4 image
-rw-r--r-- | classes/image_types_ota.bbclass | 195 | ||||
-rw-r--r-- | classes/sota.bbclass | 7 |
2 files changed, 122 insertions, 80 deletions
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 9581971..0b2f7a1 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass | |||
@@ -7,9 +7,8 @@ | |||
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 | |
11 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ | 11 | do_image_ota_ext4[depends] += "e2fsprogs-native:do_populate_sysroot" |
12 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" | ||
13 | 12 | ||
14 | calculate_size () { | 13 | calculate_size () { |
15 | BASE=$1 | 14 | BASE=$1 |
@@ -51,92 +50,132 @@ export OSTREE_BOOTLOADER | |||
51 | 50 | ||
52 | export GARAGE_TARGET_NAME | 51 | export GARAGE_TARGET_NAME |
53 | 52 | ||
54 | IMAGE_CMD_otaimg () { | 53 | 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 | |||
60 | if [ -z "$OSTREE_OSNAME" ]; then | ||
61 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | ||
62 | fi | ||
63 | 54 | ||
64 | if [ -z "$OSTREE_BRANCHNAME" ]; then | 55 | ## Common OTA image setup |
65 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | 56 | fakeroot do_otasetup () { |
66 | fi | 57 | |
58 | if [ -z "$OSTREE_REPO" ]; then | ||
59 | bbfatal "OSTREE_REPO should be set in your local.conf" | ||
60 | fi | ||
67 | 61 | ||
62 | if [ -z "$OSTREE_OSNAME" ]; then | ||
63 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | ||
64 | fi | ||
68 | 65 | ||
69 | PHYS_SYSROOT=`mktemp -d ${WORKDIR}/ota-sysroot-XXXXX` | 66 | if [ -z "$OSTREE_BRANCHNAME" ]; then |
70 | 67 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | |
71 | ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} | 68 | 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 | 69 | ||
116 | rm -rf ${HOME_TMP} | 70 | # HaX! Since we are using a peristent directory, we need to be sure to clean it on run. |
71 | mkdir -p ${OTA_SYSROOT} | ||
72 | rm -rf ${OTA_SYSROOT}/* | ||
73 | |||
74 | ostree admin --sysroot=${OTA_SYSROOT} init-fs ${OTA_SYSROOT} | ||
75 | ostree admin --sysroot=${OTA_SYSROOT} os-init ${OSTREE_OSNAME} | ||
76 | mkdir -p ${OTA_SYSROOT}/boot/loader.0 | ||
77 | ln -s loader.0 ${OTA_SYSROOT}/boot/loader | ||
78 | |||
79 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then | ||
80 | mkdir -p ${OTA_SYSROOT}/boot/grub2 | ||
81 | ln -s ../loader/grub.cfg ${OTA_SYSROOT}/boot/grub2/grub.cfg | ||
82 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then | ||
83 | touch ${OTA_SYSROOT}/boot/loader/uEnv.txt | ||
84 | else | ||
85 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" | ||
86 | fi; | ||
87 | |||
88 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
89 | |||
90 | ostree --repo=${OTA_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} | ||
91 | export OSTREE_BOOT_PARTITION="/boot" | ||
92 | kargs_list="" | ||
93 | for arg in ${OSTREE_KERNEL_ARGS}; do | ||
94 | kargs_list="${kargs_list} --karg-append=$arg" | ||
95 | done | ||
96 | |||
97 | ostree admin --sysroot=${OTA_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} | ||
98 | |||
99 | # Copy deployment /home and /var/sota to sysroot | ||
100 | HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX` | ||
101 | |||
102 | 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 | ||
103 | mv ${HOME_TMP}/var/sota ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
104 | mv ${HOME_TMP}/var/local ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
105 | # Create /var/sota if it doesn't exist yet | ||
106 | mkdir -p ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota || true | ||
107 | # Ensure the permissions are correctly set | ||
108 | chmod 700 ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
109 | mv ${HOME_TMP}/usr/homedirs/home ${OTA_SYSROOT}/ || true | ||
110 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | ||
111 | install -d ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | ||
112 | # Set package version for the first deployment | ||
113 | target_version=${ostree_target_hash} | ||
114 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
115 | target_version=${GARAGE_TARGET_VERSION} | ||
116 | fi | ||
117 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${OTA_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/installed_versions | ||
118 | echo "All done. Cleaning up dir: ${HOME_TMP}" | ||
119 | rm -rf ${HOME_TMP} | ||
120 | } | ||
117 | 121 | ||
118 | # Calculate image type | 122 | ## 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}") | 123 | create_ota () { |
124 | FS_TYPE=${1} | ||
125 | # Calculate image type | ||
126 | 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 | 127 | ||
121 | if [ $OTA_ROOTFS_SIZE -lt 0 ]; then | 128 | if [ $OTA_ROOTFS_SIZE -lt 0 ]; then |
122 | exit -1 | 129 | exit -1 |
123 | fi | 130 | fi |
124 | eval local COUNT=\"0\" | 131 | eval local COUNT=\"0\" |
125 | eval local MIN_COUNT=\"60\" | 132 | eval local MIN_COUNT=\"60\" |
126 | if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then | 133 | if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then |
127 | eval COUNT=\"$MIN_COUNT\" | 134 | eval COUNT=\"$MIN_COUNT\" |
128 | fi | 135 | fi |
129 | 136 | ||
130 | # create image | 137 | # create image |
138 | if [ "${FS_TYPE}" = "ext4" ]; then | ||
131 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg | 139 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg |
132 | sync | 140 | sync |
133 | dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=$OTA_ROOTFS_SIZE count=$COUNT bs=1024 | 141 | 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} | 142 | 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 | 143 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg |
138 | ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | 144 | ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg |
145 | elif [ "${FS_TYPE}" = "tar" ]; then | ||
146 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar | ||
147 | tar -cf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar -C ${OTA_SYSROOT} . | ||
148 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar | ||
149 | ln -s ${IMAGE_NAME}.otaimg.tar ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar | ||
150 | # To fit in with the rest of yocto's image utils, we create a rootfs.ota-tar in the deploy dir | ||
151 | cp ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar ${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ota-tar | ||
152 | else | ||
153 | rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg* | ||
154 | bbfatal "create_ota Function called with unknown or unspecified FS_TYPE of ${FS_TYPE}. Failing!" | ||
155 | fi | ||
156 | } | ||
157 | |||
158 | IMAGE_CMD_ota-ext4 () { | ||
159 | |||
160 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'ota-ext4', 'true', 'false', d)}; then | ||
161 | # create ext4 | ||
162 | create_ota "ext4" | ||
139 | fi | 163 | fi |
140 | } | 164 | } |
141 | 165 | ||
142 | IMAGE_TYPEDEP_otaimg = "ostree" | 166 | IMAGE_CMD_ota-tar () { |
167 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'ota-tar', 'true', 'false', d)}; then | ||
168 | # create tarball | ||
169 | create_ota "tar" | ||
170 | fi | ||
171 | } | ||
172 | |||
173 | do_otasetup[doc] = "Sets up the base ota rootfs used for subsequent image generation" | ||
174 | do_otasetup[depends] += "virtual/fakeroot-native:do_populate_sysroot \ | ||
175 | ${@'grub:do_populate_sysroot' if d.getVar('OSTREE_BOOTLOADER', True) == 'grub' else ''} \ | ||
176 | ${@'virtual/bootloader:do_deploy' if d.getVar('OSTREE_BOOTLOADER', True) == 'u-boot' else ''}" | ||
177 | |||
178 | addtask do_otasetup after do_image_ostree before do_image_ota_ext4 do_image_ota_tar | ||
179 | |||
180 | IMAGE_TYPEDEP_ota-ext4 = "ostree" | ||
181 | IMAGE_TYPEDEP_ota-tar = "ostree" | ||
diff --git a/classes/sota.bbclass b/classes/sota.bbclass index e1c5ecd..3aca92c 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 ota-tar.xz', ' ', 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" |