10 Feb 2015

how to write init.d scripts to control cpu parameters

We often use lot of apps that set a process to run on boot.Best example of this is cpu controlling apps .We set the desired frequencies to run on boot so that we dont need to set manually each time the phone restarts.We can actually set frequencies and governors and display wake options and lot more kernel features to run at boot by using init.d scripts instead of using apps.You don't need any programming languages to make a init.d scripts.So anyone with little patience can write init.d script.So lets get started.

So what are init.d scripts?

Init is short form of initialization. which means it is the first process that start during boot.Once the process start it continues till the phone shutdowns.These scripts are initiated by the kernel.
in this guide we will teach you how to create a init.d script to set cpu parameters.

How to create a init.d scripts:

how to write init.d scripts to control cpu parameters
how to write init.d scripts to control cpu parameters
  • This is basically a text file which can either be created in desktop and can be transferred to handset after writing the code.If you don't have access to desktop or laptop you can use root explorer to create text documents in android.There are lot of root explorers available in playstore and you can download any one of them.
  • You must have root access on your android device.Just in case if you have disabled root permissions enable them as creating a file in root folders definitely requires privileged permissions.
  • Install latest version of busy box from playstore without which scripts doesn't work properly.
  • You need a rom which supports init.d scripts .Although most custom rom will have support for init.d scripts,Stock kernel may not support init.d scripts unless developers adds it for you.
  • You need to have patience while testing them.If you write script with parameters which are not supposed meant for your device there are chances of bricking it.Though it only causes soft brick you have to be very careful.
  • You need to have a custom recovery installed on your device so that you can make a nandroid backup before implementing scripts.
First get cpu frequency table using any cpu controlling apps like trickster mod because you cant set what ever frequency you want to.You can set only those which the processor is designed for and the frequencies varies with each type of processor.
Init.d scripts are usually located in "/system/etc/init.d/"
Using root explorer navigate to system and then find a folder with name etc and search for init.d folder and open it.
Create a file with anyname you want in init.d folder which you have located previously
Type "#!/system/bin/sh" to start the script
Now lets first see how to set up a maximum cpu frequency on boot
type "echo 1520000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
If you observe the code it started with "echo"  what ever the code after it will be executed.
If you want to set minimum frequency then use this
"echo 300000> /sys/devices/system/cpu/cpu0/cpufrequecy/scaling_min_frequency"
in my case my cpu max and min frequencies are 1.52ghz and 300mhz.Your device max and min cpu frequencies may vary and you have to ebter those values

Setting a cpu governer:

Type echo Governer name  > /sys/devices/system/cpu/cpu0/cpufrew/scaling_governer

Turing on double tap to wake device :

Echo 1 > /sys/android_touch/dt2w
where value 1 means your are activating double tap 2 wake feature.To disable use "0" instead of 1.

Turn on fast charge :

echo 1 > /sys/devices/platform/battery/fast_charge
use "0" to disable fast charge

If know the features of the kernel then you can simply set them to run at boot just by following the simple code
Echo parameter/value > location of file what you want to target

Points to be kept in mind while writing init.d scripts:

1.First note down all the kernel features which the developer points outs in his thread
2.Explore all the root files of the phone so that you have an idea Where the requires files are located at and don't mess with the root files as any modification to root files may damage your phone
3.Location of files may vary from device to device
4.Double tap to wake and fast charge are kernel related .so your code for double tap to wake may not work if kernel doesn't support it.
5.Most important while entering the location  make sure that you are actually pointing towards a  file not folder to be clear folders are "/system" while file is "sys/devices/system/cpu/cpu0/cpufrequecy/scaling_min_frequency"
6.Have a backup of current rom to be on safer side just in case if anything goes wrong you can restore it.
By using init.d scripts you are controlling your device cpu by yourself which can also be done by using an app but you will be learning something new related to android development.So try to write a init.d script to change cpu parameters.
If you want find any mistakes in this article or want to add something to the article please let us know in the comment section below.

how to write init.d scripts to control cpu parameters Reviewed by Radha Krishna on 23:18 Rating: 5 We often use lot of apps that set a process to run on boot.Best example of this is cpu controlling apps .We set the desired frequencies to...

No comments: