[Moto G5S  ROMs, Kernels, Recoveries, & Other Devel] DoctorStrange96:
#include "std_disclaimer.h"

/*
* Your warranty is now void... Well, probably not.
*
* I am not responsible for bricked devices, dead SD cards,
* thermonuclear war, or you getting fired because the alarm app failed. Please
* do some research if you have any concerns about features included in this ROM
* before flashing it! YOU are choosing to make these modifications, and if
* you point the finger at me for messing up your device, I will laugh at you.
* A lot.
*
* Tl;dr: if your device crashes and burns, I'm sorry, but I'm not to be blamed.
*/

Hey guys.

This is a guide on how to install official Android 8.1.0 "Oreo" on our beloved, forgotten, poor Moto G5s (montana). As you all may know, Lenovorola still hasn't released Oreo for everyone worldwide. Only a few Latin American countries are receiving the update, with Brazil due to receive it Soon™, since we've already received the August security patch (still Nougat though :/).

Update 2018.09.29: Brazil and India have also started receiving Oreo, but with a different build (OPP28.65-37-2).

However, this is Lenovorola we're dealing with, so I went ahead, captured the OTA and created a TWRP flashable zip, by patching the June firmware (NPPS26.102-49-11) with said OTA. And also, there's the standard .xml.zip to be used with fastboot, directly from Moto.

For those of you who want to keep everything stock, locked bootloader and all, I recommend going with the fastboot zip. For those who already have unlocked their phone's bootloaders and have TWRP installed, or are coming from a custom ROM but don't want to fiddle around with fastboot, you should use the TWRP flashable zip.

I can't stress this enough. ALWAYS BACK UP YOUR STUFF!!!! Do a TWRP backup (data, system, boot). I recommend backing up the contents of your internal storage as well. And for those willing to downgrade at some point, back up your persist and efs partitions, otherwise you'll lose IMEI!

Oh, and I assume you already have adb, fastboot and the Motorola USB drivers installed. In case you don't...

Motorola USB Drivers

Android SDK Platform Tools (includes adb & fastboot)

If you use Linux, you don't need to install any drivers, but you may have to configure udev to allow fastboot to detect your device. But that, along with telling how to configure adb and fastboot, is beyond the scope of this thread.

I don't know how things work in the Apple side, so kindly don't ask me how to do that on macOS.

This firmware should work on all Moto G5s models (XT1791/2/3/4/5/7). I can't tell if it works on model XT1799-2 (aka Green Pomelo / Qingyou).

A few warnings:

1. Forced encryption has not been disabled. So, if your phone is not encrypted, it will be encrypted again upon the very first boot. Don't interrupt the process, otherwise you'll lose ALL of your data! (You can flash @Zackptg5's dm-verity / forced encryption disabler if you want to)

2. Xposed doesn't work, whether it's installed to /system or via Magisk (systemless). I've already opened an issue on GitHub and am awaiting a reply.

3. (Fastboot only) Updating to this firmware will also update your bootloader and partition table. If you're unsure about that and/or afraid of a possible hard brick, skip the gpt and bootloader lines.

4. Please install the proper build for your software channel. For retbr and retin, use OPP28.65-37-2. For the other channels, go with OPP28.65-37.

5. If your phone's software channel is retbr or retin and you have already flashed the -37 build, you can simply dirty flash the -37-2 build over it. No need to factory reset / fastboot erase userdata.

With that out of the way, let's get to what matters most.

Installation Guide:

Thanks to:

[MENTION=7346927]NZedPred[/MENTION] for the excellent tutorial on how to build flashable zips based on stock firmware and/or OTAs

[MENTION=7672302]Cesarcami53[/MENTION] for telling us that the update was out for retla

[MENTION=6298645]erfanoabdi[/MENTION] for his Motorola OTA Link Generator and IMG Patch Tools

[MENTION=4554317]lohanbarth[/MENTION] for mirroring the fastboot zips to AFH / Mega

In case I forgot someone, please do let me know.