From 42018f80146e9c1049327e35ecbbbaf0b2eedf19 Mon Sep 17 00:00:00 2001
From: Lucas Ramage <ramage.lucas@openmailbox.org>
Date: Sun, 11 Feb 2018 06:41:41 -0500
Subject: [PATCH] mkbootimg: replace Python version with osm0sis' C version
 (#1193)

Closes #441. Adjust bootimg_analyze code:
* Install mkbootimg (which now provides unpackbootimg) instead of
  unpackbootimg. In theory, pmbootstrap should recognize this
  automatically, however right now it does not yet handle this case.
* The file names of the extracted files have changed.
---
 aports/main/mkbootimg/APKBUILD     | 23 +++++++++++++----------
 aports/main/unpackbootimg/APKBUILD | 21 ---------------------
 pmb/parse/bootimg.py               | 14 +++++++-------
 3 files changed, 20 insertions(+), 38 deletions(-)
 delete mode 100644 aports/main/unpackbootimg/APKBUILD

diff --git a/aports/main/mkbootimg/APKBUILD b/aports/main/mkbootimg/APKBUILD
index c21221e28..f6df016d1 100644
--- a/aports/main/mkbootimg/APKBUILD
+++ b/aports/main/mkbootimg/APKBUILD
@@ -1,21 +1,24 @@
 pkgname=mkbootimg
-pkgver=14.1
-pkgrel=1
-pkgdesc="Android bootimg (zimage + initramfs) creation tool"
-url="https://github.com/LineageOS/android_system_core/blob/cm-14.1/mkbootimg/mkbootimg"
-arch="noarch"
+pkgver=2017.12.13
+pkgrel=0
+pkgdesc="Android bootimg creation tool"
+url="https://github.com/osm0sis/mkbootimg"
+arch="all"
 license="APACHE2"
-depends="python3"
+depends=""
+provides="unpackbootimg"
 subpackages=""
-source="$pkgname::https://raw.githubusercontent.com/LineageOS/android_system_core/cm-14.1/mkbootimg/mkbootimg"
+source="$pkgname.tar.gz::https://github.com/osm0sis/$pkgname/archive/$pkgver.tar.gz"
 options="!check"
+workdir="$pkgname-$pkgver"
 
 build() {
-	sed -i -e 's./usr/bin/env python./usr/bin/env python3.' $srcdir/$pkgname
+	make -j1
 }
 
 package() {
-	install -Dm755 $srcdir/$pkgname $pkgdir/usr/bin/$pkgname
+	install -Dm755 "$srcdir/$workdir/mkbootimg" "${pkgdir}/usr/bin/mkbootimg"
+	install -Dm755 "$srcdir/$workdir/unpackbootimg" "${pkgdir}/usr/bin/unpackbootimg"
 }
 
-sha512sums="71ab9b6dfe19096bf6b33a8c46148dbe2b8b71fd693dcaf8cdba7a932e19bb7d29c3c245148a4b27119a6b883fc8f0ba04f5f815da0c40410b2b11d9fa1b7cd7  mkbootimg"
+sha512sums="39820ee581f007b6e7c69f83ae6d54e99d32869604d1a960421c0c588fa55917f686104782b1e5ff5cb586f7efb19e9b9db11e69031cbb5e22462ab9d39cdc20  mkbootimg.tar.gz"
diff --git a/aports/main/unpackbootimg/APKBUILD b/aports/main/unpackbootimg/APKBUILD
deleted file mode 100644
index 3018631ae..000000000
--- a/aports/main/unpackbootimg/APKBUILD
+++ /dev/null
@@ -1,21 +0,0 @@
-pkgname=unpackbootimg
-pkgver="14.1"
-pkgrel=1
-pkgdesc="Android bootimg (zimage + initramfs) extraction tool"
-url="https://github.com/LineageOS/android_system_core"
-arch="noarch"
-license="APACHE2"
-depends="python3"
-source="$pkgname-$pkgver.py::https://raw.githubusercontent.com/LineageOS/android_system_core/cm-${pkgver}/mkbootimg/${pkgname}"
-options="!check"
-
-build() {
-	cp "$srcdir"/"$pkgname"-"$pkgver".py "$srcdir"/"$pkgname"
-	sed -i -e 's./usr/bin/env python./usr/bin/env python3.' "$srcdir"/"$pkgname"
-}
-
-package() {
-	install -Dm755 "$srcdir"/"$pkgname" "$pkgdir"/usr/bin/"$pkgname"
-}
-
-sha512sums="b86022b3f16a6a35c68a7dd00b0ce2dcac667162f11581090bdb07d50a3ea93a74c2f493405d3d6751d40bf463c022216738ad8bcafc457dfc55e08aa5c2ed0e  unpackbootimg-14.1.py"
diff --git a/pmb/parse/bootimg.py b/pmb/parse/bootimg.py
index 9fef50f87..63e272b0b 100644
--- a/pmb/parse/bootimg.py
+++ b/pmb/parse/bootimg.py
@@ -27,7 +27,7 @@ def bootimg(args, path):
 
     logging.info("NOTE: You will be prompted for your sudo password, so we can set"
                  " up a chroot to extract and analyze your boot.img file")
-    pmb.chroot.apk.install(args, ["file", "unpackbootimg"])
+    pmb.chroot.apk.install(args, ["file", "mkbootimg"])
 
     temp_path = pmb.chroot.other.tempfolder(args, "/tmp/bootimg_parser")
     bootimg_path = args.work + "/chroot_native" + temp_path + "/boot.img"
@@ -52,20 +52,20 @@ def bootimg(args, path):
     # Get base, offsets, pagesize, cmdline and qcdt info
     with open(bootimg_path + "-base", 'r') as f:
         output["base"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
-    with open(bootimg_path + "-kernel_offset", 'r') as f:
+    with open(bootimg_path + "-kerneloff", 'r') as f:
         output["kernel_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
-    with open(bootimg_path + "-ramdisk_offset", 'r') as f:
+    with open(bootimg_path + "-ramdiskoff", 'r') as f:
         output["ramdisk_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
-    with open(bootimg_path + "-second_offset", 'r') as f:
+    with open(bootimg_path + "-secondoff", 'r') as f:
         output["second_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
-    with open(bootimg_path + "-tags_offset", 'r') as f:
+    with open(bootimg_path + "-tagsoff", 'r') as f:
         output["tags_offset"] = ("0x%08x" % int(f.read().replace('\n', ''), 16))
     with open(bootimg_path + "-pagesize", 'r') as f:
         output["pagesize"] = f.read().replace('\n', '')
     with open(bootimg_path + "-cmdline", 'r') as f:
         output["cmdline"] = f.read().replace('\n', '')
-    output["qcdt"] = ("true" if os.path.isfile(bootimg_path + "-dt") and
-                      os.path.getsize(bootimg_path + "-dt") > 0 else "false")
+    output["qcdt"] = ("true" if os.path.isfile(bootimg_path + "-dtb") and
+                      os.path.getsize(bootimg_path + "-dtb") > 0 else "false")
 
     # Cleanup
     pmb.chroot.root(args, ["rm", "-r", temp_path])
-- 
GitLab