summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--classes/image_types_ota.bbclass161
1 files changed, 81 insertions, 80 deletions
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass
index 627e890..56ba726 100644
--- a/classes/image_types_ota.bbclass
+++ b/classes/image_types_ota.bbclass
@@ -45,97 +45,98 @@ calculate_size () {
45} 45}
46 46
47IMAGE_CMD_otaimg () { 47IMAGE_CMD_otaimg () {
48 if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'true', 'false', d)}; then 48 if ${@bb.utils.contains('IMAGE_FSTYPES', 'otaimg', 'false', 'true', d)}; then
49 if [ -z "$OSTREE_REPO" ]; then 49 return
50 bbfatal "OSTREE_REPO should be set in your local.conf" 50 fi
51 fi 51 if [ -z "$OSTREE_REPO" ]; then
52 52 bbfatal "OSTREE_REPO should be set in your local.conf"
53 if [ -z "$OSTREE_OSNAME" ]; then 53 fi
54 bbfatal "OSTREE_OSNAME should be set in your local.conf"
55 fi
56 54
57 if [ -z "$OSTREE_BRANCHNAME" ]; then 55 if [ -z "$OSTREE_OSNAME" ]; then
58 bbfatal "OSTREE_BRANCHNAME should be set in your local.conf" 56 bbfatal "OSTREE_OSNAME should be set in your local.conf"
59 fi 57 fi
60 58
61 PHYS_SYSROOT=`mktemp -d ${WORKDIR}/ota-sysroot-XXXXX` 59 if [ -z "$OSTREE_BRANCHNAME" ]; then
60 bbfatal "OSTREE_BRANCHNAME should be set in your local.conf"
61 fi
62 62
63 ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT} 63 PHYS_SYSROOT=`mktemp -d ${WORKDIR}/ota-sysroot-XXXXX`
64 ostree admin --sysroot=${PHYS_SYSROOT} os-init ${OSTREE_OSNAME}
65 64
66 mkdir -p ${PHYS_SYSROOT}/boot/loader.0 65 ostree admin --sysroot=${PHYS_SYSROOT} init-fs ${PHYS_SYSROOT}
67 ln -s loader.0 ${PHYS_SYSROOT}/boot/loader 66 ostree admin --sysroot=${PHYS_SYSROOT} os-init ${OSTREE_OSNAME}
68 67
69 if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then 68 mkdir -p ${PHYS_SYSROOT}/boot/loader.0
70 mkdir -p ${PHYS_SYSROOT}/boot/grub2 69 ln -s loader.0 ${PHYS_SYSROOT}/boot/loader
71 ln -s ../loader/grub.cfg ${PHYS_SYSROOT}/boot/grub2/grub.cfg
72 elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then
73 touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt
74 else
75 bbfatal "Invalid bootloader: ${OSTREE_BOOTLOADER}"
76 fi
77 70
78 ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME}) 71 if [ "${OSTREE_BOOTLOADER}" = "grub" ]; then
79 72 mkdir -p ${PHYS_SYSROOT}/boot/grub2
80 ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash} 73 ln -s ../loader/grub.cfg ${PHYS_SYSROOT}/boot/grub2/grub.cfg
81 kargs_list="" 74 elif [ "${OSTREE_BOOTLOADER}" = "u-boot" ]; then
82 for arg in ${OSTREE_KERNEL_ARGS}; do 75 touch ${PHYS_SYSROOT}/boot/loader/uEnv.txt
83 kargs_list="${kargs_list} --karg-append=$arg" 76 else
84 done 77 bbfatal "Invalid bootloader: ${OSTREE_BOOTLOADER}"
85 78 fi
86 ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash}
87
88 # Copy deployment /home and /var/sota to sysroot
89 HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX`
90 tar --xattrs --xattrs-include='*' -C ${HOME_TMP} -xf ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 ./usr/homedirs ./var/local || true
91
92 cp -a ${IMAGE_ROOTFS}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true
93 # Create /var/sota if it doesn't exist yet
94 mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota
95 # Ensure the permissions are correctly set
96 chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota
97
98 mv ${HOME_TMP}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true
99 mv ${HOME_TMP}/usr/homedirs/home ${PHYS_SYSROOT}/ || true
100 # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local)
101 install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local
102 # Set package version for the first deployment
103 target_version=${ostree_target_hash}
104 if [ -n "${GARAGE_TARGET_VERSION}" ]; then
105 target_version=${GARAGE_TARGET_VERSION}
106 elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then
107 target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version")
108 fi
109 mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import
110 echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions
111 79
112 rm -rf ${HOME_TMP} 80 ostree_target_hash=$(cat ${OSTREE_REPO}/refs/heads/${OSTREE_BRANCHNAME})
81
82 ostree --repo=${PHYS_SYSROOT}/ostree/repo pull-local --remote=${OSTREE_OSNAME} ${OSTREE_REPO} ${ostree_target_hash}
83 kargs_list=""
84 for arg in ${OSTREE_KERNEL_ARGS}; do
85 kargs_list="${kargs_list} --karg-append=$arg"
86 done
87
88 ostree admin --sysroot=${PHYS_SYSROOT} deploy ${kargs_list} --os=${OSTREE_OSNAME} ${ostree_target_hash}
89
90 # Copy deployment /home and /var/sota to sysroot
91 HOME_TMP=`mktemp -d ${WORKDIR}/home-tmp-XXXXX`
92 tar --xattrs --xattrs-include='*' -C ${HOME_TMP} -xf ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.rootfs.ostree.tar.bz2 ./usr/homedirs ./var/local || true
93
94 cp -a ${IMAGE_ROOTFS}/var/sota ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true
95 # Create /var/sota if it doesn't exist yet
96 mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota
97 # Ensure the permissions are correctly set
98 chmod 700 ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota
99
100 mv ${HOME_TMP}/var/local ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/ || true
101 mv ${HOME_TMP}/usr/homedirs/home ${PHYS_SYSROOT}/ || true
102 # Ensure that /var/local exists (AGL symlinks /usr/local to /var/local)
103 install -d ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/local
104 # Set package version for the first deployment
105 target_version=${ostree_target_hash}
106 if [ -n "${GARAGE_TARGET_VERSION}" ]; then
107 target_version=${GARAGE_TARGET_VERSION}
108 elif [ -e "${STAGING_DATADIR_NATIVE}/target_version" ]; then
109 target_version=$(cat "${STAGING_DATADIR_NATIVE}/target_version")
110 fi
111 mkdir -p ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import
112 echo "{\"${ostree_target_hash}\":\"${GARAGE_TARGET_NAME}-${target_version}\"}" > ${PHYS_SYSROOT}/ostree/deploy/${OSTREE_OSNAME}/var/sota/import/installed_versions
113 113
114 # Calculate image size 114 rm -rf ${HOME_TMP}
115 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}")
116 115
117 if [ ${OTA_ROOTFS_SIZE} -lt 0 ]; then 116 # Calculate image size
118 exit -1 117 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}")
119 fi
120 eval local COUNT=\"0\"
121 eval local MIN_COUNT=\"60\"
122 if [ ${OTA_ROOTFS_SIZE} -lt ${MIN_COUNT} ]; then
123 eval COUNT=\"${MIN_COUNT}\"
124 fi
125 118
126 # create image 119 if [ ${OTA_ROOTFS_SIZE} -lt 0 ]; then
127 rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg 120 exit -1
128 sync
129 dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=${OTA_ROOTFS_SIZE} count=${COUNT} bs=1024
130 mkfs.ext4 -O ^64bit ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg -L otaroot -d ${PHYS_SYSROOT}
131 rm -rf ${PHYS_SYSROOT}
132
133 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg
134 ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg
135 # for forward compatibility
136 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4
137 ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4
138 fi 121 fi
122 eval local COUNT=\"0\"
123 eval local MIN_COUNT=\"60\"
124 if [ ${OTA_ROOTFS_SIZE} -lt ${MIN_COUNT} ]; then
125 eval COUNT=\"${MIN_COUNT}\"
126 fi
127
128 # create image
129 rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg
130 sync
131 dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=${OTA_ROOTFS_SIZE} count=${COUNT} bs=1024
132 mkfs.ext4 -O ^64bit ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg -L otaroot -d ${PHYS_SYSROOT}
133 rm -rf ${PHYS_SYSROOT}
134
135 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg
136 ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg
137 # for forward compatibility
138 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4
139 ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.ota-ext4
139} 140}
140 141
141IMAGE_TYPEDEP_otaimg = "ostree" 142IMAGE_TYPEDEP_otaimg = "ostree"