From 01f7c6a5f74e8baaa452b9341eaace69bd522412 Mon Sep 17 00:00:00 2001 From: Anton Gerasimov Date: Wed, 2 Nov 2016 12:05:44 +0100 Subject: OTA-enabled live image for Porter board Bug-AGL: SPEC-307 Change-Id: I74ddc2622048a50243b82fbf023aa05c33322af4 Signed-off-by: Anton Gerasimov --- meta-sota/classes/sdcard_image-porter-ota.bbclass | 75 +++++++++++++++++++++++ meta-sota/classes/sdcard_image-rpi-ota.bbclass | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 meta-sota/classes/sdcard_image-porter-ota.bbclass (limited to 'meta-sota') 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 +} + diff --git a/meta-sota/classes/sdcard_image-rpi-ota.bbclass b/meta-sota/classes/sdcard_image-rpi-ota.bbclass index 12c1f40..2fa03c4 100644 --- a/meta-sota/classes/sdcard_image-rpi-ota.bbclass +++ b/meta-sota/classes/sdcard_image-rpi-ota.bbclass @@ -79,7 +79,7 @@ IMAGE_CMD_rpi-sdimg-ota[vardepsexclude] += "DATETIME" IMAGE_CMD_rpi-sdimg-ota () { # Align partitions - OTAROOT_SIZE=`du -Lb ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.${SDIMG_OTA_ROOTFS_TYPE} | cut -f1` + 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}) -- cgit 1.2.3-korg