[elbe-devel] [PATCH 2/2] elbepack: packers: add support for android-sparse

Thomas Weißschuh thomas.weissschuh at linutronix.de
Thu Dec 5 10:35:39 CET 2024


android-sparse is a image format created by Android and also used by
various other embedded system flashing tools.
Add native support for it.

Suggested-by: Javier Fernandez Pastrana <jfpastrana at linutronix.de>
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 debian/control                            |  1 +
 elbepack/packers.py                       | 14 ++++++++++++++
 elbepack/schema/dbsfed.xsd                |  3 ++-
 newsfragments/+android-sparse.feature.rst |  8 ++++++++
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/debian/control b/debian/control
index cc71379a871acf5193454b7e766b4e06462eebba..196b0f319c49c0fb1b5475e1f381fb63adbb7bc7 100644
--- a/debian/control
+++ b/debian/control
@@ -111,6 +111,7 @@ Package: python3-elbe-buildenv
 Architecture: all
 Depends: ${misc:Depends}, ${python3:Depends},
   python3,
+  android-sdk-libsparse-utils,
   binfmt-support,
   btrfs-progs,
   debootstrap,
diff --git a/elbepack/packers.py b/elbepack/packers.py
index 7b7b028e0365b4038e2d4fcc77548bf97fd3bec0..006510125395ed45b28ce3ef3ce2aaf45aadb419 100644
--- a/elbepack/packers.py
+++ b/elbepack/packers.py
@@ -70,6 +70,19 @@ class TarArchiver(Packer):
         return fname + self.suffix
 
 
+class AndroidSparsePacker(Packer):
+    def pack_file(self, builddir, fname):
+        try:
+            fpath = os.path.join(builddir, fname)
+            do(['img2simg', fpath, fpath + '.simg'])
+            return fname + '.simg'
+        except subprocess.CalledProcessError:
+            # in case of an error, we just return None
+            # which means, that the orig file does not
+            # exist anymore
+            return None
+
+
 packers = {'none': NoPacker(),
            'gzip': InPlacePacker(['gzip', '-f'], '.gz'),
            'zstd': InPlacePacker(['zstd', '-T0'], '.zst'),
@@ -77,6 +90,7 @@ packers = {'none': NoPacker(),
            'tarxz': TarArchiver('--use-compress-program="xz -T0 -M40%"', '.tar.xz'),
            'targz': TarArchiver('--auto-compress', '.tar.gz'),
            'tarzstd': TarArchiver('--use-compress-program="zstd -T0"', '.tar.zst'),
+           'android-sparse': AndroidSparsePacker(),
            }
 
 default_packer = packers['targz']
diff --git a/elbepack/schema/dbsfed.xsd b/elbepack/schema/dbsfed.xsd
index 9f41dcbf47e375b250679bf8b532a90a05b8d3d8..e45920b33400ffb724506ffcb362352dba796511 100644
--- a/elbepack/schema/dbsfed.xsd
+++ b/elbepack/schema/dbsfed.xsd
@@ -2576,7 +2576,7 @@ SPDX-FileCopyrightText: Linutronix GmbH
          <annotation>
           <documentation>
           Describes the compressor for the resulting image from the
-          following values:(none, gzip, zstd, tar, targz, tarxz, tarzstd).
+          following values:(none, gzip, zstd, tar, targz, tarxz, tarzstd, android-sparse).
           </documentation>
          </annotation>
         </attribute>
@@ -2593,6 +2593,7 @@ SPDX-FileCopyrightText: Linutronix GmbH
       <enumeration value="tarxz" />
       <enumeration value="targz" />
       <enumeration value="tarzstd" />
+      <enumeration value="android-sparse" />
     </restriction>
   </simpleType>
 
diff --git a/newsfragments/+android-sparse.feature.rst b/newsfragments/+android-sparse.feature.rst
new file mode 100644
index 0000000000000000000000000000000000000000..2706d3c54112699e49e095b77a65b469f60ffe88
--- /dev/null
+++ b/newsfragments/+android-sparse.feature.rst
@@ -0,0 +1,8 @@
+Add support for Android sparse images.
+Example:
+
+.. code-block:: xml
+
+        <project-finetuning>
+                <set_packer packer="android-sparse">sda.img</set_packer>
+        </project-finetuning>

-- 
2.47.1



More information about the elbe-devel mailing list