[TUTORIAL]How to setup SP_Flash_Tool_Linux (MTK/MediaTek Soc)

Search This thread

Miss Montage

Senior Member
Mar 3, 2015
208
157
This works only on Linux 64-bit
DISCLAIMER: It is always risky to flash your mobile device. I do not and will not take any responsibility for bootloops and bricks.
Please check carefully that the ROM or recovery.img you want to flash is suitable for your specific device and for the sp_flash_tool. The firmware directory should neither contain meta-inf nor system folder, but something_with_a_scatter.txt and a system.img
Backup your phone before flashing!
Your phone's battery should be at least half charged (50 percent) before you start this.

I successfully ran these steps on my UMI Hammer with Linux Ubuntu 14.04 and 16.04. I do not have other devices or Linux derivates and do not plan to buy/install any.

CREDITS and a zillion thanks to Sergio Rivero for his excellent tutorial on mibqyyo.com!!!!
Also many thanks to N2K1 for giving me some more background information!

So here we go:

Step 1:
If you haven't done so before, install the Linux generic usb-drivers package:
Code:
sudo apt-get update
sudo apt install libusb-dev
Download SP Flash Tool Linux (latest version): http://mtk2000.ucoz.ru/load/soft/soft_mtk/sp_flash_tool/5-1-0-14 (Password to extract currently is mtk2000v3)
or here https://androidmtk.com/smart-phone-flash-tool
In case you haven't done before, install unrar:
Code:
sudo apt install unrar
Extract the downloaded file -> graphic file manager (e.g. Nautilus): double-click and extract. Terminal:
Code:
unrar x path_to_file
(from now on: please adapt paths to your own settings)
Move the new folder „sp_flash_tool“ to a directory of your choice.
Code:
mv /home/username/Downloads/sp_flash_tool /home/username/...
You might also need to install libqtwebkit4 (it just happened to me on Linux Ubuntu 16.04):
Code:
sudo apt install libqtwebkit4

[Only For Ubuntu 16.10 and newer]
Run
Code:
dpkg -x libpng12-0_1.2.54-1ubuntu1.1_amd64.deb /tmp/libpng2
cp /tmp/libpng2/lib/x86_64-linux-gnu/libpng12.so.0.54.0 lib
cd lib
ln -s libpng12.so.0.54.0 libpng12.so.0
These libraries are still required for the flash tool but have been removed from new Ubuntu versions.
Thanks @hanalinqu, @z3r0c00l_2k https://xdaforums.com/showpost.php?p=73484473&postcount=216 and @opticyclic https://xdaforums.com/showpost.php?p=81543495&postcount=285 for this information!

Step 2:

Change into the newly created directory:
Code:
cd /sp_flash_tool
We make one file executable by typing:
Code:
chmod +x flash_tool

In order to avoid running the flash_tool as root user, you need to add a standard user to the usergroup "dialout" (thanks to @egalus for this bit!)
Code:
sudo adduser username dialout
For Arch Linux:
Code:
gpasswd -a username uucp

and activate the membership immediately
Code:
newgrp - dialout
(Arch Linux):
Code:
newgrp - uucp

Step 3:

Now you can open the tool:

Code:
./flash_tool
or double-click on the flash_tool icon.
You can try at this stage if the flash tool connects to your phone:
In the user interface, choose tab „Download“. Hit "scatter-loading", navigate to a directory with a valid firmware for your device and choose the scatter-file.
For testing purposes uncheck "name" and check one of the smaller files in the list below (for example "logo")
Switch off your device. Hit the "Download" button in SP_Flash_Tool and connect your phone to the computer. Some devices require you to take off the battery for about 10 seconds, with others you need to press Vol+ or Vol- while plugging the cable into the phone. Please look up device-specific threads and try out different options.

If nothing happens at all, open a second terminal, run
Code:
dmesg | grep usb
and look out for a MediaTek entry. If there is none → did you install libusb-dev (Step 1?)
If the answer is yes, you might need to create a persistent udev rule for the MTK Preloader:
Code:
sudo gedit /etc/udev/rules.d/80-persistent-usb.rules
Add the following line to the file:
Code:
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0e8d", ATTR{idProduct}=="*"
Save the file and exit.
Reload the usb-rules:
Code:
sudo service udev restart
Disconnect the usb data cable from the computer and the smartphone. Close the flash tool. Switch on your phone (fastboot mode will do). Repeat the first paragraph of Step 3.

If the tool connects, within a few seconds a red progress bar will appear. Unfortunately, in my case an error message came along with it:
S_BROM_CMD_JUMP_DA_FAIL (2035)
There is a connection, but also one more obstacle to overcome...

Step 4:
Now we come to the interesting part, which cost me 2 weeks of (futile) research and frustration. Finally I found Sergio Riveros tutorial on mibqyyo. Thanks to him again and again and again for this priceless piece of information :)
The “modemmanager” package integrated by default within Linux Ubuntu 14.04 and later is not compatible with the MTK Flash Tool for Linux
To put it in different words: The modem manager controls port /dev/ttyACM0 and disables the Flash Tool. So we blacklist it for the two MTK vendor IDs the flash tool uses:
Code:
sudo gedit /etc/udev/rules.d/20-mm-blacklist-mtk.rules
You insert these two lines:
Code:
ATTRS{idVendor}=="0e8d", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="6000", ENV{ID_MM_DEVICE_IGNORE}="1"
Save the file, exit and restart udev:
Code:
sudo service udev restart

Switch your phone on (fastboot mode will suffice) and off again.

Step 5:
Code:
./flash_tool
or double-click on the flash_tool icon.
Now everything should run smoothly. In case you encounter
Code:
BROM ERROR : S_SECURITY_SF_CODE_FORMAT_FORBIDDEN (6012) , MSP ERROE CODE : 0x00
change the download agent to MTK_AllInOne_DA.bin (screenshot #4)
There are plenty of tutorials on the web for the further steps.
Happy flashing! When a green circle with a white checkmark appears, you are done. You can close the flash tool and disconnect your phone. For a clean start with a new ROM boot into recovery and wipe data/factory reset.
 
Last edited:

Yoshi_Guy

Senior Member
Jun 12, 2015
197
442
Atlantis
Great post!

Just wanted to say you saved me HOURS OR DAYS OR WEEKS of time on the modemmanager thing. I have Arch Linux, successfully ported over this tutorial, but I had no idea the modemmanager package was causing the issue. SP Flash Tool was the last frontier for using my Android devices on Linux. Thanks so much!
 

Miss Montage

Senior Member
Mar 3, 2015
208
157
You are very welcome! Since it took me two weeks to find the cause for "S_BROM_Error [2035]" I wanted to spare other "victims" the experience :)
 
Last edited:
  • Like
Reactions: spikey-1973

daltonfury42

Member
Jul 21, 2014
7
0
This is a very nice, HQ post. Keep up the good work.

But I would like to suggest two corrections:

1) The mv command is unnecessary. you don't have to copy the folder to the root directory to run it as root.

2) Please also add a final step to delete the udev rules so as to re-enable the modem manager after rooting.

Though most of the people who would be reading your thread would be knowledgeable linux users, they won't need these suggestions, but anyways, it would make your guide complete.
 

Miss Montage

Senior Member
Mar 3, 2015
208
157
Thanks for your feedback @daltonfury42 :)
1) Of course you don't need to move to move the folder to / .As I wrote, you can also use your /home/user directory. But you shouldn't keep it in "/Downloads" or "/tmp", since you might have deleted the folder by the next time you want to use the flash-tool.

Step 2), as you suggest it, is redundant on a private computer, because you blacklist the modemmanager for the flash-tool only, and for nothing else. SP_Flash_Tool uses different Vendor and Product IDs than MTP/USB/ADB/Fastboot mode, and these IDs are not related to your specific device. So the modem manager is up and running - even while you flash - on every other active (network-relevant) usb-port of your computer :) And it will be up and running on the usb-port you use for the flash-tool when you disconnect the phone and then plug in something else - or the same phone in a different mode... But due to the permanent
Code:
/etc/udev/rules.d/20-mm-blacklist-mtk.rules
entry the modem manager will be automatically blocked if you connect your phone to the SP_Flash_Tool a second time - no matter which port: no further preparations necessary :)
If you want to check it out, take a look the output of
Code:
dmesg | grep usb
connecting your phone "normally" and compare it with the same command -> output connecting your phone to the SP_Flash_Tool - and/or to the contents of the file "usb_setting.xml" in the SP_Flash_Tool directory :) My udev rule simply tells the modem manager to ignore two vendor IDs named in that file.
edit: if you "flash" your linux computer more often than your Android device, you should remember to backup the folder and the udev rules :)
 
Last edited:
  • Like
Reactions: hacknmtk

daltonfury42

Member
Jul 21, 2014
7
0
Thanks for your feedback @daltonfury42 :)
1) Of course you don't need to move to move the folder to / .As I wrote, you can also use your /home/user directory. But you shouldn't keep it in "/Downloads" or "/tmp", since you might have deleted the folder by the next time you want to use the flash-tool.

Step 2), as you suggest it, is redundant on a private computer, because you blacklist the modemmanager for the flash-tool only, and for nothing else. SP_Flash_Tool uses different Vendor and Product IDs than MTP/USB/ADB/Fastboot mode, and these IDs are not related to your specific device. So the modem manager is up and running - even while you flash - on every other active (network-relevant) usb-port of your computer :) And it will be up and running on the usb-port you use for the flash-tool when you disconnect the phone and then plug in something else - or the same phone in a different mode... But due to the permanent
Code:
/etc/udev/rules.d/20-mm-blacklist-mtk.rules
entry the modem manager will be automatically blocked if you connect your phone to the SP_Flash_Tool a second time - no matter which port: no further preparations necessary :)
If you want to check it out, take a look the output of
Code:
dmesg | grep usb
connecting your phone "normally" and compare it with the same command -> output connecting your phone to the SP_Flash_Tool - and/or to the contents of the file "usb_setting.xml" in the SP_Flash_Tool directory :) My udev rule simply tells the modem manager to ignore two vendor IDs named in that file.
edit: if you "flash" your linux computer more often than your Android device, you should remember to backup the folder and the udev rules :)

@Miss Montage, very informative. Thankyou.
 

Miss Montage

Senior Member
Mar 3, 2015
208
157
Where did you get the scatter file? Generally this error code means that the partition table is different to the one on your device. This should only be the case - occasionally - if you flash a complete firmware.
(Or replace Android through Ubuntu / vc. vs.)
 
Last edited:

Al3XKOoL

Inactive Recognized Developer
Mar 8, 2011
675
1,461
40
Tenerife (Canary Islands, Spain)
Where did you get the scatter file? Generally this error code means that the partition table is different to the one on your device. This should only be the case - here and then - if you flash a complete firmware.
(Or replace Android through Ubuntu / vc. vs.)

I know this error, so I am surprised
scatter is from my stock rom. Same i used to flash.
 
  • Like
Reactions: nojokeman

Miss Montage

Senior Member
Mar 3, 2015
208
157
Hmm, dunno why that is. Can you compare the scatter.txt to the /proc/emmc file on your phone?
And at what stage do you get the error? Immediately after connecting or later?
 
Last edited:

Al3XKOoL

Inactive Recognized Developer
Mar 8, 2011
675
1,461
40
Tenerife (Canary Islands, Spain)
Hmm, dunno why that is. Can you compare the scatter.txt to the /proc/emmc file on your phone?
And at what stage do you get the error? Immediately after connecting or later?

Right now I remembered in windows long ago got the same problem.
This happens if I try to use flash sp tool new versions

In windows:
Working: v5.1352.01
Not Working: v5.1512.00.000
 
  • Like
Reactions: spaten3

Miss Montage

Senior Member
Mar 3, 2015
208
157
Hmm, I will compare these lines to a successful log:
08/13/15 23:57:01.942 BROM_DLL[6767][6774]: FlashTool_ReadPartitionInfo(0x7f7b840038a0,0x7f7b84013310,0x7f7b00000013): mutex: LOCK ... (mutex.cpp:151)
08/13/15 23:57:01.942 BROM_DLL[6767][6774]: FlashTool_ReadPartitionInfo(0x7f7b840038a0,0x7f7b84013310,0x7f7b00000013): mutex: UNLOCK. (mutex.cpp:166)
08/13/15 23:57:01.943 BROM_DLL[6767][6774]: FlashTool_Disconnect(0x840038A0): mutex: LOCK ... (mutex.cpp:151)
 
  • Like
Reactions: Al3XKOoL

Top Liked Posts

  • There are no posts matching your filters.
  • 62
    This works only on Linux 64-bit
    DISCLAIMER: It is always risky to flash your mobile device. I do not and will not take any responsibility for bootloops and bricks.
    Please check carefully that the ROM or recovery.img you want to flash is suitable for your specific device and for the sp_flash_tool. The firmware directory should neither contain meta-inf nor system folder, but something_with_a_scatter.txt and a system.img
    Backup your phone before flashing!
    Your phone's battery should be at least half charged (50 percent) before you start this.

    I successfully ran these steps on my UMI Hammer with Linux Ubuntu 14.04 and 16.04. I do not have other devices or Linux derivates and do not plan to buy/install any.

    CREDITS and a zillion thanks to Sergio Rivero for his excellent tutorial on mibqyyo.com!!!!
    Also many thanks to N2K1 for giving me some more background information!

    So here we go:

    Step 1:
    If you haven't done so before, install the Linux generic usb-drivers package:
    Code:
    sudo apt-get update
    sudo apt install libusb-dev
    Download SP Flash Tool Linux (latest version): http://mtk2000.ucoz.ru/load/soft/soft_mtk/sp_flash_tool/5-1-0-14 (Password to extract currently is mtk2000v3)
    or here https://androidmtk.com/smart-phone-flash-tool
    In case you haven't done before, install unrar:
    Code:
    sudo apt install unrar
    Extract the downloaded file -> graphic file manager (e.g. Nautilus): double-click and extract. Terminal:
    Code:
    unrar x path_to_file
    (from now on: please adapt paths to your own settings)
    Move the new folder „sp_flash_tool“ to a directory of your choice.
    Code:
    mv /home/username/Downloads/sp_flash_tool /home/username/...
    You might also need to install libqtwebkit4 (it just happened to me on Linux Ubuntu 16.04):
    Code:
    sudo apt install libqtwebkit4

    [Only For Ubuntu 16.10 and newer]
    Run
    Code:
    dpkg -x libpng12-0_1.2.54-1ubuntu1.1_amd64.deb /tmp/libpng2
    cp /tmp/libpng2/lib/x86_64-linux-gnu/libpng12.so.0.54.0 lib
    cd lib
    ln -s libpng12.so.0.54.0 libpng12.so.0
    These libraries are still required for the flash tool but have been removed from new Ubuntu versions.
    Thanks @hanalinqu, @z3r0c00l_2k https://xdaforums.com/showpost.php?p=73484473&postcount=216 and @opticyclic https://xdaforums.com/showpost.php?p=81543495&postcount=285 for this information!

    Step 2:

    Change into the newly created directory:
    Code:
    cd /sp_flash_tool
    We make one file executable by typing:
    Code:
    chmod +x flash_tool

    In order to avoid running the flash_tool as root user, you need to add a standard user to the usergroup "dialout" (thanks to @egalus for this bit!)
    Code:
    sudo adduser username dialout
    For Arch Linux:
    Code:
    gpasswd -a username uucp

    and activate the membership immediately
    Code:
    newgrp - dialout
    (Arch Linux):
    Code:
    newgrp - uucp

    Step 3:

    Now you can open the tool:

    Code:
    ./flash_tool
    or double-click on the flash_tool icon.
    You can try at this stage if the flash tool connects to your phone:
    In the user interface, choose tab „Download“. Hit "scatter-loading", navigate to a directory with a valid firmware for your device and choose the scatter-file.
    For testing purposes uncheck "name" and check one of the smaller files in the list below (for example "logo")
    Switch off your device. Hit the "Download" button in SP_Flash_Tool and connect your phone to the computer. Some devices require you to take off the battery for about 10 seconds, with others you need to press Vol+ or Vol- while plugging the cable into the phone. Please look up device-specific threads and try out different options.

    If nothing happens at all, open a second terminal, run
    Code:
    dmesg | grep usb
    and look out for a MediaTek entry. If there is none → did you install libusb-dev (Step 1?)
    If the answer is yes, you might need to create a persistent udev rule for the MTK Preloader:
    Code:
    sudo gedit /etc/udev/rules.d/80-persistent-usb.rules
    Add the following line to the file:
    Code:
    SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0e8d", ATTR{idProduct}=="*"
    Save the file and exit.
    Reload the usb-rules:
    Code:
    sudo service udev restart
    Disconnect the usb data cable from the computer and the smartphone. Close the flash tool. Switch on your phone (fastboot mode will do). Repeat the first paragraph of Step 3.

    If the tool connects, within a few seconds a red progress bar will appear. Unfortunately, in my case an error message came along with it:
    S_BROM_CMD_JUMP_DA_FAIL (2035)
    There is a connection, but also one more obstacle to overcome...

    Step 4:
    Now we come to the interesting part, which cost me 2 weeks of (futile) research and frustration. Finally I found Sergio Riveros tutorial on mibqyyo. Thanks to him again and again and again for this priceless piece of information :)
    The “modemmanager” package integrated by default within Linux Ubuntu 14.04 and later is not compatible with the MTK Flash Tool for Linux
    To put it in different words: The modem manager controls port /dev/ttyACM0 and disables the Flash Tool. So we blacklist it for the two MTK vendor IDs the flash tool uses:
    Code:
    sudo gedit /etc/udev/rules.d/20-mm-blacklist-mtk.rules
    You insert these two lines:
    Code:
    ATTRS{idVendor}=="0e8d", ENV{ID_MM_DEVICE_IGNORE}="1"
    ATTRS{idVendor}=="6000", ENV{ID_MM_DEVICE_IGNORE}="1"
    Save the file, exit and restart udev:
    Code:
    sudo service udev restart

    Switch your phone on (fastboot mode will suffice) and off again.

    Step 5:
    Code:
    ./flash_tool
    or double-click on the flash_tool icon.
    Now everything should run smoothly. In case you encounter
    Code:
    BROM ERROR : S_SECURITY_SF_CODE_FORMAT_FORBIDDEN (6012) , MSP ERROE CODE : 0x00
    change the download agent to MTK_AllInOne_DA.bin (screenshot #4)
    There are plenty of tutorials on the web for the further steps.
    Happy flashing! When a green circle with a white checkmark appears, you are done. You can close the flash tool and disconnect your phone. For a clean start with a new ROM boot into recovery and wipe data/factory reset.
    5
    edent; BROM Exception! ( BROM ERROR : S_COM_PORT_OPEN_FAIL (1013) [COM said:
    Failed to open COM port.[/CODE]

    dear edent,

    I had the same as you (error1013)

    I just started flash_tool in root mode (sudo ./flash_tool.sh)
    and it worked...

    arnold
    3
    Please change your tutorial and remove the security risk of executing flash_tool as root.
    As far as I understand the flashing procedure it is just using a serial connection to upload the rom to the mobile device thus it only needs one special right not every user might have:
    The user needs write permission to the MTK usb-device.
    At least for ubuntu it suffices to add the user to the dialout group as groupmembers get access to every modem.
    Maybe logging out and back in again after adding the user to the group is needed.

    I tested this by flashing my Jiayu S3 (which used /dev/ttyACM0) using ubuntu 15.04 and a user who is a member of the dialout group - no problem at all, thus no need for root except for adding the user to the group dialout.

    Never execute anything you download from places like needrom as root user - at least not on a system you need or have data on that you need!
    2
    Well, that's what life's supposed to be - give and take :) You are especially welcome!
    2
    Great post!

    Just wanted to say you saved me HOURS OR DAYS OR WEEKS of time on the modemmanager thing. I have Arch Linux, successfully ported over this tutorial, but I had no idea the modemmanager package was causing the issue. SP Flash Tool was the last frontier for using my Android devices on Linux. Thanks so much!