• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

Development [Tool] Flash Custom ROMs through Fastboot [mojito / sunny]

Search This thread

MPK99

Senior Member
Jun 25, 2017
524
365
Mexico
gitlab.com
Redmi Note 10
Are you struggling to install custom roms on this device?
Lots of recovery errors?
Can't boot to any rom?
Don't worry. Fastboot is a good way to avoid such nonsense...
ota-update-using-adb-fastboot_proc.jpg

Install any custom rom & miui recovery rom through fastboot

Steps:
1. Extract Fastboot OTA Tool. Put the ROM zip in it's root.
2. Run the flash script.
3. Wait till the script asks for device.
4. Boot device to fastboot & connect.

After Installation, it'll be headed to recovery:
You can format to start fresh (or)
Just boot up, for dirty flash way

Windows users:
Make sure you have usb drivers installed through manual method. This is done only once.
Refer this on how to install them... Download USB Drivers from here.

Linux users: Must have latest python & pip

For Ubuntu distros:
sudo apt install python python-pip
And have an alias into ~/.bashrc or ~/.bash_aliases file:
alias python=python3

For Arch based distros:
sudo pacman -S python python-pip

For Fedora:
sudo dnf install snapd python3.9 python3-pip

For Mac users, make sure you allow img2simg tool from Privacy & Security to work. Or Disable Gatekeeper temperorily.

Thanks to @LoV432 for his auto extraction idea.
& @lyoko_xana to bringup Mac issues.
If you have any trouble using this tool, please feel free to reply here...

Happy flashing
 
Last edited:

StaryMuz

Senior Member
Dec 27, 2012
397
127
According to the script, it is used exclusively for pure flash.
Can you please make an option for upgrade (dirty flash) as well?
 

MPK99

Senior Member
Jun 25, 2017
524
365
Mexico
gitlab.com
Redmi Note 10
According to the script, it is used exclusively for pure flash.
Can you please make an option for upgrade (dirty flash) as well?
It does dirty flash bydefault (caz it doesn't affect data partition). It'll be clean flash only when you wipe from recovery at post install... 🙂
I've edited post & clarified this...
 
Last edited:

LoV432

Senior Member
Aug 3, 2016
131
43
Redmi Note 10
This adds auto rom extraction to the OTA based script. So you just put the rom zip in the root directory and the script auto extracts it.

Disclaimer: I have no actual knowledge of this so theres a 50/50 chance this might nuke your pc or something :D
 

Attachments

  • Flasher.zip
    763.4 KB · Views: 69
  • Like
Reactions: MPK99

MPK99

Senior Member
Jun 25, 2017
524
365
Mexico
gitlab.com
Redmi Note 10
Newer update.
Fastboot_OTA_20210715
Instructions in the main thread.

Changelog (2021-07-15):
- Auto Extraction support (Thanks to @LoV432 for the idea)
- Merged updater script & payload extractions
- Fixed "Partition does not exist" error
- Updated flash instructions for linux & mac

If you have trouble working with fastboot for windows, follow this guide if you're ok installing manually
 
Last edited:

StaryMuz

Senior Member
Dec 27, 2012
397
127
Script error.
Vendor is entered only as Vendor, not as Vendor_a or Vendor_b.
The script did everything correctly after editing.

tools\fastboot %* delete-logical-partition vendor
tools\fastboot %* create-logical-partition vendor 4096


And then flash to a/b:
tools\fastboot %* flash -w system_a output\system.img
tools\fastboot %* flash system_ext_a output\system_ext.img
tools\fastboot %* flash -w system_b output\system.img
tools\fastboot %* flash system_ext_b output\system_ext.img
tools\fastboot %* flash product_a output\product.img
tools\fastboot %* flash product_b output\product.img
 

MPK99

Senior Member
Jun 25, 2017
524
365
Mexico
gitlab.com
Redmi Note 10
Script error.
Vendor is entered only as Vendor, not as Vendor_a or Vendor_b.
The script did everything correctly after editing.

tools\fastboot %* delete-logical-partition vendor
tools\fastboot %* create-logical-partition vendor 4096


And then flash to a/b:
tools\fastboot %* flash -w system_a output\system.img
tools\fastboot %* flash system_ext_a output\system_ext.img
tools\fastboot %* flash -w system_b output\system.img
tools\fastboot %* flash system_ext_b output\system_ext.img
tools\fastboot %* flash product_a output\product.img
tools\fastboot %* flash product_b output\product.img
Fastbootd already capable of retrieving active slot through get-active-slot implicitly & flash it to inactive slot. No need to explicitly declare & flash on a specific slot.
It's mandatory for physical partitions, not for logical partitions.

Also, explicit declaration is a bad practice
 
Last edited:

StaryMuz

Senior Member
Dec 27, 2012
397
127
I was wrong about Vendor.
I flashed PE+ and the system did not load afterwards.
After editing the following, it worked.
tools\fastboot -w %* flash system_a output\system.img
tools\fastboot %* flash system_ext_a output\system_ext.img
tools\fastboot -w %* flash system_b output\system.img
tools\fastboot %* flash system_ext_b output\system_ext.img
tools\fastboot %* flash product_a output\product.img
tools\fastboot %* flash product_b output\product.img
tools\fastboot %* flash vendor_a output\product.img
tools\fastboot %* flash vendor_b output\product.img


But that's not right either.
I found out that:
Slot B should not flash during an update, only during a full ROM install.
For the update, it is flash to slot A, from where the running system updates itself (running from slot B).
The instructions executed during full flash and update should therefore be adapted to this.
Full flash to both B and A.
Update to A only.
If the update then fails, the system can roll back.

EDIT: scripts

I edited your script to flash only to A and only to B.:
@Echo off
cd "%~dp0"

echo This is a recovery rom installation script for Windows
mkdir output
tools\7za.exe x *.zip -aos

if exist payload.bin if not exist output\vendor.img (
echo.
echo Extracting images from the build...
tools\payload_dumper.exe payload.bin
)

if exist dynamic_partitions_op_list (
echo.
echo Decompressing system
tools\bin\brotli.exe -d system.new.dat.br
echo Decompressing system_ext
tools\bin\brotli.exe -d system_ext.new.dat.br
echo Decompressing product
tools\bin\brotli.exe -d product.new.dat.br
echo Decompressing vendor
tools\bin\brotli.exe -d vendor.new.dat.br
echo Unpacking all the images...
tools\bin\sdat2img.exe system.transfer.list system.new.dat output\system.img
tools\bin\sdat2img.exe system_ext.transfer.list system_ext.new.dat output\system_ext.img
tools\bin\sdat2img.exe product.transfer.list product.new.dat output\product.img
tools\bin\sdat2img.exe vendor.transfer.list vendor.new.dat output\vendor.img
)

echo.
echo Checking fastboot version. If it's not v31 or above, you're screwed...!
tools\fastboot %* --version

echo.
echo Flashing stock boot for mojito
fastboot --set-active=a
tools\fastboot %* flash boot_b tools\boot_mojito.img
fastboot --set-active=b
echo Booting to fastbootd
tools\fastboot %* reboot fastboot
fastboot --set-active=a

echo.
echo Removing existing logical partitions only slot B ...
tools\fastboot %* delete-logical-partition vendor_b
tools\fastboot %* delete-logical-partition system_b
tools\fastboot %* delete-logical-partition system_ext_b
tools\fastboot %* delete-logical-partition product_b

echo.
echo Creating new logical partitions...
tools\fastboot %* create-logical-partition vendor_b 4096
tools\fastboot %* create-logical-partition system_b 4096
tools\fastboot %* create-logical-partition system_ext_b 4096
tools\fastboot %* create-logical-partition product_b 4096


echo.
echo Flashing the ROM...
echo Just ignore the below sparse file errors...
tools\fastboot -w %* flash system_b output\system.img
tools\fastboot %* flash system_ext_b output\system_ext.img
tools\fastboot %* flash product_b output\product.img
tools\fastboot %* flash vendor_b output\vendor.img

echo.
echo Flashing boot partitions...
tools\fastboot %* reboot bootloader
tools\fastboot %* flash boot_b output\boot.img
tools\fastboot %* flash vendor_boot_b output\vendor_boot.img
fastboot --set-active=b

echo.
echo Cleaning Stuff...
rmdir /q /s META-INF output
del /f *.img *.br *.dat *.list payload.bin care_map.pb payload_properties.txt dynamic_partitions_op_list

echo.
echo Done. Rebooting to recovery...
timeout 1 > nul
echo ...3...
timeout 1 > nul
echo ..2..
timeout 1 > nul
echo .1.
timeout 1 > nul
tools\fastboot %* reboot recovery
echo Done...

pause
@Echo off
cd "%~dp0"

echo This is a recovery rom installation script for Windows
mkdir output
tools\7za.exe x *.zip -aos

if exist payload.bin if not exist output\vendor.img (
echo.
echo Extracting images from the build...
tools\payload_dumper.exe payload.bin
)

if exist dynamic_partitions_op_list (
echo.
echo Decompressing system
tools\bin\brotli.exe -d system.new.dat.br
echo Decompressing system_ext
tools\bin\brotli.exe -d system_ext.new.dat.br
echo Decompressing product
tools\bin\brotli.exe -d product.new.dat.br
echo Decompressing vendor
tools\bin\brotli.exe -d vendor.new.dat.br
echo Unpacking all the images...
tools\bin\sdat2img.exe system.transfer.list system.new.dat output\system.img
tools\bin\sdat2img.exe system_ext.transfer.list system_ext.new.dat output\system_ext.img
tools\bin\sdat2img.exe product.transfer.list product.new.dat output\product.img
tools\bin\sdat2img.exe vendor.transfer.list vendor.new.dat output\vendor.img
)

echo.
echo Checking fastboot version. If it's not v31 or above, you're screwed...!
tools\fastboot %* --version

echo.
echo Flashing stock boot for mojito
fastboot --set-active=b
tools\fastboot %* flash boot_a tools\boot_mojito.img
fastboot --set-active=a
echo Booting to fastbootd
tools\fastboot %* reboot fastboot
fastboot --set-active=b

echo.
echo Removing existing logical partitions only slot A ...
tools\fastboot %* delete-logical-partition vendor_a
tools\fastboot %* delete-logical-partition system_a
tools\fastboot %* delete-logical-partition system_ext_a
tools\fastboot %* delete-logical-partition product_a

echo.
echo Creating new logical partitions...
tools\fastboot %* create-logical-partition vendor_a 4096
tools\fastboot %* create-logical-partition system_a 4096
tools\fastboot %* create-logical-partition system_ext_a 4096
tools\fastboot %* create-logical-partition product_a 4096


echo.
echo Flashing the ROM...
echo Just ignore the below sparse file errors...
tools\fastboot -w %* flash system_a output\system.img
tools\fastboot %* flash system_ext_a output\system_ext.img
tools\fastboot %* flash product_a output\product.img
tools\fastboot %* flash vendor_a output\vendor.img

echo.
echo Flashing boot partitions...
tools\fastboot %* reboot bootloader
tools\fastboot %* flash boot_a output\boot.img
tools\fastboot %* flash vendor_boot_a output\vendor_boot.img
fastboot --set-active=a

echo.
echo Cleaning Stuff...
rmdir /q /s META-INF output
del /f *.img *.br *.dat *.list payload.bin care_map.pb payload_properties.txt dynamic_partitions_op_list

echo.
echo Done. Rebooting to recovery...
timeout 1 > nul
echo ...3...
timeout 1 > nul
echo ..2..
timeout 1 > nul
echo .1.
timeout 1 > nul
tools\fastboot %* reboot recovery
echo Done...

pause
 
Last edited:

MPK99

Senior Member
Jun 25, 2017
524
365
Mexico
gitlab.com
Redmi Note 10
I was wrong about Vendor.
I flashed PE+ and the system did not load afterwards.
After editing the following, it worked.
tools\fastboot -w %* flash system_a output\system.img
tools\fastboot %* flash system_ext_a output\system_ext.img
tools\fastboot -w %* flash system_b output\system.img
tools\fastboot %* flash system_ext_b output\system_ext.img
tools\fastboot %* flash product_a output\product.img
tools\fastboot %* flash product_b output\product.img
tools\fastboot %* flash vendor_a output\product.img
tools\fastboot %* flash vendor_b output\product.img


But that's not right either.
I found out that:
Slot B should not flash during an update, only during a full ROM install.
For the update, it is flash to slot A, from where the running system updates itself (running from slot B).
The instructions executed during full flash and update should therefore be adapted to this.
Full flash to both B and A.
Update to A only.
If the update then fails, the system can roll back.

EDIT: scripts

I edited your script to flash only to A and only to B.:
@Echo off
cd "%~dp0"

echo This is a recovery rom installation script for Windows
mkdir output
tools\7za.exe x *.zip -aos

if exist payload.bin if not exist output\vendor.img (
echo.
echo Extracting images from the build...
tools\payload_dumper.exe payload.bin
)

if exist dynamic_partitions_op_list (
echo.
echo Decompressing system
tools\bin\brotli.exe -d system.new.dat.br
echo Decompressing system_ext
tools\bin\brotli.exe -d system_ext.new.dat.br
echo Decompressing product
tools\bin\brotli.exe -d product.new.dat.br
echo Decompressing vendor
tools\bin\brotli.exe -d vendor.new.dat.br
echo Unpacking all the images...
tools\bin\sdat2img.exe system.transfer.list system.new.dat output\system.img
tools\bin\sdat2img.exe system_ext.transfer.list system_ext.new.dat output\system_ext.img
tools\bin\sdat2img.exe product.transfer.list product.new.dat output\product.img
tools\bin\sdat2img.exe vendor.transfer.list vendor.new.dat output\vendor.img
)

echo.
echo Checking fastboot version. If it's not v31 or above, you're screwed...!
tools\fastboot %* --version

echo.
echo Flashing stock boot for mojito
fastboot --set-active=a
tools\fastboot %* flash boot_b tools\boot_mojito.img
fastboot --set-active=b
echo Booting to fastbootd
tools\fastboot %* reboot fastboot
fastboot --set-active=a

echo.
echo Removing existing logical partitions only slot B ...
tools\fastboot %* delete-logical-partition vendor_b
tools\fastboot %* delete-logical-partition system_b
tools\fastboot %* delete-logical-partition system_ext_b
tools\fastboot %* delete-logical-partition product_b

echo.
echo Creating new logical partitions...
tools\fastboot %* create-logical-partition vendor_b 4096
tools\fastboot %* create-logical-partition system_b 4096
tools\fastboot %* create-logical-partition system_ext_b 4096
tools\fastboot %* create-logical-partition product_b 4096


echo.
echo Flashing the ROM...
echo Just ignore the below sparse file errors...
tools\fastboot -w %* flash system_b output\system.img
tools\fastboot %* flash system_ext_b output\system_ext.img
tools\fastboot %* flash product_b output\product.img
tools\fastboot %* flash vendor_b output\vendor.img

echo.
echo Flashing boot partitions...
tools\fastboot %* reboot bootloader
tools\fastboot %* flash boot_b output\boot.img
tools\fastboot %* flash vendor_boot_b output\vendor_boot.img
fastboot --set-active=b

echo.
echo Cleaning Stuff...
rmdir /q /s META-INF output
del /f *.img *.br *.dat *.list payload.bin care_map.pb payload_properties.txt dynamic_partitions_op_list

echo.
echo Done. Rebooting to recovery...
timeout 1 > nul
echo ...3...
timeout 1 > nul
echo ..2..
timeout 1 > nul
echo .1.
timeout 1 > nul
tools\fastboot %* reboot recovery
echo Done...

pause
@Echo off
cd "%~dp0"

echo This is a recovery rom installation script for Windows
mkdir output
tools\7za.exe x *.zip -aos

if exist payload.bin if not exist output\vendor.img (
echo.
echo Extracting images from the build...
tools\payload_dumper.exe payload.bin
)

if exist dynamic_partitions_op_list (
echo.
echo Decompressing system
tools\bin\brotli.exe -d system.new.dat.br
echo Decompressing system_ext
tools\bin\brotli.exe -d system_ext.new.dat.br
echo Decompressing product
tools\bin\brotli.exe -d product.new.dat.br
echo Decompressing vendor
tools\bin\brotli.exe -d vendor.new.dat.br
echo Unpacking all the images...
tools\bin\sdat2img.exe system.transfer.list system.new.dat output\system.img
tools\bin\sdat2img.exe system_ext.transfer.list system_ext.new.dat output\system_ext.img
tools\bin\sdat2img.exe product.transfer.list product.new.dat output\product.img
tools\bin\sdat2img.exe vendor.transfer.list vendor.new.dat output\vendor.img
)

echo.
echo Checking fastboot version. If it's not v31 or above, you're screwed...!
tools\fastboot %* --version

echo.
echo Flashing stock boot for mojito
fastboot --set-active=b
tools\fastboot %* flash boot_a tools\boot_mojito.img
fastboot --set-active=a
echo Booting to fastbootd
tools\fastboot %* reboot fastboot
fastboot --set-active=b

echo.
echo Removing existing logical partitions only slot A ...
tools\fastboot %* delete-logical-partition vendor_a
tools\fastboot %* delete-logical-partition system_a
tools\fastboot %* delete-logical-partition system_ext_a
tools\fastboot %* delete-logical-partition product_a

echo.
echo Creating new logical partitions...
tools\fastboot %* create-logical-partition vendor_a 4096
tools\fastboot %* create-logical-partition system_a 4096
tools\fastboot %* create-logical-partition system_ext_a 4096
tools\fastboot %* create-logical-partition product_a 4096


echo.
echo Flashing the ROM...
echo Just ignore the below sparse file errors...
tools\fastboot -w %* flash system_a output\system.img
tools\fastboot %* flash system_ext_a output\system_ext.img
tools\fastboot %* flash product_a output\product.img
tools\fastboot %* flash vendor_a output\vendor.img

echo.
echo Flashing boot partitions...
tools\fastboot %* reboot bootloader
tools\fastboot %* flash boot_a output\boot.img
tools\fastboot %* flash vendor_boot_a output\vendor_boot.img
fastboot --set-active=a

echo.
echo Cleaning Stuff...
rmdir /q /s META-INF output
del /f *.img *.br *.dat *.list payload.bin care_map.pb payload_properties.txt dynamic_partitions_op_list

echo.
echo Done. Rebooting to recovery...
timeout 1 > nul
echo ...3...
timeout 1 > nul
echo ..2..
timeout 1 > nul
echo .1.
timeout 1 > nul
tools\fastboot %* reboot recovery
echo Done...

pause
You're wrong about many other things. I don't encourage manual slot selection. Fastboot decides this based on the current active slot...
You shouldn't flash the updates through manual slot selection, that's not how A/B partition scheme works.
 
Last edited:

StaryMuz

Senior Member
Dec 27, 2012
397
127
It is possible that I did not understand all the processes correctly, but your tool did not work as it should for me with PE+.
Everything that preceded it:
- In a functional old version of PE+, I did an OTA update.
- After a reboot, the system should have updated, but it was left hanging in the system loading (even for tens of minutes).
- So I made a dirty flash using your tool. Without a factory reset, I booted the system, but it still hung in startup. During the flash process, it seemed to me that something was flash only to the A slot, and something to both A and B. This led me to the idea of editing the flash slots manually.
- So I had system, system_ext, product and vendor flashed into both slots. This resulted in the system booting without factory settings. However, the system started as new, without data and settings.
- I then experimented a bit and uploaded using flash to A, then flash to B, different systems. If I ran the last flash A system, it worked. Then I changed the active slot to the first flash B slot and also the second system started. But the other system started updating and performed some action. It kept working. I rebooted into the active A slot again, but the previous A system no longer started.

There must be a bug somewhere in the current use of updates and flash custom ROMs.
 

MPK99

Senior Member
Jun 25, 2017
524
365
Mexico
gitlab.com
Redmi Note 10
It is possible that I did not understand all the processes correctly, but your tool did not work as it should for me with PE+.
Everything that preceded it:
- In a functional old version of PE+, I did an OTA update.
- After a reboot, the system should have updated, but it was left hanging in the system loading (even for tens of minutes).
- So I made a dirty flash using your tool. Without a factory reset, I booted the system, but it still hung in startup. During the flash process, it seemed to me that something was flash only to the A slot, and something to both A and B. This led me to the idea of editing the flash slots manually.
- So I had system, system_ext, product and vendor flashed into both slots. This resulted in the system booting without factory settings. However, the system started as new, without data and settings.
- I then experimented a bit and uploaded using flash to A, then flash to B, different systems. If I ran the last flash A system, it worked. Then I changed the active slot to the first flash B slot and also the second system started. But the other system started updating and performed some action. It kept working. I rebooted into the active A slot again, but the previous A system no longer started.

There must be a bug somewhere in the current use of updates and flash custom ROMs.
Everything works for me & the users on telegram support groups too.
For dirty flash to work properly, updated slot also must have the same set of ROM, magisk, kernel, boot, it's modules, etc... That you've used in your last rom
It's always recommended that keep backups of everything especially for this device as A/B is still very new to the developers.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    Are you struggling to install custom roms on this device?
    Lots of recovery errors?
    Can't boot to any rom?
    Don't worry. Fastboot is a good way to avoid such nonsense...
    ota-update-using-adb-fastboot_proc.jpg

    Install any custom rom & miui recovery rom through fastboot

    Steps:
    1. Extract Fastboot OTA Tool. Put the ROM zip in it's root.
    2. Run the flash script.
    3. Wait till the script asks for device.
    4. Boot device to fastboot & connect.

    After Installation, it'll be headed to recovery:
    You can format to start fresh (or)
    Just boot up, for dirty flash way

    Windows users:
    Make sure you have usb drivers installed through manual method. This is done only once.
    Refer this on how to install them... Download USB Drivers from here.

    Linux users: Must have latest python & pip

    For Ubuntu distros:
    sudo apt install python python-pip
    And have an alias into ~/.bashrc or ~/.bash_aliases file:
    alias python=python3

    For Arch based distros:
    sudo pacman -S python python-pip

    For Fedora:
    sudo dnf install snapd python3.9 python3-pip

    For Mac users, make sure you allow img2simg tool from Privacy & Security to work. Or Disable Gatekeeper temperorily.

    Thanks to @LoV432 for his auto extraction idea.
    & @lyoko_xana to bringup Mac issues.
    If you have any trouble using this tool, please feel free to reply here...

    Happy flashing
    3
    According to the script, it is used exclusively for pure flash.
    Can you please make an option for upgrade (dirty flash) as well?
    It does dirty flash bydefault (caz it doesn't affect data partition). It'll be clean flash only when you wipe from recovery at post install... 🙂
    I've edited post & clarified this...
    2
    Update: 18/08/21

    Changelog:
    • Switched to 12.5.2 stock fastbootd
    • Fixed fastboot issues on ubuntu
    • Separate scripts for linux & mac from now
    2
    !! Fastboot OTA Tool Update !!

    Fastboot_OTA_20210802.zip
    Usage instructions in the main post.
    There is an error in the script (probably by copying).

    echo Flashing boot partitions...
    tools\fastboot %* reboot bootloader
    tools\fastboot %* flash boot_a boot.img
    tools\fastboot %* flash boot_b boot.img
    tools\fastboot %* flash vendor_boot_b vendor_boot.img
    tools\fastboot %* flash vendor_boot_b vendor_boot.img
    1
    this tool doesn't seem to work with xiaomi eu roms
    Currently, it's only for OTA based roms, that have payload.bin in it.
    I'll update the script for eu roms too when I get time.