From 4c10114c6624804c5e4ce2b04e51c7ffe4f879f8 Mon Sep 17 00:00:00 2001 From: AshishKumar Mishra Date: Thu, 25 Sep 2025 22:59:31 +0530 Subject: [PATCH] image_types_sparse: backport optionally remove RAW image When creating sparse images, the RAW image is no longer needed in some workflows such as Android and CI pipelines. These RAW images can be multi-GB artifacts and consume significant disk space. This change introduces a configuration option `DELETE_RAWIMAGE_AFTER_SPARSE_CMD` which, when set to "1", removes the RAW image after sparse image generation. This reduces disk usage in builds where sparse images are the final deliverables and RAW images are not required. Default behavior is unchanged: RAW images are kept unless the variable is explicitly enabled: This change corresponds to upstream f5246b7df447ac76ec04c6e5add398862d1c9ccd DELETE_RAWIMAGE_AFTER_SPARSE_CMD = "1" # Delete RAW image DELETE_RAWIMAGE_AFTER_SPARSE_CMD = "0" # Default behavior Signed-off-by: AshishKumar Mishra Signed-off-by: Khem Raj Signed-off-by: AshishKumar Mishra Signed-off-by: Gyorgy Sarvari --- meta-oe/classes/image_types_sparse.bbclass | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/meta-oe/classes/image_types_sparse.bbclass b/meta-oe/classes/image_types_sparse.bbclass index 8668739fd9..81dba96305 100644 --- a/meta-oe/classes/image_types_sparse.bbclass +++ b/meta-oe/classes/image_types_sparse.bbclass @@ -8,9 +8,17 @@ inherit image_types SPARSE_BLOCK_SIZE ??= "4096" CONVERSIONTYPES += "sparse" + +DELETE_RAWIMAGE_AFTER_SPARSE_CMD ??= "0" + CONVERSION_CMD:sparse = " \ - INPUT="${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}" && \ - truncate --no-create --size=%${SPARSE_BLOCK_SIZE} "$INPUT" && \ - img2simg -s "$INPUT" "$INPUT.sparse" ${SPARSE_BLOCK_SIZE} \ + INPUT=${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type} && \ + truncate --no-create --size=%${SPARSE_BLOCK_SIZE} $INPUT && \ + img2simg $INPUT $INPUT.sparse && \ + if [ ${DELETE_RAWIMAGE_AFTER_SPARSE_CMD} = 1 ]; then \ + rm -f $INPUT; \ + bbwarn 'Raw file $INPUT removed'; \ + fi \ " + CONVERSION_DEPENDS_sparse = "android-tools-native"