summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMing Liu <liu.ming50@gmail.com>2019-01-23 23:29:43 +0100
committerMax Krummenacher <max.krummenacher@toradex.com>2019-03-04 17:09:52 +0100
commitfd069bddeac4a81147f994051a73b1ef420a699d (patch)
treed7d08053f5843996cbd422ff6e8d8606ff71a36a
parentdbdff8e06e5ea663443948ad73e48ff796ef70e9 (diff)
image_type_tezi.bbclass: refactor image size calculating functions
Drop bootfs_get_size since it has a obvious flaw, it's being called in both do_image_teziimg and do_image_teziimg_distro but the boot files of these two tasks are different. Drop rootfs_get_size, it's trying to get the size of IMAGE_ROOTFS directory, but in some cases, that is not correct, for instance, when TEZI_ROOT_SUFFIX is 'ota.tar.gz', the rootfs directory should be OTA_SYSROOT rather than IMAGE_ROOTFS. Introduce get_uncompressed_size function, it reads the image size from a image-size file in ${T} directory, and that image size is written into this file by the image functions when they making the tarballs. Also split the duplicated bootfs tarball creating code to a common function create_bootfs, and it must run as a prefuncs before rootfs_tezi_run_json and rootfs_tezi_run_distro_json, this ensures the image size has been written to the file when the later functions run. Signed-off-by: Ming Liu <liu.ming50@gmail.com> [use _append for tar commands] Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
-rw-r--r--classes/image_type_tezi.bbclass83
1 files changed, 32 insertions, 51 deletions
diff --git a/classes/image_type_tezi.bbclass b/classes/image_type_tezi.bbclass
index 75e9a90..96c80b1 100644
--- a/classes/image_type_tezi.bbclass
+++ b/classes/image_type_tezi.bbclass
@@ -31,37 +31,22 @@ UBOOT_ENV_TEZI_RAWNAND ?= "uEnv.txt"
TDX_VERDATE ?= "-${DATE}"
TDX_VERDATE[vardepsexclude] = "DATE"
-def rootfs_get_size(d):
- import subprocess
-
- # Calculate size of rootfs in kilobytes...
- output = subprocess.check_output(['du', '-ks',
- d.getVar('IMAGE_ROOTFS')])
- return int(output.split()[0])
-
-def bootfs_get_size(d):
- import subprocess
-
- deploydir = d.getVar('DEPLOY_DIR_IMAGE')
- bootfiles = []
-
- has_kernel = d.getVar('TEZI_KERNEL_IMAGETYPE')
- if has_kernel:
- kernel = d.getVar('TEZI_KERNEL_IMAGETYPE')
- bootfiles.append(os.path.join(deploydir,kernel))
-
- has_devicetree = d.getVar('TEZI_KERNEL_DEVICETREE')
- if has_devicetree:
- for dtb in d.getVar('TEZI_KERNEL_DEVICETREE').split():
- bootfiles.append(os.path.join(deploydir, dtb))
-
- if len(bootfiles) == 0:
- return int(0)
+# append tar command to store uncompressed image size to ${T}.
+# If a custom rootfs type is used make sure this file is created before
+# compression
+IMAGE_CMD_tar_append = "; echo $(du -ks ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.tar | cut -f 1) > ${T}/image-size.tar"
+
+create_bootfs () {
+ ${IMAGE_CMD_TAR} -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar -C ${DEPLOY_DIR_IMAGE} $1
+ echo $(du -ks ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar | cut -f 1) > ${T}/image-size.bootfs.tar
+ xz -f -k -c ${XZ_COMPRESSION_LEVEL} ${XZ_THREADS} --check=${XZ_INTEGRITY_CHECK} ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar > ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar.xz
+}
- args = ['du', '-kLc']
- args.extend(bootfiles)
- output = subprocess.check_output(args)
- return int(output.splitlines()[-1].split()[0])
+def get_uncompressed_size(d, type=""):
+ suffix = type if type else '.'.join((d.getVar('TEZI_ROOT_SUFFIX') or "").split('.')[:-1])
+ with open(os.path.join(d.getVar('T'), "image-size.%s" % suffix), "r") as f:
+ size = f.read().strip()
+ return float(size)
def rootfs_tezi_emmc(d):
from collections import OrderedDict
@@ -98,7 +83,7 @@ def rootfs_tezi_emmc(d):
"filesystem_type": "FAT",
"mkfs_options": "",
"filename": imagename + ".bootfs.tar.xz",
- "uncompressed_size": bootfs_get_size(d) / 1024
+ "uncompressed_size": get_uncompressed_size(d, 'bootfs.tar') / 1024
}
},
{
@@ -109,7 +94,7 @@ def rootfs_tezi_emmc(d):
"filesystem_type": d.getVar('TEZI_ROOT_FSTYPE'),
"mkfs_options": "-E nodiscard",
"filename": imagename + imagename_suffix + "." + imagetype_suffix,
- "uncompressed_size": rootfs_get_size(d) / 1024
+ "uncompressed_size": get_uncompressed_size(d) / 1024
}
}
]
@@ -186,7 +171,7 @@ def rootfs_tezi_rawnand(d):
"content": {
"filesystem_type": "ubifs",
"filename": imagename + imagename_suffix + "." + imagetype_suffix,
- "uncompressed_size": rootfs_get_size(d) / 1024
+ "uncompressed_size": get_uncompressed_size(d) / 1024
}
}
]
@@ -263,7 +248,11 @@ python rootfs_tezi_run_json() {
rootfs_tezi_json(d, flash_type, flash_data, "image.json", uenv_file)
}
-do_image_teziimg[prefuncs] += "rootfs_tezi_run_json"
+create_tezi_bootfs () {
+ create_bootfs "${TEZI_KERNEL_IMAGETYPE} ${TEZI_KERNEL_DEVICETREE}"
+}
+
+do_image_teziimg[prefuncs] += "create_tezi_bootfs rootfs_tezi_run_json"
IMAGE_CMD_teziimg () {
bbnote "Create Toradex Easy Installer tarball"
@@ -289,12 +278,6 @@ IMAGE_CMD_teziimg () {
${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.tar.xz
;;
*)
- # Create bootfs...
- ${IMAGE_CMD_TAR} \
- -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar -C ${DEPLOY_DIR_IMAGE} \
- ${TEZI_KERNEL_IMAGETYPE} ${TEZI_KERNEL_DEVICETREE}
- xz -f -k -c ${XZ_COMPRESSION_LEVEL} ${XZ_THREADS} --check=${XZ_INTEGRITY_CHECK} ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar > ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar.xz
-
# The first transform strips all folders from the files to tar, the
# second transform "moves" them in a subfolder ${IMAGE_NAME}-Tezi_${PV}.
${IMAGE_CMD_TAR} \
@@ -344,7 +327,7 @@ def rootfs_tezi_distro_rawnand(d):
"content": {
"filesystem_type": "ubifs",
"filename": imagename + ".bootfs.tar.xz",
- "uncompressed_size": bootfs_get_size(d) / 1024
+ "uncompressed_size": get_uncompressed_size(d, 'bootfs.tar') / 1024
}
},
{
@@ -352,7 +335,7 @@ def rootfs_tezi_distro_rawnand(d):
"content": {
"filesystem_type": "ubifs",
"filename": imagename + imagename_suffix + "." + imagetype_suffix,
- "uncompressed_size": rootfs_get_size(d) / 1024
+ "uncompressed_size": get_uncompressed_size(d) / 1024
}
}
]
@@ -389,11 +372,17 @@ python rootfs_tezi_run_distro_json() {
d.appendVar("TEZI_IMAGE_UBOOT_FILES", uenv_file + " " + uboot_file + " ")
}
-do_image_teziimg_distro[prefuncs] += "rootfs_tezi_run_distro_json"
+create_tezi_distro_bootfs () {
+ create_bootfs "${TEZI_KERNEL_IMAGETYPE} ${TEZI_KERNEL_DEVICETREE} boot.scr"
+}
+
+do_image_teziimg_distro[prefuncs] += "create_tezi_distro_bootfs rootfs_tezi_run_distro_json"
IMAGE_CMD_teziimg-distro () {
bbnote "Create Toradex Easy Installer tarball"
+ cd ${DEPLOY_DIR_IMAGE}
+
# Fixup release_date in image.json, convert ${DATE} to isoformat
# This works around the non fatal ERRORS: "the basehash value changed" when DATE is referenced
# in a python prefunction to do_image
@@ -402,14 +391,6 @@ IMAGE_CMD_teziimg-distro () {
sed -i "s/%release_date%/$ISODATE/" ${DEPLOY_DIR_IMAGE}/${TEZI_IMAGE_JSON}
done
- cd ${DEPLOY_DIR_IMAGE}
-
- # Create bootfs...
- ${IMAGE_CMD_TAR} \
- -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar -C ${DEPLOY_DIR_IMAGE} \
- ${TEZI_KERNEL_IMAGETYPE} ${TEZI_KERNEL_DEVICETREE} boot.scr
- xz -f -k -c ${XZ_COMPRESSION_LEVEL} ${XZ_THREADS} --check=${XZ_INTEGRITY_CHECK} ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar > ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar.xz
-
# The first transform strips all folders from the files to tar, the
# second transform "moves" them in a subfolder ${IMAGE_NAME}-Tezi_${PV}.
${IMAGE_CMD_TAR} \