:::: MENU ::::
Monthly Archives: May 2017

Kindle Fire HD 8.9 Root, Roms and Troubleshoot

Just recently, I got a Kindle Fire HD 8.9 with LTE for very cheap price from Woot.com, one of amazon.com companies. My idea is that once you own a product, you should be able to do whatever you want. Sure it does void warranty and you might not be able to get it replaced/repaired but for a very cheap tablet I decided to take that risk. This tablet has a lot of potential given the LTE connection but because of the restricted OS that amazon has, we generally can’t do much outside of Amazon ecosystem when it comes to apps.

This tablet in particular uses Android 4.0.4, one of the KitKat versions and is considered a legacy system or OS. It was really hard to find a good solution to root and change things especially when most of the links out there no longer work and the codes were not maintained well. So in this tutorial I will try my best to provide you with all the links and downloads that are available to root your device and install latest TWRP and some custom roms.

Important: I am personally not liable if something goes wrong in the process. It’s up to you to take the risk!

What you need:

Download Zip File: Click Here!

  • Kindle Fire HD 8.9 (LTE/non-LTE) with 8.5.1 stock rom
  • Micro USB cable that came with the Tablet (important!)
  • Mac or PC
  • Adb and Fastboot installed
  • Latest Kindle USB Driver
  • Install a File Explorer app (any app will do(e.g. ES File Exp but I am using File Explorer app from Amazon App Store)

File Explorer
Before we begin, make sure your settings are set to the following:

  1. Swipe Down and tap on More button
  2. Select Device
  3. Make sure the “Allow Installation of Applications from Unknown Sources” is turned On
  4. Go back and select Security
  5. Make sure the “Enable ADB” is turned On

More Settings

Achieve Root Access

 

Getting a root access on this device is relatively easy. You just have to install the latest version of KingRoot app and try the root process. If it fails, just uninstall the app, restart the tablet, install the app and try again. Now, I have heard couple of bad things about KingRoot. It shows as threat when scanning with AVG app and says that it is a kind of an adware. But I have not found any other good rooting method that actually works. There are other apps like KingRoot but all of these apps seems to come from China 🙂 So it’s up to you to decide.

  1. Head over to Kingroot.net and download the latest apk file.
  2. Copy the apk to your tablet or Use Silk Browser to download the apk
  3. Open File Explorer and go to Downloads folder
  4. Install the apk
  5. Open the app and start the root process, make sure you are connected to internet and if it fails you try again.
  6. Once rooted, you should see as follows.
  7. Make sure everything is green and says Root Successfully and you Disable the Silent Install Option.
  8. Go to Settings inside KingRoot and see if you have Root Authorization Enabled!

Kingroot v5

Install Kingroot App

Disable KingRoot's Root Protection

Make Sure the Root Authorization is Enabled
Once the device is rooted, you should be able to verify in the settings or you can even download Root Checker app from Amazon App Store.
RootChecker


There you go! You have successfully rooted Amazon Kindle Fire HD 8.9 (LTE). Now, off to TWRP and Custom ROMs. 🙂

Backup What you have:

This step is very important! These backup files will be needed if anything goes wrong.

adb shell su -c "dd if=/dev/block/mmcblk0boot0 of=/sdcard/boot0block.img"
adb shell su -c "dd if=/dev/block/platform/omap/omap_hsmmc.1/by-name/boot of=/sdcard/stock-boot.img"
adb shell su -c "dd if=/dev/block/platform/omap/omap_hsmmc.1/by-name/recovery of=/sdcard/stock-recovery.img"
adb shell su -c "dd if=/dev/block/platform/omap/omap_hsmmc.1/by-name/system of=/sdcard/stock-system.img"

mkdir C:\KFHD89

adb pull /sdcard/boot0block.img/ [C:\KFHD89]
adb pull /sdcard/stock-boot.img/ [C:\KFHD89]
adb pull /sdcard/stock-recovery.img/ [C:\KFHD89]
adb pull /sdcard/stock-system.img/ [C:\KFHD89]

Make sure you have adb running. Just run this command in your cmd or terminal as an administrator. Your backup files should be available to you in C: drive under KFHD89 folder.

Installing Unlocked Bootloader, TWRP and Custom ROM

Since this tablet uses a legacy OS it was really hard to find the proper flashing tool to flash Recovery partition. The only apk that seems to work is called FireFlash. Also you do need the TWRP image to flash into the recovery partition.

Important: Amazon OS seems to delete the Recovery partition every time you reboot the device (or keep it in stand-by mode for a long period of time)

What you need:

  • FireFlash 1.1 APK
  • Unlocked Bootloader image file
  • TWRP image file

Go ahead and follow these steps:

  1. Install the FireFlash APK and open it
  2. Make sure you select (as shown in the image below)
    1. Flash kfh8-u-boot-prod-8.1.4.bin (check the box) it will have some red text below saying your tablet doesn’t have 8.1.4. If not, it means you already have 8.1.4 bin and you will not be able to check the check box which is all right.
    2. Select unlocked 8.4.6 bootloader image kfhd8-freedom-boot-8.4.6.img for boot partition
    3. Make sure you check Apply stack override which uses Hashcode’s bootloader
    4. Select TWRP image file kfhd8-twrp-3.0.2-2-recovery.img for Recovery Partition
    5. Make sure you disable recovery auto update
    6. Tap on Flash, Install Script
    7. It should now show a popup saying Flashing and complete the flash process
    8.  You will see a report window when done. Go ahead and hit ok.
    9. Now immediately, tap on the Reboot into recovery button. This is important because Amazon OS tends to wipe the recovery partition from time-to-time.
    10. Your tablet will restart and you will see Kindle Fire logo with the text Fire in red color. You should now boot into Recovery Mode with TWRP.
    11. If for some reason you restart or decide to go to recovery mode later, just flash the recovery partition with recovery auto update disabled using FireFlash and reboot into recovery.
    12. To know that your bootloader is unlocked, whenever you restart your tablet you’ll see Kindle Fire logo with Fire text in blue color.

Install Custom ROM

In order to install custom ROMs, make sure you have the correct rom that supports your device. It is usually in a .zip format. Once you choose the ROM that you want, just boot into recovery and in TWRP select the zip file and flash it. Make sure to wipe data, cache and davlik to restore to factory settings.

Now I heard that ROM from LiquidSmooth (they closed a while ago) is the best ROM out there for Kindle Fire HD 8.9 (both LTE and non-LTE) but I couldn’t find it anywhere. It should have been available here as LS-KK-MileStone-3.2-jem.zip for non-LTE device and LS-KK-MileStone-3.2-jemlte.zip for LTE device, but the links don’t work. So if anyone come across this ROM please do let me know. I’ll host it somewhere so that others can download. For now, I prefer to stick to stock OS as that is by far the best os for this device but will have a root so that I can install launchers that need root access.

Troubleshoot using Fastboot Command

If anything fails or you are stuck in bootloop, there is still a chance that you can fully recover your device. Make sure you have fastboot running in pc/mac and you have a backup of all your partitions as mentioned above. Now to go to a stock firmware all you need to do is shut the tablet down, open up command prompt(cmd) in Windows or terminal in Mac and do the following:

Fastboot Flash Boot Partition

fastboot -i 0x1949 flash boot stock-boot.img

Type this and hit enter it should say <waiting for device> and then go ahead and plug your device into your pc/mac. This should flash your boot image.

Fastboot Flash Recovery Partition

fastboot -i 0x1949 flash recovery stock-recovery.img

Type this and hit enter. (Now if it doesn’t do anything and is stuck. Take the USB cable out and plug it in again. Type the code above and hit enter. Do the same for the following codes.)

Fastboot Flash System Partition

fastboot -i 0x1949 flash system stock-system.img

Type this and hit enter. It will take a while. Once done type the following.

Fastboot Reboot

fastboot -i 0x1949 reboot

Your device should boot up into stock firmware!


Array Splitting using PHP’s and Java’s in-built Array Funtion

Today, I am going to talk about something simple and useful in programming. For people who are professional programmers this might seem relatively easy but for someone who is trying to learn PHP or Java having a knowlege of how arrays work might be really useful. Especially when you have a large set of data and you need to display it in multiple columns.

So let’s talk about how to use PHP’s and Java’s inbuilt array funtion to slice a large array into smaller parts. For this tutorial, I am assuming you have some knowledge of how PHP and Java works. If not, there are hundreds of websites and books available to get basic understanding.

Scenario: I was given a task to list all the 52 US states in a page so that only the ones that are flagged as active in a table inside database is shown on the page. I had to show this in 3 columns.

#State NameActive Flag
1Alabama1
2Alaska1
3Arizona0
4Arkansas1
51

Result: The result should look something like this.

Alabama
Alaska
Arkansas
California
Kentucky
Louisiana
Maine
Maryland
North Dakota
Ohio
Oklahoma
Oregon

Now, the question might seem relatively easy. And we don’t necessarily need PHP or JAVA to solve this. We could also use something on client side like JavaScript. But, I’ll show how it’s done on the server side.

Query Database for Results:

We can get the list of active states from the database as follows:

SELECT * FROM states where active_flag = 1 order by state_id asc;

For PHP you get the data as follows:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM states WHERE active_flag = 1 ORDER BY state_id ASC;";
$result = $conn->query($sql);
$states = array();
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $states[] = $row;
    }
} else {
    echo "No Results Found";
}

$conn->close();
?>

The above code connects to the database and quries the result and puts it inside the $states[] array.

In Java, you can do the same utilizing Java’s inbuilt database connection library:

Connection conn = null;
CallableStatement stmt = null;
ResultSet result = null;
ArrayList<String> states = new ArrayList<String>();
		
try {
        conn = getConnection();
	stmt = conn.prepareCall("SELECT * FROM states WHERE active_flag = 1 ORDER BY state_id ASC;");

	result = stmt.executeQuery();

	while (result.next()) {

		String state_name = result.getString("state_name");
		states.add(state_name);
	}

} catch (SQLException e) {
	LOG.log(Level.SEVERE, e.getMessage(), e);

} finally {
	result.close();
	stmt.close();
	conn.close();
}

The above code puts the result inside states array. Here, getConnection() actually connects to the database. You can google and read about how to connect to database in Java to understand it much better. But, the idea is simple. We utilize Java’s SQL library to automatically connect to the database. You just define all the required connection settings in a properties file (below is just an example).

protected static Connection getConnection() throws SQLException {
     return DriverManager.getConnection("**** Database Name ****");
}

Now that we have our results in an array. Let’s see how we can split the array into three sub arrays.

Array Count or Length

Before we do the actual splitting, we need to know the count of the total states in the array so that we can split the array evenly across the three arrays.

To do this, in PHP we use the inbuilt function count($array).

$states_count=count($states);

In Java we simply we utilize array.length property of an array.

int states_count = states.length;

Divisible by 3

Now that we know the array length, we need to know how to evenly distribute the states into three sets of list. The logic here is to make the length (or count) of the list divisible by 3 so that we can evenly distribute the states among three sets.

The concept of modulus is very helpful here. The modulo operation (or simply modulus) finds the remainder after division of one number by another. To check if a number is divisible by 3 or not we do the following:

  • First, we check to see if the number is even or odd.
  • If even, we add +1 and do the modulo operand on the length. This is done as number % divisor. If this outputs a number, besides 0, then we know the number is not divisible by divisor. Here we know length or count is even as $states_count % 2 gives us 0. If so, we loop and keep on adding 1 ($states_count++;) until we get a number that is divisible by 3 (loop until $states_count % 3 is not 0).
  • If odd, we test and see if this odd number is divisible by 3 ($states_count % 3 == 0). If the number is not divisible by 3 we keep adding 1 until we get a number that is divisible by 3.

In PHP

if($states_count % 2 == 0){
   do {
      $states_count++;
   }while($states_count % 3 != 0);
}else{
   if($states_count % 3 == 0){
      //do nothing
   }else{
      do {
	 $states_count++;
      }while($states_count % 3 != 0);
   }
}

In Java

if(states_count % 2 == 0){
   do {
      states_count++;
   }while(states_count % 3 != 0);
}else{
   if(states_count % 3 == 0){
      //do nothing
   }else{
      do {
	 states_count++;
      }while(states_count % 3 != 0);
   }
}

Split Array in 3

Now that we have an array length that is divisible by 3, we can do the following to split the array.

In PHP we will use array_slice() method to slice into three parts. The syntax for array_slice() is

array_slice(array, starting index, length);

$states_first = array_slice($states, 0, $states_count/3);
$states_second = array_slice($states, $states_count/3, $states_count/3);
$states_third = array_slice($states, ($states_count/3)*2, $states_count/3);

In Java we will use Arrays.copyOfRange method to make a copy of or split an array. The syntax for copyOfRange() is

int[] newArray = Arrays.copyOfRange(array, starting index, ending index);

ArrayList<String> states_first = new ArrayList<String>();
ArrayList<String> states_second = new ArrayList<String>();
ArrayList<String> states_third = new ArrayList<String>();

states_first = Arrays.copyOfRange(states, 0, states_count/3);
states_second = Arrays.copyOfRange(states, states_count/3, (states_count/3)*2);
states_third = Arrays.copyOfRange(states, (states_count/3)*2, states_count);

And there you go! That’s how you split an array. You can split into any number using the same concept. Let me know what you think or if you have an even better way.