Skip to content

Instantly share code, notes, and snippets.

@lucasmz-dev
Last active June 7, 2024 23:03
Show Gist options
  • Save lucasmz-dev/cca7afb146f2908f92eb681b5a4c1e38 to your computer and use it in GitHub Desktop.
Save lucasmz-dev/cca7afb146f2908f92eb681b5a4c1e38 to your computer and use it in GitHub Desktop.
How to return back to stock software in Motorola devices on Linux

I am not responsible for any type of damage when you follow this tutorial. You have been warned.

This tutorial is meant for the devices: Moto G32, G42, and G52.

Device codenames

It is important to note that these devices are usually referenced using codenames in multiple places, it is important to know which one is yours.

  • G32: devon
  • G42: hawao
  • G52: rhode

Any slight variation of these codenames means that it isn't the same device and it will most likely brick your device. (e.g. rhodec, rhodej)

Prerequisites:

  1. Android Platform Tools installed (Debian, Fedora)
  2. Keep the device in bootloader mode!
  3. Unlocked bootloader (click here if you're in a locked bootloader)
  4. Stable cable, not using any hubs (preferably the original cable, if it is indeed stable and not damaged)

Finding your device variant

Before downloading the firm/software for your device, you need to figure out what variant of that device you have in order to prevent a brick.

To figure this out, you'll need to run a fastboot command. Run this on your terminal:

fastboot getvar ro.carrier

This should return your device variant, in my case, it is RETBR.

Downloading the firmware

We will be using an unofficial source, as Motorola does not make the firmware easily accessible officially, only via the RSA tool that's only available on Windows.

  1. Visit https://mirrors.lolinet.com/firmware/lenomola/.
  2. Find your device's codename (rhode, devon, hawao) in the list and open it.
  3. Open the folder "official".
  4. Find your device's variant (RETBR, RETAIL, RETEU, RETLA...) in the list and open it.
  5. Download the most recent .zip file. This is the current firmware for your device.

image image

Do not attempt to downgrade, or use older versions of firmware. While it is possible, you won't be able to relock the bootloader, if so, it will brick your device.

Installing motoflash2sh

MotoFlash2SH is a tool created to convert the .xml files inside the .zip into .sh files that we can execute in the terminal. Motorola (for some reason?) uses .xml files, to describe the install process for their firmware. This allows us to run these on Linux.

  1. Install Python3 (search for instructions for your distro)
  2. Add /home/user/.local/bin to PATH
  3. Install motoflash2sh by running:
pip3 install https://github.com/dlenski/motoflash2sh/archive/master.zip

You should be able to run motoflash2sh in the terminal and it be found. (e.g. it will show an error that it won't find the file, but it shouldn't say it's not a recnognized command, if it does, then check PATH.)

Clearing the avb_custom_key

Custom OSes with Verified Boot 2.0 such as Calyx use this partition in order to store their signing key so that Verified Boot with a custom key works properly. It is ideal to remove this before flashing stock.

Inside a terminal, run the command:

fastboot erase avb_custom_key

Preparation

  1. Create a new empty folder
  2. Put the firmware .zip file inside it.
  3. Extract it

Now, we're going to convert the .xml into a .sh file.

  1. Open the terminal in the extracted firmware folder
  2. Run this command on the terminal
motoflash2sh flashfile.xml

You should now have a .sh file in the folder.

Installation

If you haven't already, open a terminal inside the firmware folder. Now, we'll run the .sh by running these commands:

chmod +x flashfile.sh ## Makes the file executable
./flashfile.sh ## Executes the file

Installation should now begin. Keep the cable and device stable and let it run until it finishes. If you got an error, you can also try running it with sudo to see if it works.

If you notice any errors, failures, anything of that nature, do not continue with relocking the bootloader; as it can make the situation worse.

Relocking the bootloader

If everything has gone smoothly, you should be able to now relock the bootloader. This will restore Verified Boot. To do this, run this command on the terminal:

fastboot flashing lock

Now, confirm the locking on the device.

After boot, you should go into Developer Settings and check that OEM unlocking is off.

Finished!

You should be all set now! You are now back in stock firmware.


Possible improvements

Things that I'd like to improve/mention on this tutorial but they are either too complicated, too vague of an issue, or with no solution.

  • Dealing with the A/B partition scheme issues (explained here)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment