diff mbox series

[isar-cip-core,RFC,1/8] Add new class to create a squashfs based root file system

Message ID 20211112115017.401779-2-Quirin.Gylstorff@siemens.com (mailing list archive)
State Handled Elsewhere
Headers show
Series Read-only root file system with dm-verity | expand

Commit Message

Quirin Gylstorff Nov. 12, 2021, 11:50 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

This file system is read only and use a reduced image size.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 classes/squashfs-img.bbclass | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 classes/squashfs-img.bbclass

Comments

Jan Kiszka Nov. 12, 2021, 12:41 p.m. UTC | #1
On 12.11.21 12:50, Q. Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> This file system is read only and use a reduced image size.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  classes/squashfs-img.bbclass | 42 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
>  create mode 100644 classes/squashfs-img.bbclass
> 
> diff --git a/classes/squashfs-img.bbclass b/classes/squashfs-img.bbclass
> new file mode 100644
> index 0000000..f827e8c
> --- /dev/null
> +++ b/classes/squashfs-img.bbclass
> @@ -0,0 +1,42 @@
> +#
> +# CIP Core, generic profile
> +#
> +# Copyright (c) Siemens AG, 2021
> +#
> +# Authors:
> +#  Quirin Gylstorff <quirin.gylstorff@siemens.com>
> +#
> +# SPDX-License-Identifier: MIT
> +#
> +
> +SQUASHFS_IMAGE_FILE = "${IMAGE_FULLNAME}.squashfs.img"
> +
> +IMAGER_INSTALL += "squashfs-tools"
> +
> +SQUASHFS_EXCLUDE_DIRS ?= ""
> +SQUASHFS_CONTENT ?= "${PP_ROOTFS}"
> +SQUASHFS_CREATION_ARGS ?= " "

Blank line after this.

> +# Generate squashfs filesystem image

I don't think the anonymous function does that...

> +python __anonymous() {
> +    exclude_directories = (d.getVar('SQUASHFS_EXCLUDE_DIRS') or "").split()
> +    if len(exclude_directories) == 0:
> +        return
> +    args=d.getVar('SQUASHFS_CREATION_ARGS')
> +    args+=" -wildcards"
> +    # use wildcard to exclude only content of the the directory
> +    # this allows to use the directory as a mount point
> +    for dir in exclude_directories:
> +        args+=" -e {dir}/* ".format(dir=dir)
> +    d.setVar('SQUASHFS_CREATION_ARGS', args)

How about d.appendVar?

And Python style for python functions, please.

> +}
> +
> +do_squashfs_image() {
> +    rm -f '${DEPLOY_DIR_IMAGE}/${SQUASHFS_IMAGE_FILE}'
> +
> +    image_do_mounts
> +
> +    sudo chroot "${BUILDCHROOT_DIR}" /bin/mksquashfs  \
> +        "${SQUASHFS_CONTENT}" "${PP_DEPLOY}/${SQUASHFS_IMAGE_FILE}" \
> +        ${SQUASHFS_CREATION_ARGS}
> +}
> +addtask do_squashfs_image before do_image after do_image_tools do_excl_directories
> 

This should also qualify as generic Isar class. It can start here, though.

Jan
diff mbox series

Patch

diff --git a/classes/squashfs-img.bbclass b/classes/squashfs-img.bbclass
new file mode 100644
index 0000000..f827e8c
--- /dev/null
+++ b/classes/squashfs-img.bbclass
@@ -0,0 +1,42 @@ 
+#
+# CIP Core, generic profile
+#
+# Copyright (c) Siemens AG, 2021
+#
+# Authors:
+#  Quirin Gylstorff <quirin.gylstorff@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+
+SQUASHFS_IMAGE_FILE = "${IMAGE_FULLNAME}.squashfs.img"
+
+IMAGER_INSTALL += "squashfs-tools"
+
+SQUASHFS_EXCLUDE_DIRS ?= ""
+SQUASHFS_CONTENT ?= "${PP_ROOTFS}"
+SQUASHFS_CREATION_ARGS ?= " "
+# Generate squashfs filesystem image
+python __anonymous() {
+    exclude_directories = (d.getVar('SQUASHFS_EXCLUDE_DIRS') or "").split()
+    if len(exclude_directories) == 0:
+        return
+    args=d.getVar('SQUASHFS_CREATION_ARGS')
+    args+=" -wildcards"
+    # use wildcard to exclude only content of the the directory
+    # this allows to use the directory as a mount point
+    for dir in exclude_directories:
+        args+=" -e {dir}/* ".format(dir=dir)
+    d.setVar('SQUASHFS_CREATION_ARGS', args)
+}
+
+do_squashfs_image() {
+    rm -f '${DEPLOY_DIR_IMAGE}/${SQUASHFS_IMAGE_FILE}'
+
+    image_do_mounts
+
+    sudo chroot "${BUILDCHROOT_DIR}" /bin/mksquashfs  \
+        "${SQUASHFS_CONTENT}" "${PP_DEPLOY}/${SQUASHFS_IMAGE_FILE}" \
+        ${SQUASHFS_CREATION_ARGS}
+}
+addtask do_squashfs_image before do_image after do_image_tools do_excl_directories