How to avoid TWRP Errors related to wrong Firmware for custom ROM & prepare FIRMWARE

Search This thread

wojtoo

Senior Member
Jul 29, 2016
196
96
PL
How to avoid TWRP Errors related to wrong Firmware for custom ROM & prepare FIRMWARE

One of the most frequent question related to flash custom ROM is what firmware should I use to this particular ROM
That is probably because you had, or you would like to avoid ERROR 7 during flashing in TWRP which is caused while the ROM’s updater script file checks to see if the phone model of your phone is compatible with the ROM you are installing

At the begging of flashing process updater-script check this:
Code:
getprop("ro.product.device") == "sagit" || abort("E3004: This package is for "sagit" devices; this is a "" + getprop("ro.product.device") + "".");
and trustzone
Code:
assert(sagit.verify_trustzone("TZ.BF.4.0.6-00124") == "1"); *
*(this version of TZ.BF is only example, I will describe that in the end)
Sometimes Developer allow to use wider TZBF like:
Code:
assert(sagit.verify_trustzone("TZ.BF.4.0.6-00124","TZ.BF.4.0.6-00130") == "1");

I assume that you fulfill the first condition (you have sagit, right?), so we will take to look deeper into second condition
How to know what trustzone is in the phone?

There are three methods:
1) when you lately flashed your phone with downloaded firmware or full miui rom (fastbooot or recovery) just unzip rom file (7-zip recommended) and look for tz.mbn file (see below)
2) Use app like Kernel Adiutor -> Statistics -> Device -> Trustzone (recommended method)
3) pull tz.mbn file directly from your phone

to do that you need adb tool, so under TWRP:
Code:
adb shell
cd /dev/block/bootdevice/by-name
ls -all

you should see list list of partition but what we looking for is that:

Code:
lrwxrwxrwx    1 root         root                16 May 28  1970 tz -> /dev/block/sde15

copy partition to your storage

Code:
dd if=/dev/block/sde15 of=/sdcard/tz.img

now exit adb shell

Code:
exit

and copy tz.img to computer

Code:
adb pull /sdcard/tz.img

now we need hex editor to open tz.img or tz.mbn file
I use https://mh-nexus.de/en/hxd/ but you can your favorite hex editor
open tz file, press find and write TZ.BF, there is only one TZ.BF
QC_IMAGE_VERSION_STRING=TZ.BF.4.0.6-00124...IMAGE
Now, check what trust zone is needed in ROM which you would like to flash
It should be written in TrustZone requirements file named board-info.txt. It should be in github in root
In our case :
require version-trustzone=TZ.BF.4.0.6-00124
It's also written in your ROM file META-INF\com\google\android\updater-script

Despite of that you could use one of the firmware which have the same trustzone as needed I recommend that you follow firmware demanded/recommended by your ROM's Developer

version of TZBF in particular firmware:
8.2.2.0.NCAMIEC TZ.BF.4.0.6-00105
7.8.31 global TZ.BF.4.0.6-00124
7.8.31 china TZ.BF.4.0.6-00124
7.9.7 global TZ.BF.4.0.6-00124
7.9.8 china TZ.BF.4.0.6-00124
7.9.14 china TZ.BF.4.0.6-00124
7.9.22 global TZ.BF.4.0.6-00130
7.10.12 china TZ.BF.4.0.6-00130
7.10.12 global TZ.BF.4.0.6-00130
7.10.19 china TZ.BF.4.0.6-00130
China or Global?
In attached file.md5 there are md5sums of firmware files which I checked.
It seems, there is no difference between China or Global files from the same week (miui name ROM pattern version.mm.dd)

Do it at your Own Risk. I am not responsible for any loss or damage

EDIT 2017.11.14
Now its time to prepare your firmware based on XIAOMI ROM FILE
Choose version you need and download full ROM (not fastboot) from XIAOMI servers here
extract all files
go to extracted folder and delete all files/folders except folder firmware-update and META-INF
open META-INF/com and delete folder miui
download and extract updater-script from this tutorial
open \META-INF\com\google\android and repleace updater-script with this attached (mentioned above,downloaded and extracted)
Open it with eg notepad++ and correct /7.11.13 with version with you have and save it
go to main folder with firmware-update and META-INF and mark it, click righ mouse button and choose 7zip add to achrive
choose archive format zip, compression level store
copy to your phone and flash it with TWRP
that's it :)
 

Attachments

  • hex.PNG
    hex.PNG
    24.9 KB · Views: 569
  • file.md5.zip
    1.3 KB · Views: 69
  • Przechwytywanie.PNG
    Przechwytywanie.PNG
    70.2 KB · Views: 450
  • Przechwytywanie2.PNG
    Przechwytywanie2.PNG
    51 KB · Views: 463
  • updater-script.zip
    647 bytes · Views: 135
Last edited:

wian

Senior Member
Dec 10, 2005
108
93
Great information, thanks!

Following this information, I checked tz.mbn of xiaomi.eu rom 7.10.19. It provides firmware TZ.BF.4.0.6-00130.

Is this a correct conclusion? Or does the xiaomi.eu rom require TZ.BF.4.0.6-00130 and not provide it?
 
Last edited:

wojtoo

Senior Member
Jul 29, 2016
196
96
PL
Great information, thanks!

Following this information, I checked tz.mbn of xiaomi.eu rom 7.10.19. It provides firmware TZ.BF.4.0.6-00130.

Is this a correct conclusion? Or does the xiaomi.eu rom require TZ.BF.4.0.6-00130 and not provide it?

you dont have to worry about firmware in miui.eu ROM as they come with built in firmware,as stock MIUI ROM
 

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    How to avoid TWRP Errors related to wrong Firmware for custom ROM & prepare FIRMWARE

    One of the most frequent question related to flash custom ROM is what firmware should I use to this particular ROM
    That is probably because you had, or you would like to avoid ERROR 7 during flashing in TWRP which is caused while the ROM’s updater script file checks to see if the phone model of your phone is compatible with the ROM you are installing

    At the begging of flashing process updater-script check this:
    Code:
    getprop("ro.product.device") == "sagit" || abort("E3004: This package is for "sagit" devices; this is a "" + getprop("ro.product.device") + "".");
    and trustzone
    Code:
    assert(sagit.verify_trustzone("TZ.BF.4.0.6-00124") == "1"); *
    *(this version of TZ.BF is only example, I will describe that in the end)
    Sometimes Developer allow to use wider TZBF like:
    Code:
    assert(sagit.verify_trustzone("TZ.BF.4.0.6-00124","TZ.BF.4.0.6-00130") == "1");

    I assume that you fulfill the first condition (you have sagit, right?), so we will take to look deeper into second condition
    How to know what trustzone is in the phone?

    There are three methods:
    1) when you lately flashed your phone with downloaded firmware or full miui rom (fastbooot or recovery) just unzip rom file (7-zip recommended) and look for tz.mbn file (see below)
    2) Use app like Kernel Adiutor -> Statistics -> Device -> Trustzone (recommended method)
    3) pull tz.mbn file directly from your phone

    to do that you need adb tool, so under TWRP:
    Code:
    adb shell
    cd /dev/block/bootdevice/by-name
    ls -all

    you should see list list of partition but what we looking for is that:

    Code:
    lrwxrwxrwx    1 root         root                16 May 28  1970 tz -> /dev/block/sde15

    copy partition to your storage

    Code:
    dd if=/dev/block/sde15 of=/sdcard/tz.img

    now exit adb shell

    Code:
    exit

    and copy tz.img to computer

    Code:
    adb pull /sdcard/tz.img

    now we need hex editor to open tz.img or tz.mbn file
    I use https://mh-nexus.de/en/hxd/ but you can your favorite hex editor
    open tz file, press find and write TZ.BF, there is only one TZ.BF
    QC_IMAGE_VERSION_STRING=TZ.BF.4.0.6-00124...IMAGE
    Now, check what trust zone is needed in ROM which you would like to flash
    It should be written in TrustZone requirements file named board-info.txt. It should be in github in root
    In our case :
    require version-trustzone=TZ.BF.4.0.6-00124
    It's also written in your ROM file META-INF\com\google\android\updater-script

    Despite of that you could use one of the firmware which have the same trustzone as needed I recommend that you follow firmware demanded/recommended by your ROM's Developer

    version of TZBF in particular firmware:
    8.2.2.0.NCAMIEC TZ.BF.4.0.6-00105
    7.8.31 global TZ.BF.4.0.6-00124
    7.8.31 china TZ.BF.4.0.6-00124
    7.9.7 global TZ.BF.4.0.6-00124
    7.9.8 china TZ.BF.4.0.6-00124
    7.9.14 china TZ.BF.4.0.6-00124
    7.9.22 global TZ.BF.4.0.6-00130
    7.10.12 china TZ.BF.4.0.6-00130
    7.10.12 global TZ.BF.4.0.6-00130
    7.10.19 china TZ.BF.4.0.6-00130
    China or Global?
    In attached file.md5 there are md5sums of firmware files which I checked.
    It seems, there is no difference between China or Global files from the same week (miui name ROM pattern version.mm.dd)

    Do it at your Own Risk. I am not responsible for any loss or damage

    EDIT 2017.11.14
    Now its time to prepare your firmware based on XIAOMI ROM FILE
    Choose version you need and download full ROM (not fastboot) from XIAOMI servers here
    extract all files
    go to extracted folder and delete all files/folders except folder firmware-update and META-INF
    open META-INF/com and delete folder miui
    download and extract updater-script from this tutorial
    open \META-INF\com\google\android and repleace updater-script with this attached (mentioned above,downloaded and extracted)
    Open it with eg notepad++ and correct /7.11.13 with version with you have and save it
    go to main folder with firmware-update and META-INF and mark it, click righ mouse button and choose 7zip add to achrive
    choose archive format zip, compression level store
    copy to your phone and flash it with TWRP
    that's it :)
    1
    1. Flash my file: https://drive.google.com/open?id=1z9LbjzloH2Bjz-j8NfOc2e1-VImvMLIT
    2. Wipe > format data > yes > enter > go back to main menu > reboot recovery
    3. Flash your custom rom. Enjoy!