Skip to content

Instantly share code, notes, and snippets.

@lucasmz-dev
Last active May 21, 2026 19:16
Show Gist options
  • Select an option

  • Save lucasmz-dev/cca7afb146f2908f92eb681b5a4c1e38 to your computer and use it in GitHub Desktop.

Select an option

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 was originally designed for the devices: moto g32, g42, and g52. It should also work for the moto g34/45, g84, and g 5g 2024.

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
  • g34/45: fogos
  • g84: bangkk
  • g 5g (2024): fogo

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 (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

Warning

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. Make sure to get the LATEST version available.

Caution

mirrors.lolinet.com can have out of date firmware which can cause a brick if you previously ever installed partitions with higher rollback indexes. I particularly noticed this with g84.

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.

Caution

This is unsafe on a locked bootloader, other devices should usually disallow this, but for some reason Moto allows erasing this without being on an unlocked bootloader. This can cause a hard brick if you have OEM Unlocking disabled.

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:

sh flashfile.sh

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.

Warning

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. Doing so will allow FRP to work properly. (This is the steal protection from Google)

Finished!

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


@Destewie

Destewie commented Sep 1, 2025

Copy link
Copy Markdown

Wow man i cannot say how precious this step-by-step guide is.
I followed it and everything worked out fine.

Appreciation moment, byee <3

@porobertdev

Copy link
Copy Markdown

Worked on Moto Edge 30, thank you! 🙏

@th1031

th1031 commented Dec 21, 2025

Copy link
Copy Markdown

Thank you! Worked on Moto G 5G 2024 allowing me to return it to stock from LineageOS 23. Cheers!

@perzarys

Copy link
Copy Markdown

Worked perfectly fine today on devon, running stock with locked bootloader again. The terrible "hello moto" sound is now back, yay :P Thanks for the tutorial!

@lucasmz-dev

Copy link
Copy Markdown
Author

Great to know it has worked out for y'all!

Note: you can disable the startup sound in stock by going into the sound settings.

@mandeep1152

Copy link
Copy Markdown

Hello

I have moto g34 5g ,(fogos)
I flashed a custom rom (oxygen os 15) and then I locked the bootloader

Now I'm stuck in fastboot mode
(flashing locked)
I can't boot into recovery mode

I want to ask that if I blankflash will I be able to boot into recovery? And The adb sideload official firmware from lolinet or RSA/LMSA tool

Is this possible
Please reply me I have only one device and it's very hard for me to go to service centre which is so far and also they gonna charge too much money

@lucasmz-dev

lucasmz-dev commented Feb 21, 2026

Copy link
Copy Markdown
Author

If you can't while in fastboot, run fastboot flashing unlock and unlock the bootloader, you won't be able to recover the device. Only certain ROMs support relocking and are built for that. Personally I haven't been able to get the blankflash thing to work even when I was in the mode, which you need to apparently short things to get into it.

Be fast with my suggestion (run fastboot flashing unlock), it seems the longer people take to re-unlock they get stuck with the device thinking OEM Unlocking was somehow turned off.

@mandeep1152

@mandeep1152

Copy link
Copy Markdown

@lucasmz-dev

Hey bro thanks for replying
I tried this command many times but this never works I get error it asks me to enable oem unlocking in Android settings

But to do that I need to boot in os first
But I can't boot bcz I'm bricked

@lucasmz-dev

@lucasmz-dev

Copy link
Copy Markdown
Author

@mandeep1152

Nothing you can do now.

@mandeep1152

Copy link
Copy Markdown

@lucasmz-dev
I have no other option than trying everything that is in my hand 😿

If you can help me please pm me in telegram at @manxdeep69 this is my telegram username

If you're not comfortable we can continue here only

I can't have a conversation with you here right now cuz it's 3:30 am in my country i gotta sleep

@lucasmz-dev

Copy link
Copy Markdown
Author

You have nothing else to try. Sorry. I've tried to help people in this situation many times.

Also I don't use Telegram and I don't help people in DMs, I leave it out in the open as to keep that information public.

@mandeep1152

Copy link
Copy Markdown

@lucasmz-dev

I read somewhere that blankflash restores the recovery mode if it's true I can adb side load official firmware maybe it can allow

@mandeep1152

Copy link
Copy Markdown

@lucasmz-dev yess yore right keeping information public is better idea someone else can help too

@lucasmz-dev

Copy link
Copy Markdown
Author

Then try it? There's some files in mirrors.lolinet.com (this stupid domain lol) for that but like I said I don't know how and it didn't work for me when I tried it. Fastboot doesn't allow booting into EDL, you need to short cables to do that, if that even works on these devices, but even getting in that mode through other means didn't work for me when I was finally there.

@mandeep1152

Copy link
Copy Markdown

Yes I will try it Tommorow and I'll update it here so that if I fail no one wastes his time in this situation

Thank you for guiding

@mas4112

mas4112 commented Apr 7, 2026

Copy link
Copy Markdown

Yes I will try it Tommorow and I'll update it here so that if I fail no one wastes his time in this situation

Thank you for guiding

Hey man, have you solved the issue? I have the exact issue as yours. Can you give me some insights! @mandeep1152

@o-alquimista

o-alquimista commented Apr 18, 2026

Copy link
Copy Markdown

@lucasmz-dev The last time I locked the bootloader of my G32 I was running CalyxOS (Android 15); then I used other LineageOS-based systems (e.g. "LineageOS for microG" and IodéOS — Android 16) with an unlocked bootloader. Now I'm back to the stock ROM (Android 13) installed with Motorola's Software Fix, but the bootloader is still unlocked, and it doesn't even pass MEETS_BASIC_INTEGRITY (Play Integrity).

To lock it, would it be enough for me to simply run fastboot flashing lock?

BTW, I often see on other websites people running fastboot oem lock instead. Is there a difference?

@lucasmz-dev

Copy link
Copy Markdown
Author

As long as the system is up to date, without any modifications, yes, running flashing lock will work.

I'm not sure of any difference, but I always use flashing instead of oem cause it's the more generic command.

@mandeep1152

Copy link
Copy Markdown

Yes I will try it Tommorow and I'll update it here so that if I fail no one wastes his time in this situation
Thank you for guiding

Hey man, have you solved the issue? I have the exact issue as yours. Can you give me some insights! @mandeep1152

Nope bro i sold my device

@o-alquimista

o-alquimista commented Apr 18, 2026

Copy link
Copy Markdown

I've been reading about this "anti-rollback protection".

From XDA Forums:

You can't relock on older firmware though, eg a13---> a12 as anti rollabck protection will be triggered after Relocking and device will be bricked

Wouldn't the stock ROM qualify as an older firmware compared to CalyxOS?

I wonder, do I need to clear the avb custom key?

It is ideal to remove this before flashing stock.

I didn't remove it when I flashed stock. Is it too late, or can I remove it now?

@lucasmz-dev

Copy link
Copy Markdown
Author

Wouldn't the stock ROM qualify as an older firmware compared to CalyxOS?

No, rollback index is matched by CalyxOS

I wonder, do I need to clear the avb custom key?

You should.

I didn't remove it when I flashed stock. Is it too late, or can I remove it now?

Shouldn't be an issue if you're running stock.

@o-alquimista

o-alquimista commented Apr 18, 2026

Copy link
Copy Markdown

Thank you, it worked.

So, these were my steps:

  1. Unlock the bootloader and use Motorola's Software Fix on Windows to reinstall the stock ROM.
  2. Erase the avb_custom_key partition. (I should have done this earlier, but okay)
  3. Lock the bootloader.
  4. Go to Developer Settings and disable OEM Unlocking.

@Yash18-Max

Copy link
Copy Markdown

Can I use this process in macos also?

@lucasmz-dev

Copy link
Copy Markdown
Author

Probably

@pawel-0skill

Copy link
Copy Markdown

Works like a charm with rhode.

Some consideration for the layperson like me - if you're running an immutable distro (i use Fedore Kinoite), and you use Toolbox, remember to install android tools in the Toolbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment