[Replicant] [vendor_replicant-scripts] [PATCH 1/9] add_adb_root: switch from FSO's unbootimg to abootimg

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Fri Oct 1 17:47:51 UTC 2021


While abootimg git[1] has no new commits since 2021, FSO's
unbootimg is not maintained at all as work on the
Freesmartphone.org has stopped.

As abootimg is used by diffoscope and it is pakcaged by
Debian and Guix, so it's probably better to use to abootimg
since more people will more likely already have it in the
distribution they use and since it's a dependency of
diffoscope we are more likely tools with the same command
line interface in the future than the interface of FSO's
unbootimg.

I added a package for abootimg 6.0 in Parabola and Aur in
order to make it easier for Parabola users to transition
from fso-unbootimg to abootimg.

[1]https://github.com/ggrandou/abootimg

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 images/add_adb_root/add_adb_root.py | 34 ++++++++++++++++-------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/images/add_adb_root/add_adb_root.py b/images/add_adb_root/add_adb_root.py
index c47a90b..b13d69f 100755
--- a/images/add_adb_root/add_adb_root.py
+++ b/images/add_adb_root/add_adb_root.py
@@ -48,24 +48,21 @@ def automatically_identify_file(path):
     # TODO: is it really relevant?
     file_infos['target'] = None
 
-    output = str(sh.unbootimg("-i", path)).split(os.linesep)
+    output = str(sh.abootimg("-i", path)).split(os.linesep)
 
     for line in output:
-        if line.startswith('kernel load addr:'):
+        if line.startswith('  kernel:'):
             for word in line.split(" "):
                 if word.startswith("0x"):
                     kernel_load_addr = int(word, 16)
                     # TODO: Add support for 64bit targets
                     file_infos['base_address'] = kernel_load_addr & 0xffff0000
 
-        if line.startswith('cmdline:'):
-            for word in line.split(" "):
-                if word.startswith("`"):
-                    file_infos['cmdline'] = \
-                        word.replace("`", "").replace("'", "")
+        if line.startswith('* cmdline = '):
+            file_infos['cmdline'] = line[len('* cmdline = '):]
 
-        if line.startswith('id:'):
-            file_infos['id'] = re.sub("^id: *", "", line)
+        if line.startswith('* id ='):
+            file_infos['id'] = line[len('* id ='):].replace(" 0x", "")
 
     return file_infos
 
@@ -83,9 +80,18 @@ def identify_file(path):
 
 def identify_image_type(path):
     try:
-        output = sh.unbootimg("-i", path)
+        output = sh.abootimg("-i", path)
     except Exception as e:
-        if e.stderr == b'error: supplied file is not an Android boot image\n':
+
+        no_android_magic_value = False
+        not_a_valid_android_boot_image = False
+        for line in e.stderr.decode().split(os.linesep):
+            if re.search(': no Android Magic Value$', line):
+                no_android_magic_value = True
+            if re.search(': not a valid Android Boot Image.$', line):
+                not_a_valid_android_boot_image = True
+
+        if no_android_magic_value and not_a_valid_android_boot_image:
             return ImageType.zImage
         else:
             return ImageType.unknown
@@ -214,15 +220,13 @@ def add_adb_to_bootimage(input_file, output_file):
     kernel = tmpdir + os.sep + "kernel.img"
     ramdisk = tmpdir + os.sep + "ramdisk.cpio"
     compressed_ramdisk = ramdisk + ".gz"
+    config = tmpdir + os.sep + "bootimg.cfg"
 
     # TODO: autodetect cmdline and base_address
     base_address = file_infos['base_address']
     cmdline = file_infos['cmdline']
 
-    # TODO: check output
-    output = sh.unbootimg("--kernel", kernel,
-                          "--ramdisk", compressed_ramdisk,
-                          "-i", input_file)
+    sh.abootimg("-x", input_file, config, kernel, compressed_ramdisk)
 
     sh.gunzip(compressed_ramdisk)
 
-- 
2.33.0



More information about the Replicant mailing list