Friday, April 7, 2017

LineageOS: Rebuilding the XT1095 Victara Image to work with the Chinese version XT1085 (Hardcore Raw Edition)

NOTE: The text that follows is not edited and may not even be coherent.  I don't have time to make it nice and pretty for the public, but these are my "dump notes" I use when rebuilding the XT1095 ROMs to work on the XT1085.  They're better from a technical perspective than the other article I wrote, although they lack the explanation as to why it's necessary...hopefully I'll have the energy (or focus) to come back to this later and edit it.  If I remember correctly, these are my personal edits to an XDA article on a very similar subject...

UPDATE: With Lineage there are two extra steps now to convert the image to a sparse image and to convert the file_contexts.bin file to file_contexts (no .bin).  I just followed these instructions to convert a March 2018 image of LineageOS 14.1 and I realize that these instructions are pretty rough.  Very sorry - I hope to update them soon.

XDA: [DEV] sdat2img 1.0 - img2sdat 1.2 ◦ Unpack/re-pack android DAT files

Ubuntu x64 - Guide
A. Prerequisites | Getting Ready
1. You must run all of these commands from an Ubuntu x64 operating system.  I am using Ubuntu LTS 16.04.
2. 10 GB of free space (for the temporary files)
3. Download all of the scripts listed on the XDA site.  You'll need and put them in a folder on your Linux system. I created one in my home directory called \BUILD.  Here are the download links as of 2017 Aug 9:


          Note: Make each script executable (including the sefcontext binary under lib64 for the convert tool

4. Install all package dependencies that you'll need to run the scripts, namely:
  • python3
  • build-essential
  • android-tools-fsutils
5. Download the ROM ZIP file that you want to edit. I use LineageOS 14.1 for Victara
6. Extract the ROM ZIP file into a new folder on your computer. I make a new folder called \VictaraLineage in my home directory. The typical ROM will contain the following files:

  •  boot.img
  •  file_contexts.bin
  •  system.new.dat
  •  system.patch.dat
  •  system.transfer.list
  •  \install
  •  \META-INF
  •  \system
7. Copy the system.transfer.listsystem.new.dat, and file_contexts.bin files into the \BUILD folder with your scripts.

B. Converting the Image to EXT4

1. You will first use the sdat2img binary; the usage is as follows. CD into the BUILD folder:
          ./sdat2img.py <transfer_list> <system_new_file> <system_ext4>
            - <transfer_list> = input, system.transfer.list from rom zip
            - <system_new_file> = input, system.new.dat from rom zip
            - <system_ext4> = output ext4 raw image file

          an quick example:
            sudo ./sdat2img.py system.transfer.list system.new.dat new_system.img

Note: By running this command the script will create a new file called my_new_system.img which is the raw ext4 image.  This IMG file will be about 2.9GB.

2. Delete the system.transfer.list and system.new.dat files from the \BUILD directory to free up space and avoid conflicts or confusion later.

C. Convert the file_contexts.bin file
Nougat now uses a file_contexts file instead of the old file_contexts.bin. Run the following script to create the older file format:

          sudo ./convert.sh
Copy the file from the "convert" subfolder back into the BUILD folder.

D. Decompress and Re-compress the image to a new size
3. Mount the ext4 raw image into an output folder so we can see apks/jars etc.  To do this we need to type this command:

          sudo mount -t ext4 -o loop new_system.img LinOS14


Note: To increase the likelihood of success, I first create the mount point's folder...I'm not a seasoned Linux guy, so this might not be necessary, but it works well for me when I do.

As you can see there is a new folder called output which we can edit/modify/delete your files. I see the following on a recent LineageOS 14.1 image:

  • build.prop
  • recovery-from-boot.p
  • \addon.d
  • \app
  • \bin
  • \etc
  • \fake-libs
  • \fonts
  • \framework
  • \lib
  • \media
  • \priv-app
  • \tts
  • \usr
  • \vendor
  • \xbin

E. To compress it back to a raw ext4 image, to do this we need the make_ext4fs binary. Make sure you have the file_contexts file (taken from the Rom zip) inside the make_ext4fs path. Then type this (got issues? see here)
./make_ext4fs -T 0 -S file_contexts -l 1073741824 -a system system_new.img output/
You will get the new raw ext4 image called 'system_new.img' ready for the next step.

<<My command for the XT1085 looks like:
sudo make_ext4fs -T 0 -S file_contexts -l 2046820352 -a system new_raw_system.img LinOS14/

Unmount the image file

sudo umount LinOS14

Step 3 - Converting = EXT4 (raw image) -> IMG (sparse image)

Now we need to convert the ext4 raw image into a sparse image. For this you need img2simg binary in the BUILD directory (see pre-requisites)
The usage is simple:  img2simg <raw_image_file> <sparse_image_file>


My command is
img2simg new_raw_system.img new_sparse_system.img

Step 4 - Converting = EXT4 (raw image) -> DAT (sparse data)
Now we need the img2sdat binary, the usage is very simple:
./img2sdat.py <system_sparse_img>
- <system_sparse_img> = name of input ext4 raw image file

and a quick example:
sudo ./img2sdat my_new_system.img
<<My command for the XT1085 looks like:
 ./img2sdat.py new_sparse_system.img

Type "4" and enter for Android Nougat 7.0
The script output will be a new

  • system.transfer.list
  • system.patch.dat
  • system.new.dat


Step 5 Move the New Files Back into the ZIP
A. Copy the system.transfer.list and system.new.dat into the original unzipped ROM image folder, overwriting the originals (ignore the system.patch.dat file)
B. Rezip the files into a new ZIP, and for consistency's sake rename the ZIP exactly like the original ZIP but with XT1085VERSION at the end
C. Copy that ZIP file away from your BUILD and SCRIPT folders to avoid deleting it when cleaning up
D. CLEANUP

 Delete build information...it's big
 .img



ROM: LineageOS 14.1 for Moto X (2014) Chinese Edition, XT1085

   The Chinese edition of the Motorola Moto X 2014 (XT1085) has a smaller system partition than the Moto X in the rest of the world (XT1095).  The code name for this phone is "Victara".

   There's several scripts and tools available to repack the LineageOS build for the XT1095 (see my other article on the subject or the original XDA article).  I've run these scripts and am happy to make the shrunken ZIP file available for download.

lineage-14.1-20170804-nightly-victara-signed-xt1085version.zip
DOWNLOAD LINK (Google Drive)

MD59fa293e463cba3829262646d08d0eae8

   NOTE: Other than unpacking the zip, recompiling the image to a smaller system partition, and rezipping there is no modification to the download available on LineageOS' site (BIG thanks to the hard work they're doing over there on this new Android build).

Google Services
   If you're installing this image on your Moto XT1085, you'll also want to install the latest Opengapps for Android 7.1, ARM - I use the Nano package myself, with great success.

Recovery Image
   The standard recovery partition image from TWRP works well, without modification.  You can download that from their website; here's a direct link to the victara download page.

E

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.

Saturday, October 17, 2015

Windows Update Tips - Clearing Windows Update History or...Everthing

At time Windows Update can become stuck or unstable.  Here's s few tips on troubleshooting Windows Update (I'm using Windows 7 as my reference).

Clearing Download Cache
Stop Service:
   net stop wuauserv
Delete only the %windir%\Software Distribution\Download folder

Resetting Windows Update History
Stop service:
   net stop wuauserv
Delete Entire %windir%\Software Distribution Folder

Resetting all Windows Update Components (The Nuclear Option)
Stop all Windows Update related services:
   net stop bits
   net stop wuauserv
   net stop appidsvc
   net stop cryptsvc

Some References on Windows Updates
Microsoft.com: How do I reset Windows Update components?

[SOLVED] Lenovo A6000 Update Error: "Your phone has not switched carriers an cannot be upgraded" (status 101)

     My Lenovo A6000 has been stuck on Android 4.4.4 ever since I bought it...I was so happy when the system updater notified me that an upgrade was available!  After downloading the 1GB update though it failed to install.  So I tried it again...and the installation failed again.  So what is a self-respecting Android user supposed to do but go find the OTA and download it from XDA-Developers.  I downloaded this ROM here:



I made a backup of this ZIP here, but I make no warranty about it's safety or legitimacy:


     (Note: Later I found this link too...for what it's worth. Lenovo a6000 plus Lolipop 5.0.2 official OTA zip file(Google drive)

     To install it, I saved the file to my SD Card and then powered off the phone.  The instructions for going into Recovery mode are (source: How to Enter Recovery Mode on A6000):


  • Power off your device.
  • Boot in recovery mode by pressing and holding Volume Up and Power Button at the same time.
  • Release all buttons when the Lenovo A6000 screen flickers and in a few seconds the Recovery screen will appear.
  • When the Android image appears press Power shortly

     After installing the ZIP file from the SD Card (one of the options in recovery mode) I got an error that the installation did not finish...but on rebooting the phone the OS was at version 5.0.2! What?!  Almost immediately after that  it prompted me to install another update, version S056, a 156MB update. Downloaded, rebooted, and then got this error:
LENOVO A6000 System Update Kraft-A6000_S054_150915 - lenovoError details..Stock recovery says, "Your phone does not switch carrier, cannot upgrade"E: Error in /data/data/com.Lenovo.its/ap_its packages/(long hash numbers)-Lenovo ota.zip
Status(101)Installation aborted
     Man...what is the deal with Lenovo's ROMs?! After searching the Internet it becomes very obvious that the Lollipop upgrade for Lenovo phones is NOT GOING WELL. (Example: Lenovo Forum).  After some searching and finding many solutions that involve downgrading, using ADB, and other advanced method I found two off-the-cuff remarks that the "Carrier" ZIP files are bundled in the original "Kraft-A6000_S052_150825_WCCA.zip" file. So the solution I found to work for me was:
  1. Extract Kraft-A6000_S052_150825_WCCA.zip on a desktop computer (I used Windows)
  2. Locate the correct country .zip file in the extracted files. For me the file I needed was HongKong.ota.zip
  3. Connect the phone the computer via USB and copy that file to the root of the SD Card (I used MTP mode).
  4. When I tried to boot the phone into Recovery mode using the original instructions above the phone was unresponsive at the touch menu (so many bugs!)...so the only way I found to easily force the phone into recovery mode is to allow the System Update Utility to download and attempt to install the 156MB update...and then FAIL which leaves you in Recovery mode thankfully.  Select install update from SD Card and then choose your country's specific OTA.ZIP file.  This succeded and automatically rebooted the phone.

     I made a backup of the ZIPs here, but I make no warranty about it's safety or legitimacy:


     After this procedure the System Update worked for me successfully after re-downloading the 156MB package again.

Monday, May 4, 2015

HOW TO: Create a bootable USB flash drive in Windows from an ISO (Manually)

Summary:
A bootable USB flash drive can be used as an alternative to booting from CD or PXE on a enterprise network.

Prerequisites:
  • ISO file that you want to boot from (Linux, Windows, etc.).  In the example below I will make a bootable Windows 8 Installation CD USB drive.
  • USB Flash Drive: Verify that it is large enough to hold the entire contents of the ISO file
  • 7-Zip: Used to extract the .ISO file to the USB Flash Drive. [DOWNLOAD]

Preparing the bootable USB Flash Drive:
1. Insert a USB Flash Drive into a Windows 7 or Windows 8 client.
2. As an Administrator launch the Command Prompt. (Windows Logo + R, type: cmd.exe, Enter)
3. In the Command Prompt type:


ATTENTION: Replace '#' with the DISK number of the USB Flash Drive.

diskpart
list disk
select disk #

clean
create par primary
select par 1
active
format fs=fat32 label="Win8ProInstall" quick
assign
exit


Diskpart in Command Prompt


4. It may be necessary to remove the USB Flash Drive and re-insert it.
5. Locate the file windows8pro.iso on you local computer (or whatever the ISO you have is called)
6. Right-click on the file windows8pro.iso and locate the 7-Zip context menu option.
7. From the 7-Zip context menu select the option "Extract files...".
8. In the "Extract" dialog enter the drive letter of the USB Flash Drive and click "OK" to begin extracting the files.
9. Once the extract process completes, eject the USB Flash Drive. Test the drive to ensure that it is ready for production use.

Alternate Instructions - Especially for Linux based ISO's:
Although I've had less success with creating Windows bootable USB drives with another tool called UnetbootIn - it can create bootable USB drives without the need for entering data in a command prompt.  Personally I've found this tool to work much more reliably with Linux bootable drives.

UnetbootIn Project Homepage