[v2,3/7] move squashfs imagetype class from CIP to ISAR

Message ID 20250123095223.2928575-4-felix.moessbauer@siemens.com
State Superseded, archived
Headers show
Series Add iso9660 image support for ISAR | expand

Commit Message

Felix Moessbauer Jan. 23, 2025, 9:52 a.m. UTC
As a preparation for live images, we move the squashfs class from
isar-cip-core to ISAR and register it as always included.

ISAR-cip-core revision: 0e85378341fb7b37cf95b1c910ca0260cf4f5cf4

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta-isar/classes/squashfs.bbclass | 47 ++++++++++++++++++++++++++++++
 meta/classes/image.bbclass         |  2 +-
 2 files changed, 48 insertions(+), 1 deletion(-)
 create mode 100644 meta-isar/classes/squashfs.bbclass

Patch

diff --git a/meta-isar/classes/squashfs.bbclass b/meta-isar/classes/squashfs.bbclass
new file mode 100644
index 00000000..9cd7ed3d
--- /dev/null
+++ b/meta-isar/classes/squashfs.bbclass
@@ -0,0 +1,47 @@ 
+# squashfs image rootfs
+#
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2021-2025
+#
+# SPDX-License-Identifier: MIT
+
+def get_free_mem():
+    try:
+        with open('/proc/meminfo') as meminfo:
+            lines = meminfo.readlines()
+            for line in lines:
+                if line.startswith('MemAvailable:'):
+                    return int(line.split()[1]) * 1024
+    except FileNotFoundError:
+        pass
+    return 4*1024*1024*1024  # 4G
+
+IMAGER_INSTALL:squashfs += "squashfs-tools"
+
+SQUASHFS_EXCLUDE_DIRS ?= ""
+SQUASHFS_CONTENT ?= "${PP_ROOTFS}"
+SQUASHFS_CREATION_ARGS ?= ""
+
+SQUASHFS_THREADS ?= "${@oe.utils.cpu_count(at_least=2)}"
+SQUASHFS_MEMLIMIT ?= "${@int(get_free_mem() * 3/4)}"
+SQUASHFS_CREATION_LIMITS = "-mem ${SQUASHFS_MEMLIMIT} -processors ${SQUASHFS_THREADS}"
+
+python __anonymous() {
+    exclude_directories = d.getVar('SQUASHFS_EXCLUDE_DIRS').split()
+    if len(exclude_directories) == 0:
+        return
+    # Use wildcard to exclude only content of the directory.
+    # This allows to use the directory as a mount point.
+    args = " -wildcards"
+    for dir in exclude_directories:
+        args += " -e '{dir}/*' ".format(dir=dir)
+    d.appendVar('SQUASHFS_CREATION_ARGS', args)
+}
+
+IMAGE_CMD:squashfs[depends] = "${PN}:do_transform_template"
+IMAGE_CMD:squashfs[vardepsexclude] += "SQUASHFS_CREATION_LIMITS"
+IMAGE_CMD:squashfs() {
+    ${SUDO_CHROOT} /bin/mksquashfs \
+        '${SQUASHFS_CONTENT}' '${IMAGE_FILE_CHROOT}' \
+        -noappend ${SQUASHFS_CREATION_LIMITS} ${SQUASHFS_CREATION_ARGS}
+}
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index db21cc76..49861b75 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -129,7 +129,7 @@  IMAGE_BASETYPES = "${@get_image_basetypes(d)}"
 
 # image types
 IMAGE_CLASSES ??= ""
-IMGCLASSES = "imagetypes imagetypes_wic imagetypes_vm imagetypes_container"
+IMGCLASSES = "imagetypes imagetypes_wic imagetypes_vm imagetypes_container squashfs"
 IMGCLASSES += "${IMAGE_CLASSES}"
 inherit ${IMGCLASSES}