diff options
author | Matei Valeanu <Matei.Valeanu@enea.com> | 2019-06-12 17:59:53 +0200 |
---|---|---|
committer | Martin Borg <martin.borg@enea.com> | 2019-06-26 14:39:33 +0200 |
commit | 1004579ca431cdb239295dc6771af45b41b2791a (patch) | |
tree | 001010e9e36599fa7e9d2e6281aa1573be054fca | |
parent | c9704949a3cf50d40078340908dff34c48dba948 (diff) | |
download | meta-el-nfv-access-1004579ca431cdb239295dc6771af45b41b2791a.tar.gz |
ostree and otaimg enhancements
override_image_types_ostree.inc - do_image_ostree task:
-add dirs, cleandirs flags, to avoid mktemp, rm, cd, and to
also remove at clean
-add subimages, imgsuffix flags, to use automatic link creation
-create image in IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE
to use the automatic deploy and clean mechanism (also helps
in cleaning old images)
override_image_types_ota.inc - do_image_otaimg task:
-add dirs, cleandirs flags, to avoid mktemp, rm, cd, and to
also remove at clean
-avoid untar-ing the ostree image, and use OSTREE_ROOTFS
-create image in IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE
to use the automatic deploy and clean mechanism
Move OSTREE_REPO to "${WORKDIR}/ostree-repo", instead of
DEPLOY_DIR_IMAGE, this repo is needed for otaimg creation
sota_xeon-d.bbclass sota_atom-c3000.bbclass:
-set ROOTFS_sota to IMGDEPLOYDIR insted of DEPLOY_DIR_IMAGE,
as this is where the otaimg is now created; also use IMAGE_LINK_NAME
istead of IMAGE_NAME, to have the correct reference to the image,
even if the image was built in a previous run (IMAGE_NAME differs
in this case)
Change-Id: I44e87311d1819b80d34f924630d09e429d411d41
Signed-off-by: Matei Valeanu <Matei.Valeanu@enea.com>
-rw-r--r-- | classes/override_image_types_ostree.inc | 29 | ||||
-rw-r--r-- | classes/override_image_types_ota.inc | 98 | ||||
-rw-r--r-- | classes/sota_atom-c3000.bbclass | 2 | ||||
-rw-r--r-- | classes/sota_xeon-d.bbclass | 2 | ||||
-rw-r--r-- | images/enea-nfv-access-host-common.inc | 1 |
5 files changed, 118 insertions, 14 deletions
diff --git a/classes/override_image_types_ostree.inc b/classes/override_image_types_ostree.inc index ac584e5..241afcd 100644 --- a/classes/override_image_types_ostree.inc +++ b/classes/override_image_types_ostree.inc | |||
@@ -1,3 +1,18 @@ | |||
1 | # overrides meta-updater/classes/image_types_ostree.bbclass | ||
2 | # - add do_image_ostree flags: | ||
3 | # - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean | ||
4 | # - subimages, imgsuffix: to use automatic link creation | ||
5 | # - override of IMAGE_CMD_ostree | ||
6 | # - use the added flags | ||
7 | # - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE | ||
8 | |||
9 | OSTREE_ROOTFS="${WORKDIR}/ostree-root" | ||
10 | do_image_ostree[dirs] = "${OSTREE_ROOTFS}" | ||
11 | do_image_ostree[cleandirs] = "${OSTREE_ROOTFS}" | ||
12 | do_image_ostree[subimages] = "rootfs.ostree.tar.bz2" | ||
13 | do_image_ostree[imgsuffix] = "." | ||
14 | export OSTREE_ROOTFS | ||
15 | |||
1 | IMAGE_CMD_ostree () { | 16 | IMAGE_CMD_ostree () { |
2 | if [ -z "$OSTREE_REPO" ]; then | 17 | if [ -z "$OSTREE_REPO" ]; then |
3 | bbfatal "OSTREE_REPO should be set in your local.conf" | 18 | bbfatal "OSTREE_REPO should be set in your local.conf" |
@@ -7,13 +22,10 @@ IMAGE_CMD_ostree () { | |||
7 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | 22 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" |
8 | fi | 23 | fi |
9 | 24 | ||
10 | OSTREE_ROOTFS=`mktemp -du ${WORKDIR}/ostree-root-XXXXX` | 25 | cp -a ${IMAGE_ROOTFS}/* ${OSTREE_ROOTFS} |
11 | cp -a ${IMAGE_ROOTFS} ${OSTREE_ROOTFS} | ||
12 | chmod a+rx ${OSTREE_ROOTFS} | 26 | chmod a+rx ${OSTREE_ROOTFS} |
13 | sync | 27 | sync |
14 | 28 | ||
15 | cd ${OSTREE_ROOTFS} | ||
16 | |||
17 | for d in var/*; do | 29 | for d in var/*; do |
18 | if [ "${d}" != "var/local" ]; then | 30 | if [ "${d}" != "var/local" ]; then |
19 | rm -rf ${d} | 31 | rm -rf ${d} |
@@ -125,16 +137,11 @@ IMAGE_CMD_ostree () { | |||
125 | # Copy image manifest | 137 | # Copy image manifest |
126 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest | 138 | cat ${IMAGE_MANIFEST} | cut -d " " -f1,3 > usr/package.manifest |
127 | 139 | ||
128 | cd ${WORKDIR} | ||
129 | |||
130 | # Create a tarball that can be then commited to OSTree repo | 140 | # Create a tarball that can be then commited to OSTree repo |
131 | OSTREE_TAR=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 | 141 | OSTREE_TAR=${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ostree.tar.bz2 |
132 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . | 142 | tar -C ${OSTREE_ROOTFS} --xattrs --xattrs-include='*' -cjf ${OSTREE_TAR} . |
133 | sync | 143 | sync |
134 | 144 | ||
135 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | ||
136 | ln -s ${IMAGE_NAME}.rootfs.ostree.tar.bz2 ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 | ||
137 | |||
138 | if ! ostree --repo=${OSTREE_REPO} refs 2>&1 > /dev/null; then | 145 | if ! ostree --repo=${OSTREE_REPO} refs 2>&1 > /dev/null; then |
139 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 | 146 | ostree --repo=${OSTREE_REPO} init --mode=archive-z2 |
140 | fi | 147 | fi |
@@ -145,6 +152,4 @@ IMAGE_CMD_ostree () { | |||
145 | --skip-if-unchanged \ | 152 | --skip-if-unchanged \ |
146 | --branch=${OSTREE_BRANCHNAME} \ | 153 | --branch=${OSTREE_BRANCHNAME} \ |
147 | --subject="Commit-id: ${IMAGE_NAME}" | 154 | --subject="Commit-id: ${IMAGE_NAME}" |
148 | |||
149 | rm -rf ${OSTREE_ROOTFS} | ||
150 | } | 155 | } |
diff --git a/classes/override_image_types_ota.inc b/classes/override_image_types_ota.inc new file mode 100644 index 0000000..17508b2 --- /dev/null +++ b/classes/override_image_types_ota.inc | |||
@@ -0,0 +1,98 @@ | |||
1 | # overrides meta-updater/classes/image_types_ota.bbclass | ||
2 | # - add do_image_otaimg flags: | ||
3 | # - dirs, cleandirs: to avoid mktemp, rm, cd, and to also remove at clean | ||
4 | # - override of IMAGE_CMD_otaimg | ||
5 | # - use the added flags | ||
6 | # - avoid untar-ing the ostree image, and use OSTREE_ROOTFS | ||
7 | # - IMGDEPLOYDIR, instead of DEPLOY_DIR_IMAGE | ||
8 | |||
9 | OSTREE_REPO = "${WORKDIR}/ostree-repo" | ||
10 | PHYS_SYSROOT = "${WORKDIR}/ota-sysroot" | ||
11 | |||
12 | do_image_otaimg[dirs] = "${PHYS_SYSROOT}" | ||
13 | do_image_otaimg[cleandirs] = "${PHYS_SYSROOT}" | ||
14 | |||
15 | IMAGE_CMD_otaimg () { | ||
16 | if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then | ||
17 | if [ -z "$OSTREE_REPO" ]; then | ||
18 | bbfatal "OSTREE_REPO should be set in your local.conf" | ||
19 | fi | ||
20 | |||
21 | if [ -z "$OSTREE_OSNAME" ]; then | ||
22 | bbfatal "OSTREE_OSNAME should be set in your local.conf" | ||
23 | fi | ||
24 | |||
25 | if [ -z "$OSTREE_BRANCHNAME" ]; then | ||
26 | bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" | ||
27 | fi | ||
28 | |||
29 | ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} | ||
30 | ostree admin --sysroot=${PHYS_SYSROOT} os-init ${OSTREE_OSNAME} | ||
31 | |||
32 | mkdir -p ${PHYS_SYSROOT}/boot/loader.0 | ||
33 | ln -s loader.0 ${PHYS_SYSROOT}/boot/loader | ||
34 | |||
35 | if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then | ||
36 | mkdir -p ${PHYS_SYSROOT}/boot/grub2 | ||
37 | ln -s ../loader/grub.cfg ${PHYS_SYSROOT}/boot/grub2/grub.cfg | ||
38 | elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then | ||
39 | touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt | ||
40 | else | ||
41 | bberror "Invalid bootloader: ${OSTREE_BOOTLOADER}" | ||
42 | fi; | ||
43 | |||
44 | ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) | ||
45 | |||
46 | ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} | ||
47 | export OSTREE_BOOT_PARTITION="/boot" | ||
48 | kargs_list="" | ||
49 | for arg in ${OSTREE_KERNEL_ARGS}; do | ||
50 | kargs_list="${kargs_list} --karg-append=$arg" | ||
51 | done | ||
52 | |||
53 | ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash} | ||
54 | |||
55 | cp -a ${IMAGE_ROOTFS}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
56 | # Create /var/sota if it doesn't exist yet | ||
57 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
58 | # Ensure the permissions are correctly set | ||
59 | chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota | ||
60 | |||
61 | cp -a ${OSTREE_ROOTFS}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true | ||
62 | cp -a ${OSTREE_ROOTFS}/usr/homedirs/home ${PHYS_SYSROOT}/ || true | ||
63 | # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local) | ||
64 | install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local | ||
65 | # Set package version for the first deployment | ||
66 | target_version=${ostree_target_hash} | ||
67 | if [ -n "${GARAGE_TARGET_VERSION}" ]; then | ||
68 | target_version=${GARAGE_TARGET_VERSION} | ||
69 | elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then | ||
70 | target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version") | ||
71 | fi | ||
72 | mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import | ||
73 | echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions | ||
74 | |||
75 | # Calculate image type | ||
76 | 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}") | ||
77 | |||
78 | if [ $OTA_ROOTFS_SIZE -lt 0 ]; then | ||
79 | exit -1 | ||
80 | fi | ||
81 | eval local COUNT=\"0\" | ||
82 | eval local MIN_COUNT=\"60\" | ||
83 | if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then | ||
84 | eval COUNT=\"$MIN_COUNT\" | ||
85 | fi | ||
86 | |||
87 | # create image | ||
88 | dd if=/dev/zero of=${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg seek=${OTA_ROOTFS_SIZE} count=${COUNT} bs=1024 | ||
89 | mkfs.ext4 -O ^64bit ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg -L otaroot -d ${PHYS_SYSROOT} | ||
90 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | ||
91 | ln -s ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg | ||
92 | # for forward compatibility | ||
93 | rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4 | ||
94 | ln -s ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4 | ||
95 | fi | ||
96 | } | ||
97 | |||
98 | IMAGE_TYPEDEP_otaimg = "ostree" | ||
diff --git a/classes/sota_atom-c3000.bbclass b/classes/sota_atom-c3000.bbclass index f9b4864..dff4294 100644 --- a/classes/sota_atom-c3000.bbclass +++ b/classes/sota_atom-c3000.bbclass | |||
@@ -7,7 +7,7 @@ WKS_FILE_sota = "efiimage-sota.wks" | |||
7 | OSTREE_INITRAMFS_FSTYPES ?= "ext4.gz" | 7 | OSTREE_INITRAMFS_FSTYPES ?= "ext4.gz" |
8 | 8 | ||
9 | # Set .otaimg to be used as source for generating hddimg | 9 | # Set .otaimg to be used as source for generating hddimg |
10 | ROOTFS_sota = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg" | 10 | ROOTFS_sota = "${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.otaimg" |
11 | 11 | ||
12 | # OSTree initrd needs 'ramdisk_size' and 'rw' parameters in order to boot | 12 | # OSTree initrd needs 'ramdisk_size' and 'rw' parameters in order to boot |
13 | OSTREE_KERNEL_ARGS ?= "rw" | 13 | OSTREE_KERNEL_ARGS ?= "rw" |
diff --git a/classes/sota_xeon-d.bbclass b/classes/sota_xeon-d.bbclass index f9b4864..dff4294 100644 --- a/classes/sota_xeon-d.bbclass +++ b/classes/sota_xeon-d.bbclass | |||
@@ -7,7 +7,7 @@ WKS_FILE_sota = "efiimage-sota.wks" | |||
7 | OSTREE_INITRAMFS_FSTYPES ?= "ext4.gz" | 7 | OSTREE_INITRAMFS_FSTYPES ?= "ext4.gz" |
8 | 8 | ||
9 | # Set .otaimg to be used as source for generating hddimg | 9 | # Set .otaimg to be used as source for generating hddimg |
10 | ROOTFS_sota = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg" | 10 | ROOTFS_sota = "${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.otaimg" |
11 | 11 | ||
12 | # OSTree initrd needs 'ramdisk_size' and 'rw' parameters in order to boot | 12 | # OSTree initrd needs 'ramdisk_size' and 'rw' parameters in order to boot |
13 | OSTREE_KERNEL_ARGS ?= "rw" | 13 | OSTREE_KERNEL_ARGS ?= "rw" |
diff --git a/images/enea-nfv-access-host-common.inc b/images/enea-nfv-access-host-common.inc index ef6d3de..b2dd5a2 100644 --- a/images/enea-nfv-access-host-common.inc +++ b/images/enea-nfv-access-host-common.inc | |||
@@ -4,6 +4,7 @@ REQUIRE_FILES = " \ | |||
4 | " | 4 | " |
5 | REQUIRE_FILES_append_df-efi-secure-boot = " \ | 5 | REQUIRE_FILES_append_df-efi-secure-boot = " \ |
6 | classes/override_image_types_ostree.inc \ | 6 | classes/override_image_types_ostree.inc \ |
7 | classes/override_image_types_ota.inc \ | ||
7 | classes/override_grub-efi_secureboot.inc \ | 8 | classes/override_grub-efi_secureboot.inc \ |
8 | images/secure-boot.inc \ | 9 | images/secure-boot.inc \ |
9 | " | 10 | " |