diff mbox series

[isar-cip-core,2/2] swupdate-img: Add support for automatically compressing files

Message ID 6e5722e86c9ddf733464c7484158555df707cddc.1646938228.git.jan.kiszka@siemens.com (mailing list archive)
State New
Headers show
Series SWUpdate-related cleanups | expand

Commit Message

Jan Kiszka March 10, 2022, 6:50 p.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

Automatically gzip files specified in SWU_ADDITIONAL_FILES if they end
on .gz and there is an uncompressed version (without .gz suffix) in the
search path. This obsoletes the extra compress_swupdate_rootfs class
and makes the usage more convenient.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 classes/compress_swupdate_rootfs.bbclass | 21 ---------------------
 classes/secure-swupdate-img.bbclass      |  4 +---
 classes/swupdate-img.bbclass             | 15 +++++++++++++++
 classes/wic-swu-img.bbclass              |  5 +----
 recipes-core/images/secureboot.inc       |  3 +--
 recipes-core/images/swupdate.inc         |  4 ++--
 6 files changed, 20 insertions(+), 32 deletions(-)
 delete mode 100644 classes/compress_swupdate_rootfs.bbclass
diff mbox series

Patch

diff --git a/classes/compress_swupdate_rootfs.bbclass b/classes/compress_swupdate_rootfs.bbclass
deleted file mode 100644
index 2a01e59..0000000
--- a/classes/compress_swupdate_rootfs.bbclass
+++ /dev/null
@@ -1,21 +0,0 @@ 
-#
-# CIP Core, generic profile
-#
-# Copyright (c) Siemens AG, 2022
-#
-# Authors:
-#  Quirin Gylstorff <quirin.gylstorff@siemens.com>
-#
-# SPDX-License-Identifier: MIT
-#
-
-EXTRACT_PARTITIONS ?= "${IMAGE_FULLNAME}.wic.img.p4"
-
-do_compress_swupdate_rootfs () {
-    for PARTITION in ${EXTRACT_PARTITIONS}; do
-        if [ -e ${DEPLOY_DIR_IMAGE}/${PARTITION} ]; then
-            rm -f ${DEPLOY_DIR_IMAGE}/${PARTITION}.gz
-            gzip ${DEPLOY_DIR_IMAGE}/${PARTITION}
-        fi
-    done
-}
diff --git a/classes/secure-swupdate-img.bbclass b/classes/secure-swupdate-img.bbclass
index 1715c8a..330f619 100644
--- a/classes/secure-swupdate-img.bbclass
+++ b/classes/secure-swupdate-img.bbclass
@@ -21,12 +21,10 @@  INITRD_IMAGE = "${INITRAMFS_RECIPE}-${DISTRO}-${MACHINE}.initrd.img"
 
 inherit verity-img
 inherit wic-img
-inherit compress_swupdate_rootfs
 inherit swupdate-img
 
 SOURCE_IMAGE_FILE = "${WIC_IMAGE_FILE}"
 
 addtask do_verity_image after do_${SECURE_IMAGE_FSTYPE}_image
 addtask do_wic_image after do_verity_image
-addtask do_compress_swupdate_rootfs after do_wic_image
-addtask do_swupdate_image after do_compress_swupdate_rootfs
+addtask do_swupdate_image after do_wic_image
diff --git a/classes/swupdate-img.bbclass b/classes/swupdate-img.bbclass
index 7b7154f..97e833e 100644
--- a/classes/swupdate-img.bbclass
+++ b/classes/swupdate-img.bbclass
@@ -24,6 +24,21 @@  do_swupdate_image() {
     rm -f '${SWU_IMAGE_FILE}'
     cp '${WORKDIR}/${SWU_DESCRIPTION_FILE}' '${WORKDIR}/swu/${SWU_DESCRIPTION_FILE}'
 
+    # Compress files if requested
+    for file in ${SWU_ADDITIONAL_FILES}; do
+        basefile=$(basename "$file" .gz)
+        if [ "$basefile" = "$file" ]; then
+            continue
+        fi
+        for uncompressed in "${WORKDIR}/$basefile" "${DEPLOY_DIR_IMAGE}/$basefile"; do
+            if [ -e "$uncompressed" ]; then
+                rm  -f "$uncompressed.gz"
+                gzip "$uncompressed"
+                break
+            fi
+        done
+    done
+
     # Create symlinks for files used in the update image
     for file in ${SWU_ADDITIONAL_FILES}; do
         if [ -e "${WORKDIR}/$file" ]; then
diff --git a/classes/wic-swu-img.bbclass b/classes/wic-swu-img.bbclass
index 3a09721..5e6de40 100644
--- a/classes/wic-swu-img.bbclass
+++ b/classes/wic-swu-img.bbclass
@@ -9,12 +9,9 @@ 
 # SPDX-License-Identifier: MIT
 #
 
-
 inherit wic-img
-inherit compress_swupdate_rootfs
 inherit swupdate-img
 
 SOURCE_IMAGE_FILE = "${WIC_IMAGE_FILE}"
 
-addtask do_compress_swupdate_rootfs after do_wic_image
-addtask do_swupdate_image after do_compress_swupdate_rootfs
+addtask do_swupdate_image after do_wic_image
diff --git a/recipes-core/images/secureboot.inc b/recipes-core/images/secureboot.inc
index 950b41a..3e6eef8 100644
--- a/recipes-core/images/secureboot.inc
+++ b/recipes-core/images/secureboot.inc
@@ -11,8 +11,7 @@ 
 
 FILESEXTRAPATHS_prepend := "${THISDIR}/files/secure-boot:"
 
-EXTRACT_PARTITIONS = "${IMAGE_FULLNAME}.wic.img.p4"
-ROOTFS_PARTITION_NAME="${IMAGE_FULLNAME}.wic.img.p4.gz"
+ROOTFS_PARTITION_NAME = "${IMAGE_FULLNAME}.wic.img.p4.gz"
 
 SRC_URI += "file://sw-description.tmpl"
 TEMPLATE_FILES += "sw-description.tmpl"
diff --git a/recipes-core/images/swupdate.inc b/recipes-core/images/swupdate.inc
index 2e9094a..c23c103 100644
--- a/recipes-core/images/swupdate.inc
+++ b/recipes-core/images/swupdate.inc
@@ -11,11 +11,11 @@ 
 
 FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
 
-EXTRACT_PARTITIONS = "${IMAGE_FULLNAME}.wic.img.p4"
-ROOTFS_PARTITION_NAME="${IMAGE_FULLNAME}.wic.img.p4.gz"
+ROOTFS_PARTITION_NAME = "${IMAGE_FULLNAME}.wic.img.p4.gz"
 
 SRC_URI += "file://sw-description.tmpl"
 TEMPLATE_FILES += "sw-description.tmpl"
+
 TEMPLATE_VARS += "PN ROOTFS_PARTITION_NAME KERNEL_IMAGE INITRD_IMAGE"
 
 SWU_ADDITIONAL_FILES += "${INITRD_IMAGE} ${KERNEL_IMAGE} ${ROOTFS_PARTITION_NAME}"