summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2016-08-29 14:28:14 -0700
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2017-01-11 13:36:47 +0100
commita04088c51e85ea49c436f6564ac2c5552890166c (patch)
treeea8c83ff9a0e7e8b833ce0e44ca3661dc329a590
parente2b8f3d69ab62cf84c87be0a3da8e7b0388c15ab (diff)
image_type_tezi: add custom image type for Toradex Easy Installer
The Toradex Easy Installer is a Linux based installer for images. This commit adds a new image type which allows to build images flashable with this installer directly with OpenEmbedded. The installer needs a JSON based image description (image.json) which will be generated using a custom Python step. The IMAGE_CMD step then creates a bootfs tar.xz and creates a tar with the bootfs, rootfs, U-Boot and SPL, image.json and some more metadata files. This tarball can be extracted on a SD card, USB flah drive or HTTP server and consumed by the Toradex Easy Installer. Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
-rw-r--r--classes/image_type_tezi.bbclass126
1 files changed, 126 insertions, 0 deletions
diff --git a/classes/image_type_tezi.bbclass b/classes/image_type_tezi.bbclass
new file mode 100644
index 0000000..38a79c9
--- /dev/null
+++ b/classes/image_type_tezi.bbclass
@@ -0,0 +1,126 @@
+inherit image_types
+
+IMAGE_DEPENDS_tezi = "tezi-metadata:do_deploy"
+
+python rootfs_tezi_json() {
+ import json, subprocess
+ from datetime import date
+ from collections import OrderedDict
+
+ # Calculate size of rootfs...
+ output = subprocess.check_output(['du', '-ks',
+ d.getVar('IMAGE_ROOTFS', True)])
+ rootfssize_kb = int(output.split()[0])
+
+ deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
+ kernel = d.getVar('KERNEL_IMAGETYPE', True)
+
+ # Calculate size of bootfs...
+ bootfiles = [ os.path.join(deploydir, kernel) ]
+ for dtb in d.getVar('KERNEL_DEVICETREE', True).split():
+ bootfiles.append(os.path.join(deploydir, kernel + "-" + dtb))
+
+ args = ['du', '-kLc']
+ args.extend(bootfiles)
+ output = subprocess.check_output(args)
+ bootfssize_kb = int(output.splitlines()[-1].split()[0])
+
+ data = OrderedDict({ "config_format": 1, "autoinstall": False })
+
+ # Use image recipies SUMMARY/DESCRIPTION/PV...
+ data["name"] = d.getVar('SUMMARY', True)
+ data["description"] = d.getVar('DESCRIPTION', True)
+ data["version"] = d.getVar('PV', True)
+ data["release_date"] = date.isoformat(date.today())
+ if os.path.exists(os.path.join(deploydir, "prepare.sh")):
+ data["prepare_script"] = "prepare.sh"
+ if os.path.exists(os.path.join(deploydir, "wrapup.sh")):
+ data["wrapup_script"] = "wrapup.sh"
+ if os.path.exists(os.path.join(deploydir, "marketing.tar")):
+ data["marketing"] = "marketing.tar"
+ if os.path.exists(os.path.join(deploydir, "toradexlinux.png")):
+ data["icon"] = "toradexlinux.png"
+
+ product_ids = d.getVar('TORADEX_PRODUCT_IDS', True)
+ if product_ids is None:
+ bb.fatal("Supported Toradex product ids missing, assign TORADEX_PRODUCT_IDS with a list of product ids.")
+
+ data["supported_product_ids"] = d.getVar('TORADEX_PRODUCT_IDS', True).split()
+
+ imagename = d.getVar('IMAGE_NAME', True)
+ data["blockdevs"] = [
+ OrderedDict({
+ "name": "mmcblk0",
+ "partitions": [
+ {
+ "partition_size_nominal": 16,
+ "want_maximised": False,
+ "content": {
+ "label": "BOOT",
+ "filesystem_type": "FAT",
+ "mkfs_options": "",
+ "filename": imagename + ".bootfs.tar.xz",
+ "uncompressed_size": bootfssize_kb / 1024
+ }
+ },
+ {
+ "partition_size_nominal": 512,
+ "want_maximised": True,
+ "content": {
+ "label": "RFS",
+ "filesystem_type": "ext3",
+ "mkfs_options": "",
+ "filename": imagename + ".rootfs.tar.xz",
+ "uncompressed_size": rootfssize_kb / 1024
+ }
+ }
+ ]
+ }),
+ OrderedDict({
+ "name": "mmcblk0boot0",
+ "content": {
+ "filesystem_type": "raw",
+ "rawfiles": [
+ {
+ "filename": d.getVar('SPL_BINARY', True),
+ "dd_options": "seek=2"
+ },
+ {
+ "filename": d.getVar('U_BOOT_BINARY', True),
+ "dd_options": "seek=138"
+ }
+ ]
+ }
+ })]
+ deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True)
+ with open(os.path.join(deploy_dir, 'image.json'), 'w') as outfile:
+ json.dump(data, outfile, indent=4)
+ bb.note("Toradex Easy Installer metadata file image.json written.")
+}
+do_rootfs[postfuncs] =+ "rootfs_tezi_json"
+
+IMAGE_CMD_tezi () {
+ bbnote "Create bootfs tarball"
+
+ # Create list of device tree files
+ if test -n "${KERNEL_DEVICETREE}"; then
+ for DTS_FILE in ${KERNEL_DEVICETREE}; do
+ DTS_BASE_NAME=`basename ${DTS_FILE} | awk -F "." '{print $1}'`
+ if [ -e "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb" ]; then
+ KERNEL_DEVICETREE_FILES="${KERNEL_DEVICETREE_FILES} ${KERNEL_IMAGETYPE}-${DTS_BASE_NAME}.dtb"
+ else
+ bbfatal "${DTS_FILE} does not exist."
+ fi
+ done
+ fi
+
+ cd ${DEPLOY_DIR_IMAGE}
+ ${IMAGE_CMD_TAR} --transform="flags=r;s|${KERNEL_IMAGETYPE}-||" -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar -C ${DEPLOY_DIR_IMAGE} ${KERNEL_IMAGETYPE} ${KERNEL_DEVICETREE_FILES}
+ 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}_${PV}.
+ ${IMAGE_CMD_TAR} --transform='s/.*\///' --transform 's,^,${IMAGE_NAME}_${PV}/,' -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}_${PV}.tar image.json toradexlinux.png marketing.tar prepare.sh wrapup.sh ${SPL_BINARY} ${U_BOOT_BINARY} ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar.xz ${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.tar.xz
+}
+
+IMAGE_TYPEDEP_tezi += "tar.xz"