summaryrefslogtreecommitdiffstats
path: root/meta-sota/classes/sdcard_image-porter-ota.bbclass
diff options
context:
space:
mode:
authorAnton Gerasimov <anton@advancedtelematic.com>2016-11-02 12:05:44 +0100
committerAnton Gerasimov <anton@advancedtelematic.com>2016-11-02 12:05:44 +0100
commit01f7c6a5f74e8baaa452b9341eaace69bd522412 (patch)
tree4aec7de6658990aa92b47cdf49ae2493e7d1ad16 /meta-sota/classes/sdcard_image-porter-ota.bbclass
parent7530b316c94361fc8419cd8450e5d624576b704a (diff)
OTA-enabled live image for Porter board
Bug-AGL: SPEC-307 Change-Id: I74ddc2622048a50243b82fbf023aa05c33322af4 Signed-off-by: Anton Gerasimov <anton@advancedtelematic.com>
Diffstat (limited to 'meta-sota/classes/sdcard_image-porter-ota.bbclass')
-rw-r--r--meta-sota/classes/sdcard_image-porter-ota.bbclass75
1 files changed, 75 insertions, 0 deletions
diff --git a/meta-sota/classes/sdcard_image-porter-ota.bbclass b/meta-sota/classes/sdcard_image-porter-ota.bbclass
new file mode 100644
index 0000000..1b1de79
--- /dev/null
+++ b/meta-sota/classes/sdcard_image-porter-ota.bbclass
@@ -0,0 +1,75 @@
+inherit image_types
+
+# Boot partition volume id
+BOOTDD_VOLUME_ID ?= "${MACHINE}"
+
+# Boot partition size [in KiB] (will be rounded up to IMAGE_ROOTFS_ALIGNMENT)
+BOOT_SPACE ?= "4096"
+
+IMAGE_ROOTFS_ALIGNMENT = "4096"
+SDIMG_OTA_ROOTFS_TYPE ?= "otaimg"
+SDIMG_OTA_ROOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.${SDIMG_OTA_ROOTFS_TYPE}"
+
+IMAGE_TYPEDEP_porter-sdimg-ota = "${SDIMG_OTA_ROOTFS_TYPE}"
+IMAGE_DEPENDS_porter-sdimg-ota = " \
+ parted-native \
+ mtools-native \
+ dosfstools-native \
+ porter-bootfiles \
+ "
+
+SDIMG_OTA = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.porter-sdimg-ota"
+
+IMAGE_CMD_porter-sdimg-ota () {
+ OTAROOT_SIZE=`du -Lb ${SDIMG_OTA_ROOTFS} | cut -f1`
+ OTAROOT_SIZE=$(expr ${OTAROOT_SIZE} / 1024 + 1)
+ BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1)
+ BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT})
+ SDIMG_OTA_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $OTAROOT_SIZE)
+
+ echo "Creating filesystem with Boot partition ${BOOT_SPACE_ALIGNED} KiB and RootFS $OTAROOT_SIZE KiB"
+
+ # Initialize sdcard image file
+ dd if=/dev/zero of=${SDIMG_OTA} bs=1024 count=0 seek=${SDIMG_OTA_SIZE}
+
+ # Create partition table
+ parted -s ${SDIMG_OTA} mklabel msdos
+ # Create boot partition and mark it as bootable
+ parted -s ${SDIMG_OTA} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT})
+ parted -s ${SDIMG_OTA} set 1 boot on
+ # Create rootfs partition to the end of disk
+ parted -s ${SDIMG_OTA} -- unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) -1s
+ parted ${SDIMG_OTA} print
+
+ # Create a vfat image with boot files
+ BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG_OTA} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }')
+ rm -f ${WORKDIR}/boot.img
+ mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS
+ sync
+
+ mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/porter-bootfiles/* ::/
+
+ sync
+ dd if=${WORKDIR}/boot.img of=${SDIMG_OTA} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
+
+ if echo "${SDIMG_OTA_ROOTFS_TYPE}" | egrep -q "*\.xz"
+ then
+ xzcat ${SDIMG_OTA_ROOTFS} | dd of=${SDIMG_OTA} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
+ else
+ dd if=${SDIMG_OTA_ROOTFS} of=${SDIMG_OTA} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
+ fi
+
+ # Optionally apply compression
+ case "${SDIMG_OTA_COMPRESSION}" in
+ "gzip")
+ gzip -k9 "${SDIMG_OTA}"
+ ;;
+ "bzip2")
+ bzip2 -k9 "${SDIMG_OTA}"
+ ;;
+ "xz")
+ xz -k "${SDIMG_OTA}"
+ ;;
+ esac
+}
+