Wednesday, December 14, 2016

Step-by-step: Install OpenWRT on the Xiaomi Wifi Mini router from a Windows Computer (2016 edition)

UPDATE: These instructions no longer work because Xiaomi has patched the firmware bug that allowed us to bypass the security and unlock the ROM.  Now a user must install the "Developer Edition" of the official Xiaomi firmware, register the router with a Xiaomi account, and then unlock the router.  These instructions are posted in another post [LINK].

I found the instructions to install OpenWRT on the Xiaomi Wifi Mini to be difficult to follow [openwrt device page], so I've summarized the instructions below.  Please note that this is for OpenWRT 15.05.1 on the Xiaomi Mini Wifi (小米 路由器MINI )

NOTE: It appears that the Xiaomi Mini has been discontinued since it is no longer listed as an active product on Xiaomi's store. They have replaced it with two other models which do not have active OpenWRT development - however they are still available from 3rd party sellers on tmall.com

Unlock the Router & Enable Telnet

1. Connect the router to power.
2. Connect an internet patch cable to the WAN Uplink port (blue colored).
3. Connect a Windows computer to one of the Ethernet switch ports on the router (white colored).
4. Launch a web browser and connect to the administrator console by going to the following address:
http://192.168.31.1, If you cannot reach the administrator console:
     * Check the IP address on your computer and verify the it starts with 192.168.31
     * Verify that you have any VPN software turned OFF
     * Verify that the Proxy settings are disabled in “Internet Options”
5. Follow the setup wizard and configure the router.
     * Note: It will ask you to set the wifi and the administrator password. Set it to 1234567890
     * Note: All settings made during this process will be erased later, so don’t spend time making it nice...
After you complete the setup wizard, the router will reboot.
6. Connect to the web administrator console again and sign-in to the router and copy the value of the stok URL parameter from the address (for example: "9c2428de4d17e2db7e5a6a337e6f57a3")

7. Replace the <STOK> placeholder below with the value from the new router and copy this address into the URL in your browser. (Note: This will start the telnetd service on the router):
http://192.168.31.1/cgi-bin/luci/;stok=<STOK>/api/xqnetwork/set_wifi_ap?ssid=whatever&encryption=NONE&enctype=NONE&channel=1%3B%2Fusr%2Fsbin%2Ftelnetd
After about 30 seconds a successful command will display the following error code:
Chinese: {"msg":"未能連線到指定Wi-Fi(Probe timeout)","code":1616}
or English: {"msg":"Couldn't connect to this network(Probe timeout)","code":1616}
8. Replace the <STOK> placeholder below with the value from the new router and copy this address into the URL in your browser. (Note: This will change the root password from 1234567890 to 123456abc on the router):
http://192.168.31.1/cgi-bin/luci/;stok=<STOK>/api/xqsystem/set_name_password?oldPwd=1234567890&newPwd=123456abc
After about 5 seconds a successful command will display the following error code:
{"code":0}

Install OpenWRT on the Router from a Windows Computer

1. Run putty (download it if you do not have it on your computer) and start a Telnet connection to the router with the following two options:
  • Host Name (or IP address):    192.168.31.1
  • Connection type:                     Telnet


2. Sign into the console using the following account information
  • XiaoQiang login:    root
  • Password:         123456abc

3. Get the latest firmware from OpenWRT using these Telnet shell commands:
  • # cd /tmp
  • wget http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/openwrt-15.05.1-ramips-mt7620-xiaomi-miwifi-mini-squashfs-sysupgrade.bin

4. Check the MTD layout on the router to make sure you don't damage it:
  • cat /proc/mtd

If you find a line "OS1" go ahead with flashing:
mtd -r write openwrt-15.05.1-ramips-mt7620-xiaomi-miwifi-mini-squashfs-sysupgrade.bin OS1
     * Note: for LEDE, replace the file name with the correct one, like this: mtd -r write lede-17.01.2-ramips-mt7620-miwifi-mini-squashfs-sysupgrade.bin OS1
After flashing is complete, the router will reboot. Wait about 10 minutes to ensure that the firmware is installed properly and then power off the router and power it back on my disconnecting the power.

Please note that the OpenWrt binary defaults to the red color of the led instead of the orange/blue during and after finishing the boot that Xiaomi uses.

Comments on how OpenWRT runs on the Xiaomi Wifi Mini Router

  • There is LOTS of memory on the Xiaomi - it is a luxurious amount of space to install packages on and run them in memory.
  • The ROM is stable.
  • I have tested several VPN/proxy packages's on it like OpenVPN, stunnel, and shadowsocks; they all run well on OpenWRT and this hardware.
  • The Wifi is not stable. From extensive testing I assume that Xiaomi is running some custom drivers or doing some software tricks to make the wifi work properly (the wifi works perfectly on the stock Xiaomi ROM).  Suggestion - Use the Xiaomi as a router and attach another Wifi router to it for WAP functions.
  • The wifi is available for international shipping from several 3rd party sellers on Aliexpress (in China they retail for 130rmb - about US$20) [Search Results]

Wednesday, July 6, 2016

SOLUTION! Moto XT1085 Fails to Install Cyanogenmod 12/13 [DRAFT QUALITY!]

WARNING: DRAFT QUALITY SOLUTION - I'M WORKING ON TRANSLATION OF SOME PARTS FROM CHINESE AND THE STEP-BY-STEP SOLUTION.

There are some hardware differences between the XT1085 (China), the XT1092(Europe), and the XT1097(USA) variants of the Moto X 2nd generation, 2014 edition also known as “victara”.  The three different versions of the phone are identical with the exception of two things:  [1] they have different regional networking standards (radio frequencies) and [2] they have different partition configurations.


Q: Can I install Cyanogenmod (or a variant of it) on the XT1085?
A: Yes you can, but not “as-is” from the main download page.


Q: Why would I want to install Cyanogenmod on my Moto X? The Motorola stock ROM is already very minimal compared to other vendors.
The main reason that you would want to install Cyanogenmod over the exiting version of Android on the XT1085 is to remove the special Chinese security software that’s installed...and which makes the phone suspicious to monitoring and tampering.  The other reason you would want to install CM is to get Marshmallow on a phone that would otherwise be stuck on Lollipop (5.1).


Q: Why does the Cyanogenmod packages for Victara fail to install on the XT1085?
A: It is because of the second reason mentioned in the introduction: the different partition sizes for the SYSTEM partition.


The sizes of the partitions are:
  1. XT1092/XT1097 = 2902458368 bytes (or 2.9G)
  2. XT1085 = 2046820352 byte (or 2.0G)


When you try to install the Cyanogenmod package directly on to the XT1085 you will corrupt the SYSTEM partition and the phone will become unusable. (Note: To recover from a phone that has been corrupted by overwriting the Cyanogenmod package, you should go to this article (will write it soon) for a solution...don’t worry - it’s easy to fix when you know how!)


Q: How can I install Cyanogenmod on my Chinese edition of the Moto X?
UPDATE: I've already performed these steps on the cm-12.1-20151117-SNAPSHOT image of Cyanogenmod 12 (Stable) and verified that it works on my phone...no issues!  You can download it and install it (at your own risk of course) from my Google Drive file share here: Download XT1085 Mod | I'll edit a 13.0 nightly soon and post it as well.

cm-12.1-20151117-SNAPSHOT-YOG7DAO1KI-victara-XT1085mod.zip
MD5: 3b274ed11214c4dd79f1373da1548242

UPDATE 2: I've rebuilt the image file for LineageOS 14.1.  Please see my other post to direct-download the image from Google Drive. [New Post]


METHOD 1

The main method is to mount the Cyanogenmod system.new.dat file in Linux (I use Ubuntu) and repackage the file to reflect the smaller partition size.

This method was written by XPIRT on the XDA forums here: XDA - [DEV] Lollipop/Marshmallow DAT files | Compression and Decompression


Another way is to use the correct parameters and repackage the system.new.dat, replace zip package system.new.dat and system.transfer.list, methods here:


METHOD 2


Background information: In Android 5.x and newer update packages are created when the system.img file and the system.new.dat files are combined and generate a new system.img file.  The command to do this is:

make_ext4fs -T 0 -S file_contexts -l 2046820352 -a system system_new.img
Note: Download the make_ext4fs android tool for Windows from XDA developers.
The -l option is normally the size of the system partition image, which cannot be larger than the actual size of the system partition. The default Cyanogenmod package is created with 2.9GB -l option; designed for the European and American versions of the Moto X.
“mokee” compilation works  because “mokee” rolls back the CM12/13 package to the “OTA” format which was used in versions of Android before 5.0.

So, we can unpack system.new.dat, modify compile script, to install like it did before the Android 5.0.