Skip to contentSkip to conversation

1/3] image_types_sparse: backport fix pad source image to block size

PATCH New AshishKumar Mishra 2 participants 5 messages Sep 25, 2025 – Sep 29, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 1/3] image_types_sparse: backport fix pad source image to block size

From: Sean Anderson <[email protected]>

If the source image's size is not aligned to the sparse image's block size, then conversion will fail with

img2simg: libsparse/sparse.cpp:133: int write_all_blocks(sparse_file*, output_file*): Assertion `pad >= 0' failed.

This is a bug in img2simg, but an easy way to work around it is to pad the source image ourselves. The default block size of 4096 matches img2simg's default block size.

This change corresponds to upstream fb331cb62eafd1e534dee292525084ccee0ef3e1

---
 meta-oe/classes/image_types_sparse.bbclass | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
meta-oe/classes/image_types_sparse.bbclass +10 -2
index 4263593a8d..b092f68406 100644
@@ -1,8 +1,16 @@
 inherit image_types
 
+# This sets the granularity of the sparse image conversion. Chunk sizes will be
+# specified in units of this value. Setting this value smaller than the
+# underlying image's block size will not result in any further space saving.
+# However, there is no loss in correctness if this value is larger or smaller
+# than optimal. This value should be a power of two.
+SPARSE_BLOCK_SIZE ??= "4096"
+
 CONVERSIONTYPES += "sparse"
 CONVERSION_CMD:sparse = " \
-    img2simg "${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}" \
-             "${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}.sparse" \
+    INPUT="${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}" && \
+    truncate --no-create --size=%${SPARSE_BLOCK_SIZE} "$INPUT" && \
+    img2simg "$INPUT" "$INPUT.sparse" ${SPARSE_BLOCK_SIZE} \
 "
 CONVERSION_DEPENDS_sparse = "android-tools-native"
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 2/3] image_types_sparse: backport generate "don't care" chunks

From: Sean Anderson <[email protected]>

By default, img2simg will only generate raw and fill chunks. This adds support for "don't care" chunks, based on file holes. This is similar to how bmaptool works. "don't care" chunks do not need to be written, speeding up flashing time.
This change corresponds to upstream 9862a017fa7f88424f0670ba89af58e5051550b0

---
 meta-oe/classes/image_types_sparse.bbclass    |   2 +-
 ...off-most-of-sparse_file_read_normal-.patch |  60 ++++++
 ...se-Add-hole-mode-to-sparse_file_read.patch | 188 ++++++++++++++++++
 ...port-for-converting-holes-to-don-t-c.patch | 114 +++++++++++
 .../android-tools/android-tools_5.1.1.r37.bb  |   3 +
 5 files changed, 366 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-devtools/android-tools/android-tools/core/0015-libsparse-Split-off-most-of-sparse_file_read_normal-.patch
 create mode 100644 meta-oe/recipes-devtools/android-tools/android-tools/core/0016-libsparse-Add-hole-mode-to-sparse_file_read.patch
 create mode 100644 meta-oe/recipes-devtools/android-tools/android-tools/core/0017-img2simg-Add-support-for-converting-holes-to-don-t-c.patch
meta-oe/classes/image_types_sparse.bbclass +1 -1
index b092f68406..8668739fd9 100644
@@ -11,6 +11,6 @@ CONVERSIONTYPES += "sparse"
 CONVERSION_CMD:sparse = " \
     INPUT="${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${type}" && \
     truncate --no-create --size=%${SPARSE_BLOCK_SIZE} "$INPUT" && \
-    img2simg "$INPUT" "$INPUT.sparse" ${SPARSE_BLOCK_SIZE} \
+    img2simg -s "$INPUT" "$INPUT.sparse" ${SPARSE_BLOCK_SIZE} \
 "
 CONVERSION_DEPENDS_sparse = "android-tools-native"
meta-oe/recipes-devtools/android-tools/android-tools/core/0015-libsparse-Split-off-most-of-sparse_file_read_normal-.patch new file +60 -0

60 lines not on this page · raw message

meta-oe/recipes-devtools/android-tools/android-tools/core/0016-libsparse-Add-hole-mode-to-sparse_file_read.patch new file +188 -0

188 lines not on this page · raw message

meta-oe/recipes-devtools/android-tools/android-tools/core/0017-img2simg-Add-support-for-converting-holes-to-don-t-c.patch new file +114 -0

114 lines not on this page · raw message

meta-oe/recipes-devtools/android-tools/android-tools_5.1.1.r37.bb +3 -0
index cf10968296..28286d6619 100644
@@ -41,6 +41,9 @@ SRC_URI = " \
     file://core/adb_libssl_11.diff;patchdir=system/core \
     file://core/0013-adb-Support-riscv64.patch;patchdir=system/core \
     file://core/0014-add-u3-ss-descriptor-support-for-adb.patch;patchdir=system/core \
+    file://core/0015-libsparse-Split-off-most-of-sparse_file_read_normal-.patch;patchdir=system/core \
+    file://core/0016-libsparse-Add-hole-mode-to-sparse_file_read.patch;patchdir=system/core \
+    file://core/0017-img2simg-Add-support-for-converting-holes-to-don-t-c.patch;patchdir=system/core \
     file://extras/0001-ext4_utils-remove-selinux-extensions.patch;patchdir=system/extras \
     file://extras/0002-ext4_utils-add-o-argument-to-preserve-ownership.patch;patchdir=system/extras \
     file://libselinux/0001-Remove-bionic-specific-calls.patch;patchdir=external/libselinux \
Signature · 1 line
2.43.0
#2 lore raw

PATCH 1/1 3/3] image_types_sparse: backport optionally remove RAW image

In reply to AshishKumar Mishra

From: AshishKumar Mishra <[email protected]>

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

---
 meta-oe/classes/image_types_sparse.bbclass | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
meta-oe/classes/image_types_sparse.bbclass +11 -3
index 8668739fd9..81dba96305 100644
@@ -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"
Signature · 1 line
2.43.0
#3 lore raw

Re: [kirkstone][PATCH] 3/3] image_types_sparse: backport optionally remove RAW image

@ Gyorgy Sarvari  :

Good Morning .
Please do consider this patch for merge in Kirkstone If any suggestion / feedback on this , feel free to share . Will work on it accordingly
Have shared the 3 patch changes for same

Thanks ,
Ashish

#4 lore raw

Re: [oe] [kirkstone][PATCH] 3/3] image_types_sparse: backport optionally remove RAW image

Your patches are not forgotten, but stable branches are not rolling-branches.

As a non-official reference, you can check this repository:
https://git.openembedded.org/meta-openembedded-contrib/log/?h=stable/kirkstone-nut
This is where I stage the patches for testing for the next kirkstone pull request - though it is a fluid branch and changes relatively often, it is the best indicator I can offer you at this moment about what can be expected. Most probably this will be merged into the final branch.

This repo/branch is not canonical. I use it now, but might change in the future.

Quoted 19 lines · Ashish Mishra via lists.openembedded.org

@ Gyorgy Sarvari  :

Good Morning .
Please do consider this patch for merge in Kirkstone If any suggestion / feedback on this , feel free to share . Will work on it accordingly
Have shared the 3 patch changes for same

Thanks ,
Ashish

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#120007): https://lists.openembedded.org/g/openembedded-devel/message/120007
Mute This Topic: https://lists.openembedded.org/mt/115434756/6084445
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-