Platinum Member

Rank: 4

Credits
4796
Device
Redmi 4A
Online time
210 Hours
Send PM

Mi BandMIUI 2015Fantastic!I Love MIUIAwesome!MIUI 6FlashholicMIUI 7MIUI 2016Xiaomi Mi 4RedmiRedmi 2Mi Note800K Forum Members300K Forum MembersMIUI 4th Anniversary500K Forum Members1 Million Forum MembersMIUI 100 Million UsersMIUI English Forum 2013Summer Mi BunnyI Love Mi BunnyAlpaca Mi Bunny Class A Beta TeamMIUI FollowerAndroid GuruHumor MasterUpdates LoverMIUI Medals CollectorForum Contest LoverMIUI Global Forum 2014MIUI Android 4.4 KitKatOTA FeedbackDie-hard MIUI FanPioneer of MIUI English Forum

[Tools, Tips & Tutorials] Manage Redmi under Linux through adb

[ Promote]
18329 7 |
20:09, Oct-10-2014 | From PC
|
|
Go to reply no.
This post was edited by ATP:RedRice at 19:36, Dec-04-2014

Manage Redmi under Linux through adb !

Yeah, it's possible to flash, root, backup, etc... through adb tools (named too adb commands).
Drop fastboot, you can not use it !

Note: It's important to understand thoses informations :

- If your phone is setting on 'USB computer connexion' at 'Charge only', it's not recognized!
- With both modes 'stock recovery', 'fastboot', it's not recognized!
- Need alternative recovery installed, as TWRP or CWM. I repeat: Unfortunately, with the stock recovery, it is not possible
- Go to Settings > Developer options > USB debugging: activate by sliding to the right. It's need for adb!

Made all changes at your responsability, and your risks.
I'm not responsable of yours actions, egual for this community!

It's better to know how to used to the commands Linux, if not: go out your way!

1/ Configure your Linux, and install adb tools:


To install adb tools, since 13.04, it's onto Ubuntu servers. No more servers are necessary.
If you use an Ubuntu version oldiers, you can use the Phablet Tool PPA! (You can use this with earliers, to obtain updating versions...)

For ADB recognition, it's necessary to create a file named "~/.android/adb_usb.ini".
(think to setting USB debugging into you ROM session)
Write just this:
  1. 0x2717
  2. 0x0bb4
Copy the Code
Note: The first declaration is to recognize Redmi when it's into session Android; the second is when your phone is into an alternative recovery.

Put this file into cached folder ".android", into your home folder. If this folder not exists, create-it!

It's interesting too to write '/etc/udev/rules.d/51-android.rules' file as:
  1. # Xiaomi Hongmi - TWRP or CWM: recognized as HTC (High Tech Computer Corp.) Android Phone [Fairphone First Edition (FP1)]
  2. SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0c03", MODE="0666", OWNER="you"
  3. # Xiaomi Hongmi WCDMA - PTP Mode
  4. SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1210", MODE="0666", OWNER="you"
  5. # Xiaomi Hongmi WCDMA - PTP Mode with USB Debug
  6. SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1218", MODE="0666", OWNER="you"
  7. # Xiaomi Hongmi WCDMA - USB Mode == Built-in CD-ROM Mode!
  8. SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1220", MODE="0666", OWNER="you"
  9. # Xiaomi Hongmi WCDMA - USB Mode with USB Debug
  10. SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1228", MODE="0666", OWNER="you"
  11. # Xiaomi Hongmi WCDMA - MTP Mode
  12. SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1240", MODE="0666", OWNER="you"
  13. # Xiaomi Hongmi WCDMA - MTP Mode with USB Debug
  14. SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="1248", MODE="0666", OWNER="you"
Copy the Code
You do to modify the OWNER information by your Linux identifiant, your username!
After this, restart the udev subsystem. (sudo service udev restart)!

Note:  You can use this other tutorial to access your Redmi (1, 1S, Note) with Linux!

=> Assume adb recognize your phone, and write into your console:
  1. $ adb devices
  2. * daemon not running. starting it now on port 5037 *
  3. * daemon started successfully *
  4. List of devices attached
  5. 6DYHYD9DZTO7TKLZ        device
Copy the Code

2/ Obtain informations partitions


Open your prefered console:
  1. $ adb shell cat /proc/dumchar_info
  2. Part_Name    Size    StartAddr    Type    MapTo
  3. preloader    0x0000000000600000   0x0000000000000000   2   /dev/misc-sd
  4. mbr          0x0000000000080000   0x0000000000000000   2   /dev/block/mmcblk0
  5. ebr1         0x0000000000080000   0x0000000000080000   2   /dev/block/mmcblk0p1
  6. pmt          0x0000000000400000   0x0000000000100000   2   /dev/block/mmcblk0
  7. pro_info     0x0000000000300000   0x0000000000500000   2   /dev/block/mmcblk0
  8. nvram        0x0000000000500000   0x0000000000800000   2   /dev/block/mmcblk0
  9. protect_f    0x0000000000a00000   0x0000000000d00000   2   /dev/block/mmcblk0p2
  10. protect_s    0x0000000000a00000   0x0000000001700000   2   /dev/block/mmcblk0p3
  11. seccfg       0x0000000000020000   0x0000000002100000   2   /dev/block/mmcblk0
  12. uboot        0x0000000000060000   0x0000000002120000   2   /dev/block/mmcblk0
  13. bootimg      0x0000000000600000   0x0000000002180000   2   /dev/block/mmcblk0
  14. recovery     0x0000000000600000   0x0000000002780000   2   /dev/block/mmcblk0
  15. sec_ro       0x0000000000600000   0x0000000002d80000   2   /dev/block/mmcblk0p4
  16. misc         0x0000000000080000   0x0000000003380000   2   /dev/block/mmcblk0
  17. logo         0x0000000000300000   0x0000000003400000   2   /dev/block/mmcblk0
  18. ebr2         0x0000000000080000   0x0000000003700000   2   /dev/block/mmcblk0
  19. expdb        0x0000000000a00000   0x0000000003780000   2   /dev/block/mmcblk0
  20. android      0x0000000028a00000   0x0000000004180000   2   /dev/block/mmcblk0p5
  21. cache        0x0000000007e00000   0x000000002cb80000   2   /dev/block/mmcblk0p6
  22. usrdata      0x0000000080000000   0x0000000034980000   2   /dev/block/mmcblk0p7
  23. fat          0x0000000033000000   0x00000000b4980000   2   /dev/block/mmcblk0p8
  24. bmtpool      0x0000000001500000   0x00000000ff9f00a8   2   /dev/block/mmcblk0
  25. Part_Name:Partition name you should open;
  26. Size:size of partition
  27. StartAddr:Start Address of partition;
  28. Type:Type of partition(MTD=1,EMMC=2)
  29. MapTo:actual device you operate
Copy the Code
Note: Informations 'Size' and 'StartAddr' are hexadecimal values!
See others informations about dumchar_info...

3/ Root your phone!

After installing an alternative recovery, and connecting your phone at your computer by USB, reboot into alternative recovery:

1/ You need to download SuperSU: http://download.chainfire.eu/supersu
2/ After downloading, unzip the archive...

Into your console, made this changes:
  1. adb shell busybox mount /system
  2. adb install /folder_archive_SuperSU_unzip/UPDATE-SuperSU-v2.02/common/Superuser.apk
  3. adb push /folder_archive_SuperSU_unzip/UPDATE-SuperSU-v2.02/arm/su /system/xbin/
  4. adb shell chmod 06755 /system/xbin/su
  5. adb shell chown 0:0 /system/xbin/su
  6. adb shell ln -s /system/xbin/su /system/bin/su
  7. adb shell busybox umount /system #
  8. adb shell reboot
Copy the Code
Note:
- If first command fail, use this: 'adb shell busybox mount /dev/block/mmcblk0p5 /system'
- If second fail, push Superuser.apk, chmod to 0644, and chown @ 0:0...
- The chmod 06755 onto binary su is relative at your Android version (JB: 4.2.2). With KK, this will change...
- The information 'UPDATE-SuperSU-v2.02' will change according to number version when you download-it!

4/ Flashing your phone!

This operation is same to backup!

After installing an alternative recovery, and connecting your phone at your computer by USB, reboot into alternative recovery:

Into your console:
  1. adb shell busybox mount /system
  2. adb push recovery.img /system/recovery.img
Copy the Code
Note: You can push your recovery into /sdcard/, or /tmp/ if you want...

=> Now, a new step more complicated: How to use hexadecimal values!
- Obtain hexadecimal value 'Size' of partition recovery and transform into decimal value:
  1. $ echo $((0x0000000000600000))
  2. 6291456
Copy the Code
Note:
- VERY IMPORTANT: Check absolutly you use hex value 'Size'! Don't confuse with 'StartAddr'... You will risk to brick!
- They are few methods to transform hex value to dec value. My prefered is: bc <<< "ibase=16;obase=A;hex_value_without_0x".

=> Now, we need to write recovery.img into system Android, with the good dec value:
  1. $ adb shell su -c dd if=/system/recovery.img of=/dev/recovery count=1 bs=6291456
Copy the Code
Note: As you see, this command adb use binary su. Your phone need rooted!
- It exists another method to write recovery, little more complicated: obtain both hex value 'Size' and 'StartAddr', transform thoses to dec values, and divized thoses by 4096. Value 'MapTo' is need too.
  1. $ adb shell su -c dd if=/system/recovery.img of=/dev/block/mmcblk0 bs=4096 count=1536 skip=10112
Copy the Code
____

You've understand how flashing, use this method to get nvram partition, and  others...

And to backup?

It's same method, but you need to reverse input file and output file into binary dd, with the good hex values, to transformed dec values...
When it's done, call adb pull file_backup.img...
To finish, think to remove into system android the file backuped.

____


Enjoy-IT!
Enjoy-ID!

____

For your information: i develop scripts bash to use easy thoses commands.
My project is into github: https://github.com/hucste/MTKZenyT

10/16/14:
ROOT and UNROOT run correctly. BACKUP is implemented, but need more tests!
10/29/14: v1.2 ... to launch tool with options into console.

Favorite9 Share

Rated by 6 people   Experience Reason  

asliabir + 1 Great!
oleg.a.ch + 1 Thanks!
ian_x86 + 1 Fantastic!
Mohammad_Sultan + 1 Thanks!
grapox + 2 Awesome!
rocco6 + 5 Awesome!

Experience +11  View Rating Log

ATP: MiTu: I'm alive! ~ Xiaomi Redmi WCDMA
----
Redmi 1: FAQs,...
Linux: access by USB Cable, QQ

Elite Member

Rank: 6Rank: 6

Credits
9954
Device
Redmi
Online time
454 Hours
Send PM

Mi KeyMi BoxMi BandMi In-Ear HeadphonesAwesome!Fantastic!MIUI 2015FlashholicI Love MIUIRedmiXiaomi Mi 4Thanksgiving DayDiwali 300K Forum Members1st AnniversaryHilal Ramadan MIUI Fan From PhilippinesMIUI 100 Million UsersHappy DiwaliFan Of MIUI SpainMIUI 50 Million UsersAtaturk MourningHappy Singles' DayMIUI 4th AnniversarySummer Mi BunnyAlpaca Mi Bunny I Love Mi BunnyClass A Beta TeamMIUI Beta TeamMIUI Beta Team VIPPioneer of MIUI English Forum MIUI FollowerSenior Beta TesterAndroid GuruStar Of IconsMIUI Android 4.4 KitKatUpdates LoverForum Contest LoverMIUI Global Forum 2014Inbox ZeroYouth PledgeOTA FeedbackMost Active MIUIerMIUI Twitter FollowerDie-hard MIUI FanHumor Master

20:23, Oct-10-2014 | From PC
|
Great! Thanks, will come handy when I make the switch to Linux

Platinum Member

Rank: 4

Credits
4796
Device
Redmi 4A
Online time
210 Hours
Send PM

Mi BandMIUI 2015Fantastic!I Love MIUIAwesome!MIUI 6FlashholicMIUI 7MIUI 2016Xiaomi Mi 4RedmiRedmi 2Mi Note800K Forum Members300K Forum MembersMIUI 4th Anniversary500K Forum Members1 Million Forum MembersMIUI 100 Million UsersMIUI English Forum 2013Summer Mi BunnyI Love Mi BunnyAlpaca Mi Bunny Class A Beta TeamMIUI FollowerAndroid GuruHumor MasterUpdates LoverMIUI Medals CollectorForum Contest LoverMIUI Global Forum 2014MIUI Android 4.4 KitKatOTA FeedbackDie-hard MIUI FanPioneer of MIUI English Forum

 Author| 19:53, Oct-29-2014 | From PC
|
New version 1.2!

To launch this tool with options into console...
ATP: MiTu: I'm alive! ~ Xiaomi Redmi WCDMA
----
Redmi 1: FAQs,...
Linux: access by USB Cable, QQ

Senior Member

Rank: 2

Credits
176
Device
Redmi 1S
Online time
44 Hours
Send PM

Mi In-Ear Headphones300K Forum MembersFan Of MIUI India

21:58, Jan-12-2015 | From PC
|
thanks

Senior Member

Rank: 2

Credits
178
Device
Redmi 1S
Online time
57 Hours
Send PM

MIUI 7

13:52, Jan-24-2015 | From PC
|
Thanks man .... works great on my linux box

Senior Member

Rank: 2

Credits
180
Device
0
Online time
63 Hours
Send PM
01:50, Mar-10-2015 | From PC
|
This post was edited by Micky007Mi at 02:03, Mar-10-2015

Hey guys!Very useful Thread!Thank you!Can anyone help me?I'm using Linux Mint 17.1 Rebecca x64(I have followed the guide in the right way)and I'm having issue trying to mount MTP normally (I mean using android) and throug TWRP 2.8.1.1(I use 2.8.1.1 instead of 2.8.5.0 because with 2.8.1.1 no one has ever had problems), Mint give me error window with the message Unable to mount "HM 1S" Unable to open the MTP «[usb:002,074]»;this is the problem,what should I do in order to fix it?
EDIT:If I type 'lsusb' in terminal when connected through TWRP with MTP Enabled it shows me the device as ''Bus 002 Device 076: ID 18d1:4ee2 Google Inc. Nexus 4 (debug)'' and if I type in TWRP with MTP Disabled or USB Storage Mounted i get it as ''Bus 002 Device 077: ID 18d1:d002 Google Inc.''and if I type with Android normally booted and MTP Enabled I get it as ''Bus 002 Device 087: ID 2717:1268''  
but with only USB-Debug Enabled I get''Bus 002 Device 088: ID 18d1:d002 Google Inc.''and with PTP''Bus 002 Device 089: ID 2717:1218  
''.I hope these informations will be useful

Diamond Member

Rank: 5Rank: 5

Credits
1642
Device
Redmi Note LTE
Online time
167 Hours
Send PM

Fantastic!Flashholic500K Forum MembersXiaomi 5th AnniversaryMIUI FB FollowerForum Contest Lover

02:43, Mar-23-2015 | From PC
|
Thanks for Guide

Senior Member

Rank: 2

Credits
28
Device
Mi Max 32GB
Online time
2 Hours
Send PM
22:58, Mar-03-2017 | From PC
|
Would this work for the Mi Max as well? or do we need to enter different values in the adb_usb.ini file?

Credits Management

Quick Reply Top Return to the list