Sunday, January 4, 2015

Resize userdata partition on a Rockchip device

Hello there and Happy New Year!

No, I am not a sad fellow who couldn't go to a party on a New Year's Eve. I made the party at home with my family and after that, I have thought to post the instructions to resize an Android partition for other people who, like me (previous of this procedure) couldn't manage to use a tablet (or a phone) with only few apps installed.

For a short version of this procedure, I will prepare another post with much less talk and more instructions to be followed (without introduction, warnings, explanations if you consider yourself an "expert" which doesn't need such things).

1. Introduction

I have spent an entire day (yes, the 31st of December) to find, modify and install a proper version of an Android firmware for my tablet, because the original operating system had so many flaws and hidden bugs that made the device unusable.
I don't know if it's a problem with only my device or the same apply to all devices of that model, but a simple task like opening the tablet (or wakening up from standby) could lead to 5 to 10 minutes when no other task could be performed.
Simply opening the mail app or play store and install something (typical 5 minutes of time spent by the user to perform these actions) was so slow due to inexplicable freezes and screen not responding that sometimes a half hour was spent for this actions, with many occasions of frustration.

I had received the tablet as a prize on an IT contest and the shop which held the contest delivered me the device without providing a warranty. So, I had to try and fail many times to make an usable device from this tablet by downloading firmware files from the producer or from various sites on the internet.

Today, I have succeeded, but with the help of another Android firmware (same version 4.1.1 as original) compiled for my tablet, found on a different site than the producer's.

Some producers (in fact many, majority of them) don't allow to root their devices, while others (very few) are ok if their customers root the devices and in other rare occasions, they (producers/sellers) even instruct the users how to root their devices or maybe they sell tablet and phone devices already rooted.

The reason? Rooting a device is not dangerous for the device, that procedure will not damage the device (if it's done properly).
The danger that a root procedure will imply is the fact that the device will become more vulnerable due to an improper use.
If you use an application to format/resize partition and you don't know what you are doing, that will break a device.
If you use an application to modify the frequencies a processor is running at, you will probably not doing it to lower the numbers and gain extra days in battery autonomy, more likely you will do it to raise the frequencies and make the device more faster, snappier, powerful, but instead of that, you will damage the processor and the device, because the processor will become hotter that usual and it will break temporary or even permanently.
If you use a rooting application and you don't read properly all messages displayed on the screen when you are installing various applications but instead, you just tap on "OK" or "Allow", you are making the device more vulnerable to spyware, adware, keyloggers and viruses.


So, a little warning:
WARNING! Altering device specs (partitions, frequencies, etc.) may lead to a damaged device!
Do not attempt to proceed further if you will not take the responsibility of a possible device failure.

Due to a wide configuration specs of devices sold on this planet, no procedure will be 100% successful for all devices, even for the same brand/model.
I am not responsible for any damage that will arise if you follow this procedure.

If you do continue with the modifications of the Android operating system of the device, you will make it on your own risk!
The procedure will ERASE ALL DATA ON DEVICE (should not erase the external SD Card - the one in the external slot if the device has one - but just in case, before doing anything, safely remove from settings-storage the external SD Card and extract it from the device slot), so make a Nandroid backup first in case that you want to restore the original firmware or to recover applications or settings from it.

3. What do you want? (this procedure applies to the following case)
When your device (phone or tablet) states that no more applications can be installed due to insufficient space available. This is usually very frequent when the device has only 1GB of userdata space available (userdata is the space-partition where all the applications are installed) or after you reach the limit of storage space when installing application on a 4GB or 8GB userdata space and you want more applications to install.
There are very few producers which are allowing wide ranges of userdata space storage or even make the android to resize that space dynamically depending on the total amount of space, but these producers are not Rockchip integrators, they are using own models of processors and chipsets (Samsung, Sony, LG, etc.)

You can try to move some of the applications on the SDCard, but there is another problem[s].

For Android 2+ and 3+ you should use applications that will move the apps data onto the SDCard, but for Android 4+ these applicationa are not needed anymore due to native ability of the A4+ to allow (usually, when is not forbidden by the device producer/manufacturer/seller) moving applications onto the SDCard.

Another problem is that the device is partitioned in such a way that it will be described as an internal storage and a SDCard storage (this is shown in Settings-Storage) but in fact, the internal storage and SD card storage are in fact onto the same storage chip (internal), so it's just a conventional naming.
If the device has a visible slot for SDCard, that card will be mostly shown also as SDCard, but the file manager applications (File Manager, Ghost Commander, etc) will access that storage under the name of External SD Card.

And there is another problem with the applications themselves, because they have to be written in such specific way that they are allowing moving the application onto the SDCard and the moving procedure will not brake the application itself (running an application should be always done correctly, no matter where the application reside on the storage device) because some of them cannot access anything but internal storage or if they are able to access the external storage, they should run without problems (GReader for example is a RSS application which can be installed onto the internal or external storage, but onto the external storage, the widget and the icon of the application cannot display the proper amount of news available).

Finally, the last problem that I remember for now is the fact that not all the application data is moved onto the SDCard, meaning the fact that on Android 4+, when you move an application onto the SDCard, only a portion of the app data is moved, along with a copy of the application, but the application itself will also remain on the internal storage, so basically, this is not very useful for many small applications but for few, large apps such as games (Nitro Nations, Minions, etc).

4. What do you need to perform the procedure.
a) beside the obvious device (having at least 50% charged battery and at least 8GB of internal chip storage) with the 1GB available for userdata storage (also applies on devices with 2 or even 3 GB userdata storage space if you want), you will need
b) an USB cable for your device (mini or micro USB depends of your device model)
c) firmware of the device (operating system), in a .img file format (not a .zip file) and should be the whole firmware, not only an update
d) a .zip file called "" (which is containing a lot of tools) - search for it on google
e) a .zip file called "" (needed to load the prepared/modified firmware back on the device) - (version 1.5 is for RK29 devices and other 1,6 or 1.7 version are for RK30 devices) - search for it on google

If your device doesn't have at least 8GB of internal storage, performing the operation on a 4GB device or less could increase the chances to brick (damage) the device.
If your device has less than 8GB of internal storage (let's say 4GB because it's a very common storage size) and the device doesn't have a slot for an external SDCard, I think that it will be pointless to perform the procedure because you will have only applications installed without music or movie files or books and so on, so the device will be used only for few games and internet browsing, tasks that any cheap device will perform satisfactory, without the need of large storage space and applying the resize partition procedure.

If you do insist to perform the procedure to increase the application storage space on a 4GB device (with increased risks), at least do it if your device has an external SD card slot where you can insert an 8GB or 16GB card to store your personal files (there are very few chances that a 32GB or more external SD card inserted in a cheap device will be read).
Instead, you should buy a new device (prices around 100$ or Euros are OK for cheap devices with 8 or even 16GB internal storage).

5. Doing (performing the procedure)
OK, so we have the image firmware of the device, usually called "devicename_android_versionofandroid.img".
We are talking here about Rockchip devices, which are devices with a chipset (processor) built by Rockchip manufacturer. It doesn't matter if the device is assembled by Asus or Prestigio, or Serioux, or Oma, or any other medium-low producer. Usually Samsung and LG and Lenovo are using other types of processors.

First, we have to know which type of the processor is on the device (RK29 or RK30) in order to use the correct file for disassembly and re-assembly of the device firmware image file. This can be done by searching on the internet (forums or even producer/manufacturer's site).
Any older devices with older chipsets don't matter so much now, so don't apply this procedure but instead buy a new, modern device.

Then, make a folder where you put the firmware .img file along with the "" file. Try to make a short name folder and also the path for this folder should be as shortest as possible (not "D:\Android\firmware\modification\Device\1st try\all files\build\resize partition\..." but instead "D:\Resize_Part") and without strange characters (@#$%^&*()~[]{} spaces, etc) - I think that underline "_" will work as a separation character).

Extract the "" file in the same folder, so all the files contained in the archive will be in the same folder as firmware .img file of the device (not a folder inside another folder).

Rename the image file of the firmware to "wendal.img".

Run the file "Runme.bat" (if your operating system is Windows 7 or 8 or 10, you should run this with administrative privileges - run as administrator) and follow instructions.

Press "1" on your keyboard and then press "enter" key to extract the "wendal.img" file you have in a temporary folder "Temp". During procedure, other .img files will be created, do not alter or open them in any way.

Don't close the batch file (cmd application) yet after the extraction messages. If you do close it, you can run it again but don't press "1" again, you should move to the "2" step of the file by pressing it after all the below steps are followed (locating and modifying parameter file).

Navigate to the "Temp" folder and locate the "parameter" file (does not contain an extension).

Open the "parameter" file with Notepad2 or Notepad++ (not default Notepad from Windows) - search for them on google

Locate the line named "CMDLINE". Here, we will make adjustments regarding the partitions. All names and sizes specified there will have to remain in the same order, do not switch places or arrange them alphabetically or anything.

Because we will modify the size of the "userdata" partition, all other following partitions will have to be moved (by writing the modified position from where they start) with the same amount of the size that we are putting for userdata partition.

If we want that userdata partition to have 2GB instead of 1GB, all other following partitions will have to be moved by 1GB (2GB-1GB).
If we want that userdata partition to have 3GB (this is the size I recommend) instead of 2GB or 1GB, we need to move the other following partitions by 2GB or by 1GB if we had initially a 2GB userdata partition or we have [prepared] previously another firmware with 2GB but we decided that is not enough.

So, locate on the CMDLINE the part with userdata (example: 0x00200000@0x00168000(userdata)). The first parameter (before @) is the size of the partition, the second parameter (after @) is the position from where the partition is starting. We modify the first parameter for "userdata" partition (the size) but for all the following ones, we modify the second parameter (from where to start each of them).

Pay attention that we want to resize the userdata partition (written as "userdata" in the parameter file), not the user partition (written as "user" in parameter file). The user partition (written last in the parameter file) is the partition not where the applications will be installed, but where the user is able to create/move/delete freely folders and files, where all downloads are stored, where all pictures and music files are located after we download them from internet or put with a file manager from our computer.

Modify the size from 0x00200000 (1GB) to 0x00400000 for 2GB or 0x00600000 for 3GB (again, talking about "userdata").

All following partitions will have added the difference we put on the userdata. Each 1GB is 0x00200000, so for userdata to have 2GB, we move by 1GB (0x002 becomes 0x004 - just the 3rd number after 0x is modified). For userdata to have 3GB, we move the other partitions by 2GB (0x006)

It should look like this (example):
For 2GB of userdata

For 3GB of userdata

The numbers from above may differ on your firmware image file, that's why I said that you need to modify only the 3rd character after the "0x".
If you do have other numbers there, you add "0x002" for each extra 1GB you want.

After all numbers are modified, save the parameter file and close it.

Return to "runme.bat" file which is still running or if you closed it, run the file again.

Press "2" on your keyboard and then "enter" key.
The tools are now running again to compile the modification and making a file which will be loaded after that.
Wait for tools to finish and another file will appear "wendal_new.img". Again, do not mess with other .img files that were created by the tools.

After the tools have been finished their tasks and a file "wendal_new.img" has been created, this file is the one that you will load on the device, with all modifications that you've made.
You can rename this file as you like or you can keep its name.

Extract the "" file (or the version which applies to your chipset or you can try with this 1.5 version to load a RK30 chipset) and it should create another folder.

Navigate inside this folder and run the file "RKBatchTool.exe".
For best results, this file should be run on a Windows XP computer or a 32bit Windows 7 computer because correct android drivers are a little hard to be found for 64 bit Windows 7 or above operating systems.

If the device (phone or tablet) is not powered down, do it now. If you forgot to make an Android backup (called nandroid) from recovery menu, you can do it also now and after that you should restart the device and connect to a computer and copy the files from internal or SD card storage onto that computer (because all internal storage will be erased when we load the new firmware file).
The correct procedure to access the recovery menu and to perform a nandroid backup is available on the internet for your specific device model.

Connect the USB cable to the computer, but not yet to the device.

With the device powered off, try accessing loader state of the device. The correct procedure for your specific device model can be found on internet (I think), but usually, try one of the following and while pressing the keys connect the USB cable to the device:
a) press volume + and keep it pressed while connecting the cable;
b) press volume + and keeping it pressed, simultaneously press also the power button of the device while connecting the cable
c) press volume - instead of volume + and keeping it pressed, connect the cable
d) press volume - and power button of the device and keep them pressed while connecting the USB cable
e) if the device has a physical button for Menu, press this button and keep it pressed while connecting the cable
f) press volume + and Menu buttons simultaneously and while keeping them pressed, connect the cable
g) press volume - and Menu buttons and connect USB cable

Again, the specific key combination for your device model can be found on internet if none of the above is working.
You could try these combinations with USB debugging turned ON (from Developer menu after unlocking it by pressing several times on build number from Settings-About section of your device).

When one of the above steps is working, a message pops up on the computer saying that a new device was discovered and needs drivers to be loaded. When this message is displayed, release all buttons of the device.

If your device was never connected to the computer in this manner (not the usual way to connect the device to the computer while the device is powered on), the computer will not find any drivers to be loaded. It will display an error message that no drivers could be found for your device.

Don't worry, just open the device manager and update that device drivers (with the exclamation mark or question mark - Android device), pointing to search automatically or manually to the folder where "RKBatchTool" is extracted. In that folder will be available another folder called "Driver". Point to the correct folder inside that also, for 32 or 64 bits operating system of your computer and wait for drivers to be correctly installed.

During this procedure, do not disconnect the device from computer and do not press any of its buttons.

When all above steps to connect the device to the computer are correctly followed, the "RKBatchTool" will display a green rectangle where the device was discovered and connected. Usually, this green rectangle is on number "1" because you are connecting only one device at the time in loader state.

In "RKBatchTool" application on the computer, press the browse button (those 3 dots from upper right) and navigate and select the image file you have prepared ("wendal_new.img" file or the one you have renamed).

The file properties will be read and it will wait for your instructions.
Although it's said there that the firmware file was loaded, it's not yet loaded onto the device, but it's loaded in the application.

Warning again: doing the following will erase your device. You will lose all files from internal storage of the device.
Extract the SDCard from the slot if you have an external one, just in case anything goes wrong and you have important files on that storage device.

When the green number is displayed and you have selected the new file to be loaded on the device, press "RESTORE" button from "RKBatchTool" application. This will load the new file, erasing at first all data from the device.
If you didn't select the correct loader state of the device when connecting it to the computer, the number of the device may be pink or magenta instead of green. You can press the "SWITCH" button from "RKBatchTool" to put the device in the correct loader state and after that, when the number is green press "RESTORE" button.

DO NOT PRESS "Upgrade" or "Clear" buttons.

After you have pressed the "RESTORE" button, wait for the application to finish the tasks.
First, it will format the device, then it will load the new firmware and after that it will verify the loaded firmware.
DO NOT PRESS ANY BUTTONS of the application and DO NOT DISCONNECT THE DEVICE and DO NOT RESTART OR POWER OFF THE COMPUTER (pay attention with desktop computers, use an UPS device or a laptop).
Failing to do so, it will brick (damage) your device. It may or it may not be recovered if this happens, so be careful.

After the verifying step of the firmware has finished, the device will restart. At this point, you can close the "RKBatchTool" window and disconnect the device from computer.
Depending on the firmware image file, the device should enter in the recovery menu by itself and erase (format) the partitions (also without the user interaction). If it doesn't, it may hang at boot loader screen (animation).
If this happens, or if you want to be sure that everything is prepared correctly, try to access the recovery menu of the device and perform an erase or format of the "cache" and "dalvik" partitions and after that, select "restore factory settings" from that menu also and wait to finish all tasks.
Then select "restart" or "reboot system" from recovery menu and wait for device to power up correctly.

6. Testing
If the procedure is successful, your device should power up and enter android configuration wizard where you select language, wifi, google account and so on.
If the device don't do that, try to access the recovery menu and format cache and dalvik partitions, then select to restore factory settings.
If this is unsuccessful, try to load again the firmware file by connecting the device in the loader state and performing the procedure with the "RKBatchTool" application.
If this is unsuccessful also, re-trace the steps for the whole procedure to modify the file, correct the mistakes and load the new file.
If this is also unsuccessful, connect the device in loader state and load the original firmware file of the device (the one that you used it to be decompiled, it's the file renamed "wendal.img") to restore a functioning device (all settings and files will be lost for the moment, but you will have a device on which you can install Titanium Backup application and extract apps and settings from the nandroid backup you may have performed earlier and restore the one you want.

If this procedure didn't have any success and you are not able to restore a functioning firmware file and your device cannot boot anymore, well, you had bad luck.
I did warned you several times, though.
Try to pray more at your cat goddess or spaghetti monster or whatever you worship or you can try to search more on the internet how to restore a bricked device (soft brick - meaning only the software is damaged, the hardware of the device was not affected if you didn't dropped on the floor or no hammers were applied due to frustration :D )

Ok, so let's say your device has booted correctly. If you go to the Settings menu of the device, Storage area, the amount of storage space for the application should be displayed around the value you have prepared. It will not be exactly the same, due to the fact that some internal applications of the android operating system will have reserved some space from that total amount.
So, if you have selected 3GB for applications storage size, it should be around 2.8 - 2.88GB available.

The rest of the partitions will be resized accordingly. If you have 8GB of total amount of internal storage, it should be 3GB for applications, 0.5-1GB for other internal storage space (may be hidden) and the rest of 4-4.5GB available for user to download files and whatever.

Now, start to install any applications you want from google play store or aptoide or wherever until the first 1GB space is used. If it's successful and you can install more than 1GB of applications on a 2 or 3GB userdata partition (or even more if you dare and have the internal storage space), then you will enjoy using your device.
Otherwise, the manufacturer or producer of the device put some limits in the firmware (hard coded limits) and even that the storage space is displayed larger than 1GB, the android operating system will not let you install more than that.
It will display errors after reaching the 1GB limit or it will let you install apps but when you are trying to access the app, that application will start and run with errors or even it will not start at all. Maybe some other user files will be deleted or even corrupted on the external SD Card if you access them from the application which seems to be "installed" after the hard coded storage limit.

7. Conclusion
If you are happy with the modifications, I am glad that I was able to help you.
If you bricked your device, I have warned you about this possibility and you should try to find where is the error.
If you don't want to do it, you should have not tried in the first place to perform such modifications and you should go back to your apple device. :P

Requirements: 8GB or more internal storage, 50% or more battery capacity, the correct image firmware for the device, the correct application for computer, the correct drivers and operating system.
Goal: making a cheap device to last longer on the moral (technical) obsolescence.
Satisfaction: getting a little nerdy experience and learning a useful trick for many devices.

This procedure can be applied for any Rockchip device, for any userdata limits if you have the storage space. You have to adjust accordingly the size and starting point of the partitions.

1 comment:

Mihael Bogomolec said...

work great on my PMP5780D