[v4,4/8] imagetypes: restructure files

Message ID 20220428060615.986332-5-adriaan.schmidt@siemens.com
State Accepted, archived
Headers show
Series imagetypes | expand

Commit Message

Schmidt, Adriaan April 27, 2022, 10:06 p.m. UTC
Instead of per-type classes *-img.bbclass, we move to
- imagetypes.bbclass for the "simple" types and the conversions
- dedicated files for the more complex types:
  - imagetypes_wic.bbclass
  - imagetypes_vm.bbclass
  - imagetypes_contaier.bbclass

Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
---
 meta/classes/cpiogz-img.bbclass               | 14 ---
 meta/classes/ext4-img.bbclass                 | 15 ---
 meta/classes/fit-img.bbclass                  | 22 -----
 meta/classes/image.bbclass                    | 54 +++++------
 meta/classes/imagetypes.bbclass               | 93 +++++++++++++++++++
 ...g.bbclass => imagetypes_container.bbclass} |  0
 .../{vm-img.bbclass => imagetypes_vm.bbclass} |  0
 ...wic-img.bbclass => imagetypes_wic.bbclass} |  0
 meta/classes/targz-img.bbclass                |  8 --
 meta/classes/ubi-img.bbclass                  | 20 ----
 meta/classes/ubifs-img.bbclass                | 19 ----
 11 files changed, 114 insertions(+), 131 deletions(-)
 delete mode 100644 meta/classes/cpiogz-img.bbclass
 delete mode 100644 meta/classes/ext4-img.bbclass
 delete mode 100644 meta/classes/fit-img.bbclass
 create mode 100644 meta/classes/imagetypes.bbclass
 rename meta/classes/{container-img.bbclass => imagetypes_container.bbclass} (100%)
 rename meta/classes/{vm-img.bbclass => imagetypes_vm.bbclass} (100%)
 rename meta/classes/{wic-img.bbclass => imagetypes_wic.bbclass} (100%)
 delete mode 100644 meta/classes/targz-img.bbclass
 delete mode 100644 meta/classes/ubi-img.bbclass
 delete mode 100644 meta/classes/ubifs-img.bbclass

Patch

diff --git a/meta/classes/cpiogz-img.bbclass b/meta/classes/cpiogz-img.bbclass
deleted file mode 100644
index f4c33bd9..00000000
--- a/meta/classes/cpiogz-img.bbclass
+++ /dev/null
@@ -1,14 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) 2020 Siemens AG
-#
-# SPDX-License-Identifier: MIT
-
-IMAGER_INSTALL_cpio += "cpio"
-CPIO_IMAGE_FORMAT ?= "newc"
-
-IMAGE_CMD_cpio() {
-    ${SUDO_CHROOT} \
-        sh -c "cd ${PP_ROOTFS}; /usr/bin/find . | \
-               /usr/bin/cpio -H ${CPIO_IMAGE_FORMAT} -o > \
-               ${IMAGE_FILE_CHROOT}"
-}
diff --git a/meta/classes/ext4-img.bbclass b/meta/classes/ext4-img.bbclass
deleted file mode 100644
index 73d1bb57..00000000
--- a/meta/classes/ext4-img.bbclass
+++ /dev/null
@@ -1,15 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) 2015-2017 ilbers GmbH
-
-IMAGER_INSTALL_ext4 += "e2fsprogs"
-
-MKE2FS_ARGS ?=  "-t ext4"
-
-# Generate ext4 filesystem image
-IMAGE_CMD_ext4() {
-    truncate -s ${ROOTFS_SIZE}K '${IMAGE_FILE_HOST}'
-
-    ${SUDO_CHROOT} /sbin/mke2fs ${MKE2FS_ARGS} \
-                -F -d '${PP_ROOTFS}' '${IMAGE_FILE_CHROOT}'
-}
-#IMAGE_CMD_ext4[vardepsexclude] = "ROOTFS_SIZE ROOTFS_EXTRA"
diff --git a/meta/classes/fit-img.bbclass b/meta/classes/fit-img.bbclass
deleted file mode 100644
index ef65af88..00000000
--- a/meta/classes/fit-img.bbclass
+++ /dev/null
@@ -1,22 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-MKIMAGE_ARGS ??= ""
-
-FIT_IMAGE_SOURCE ??= "fitimage.its"
-
-IMAGER_INSTALL_fit += "u-boot-tools device-tree-compiler"
-
-# Generate fit image
-IMAGE_CMD_fit() {
-    if [ ! -e "${WORKDIR}/${FIT_IMAGE_SOURCE}" ]; then
-        die "FIT_IMAGE_SOURCE does not contain fitimage source file"
-    fi
-
-    # Create fit image using buildchroot tools
-    ${SUDO_CHROOT} /usr/bin/mkimage ${MKIMAGE_ARGS} \
-                -f '${PP_WORK}/${FIT_IMAGE_SOURCE}' '${IMAGE_FILE_CHROOT}'
-}
-IMAGE_CMD_fit[depends] = "${PN}:do_transform_template"
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 91c7aaaa..26b1b0df 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -11,7 +11,6 @@  SSTATE_MANIFESTS = "${TMPDIR}/sstate-control/${MACHINE}-${DISTRO}-${DISTRO_ARCH}
 
 IMAGE_INSTALL ?= ""
 IMAGE_FSTYPES ?= "${@ d.getVar("IMAGE_TYPE", True) if d.getVar("IMAGE_TYPE", True) else "ext4"}"
-IMAGE_CONVERSIONS = "gz xz"
 IMAGE_ROOTFS ?= "${WORKDIR}/rootfs"
 
 KERNEL_IMAGE_PKG ??= "${@ ("linux-image-" + d.getVar("KERNEL_NAME", True)) if d.getVar("KERNEL_NAME", True) else ""}"
@@ -85,6 +84,26 @@  inherit image-postproc-extension
 inherit image-locales-extension
 inherit image-account-extension
 
+# Extra space for rootfs in MB
+ROOTFS_EXTRA ?= "64"
+
+def get_rootfs_size(d):
+    import subprocess
+    rootfs_extra = int(d.getVar("ROOTFS_EXTRA", True))
+
+    output = subprocess.check_output(
+        ["sudo", "du", "-xs", "--block-size=1k", d.getVar("IMAGE_ROOTFS", True)]
+    )
+    base_size = int(output.split()[0])
+
+    return base_size + rootfs_extra * 1024
+
+python set_image_size () {
+    rootfs_size = get_rootfs_size(d)
+    d.setVar('ROOTFS_SIZE', str(rootfs_size))
+    d.setVarFlag('ROOTFS_SIZE', 'export', '1')
+}
+
 def get_base_type(t, d):
     bt = t
     for c in d.getVar('IMAGE_CONVERSIONS').split():
@@ -120,22 +139,10 @@  IMAGE_BASETYPES = "${@get_image_basetypes(d)}"
 
 # image types
 IMAGE_CLASSES ??= ""
-IMGCLASSES = "container-img cpiogz-img ext4-img fit-img targz-img ubi-img ubifs-img vm-img wic-img"
+IMGCLASSES = "imagetypes imagetypes_wic imagetypes_vm imagetypes_container"
 IMGCLASSES += "${IMAGE_CLASSES}"
 inherit ${IMGCLASSES}
 
-# image conversions
-CONVERSION_CMD_gz = "${SUDO_CHROOT} sh -c 'gzip -f -9 -n -c --rsyncable ${IMAGE_FILE_CHROOT} > ${IMAGE_FILE_CHROOT}.gz'"
-CONVERSION_DEPS_gz = "gzip"
-
-XZ_MEMLIMIT ?= "50%"
-XZ_THREADS ?= "${@oe.utils.cpu_count(at_least=2)}"
-XZ_THREADS[vardepvalue] = "1"
-XZ_OPTIONS ?= "--memlimit=${XZ_MEMLIMIT} --threads=${XZ_THREADS}"
-XZ_OPTIONS[vardepsexclude] += "XZ_MEMLIMIT XZ_THREADS"
-CONVERSION_CMD_xz = "${SUDO_CHROOT} sh -c 'xz -c ${XZ_OPTIONS} ${IMAGE_FILE_CHROOT} > ${IMAGE_FILE_CHROOT}.xz'"
-CONVERSION_DEPS_xz = "xz-utils"
-
 # hook up IMAGE_CMD_*
 python() {
     image_types = (d.getVar('IMAGE_FSTYPES') or '').split()
@@ -276,19 +283,6 @@  python() {
     d.appendVar('IMAGER_BUILD_DEPS', ' ' + ' '.join(sorted(imager_build_deps)))
 }
 
-# Extra space for rootfs in MB
-ROOTFS_EXTRA ?= "64"
-
-def get_rootfs_size(d):
-    import subprocess
-    rootfs_extra = int(d.getVar("ROOTFS_EXTRA", True))
-
-    output = subprocess.check_output(
-        ["sudo", "du", "-xs", "--block-size=1k", d.getVar("IMAGE_ROOTFS", True)]
-    )
-    base_size = int(output.split()[0])
-
-    return base_size + rootfs_extra * 1024
 
 # here we call a command that should describe your whole build system,
 # this could be "git describe" or something similar.
@@ -307,12 +301,6 @@  get_build_id() {
 	fi
 }
 
-python set_image_size () {
-    rootfs_size = get_rootfs_size(d)
-    d.setVar('ROOTFS_SIZE', str(rootfs_size))
-    d.setVarFlag('ROOTFS_SIZE', 'export', '1')
-}
-
 ROOTFS_CONFIGURE_COMMAND += "image_configure_fstab"
 image_configure_fstab[weight] = "2"
 image_configure_fstab() {
diff --git a/meta/classes/imagetypes.bbclass b/meta/classes/imagetypes.bbclass
new file mode 100644
index 00000000..07ad0cdb
--- /dev/null
+++ b/meta/classes/imagetypes.bbclass
@@ -0,0 +1,93 @@ 
+# This software is a part of ISAR.
+# Copyright (C) 2021 Siemens AG
+#
+# SPDX-License-Identifier: MIT
+
+#image type: tar
+IMAGER_INSTALL_tar = "tar"
+TAR_OPTIIONS ?= ""
+
+IMAGE_CMD_tar() {
+    ${SUDO_CHROOT} tar ${TAR_OPTIONS} -cvzf \
+                 ${IMAGE_FILE_CHROOT} --one-file-system -C ${PP_ROOTFS} .
+}
+
+# image type: ext4
+IMAGER_INSTALL_ext4 += "e2fsprogs"
+MKE2FS_ARGS ?=  "-t ext4"
+
+IMAGE_CMD_ext4() {
+    truncate -s ${ROOTFS_SIZE}K '${IMAGE_FILE_HOST}'
+
+    ${SUDO_CHROOT} /sbin/mke2fs ${MKE2FS_ARGS} \
+                -F -d '${PP_ROOTFS}' '${IMAGE_FILE_CHROOT}'
+}
+
+# image type: cpio
+IMAGER_INSTALL_cpio += "cpio"
+CPIO_IMAGE_FORMAT ?= "newc"
+
+IMAGE_CMD_cpio() {
+    ${SUDO_CHROOT} \
+        sh -c "cd ${PP_ROOTFS}; /usr/bin/find . | \
+               /usr/bin/cpio -H ${CPIO_IMAGE_FORMAT} -o > \
+               ${IMAGE_FILE_CHROOT}"
+}
+
+# image type: fit
+MKIMAGE_ARGS ??= ""
+FIT_IMAGE_SOURCE ??= "fitimage.its"
+IMAGER_INSTALL_fit += "u-boot-tools device-tree-compiler"
+
+IMAGE_CMD_fit() {
+    if [ ! -e "${WORKDIR}/${FIT_IMAGE_SOURCE}" ]; then
+        die "FIT_IMAGE_SOURCE does not contain fitimage source file"
+    fi
+
+    ${SUDO_CHROOT} /usr/bin/mkimage ${MKIMAGE_ARGS} \
+                -f '${PP_WORK}/${FIT_IMAGE_SOURCE}' '${IMAGE_FILE_CHROOT}'
+}
+IMAGE_CMD_fit[depends] = "${PN}:do_transform_template"
+
+# image type: ubifs
+IMAGER_INSTALL_ubifs += "mtd-utils"
+IMAGE_CMD_REQUIRED_ARGS_ubifs = "MKUBIFS_ARGS"
+
+# glibc bug 23960 https://sourceware.org/bugzilla/show_bug.cgi?id=23960
+# should not use QEMU on armhf target with mkfs.ubifs < v2.1.3
+THIS_ISAR_CROSS_COMPILE := "${ISAR_CROSS_COMPILE}"
+ISAR_CROSS_COMPILE_armhf = "${@bb.utils.contains('IMAGE_BASETYPES', 'ubifs', '1', '${THIS_ISAR_CROSS_COMPILE}', d)}"
+
+IMAGE_CMD_ubifs() {
+    ${SUDO_CHROOT} /usr/sbin/mkfs.ubifs ${MKUBIFS_ARGS} \
+                -r '${PP_ROOTFS}' '${IMAGE_FILE_CHROOT}'
+}
+
+# image type: ubi
+IMAGER_INSTALL_ubi += "mtd-utils"
+IMAGE_CMD_REQUIRED_ARGS_ubi = "UBINIZE_ARGS"
+UBINIZE_CFG ??= "ubinize.cfg"
+
+IMAGE_CMD_ubi() {
+    if [ ! -e "${WORKDIR}/${UBINIZE_CFG}" ]; then
+        die "UBINIZE_CFG does not contain ubinize config file."
+    fi
+
+    ${SUDO_CHROOT} /usr/sbin/ubinize ${UBINIZE_ARGS} \
+                -o '${IMAGE_FILE_CHROOT}' '${PP_WORK}/${UBINIZE_CFG}'
+}
+IMAGE_CMD_ubi[depends] = "${PN}:do_transform_template"
+
+# image conversions
+IMAGE_CONVERSIONS = "gz xz"
+
+CONVERSION_CMD_gz = "${SUDO_CHROOT} sh -c 'gzip -f -9 -n -c --rsyncable ${IMAGE_FILE_CHROOT} > ${IMAGE_FILE_CHROOT}.gz'"
+CONVERSION_DEPS_gz = "gzip"
+
+XZ_MEMLIMIT ?= "50%"
+XZ_THREADS ?= "${@oe.utils.cpu_count(at_least=2)}"
+XZ_THREADS[vardepvalue] = "1"
+XZ_OPTIONS ?= "--memlimit=${XZ_MEMLIMIT} --threads=${XZ_THREADS}"
+XZ_OPTIONS[vardepsexclude] += "XZ_MEMLIMIT XZ_THREADS"
+CONVERSION_CMD_xz = "${SUDO_CHROOT} sh -c 'xz -c ${XZ_OPTIONS} ${IMAGE_FILE_CHROOT} > ${IMAGE_FILE_CHROOT}.xz'"
+CONVERSION_DEPS_xz = "xz-utils"
diff --git a/meta/classes/container-img.bbclass b/meta/classes/imagetypes_container.bbclass
similarity index 100%
rename from meta/classes/container-img.bbclass
rename to meta/classes/imagetypes_container.bbclass
diff --git a/meta/classes/vm-img.bbclass b/meta/classes/imagetypes_vm.bbclass
similarity index 100%
rename from meta/classes/vm-img.bbclass
rename to meta/classes/imagetypes_vm.bbclass
diff --git a/meta/classes/wic-img.bbclass b/meta/classes/imagetypes_wic.bbclass
similarity index 100%
rename from meta/classes/wic-img.bbclass
rename to meta/classes/imagetypes_wic.bbclass
diff --git a/meta/classes/targz-img.bbclass b/meta/classes/targz-img.bbclass
deleted file mode 100644
index 74d34e29..00000000
--- a/meta/classes/targz-img.bbclass
+++ /dev/null
@@ -1,8 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
-#
-# SPDX-License-Identifier: MIT
-
-IMAGE_CMD_tar() {
-    sudo tar -cvzf ${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.tar.gz --one-file-system -C ${IMAGE_ROOTFS} .
-}
diff --git a/meta/classes/ubi-img.bbclass b/meta/classes/ubi-img.bbclass
deleted file mode 100644
index 92acb6f8..00000000
--- a/meta/classes/ubi-img.bbclass
+++ /dev/null
@@ -1,20 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-UBINIZE_CFG ??= "ubinize.cfg"
-
-IMAGER_INSTALL_ubi += "mtd-utils"
-
-# Generate ubi filesystem image
-IMAGE_CMD_ubi() {
-    if [ ! -e "${WORKDIR}/${UBINIZE_CFG}" ]; then
-        die "UBINIZE_CFG does not contain ubinize config file."
-    fi
-
-    ${SUDO_CHROOT} /usr/sbin/ubinize ${UBINIZE_ARGS} \
-                -o '${IMAGE_FILE_CHROOT}' '${PP_WORK}/${UBINIZE_CFG}'
-}
-IMAGE_CMD_ubi[depends] = "${PN}:do_transform_template"
-IMAGE_CMD_REQUIRED_ARGS_ubi = "UBINIZE_ARGS"
diff --git a/meta/classes/ubifs-img.bbclass b/meta/classes/ubifs-img.bbclass
deleted file mode 100644
index 5f1be89e..00000000
--- a/meta/classes/ubifs-img.bbclass
+++ /dev/null
@@ -1,19 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-IMAGER_INSTALL_ubifs += "mtd-utils"
-
-# glibc bug 23960 https://sourceware.org/bugzilla/show_bug.cgi?id=23960
-# should not use QEMU on armhf target with mkfs.ubifs < v2.1.3
-THIS_ISAR_CROSS_COMPILE := "${ISAR_CROSS_COMPILE}"
-ISAR_CROSS_COMPILE_armhf = "${@bb.utils.contains('IMAGE_BASETYPES', 'ubifs', '1', '${THIS_ISAR_CROSS_COMPILE}', d)}"
-
-# Generate ubifs filesystem image
-IMAGE_CMD_ubifs() {
-    # Create ubifs image using buildchroot tools
-    ${SUDO_CHROOT} /usr/sbin/mkfs.ubifs ${MKUBIFS_ARGS} \
-                -r '${PP_ROOTFS}' '${IMAGE_FILE_CHROOT}'
-}
-IMAGE_CMD_REQUIRED_ARGS_ubifs = "MKUBIFS_ARGS"