From 412cfd9a1f139fd56ca66d312c7df22aafd02e48 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 12 Oct 2018 15:38:32 +0200 Subject: image_types_ota: simplify image creation Almost all code in create_ota is either tar or ext4 specific. Move the code directly into the respective IMAGE_CMD_ functions. This gets rid of unnecessary work for the tar image and simplifies code. Signed-off-by: Stefan Agner --- classes/image_types_ota.bbclass | 43 ++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass index 8b363cc..929d092 100644 --- a/classes/image_types_ota.bbclass +++ b/classes/image_types_ota.bbclass @@ -122,48 +122,35 @@ fakeroot do_otasetup () { rm -rf ${HOME_TMP} } -## Specific image creation -create_ota () { - FS_TYPE=${1} +IMAGE_CMD_ota-ext4 () { # Calculate image type 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}") if [ $OTA_ROOTFS_SIZE -lt 0 ]; then - exit -1 + bbfatal "create_ota failed to calculate OTA rootfs size!" fi + eval local COUNT=\"0\" eval local MIN_COUNT=\"60\" if [ $OTA_ROOTFS_SIZE -lt $MIN_COUNT ]; then eval COUNT=\"$MIN_COUNT\" fi - # create image - if [ "${FS_TYPE}" = "ext4" ]; then - rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg - sync - dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=${OTA_ROOTFS_SIZE} count=$COUNT bs=1024 - mkfs.ext4 -O ^64bit ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg -L otaroot -d ${OTA_SYSROOT} - rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg - ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg - elif [ "${FS_TYPE}" = "tar" ]; then - rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar - tar -cf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar -C ${OTA_SYSROOT} . - rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar - ln -s ${IMAGE_NAME}.otaimg.tar ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar - # To fit in with the rest of yocto's image utils, we create a rootfs.ota-tar in the deploy dir - cp ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar ${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ota-tar - else - rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg* - bbfatal "create_ota Function called with unknown or unspecified FS_TYPE of ${FS_TYPE}. Failing!" - fi -} - -IMAGE_CMD_ota-ext4 () { - create_ota "ext4" + rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg + sync + dd if=/dev/zero of=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg seek=${OTA_ROOTFS_SIZE} count=$COUNT bs=1024 + mkfs.ext4 -O ^64bit ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg -L otaroot -d ${OTA_SYSROOT} + rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg + ln -s ${IMAGE_NAME}.otaimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg } IMAGE_CMD_ota-tar () { - create_ota "tar" + rm -rf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar + tar -cf ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg.tar -C ${OTA_SYSROOT} . + rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar + ln -s ${IMAGE_NAME}.otaimg.tar ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar + # To fit in with the rest of yocto's image utils, we create a rootfs.ota-tar in the deploy dir + cp ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.otaimg.tar ${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ota-tar } do_otasetup[doc] = "Sets up the base ota rootfs used for subsequent image generation" -- cgit v1.2.3-54-g00ecf