diff mbox series

[1/5,v2] image_types: add python function to get the IMAGE_FILE_MAXSIZE:fstype value

Message ID 20230806211348.1191553-2-charles-antoine.couret@mind.be
State New
Headers show
Series image_types: use IMAGE_FILE_MAXSIZE variable to create fixed partition size | expand

Commit Message

Charles-Antoine Couret Aug. 6, 2023, 9:13 p.m. UTC
It returns 0 if the variable is not set for this filesystem.

In case of fixed partitionning where the rootfs partition can't exceed an
amount of bytes, there is currently no automatic and no generic way to have
this requirement met in any case.

Until now, ROOTFS_SIZE value got from directory_size() does not takes into account
the size of required metadata for the filesystem itself (and does not work well
for other block size than 4k BTW).
Obviously it's a difficult task which depends on rootfs size and filesystem type.

The workaround was to set IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
to add the required extra margins. But when the final rootfs is closed to the
maximum size, it's difficult to adjust them correctly  And if you remove
or add new recipes in your image, you've to recompute these margins to have enough
space for these metadata when the rootfs is small, and to not have too big final
file when the rootfs is big.

It's cumbersome and error prone to just have a build failure when the final output
can't be flashed into the partition.

The solution is to follow how it's implemented in buildroot by having a
specific variable, here IMAGE_FILE_MAXSIZE, to create the final sparse file
and trying to fill it with the content of rootfs. If there is enough space,
margins are well compressed and does not consume space in the filesystem.
If there is no enough space, an error is triggered to warm the developer before
trying to use it in the device.

If IMAGE_FILE_MAXSIZE is not set, the idea is to keep the previous behaviour
for compatibility reason and to met other requirements.

Signed-off-by: Charles-Antoine Couret <charles-antoine.couret@mind.be>
---
 documentation/ref-manual/variables.rst  | 14 ++++++++++++++
 meta/classes-recipe/image_types.bbclass |  7 +++++++
 2 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/documentation/ref-manual/variables.rst b/documentation/ref-manual/variables.rst
index fc29e476cd..d0e476d2eb 100644
--- a/documentation/ref-manual/variables.rst
+++ b/documentation/ref-manual/variables.rst
@@ -3476,6 +3476,20 @@  system and gives an overview of their function and contents.
       variable, see the ":ref:`dev-manual/customizing-images:customizing images using custom \`\`image_features\`\` and \`\`extra_image_features\`\``"
       section in the Yocto Project Development Tasks Manual.
 
+   :term:`IMAGE_FILE_MAXSIZE`
+      Specifies the maximum size in kilobytes to create the image file for a
+      specific image type, which corresponds to the value set in
+      :term:`IMAGE_FSTYPES`, (e.g. ``ext3``,
+      ``btrfs``, and so forth). When setting this variable, you should use
+      an override for the associated type. Here is an example::
+
+         IMAGE_FILE_MAXSIZE:ext4 = "8192"
+
+      It overrides the :term:`IMAGE_OVERHEAD_FACTOR` and
+      :term:`IMAGE_ROOTFS_EXTRA_SPACE` mechanism for some filesystems.
+      If the maximum size is below the required size to store the rootfs content,
+      the operation will fail.
+
    :term:`IMAGE_FSTYPES`
       Specifies the formats the OpenEmbedded build system uses during the
       build when creating the root filesystem. For example, setting
diff --git a/meta/classes-recipe/image_types.bbclass b/meta/classes-recipe/image_types.bbclass
index 023eb87537..33c65e8282 100644
--- a/meta/classes-recipe/image_types.bbclass
+++ b/meta/classes-recipe/image_types.bbclass
@@ -54,6 +54,13 @@  def imagetypes_getdepends(d):
     # Sort the set so that ordering is consistant
     return " ".join(sorted(deps))
 
+def get_max_image_size(d, fs):
+    max_size = d.getVar("IMAGE_FILE_MAXSIZE:%s" % fs)
+    if max_size is not None:
+        return max_size
+
+    return 0
+
 XZ_COMPRESSION_LEVEL ?= "-9"
 XZ_INTEGRITY_CHECK ?= "crc32"