[Moto G5 Plus Guides, News, & Discussion] NZedPred:
Tools and other pre-requisites

Pre-requisites

This has been done entirely on Linux, Debian Stretch to be precise. Other 64 bit modern distros should work fine.

In all cases, it is assumed that you have extract or copy the relevant files into somewhere in your PATH.

1) IMG Patch Tools

The link to the IMG Patch Tools is here:

https://xdaforums.com/android/software-hacking/dev-img-patch-tools-sdat2img-ota-zips-t3640308 - credits to [MENTION=6298645]erfanoabdi[/MENTION]

Repo is here:

https://github.com/erfanoabdi/imgpatchtools

The first post is a description of what the tool does. The second explains usage. The third contains download links.

Download the Release version from the first link in the third post. Note that the tools are only available for Linux_x64 and MacOS.

In my case I needed to compile them on my system. Follow the instructions as per the second post. I needed to install the development libraries for zlib and libbz2, and openssl:

sudo apt-get install libbz2-dev zlib1g-dev openssl

2) IMG Repack Tools

The link to the Android img Repack Tools is here:

https://xdaforums.com/android/general/tool-android-rom-repack-tools-t3763986 - credits to [MENTION=8241686]rkhat[/MENTION]

Releases:

https://github.com/rkhat2/android-rom-repacker/releases

Source:

https://github.com/rkhat2/android-rom-repacker/tree/android-7

Download and extract the android-7 / nougat version

3) IMG to SDAT and SDAT to IMG tools

The link to the img2sdat and sdat2img tools is here:

https://xdaforums.com/android/software-hacking/how-to-conver-lollipop-dat-files-to-t2978952 - credits to [MENTION=5132229]expirt[/MENTION]

Repos are here:

https://github.com/xpirt/img2sdat

https://github.com/xpirt/sdat2img

4) Boot image tools

Get the mkbootimg tools available here:

https://github.com/xiaolu/mkbootimg_tools

Don't know of any XDA thread or developer for these.

5) SparseConverter

SparseConverter is needed to convert the Fastboot sparse chunks into an image file. This is only required for creating a TWRP flashable build from the Fastboot image files. It is not needed for an existing TWRP flashable build.

The link to SparseConverter, both the binary and source code, is here:

https://xdaforums.com/showthread.php?t=2749797 - credits to [MENTION=5860594]tal.aloni[/MENTION]

In my case, I downloaded the source code and compiled it using MonoDevelop. You can open the Visual Studio Solution file (.sln) in MonoDevelop and compile. It may also be possible to download the binary and execute it using mono. If you choose this route, adjust commands below to suit. I haven't tried this myself, so if it doesn't work try compiling it from source.

6) TWRP Flashable Template zip

Another requirement for building a TWRP flashable zip from the Fastboot images is to have a suitable template zip. I have created one and placed it here:

https://www.androidfilehost.com/?fid=5862345805528045057

7) Brotli

Brotli is a loss-less compression format that is now being used in the Oreo OTAs. Its file extension is br. You can get the latest release/source code from here:

https://github.com/google/brotli/releases

8) lz4

In some cases, device tree images are compressed using lz4. This is a standard part of many linux distributions. Use the following on Debian/Ubuntu:

sudo apt install liblz4-tool

9) A hex editor

Editing the device tree binary/blob needs a hex editor. I have used dhex because it can be used over the command line. Use the following on Debian/Ubuntu:

sudo apt install dhex

Any other hex editor will suffice.

Change log of this post

2018-06-17 - add in SparseConverter details, TWRP template zip.

2018-07-10 - change link to TWRP Flashable template - new one is edited to NOT erase modemst1 and modemst2.

2018-08-19 - add in Brotli, required for new Oreo OTAs.

2018-09-09 - add in lz4 and hex editor requirements.

2018-10-14 - add in link to sdat2img repo. Properly tag the authors of the different tools that I use (where available).