[Help][Bash][build.prop]Developers only! - Android Software/Hacking General [Developers Only]

Hello everyone, i just wanted help with my Bash script!
I usually flash nightlies and when ever i flash them, i lose my tweaks
So i decided creating a bash script for myself,
Here's how it is....
Code:
#!/system/bin/sh
## personal file
tweaks=/sdcard/tweaks
build=/system/build.prop
## loop trough $tweak
sed -r '/(#.*|^ *$)/d;/.*=.*/!d;$a' $tweak | while read line
do
## get entry from $tweak
entry=$(echo $line | sed "s/=.*//")
## if variable already present in $build
if cat $build | grep -q $entry
then
## override value in $build if different
if ! cat $build | grep -q $(cat $tweak | grep $entry)
then
sed -i "s/^${entry}=.*$/${line}/g" $build
fi
else
echo $line >> $build
fi
done
Everything works but i wanted to keep this process running (For testing purposes),
I mean after my tweaks/values get replaced, i want the same thing to happen with other values!
Eg:- /sdcard/tweak= Contains line= ro.build.model=Nexus 5,
Same file contains ro.build.model=Xperia Z,
now what i want my script to do is, First replace my phone model with Nexus 5 and after some time change it with Xperia Z without starting/stopping any other script!
But i aint too good at this!
So i require a helping hand!
I hope you get my point.

DeveDroid said:
Hello everyone, i just wanted help with my Bash script!
I usually flash nightlies and when ever i flash them, i lose my tweaks
So i decided creating a bash script for myself,
Here's how it is....
Code:
#!/system/bin/sh
## personal file
tweaks=/sdcard/tweaks
build=/system/build.prop
## loop trough $tweak
sed -r '/(#.*|^ *$)/d;/.*=.*/!d;$a' $tweak | while read line
do
## get entry from $tweak
entry=$(echo $line | sed "s/=.*//")
## if variable already present in $build
if cat $build | grep -q $entry
then
## override value in $build if different
if ! cat $build | grep -q $(cat $tweak | grep $entry)
then
sed -i "s/^${entry}=.*$/${line}/g" $build
fi
else
echo $line >> $build
fi
done
Everything works but i wanted to keep this process running (For testing purposes),
I mean after my tweaks/values get replaced, i want the same thing to happen with other values!
Eg:- /sdcard/tweak= Contains line= ro.build.model=Nexus 5,
Same file contains ro.build.model=Xperia Z,
now what i want my script to do is, First replace my phone model with Nexus 5 and after some time change it with Xperia Z without starting/stopping any other script!
But i aint too good at this!
So i require a helping hand!
I hope you get my point.
Click to expand...
Click to collapse
i caught a typo:
tweaks -> tweak
and,
First replace my phone model with Nexus 5 and after some time change it with Xperia Z without starting/stopping any other script!
why dont you try something called 'sleep' command? its very very convenient
for example:
Code:
sleep 60 #will make the script suspend for a minute

Tweakprop can handle build.proo tweaks. It grap the new build.prob against the tweaks file you created and add this to the new one. This is flasable under cwm/twrp and works quite good.

Related

[DEV][SCRIPT] Enhanced init.d support

Okay, I worked a bit on something to add a little more options to init.d scripts for my ROM's. I came up with the below solution and thought I should share it with whomever would like a bit more options in their own ROM's. This is a first draft so some of things can properly be done in other ways, but it works and it does add a lot more options when building startup scripts while it is compatible with regular init.d scripts as well. But fell free to pitch in with ideas if you like.
Note that this thread is directed to ROM cookers, but can be used by anyone that knows how to edit ramdisk's.
So there are several problems with the regular init.d methods. First of all there are two different ways of executing the scripts and it differs from ROM to ROM which method has been implemented. We have the "exec /system/bin/sysinit" which will execute all of the scripts before continuing with the normal boot and we have the service sysinit which will execute all scripts while the normal boot is running. Both are useful for different things but no ROM has both.
Also init.d will just start executing the scripts before/during the normal boot, depended on the method, but what if we need it to execute something at a specific time during boot. Before folder structures and such are created in /data? Or when the phone has completely booted into the GUI. Or before the phone is turned off and so on.
This method will implement different states where different parts of a script can be executed depended on where in the boot process we are. All it requires is a more extended sysinit file and a couple of extra lines in the init.rc file.
File: /init.rc
Code:
on early-init
##
# Whatever goes here
##
on init
##
# Whatever goes here
##
on fs
##
# Mount /system
##
# Make sure that we have the synlinks we need to use sysinit
symlink /system/bin/sysinit /system/bin/sysinit.onstart
symlink /system/bin/sysinit /system/bin/sysinit.onfs
symlink /system/bin/sysinit /system/bin/sysinit.onpostfs
symlink /system/bin/sysinit /system/bin/sysinit.onpostfsdata
symlink /system/bin/sysinit /system/bin/sysinit.onboot
symlink /system/bin/sysinit /system/bin/sysinit.onsysinit
symlink /system/bin/sysinit /system/bin/sysinit.onfinalize
symlink /system/bin/sysinit /system/bin/sysinit.oncomplete
symlink /system/bin/sysinit /system/bin/sysinit.onshutdown
exec /system/bin/sysinit.onstart
##
# Mount the rest of the partitions and remount /system without write permissions
##
exec /system/bin/sysinit.onfs
on post-fs
##
# Whatever goes here
##
exec /system/bin/sysinit.onpostfs
on post-fs-data
##
# Whatever goes here
##
exec /system/bin/sysinit.onpostfsdata
##
# If you want to include an additional *.rc file, do it here at the end of post-fs-data
##
on boot
##
# Whatever goes here
##
exec /system/bin/sysinit.onboot
start sysinit
##
# Start any other services
##
on property:init.svc.bootanim=stopped
start syscomplete
on property:sys.boot_completed=1
exec /system/bin/sysinit.onfinalize
on property:sys.shutdown.requested=1
exec /system/bin/sysinit.onshutdown
service sysinit /system/bin/sysinit.onsysinit
disabled
oneshot
service syscomplete /system/bin/sysinit.oncomplete
disabled
oneshot
##
# The rest of the file
##
File: /system/bin/sysinit
Code:
#!/system/bin/sh
export PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin
if [ -d /system/etc/init.d ]; then
case $(basename $0) in
"sysinit") INIT_STATE="$1" ;;
*) INIT_STATE="`basename $0 | cut -d '.' -f2`" ;;
esac
while :
do
if [ ! -f /sysinit.stage.prop ]; then
mount -o remount,rw /
touch /sysinit.stages.prop
mount -o remount,ro /
fi
if ( [ "$INIT_STATE" != "onfinalize" ] && [ "$INIT_STATE" != "oncomplete" ] ) || ( [ "$INIT_STATE" = "onfinalize" ] && [ ! -z "`grep onpostsysinit /sysinit.stages.prop`" ] ) || ( [ "$INIT_STATE" = "oncomplete" ] && [ ! -z "`grep onfinalize /sysinit.stages.prop`" ] ); then
if [ "$INIT_STATE" = "onsysinit" ]; then
RUN_STATES="onsysinit onpostsysinit"; sleep 1
elif [ "$INIT_STATE" = "oncomplete" ]; then
RUN_STATES="onservice oncomplete"
else
RUN_STATES="$INIT_STATE"
fi
for x in $RUN_STATES; do
log -p v -t sysinit "Switching to state '$x'..."
case $x in
# Make it compatible with old init scripts
onboot|"") FILES="`find /system/etc/init.d -type f | sort`" ;;
*) FILES="`find /system/etc/init.d -type f -iname '*.rc' | sort`" ;;
esac
for i in $FILES; do
if [ ! -d $i ] && [ -x $i ]; then
log -p v -t sysinit "Executing $i..."
if [ "$x" = "onservice" ]; then
logwrapper $i $x > /dev/null &
else
logwrapper $i $x
fi
else
log -p w -t sysinit "Skipping $i. Not an executable!"
fi
done
mount -o remount,rw /
echo $x >> /sysinit.stages.prop
mount -o remount,ro /
done
break
fi
sleep 1
done
fi
To use this you need to end the names of your init script with .rc like "55<name>.rc" instead of just "55<name>". This is to keep it compatible with regular init.d scripts.
This will allow you to build init.d scripts like this
Code:
#!/system/bin/sh
case $1 in
onstart)
# Do something right after the system partition has been mounted RW (No other partitions at this time)
;;
onfs)
# Do something right after the rest of partitions has been mounted and system has been remounted RO, before any of them are used or changed in any way.
;;
onpostfs)
# This is almost the same as onfs, only minor changes has normally been made here
;;
onpostfsdata)
# Do something after the /data partition has been rebuild with folders, permission, ownership and so on
;;
onboot)
# Do something right before Android starts booting and it's services are triggered
;;
onsysinit)
# Do something while Android is booting. This will NOT stall the boot process but run along side it
;;
onpostsysinit)
# Do something as soon as onsysinit has finished
;;
onfinalize)
# Do something when the system is almost booted, this also includes the sysinit parts above
;;
onservice)
# Do some constant work in the background (Service/Daemon)
;;
oncomplete)
# Do something when the phone is fully booted and the boot animation is gone
;;
onshutdown)
# Do something before the phone is turned off or rebooted
;;
esac
EDIT 1
Added 'onfinalize' which is actually the old oncomplete. The new oncomplete runs as a service like onsysinit and onpostsysinit to ensure that you are able to use things like "sleep" without stalling the system.
Rewrote sysinit, much cleaner now
EDIT 2
Added 'onservice' which can be used to run a constant task in the background after the phone has booted
Great concept and great work
I can see how this would be very handy!
Sent from my PG86100 using Tapatalk 2
looks intresting..Hmmmmm
Genius man. Awesome stuff.
Sent from my SCH-I500 using Tapatalk 2
Awesome great work. The last line say do comething before the phone is turned off or rebooted. is it suppose to say something.
Sent from my HTC Desire CDMA using Tapatalk 2
jayallen1980 said:
Awesome great work. The last line say do comething before the phone is turned off or rebooted. is it suppose to say something.
Sent from my HTC Desire CDMA using Tapatalk 2
Click to expand...
Click to collapse
'something' is correct, have been changed
Some examples would be good
Can you please? (Example of Executing Juwe's RAM script will be nice in all cases)
What if I want to keep init.d folder empty and integrate my scripts inside boot.img? and then execute them inside it?
varun.chitre15 said:
Some examples would be good
Can you please? (Example of Executing Juwe's RAM script will be nice in all cases)
What if I want to keep init.d folder empty and integrate my scripts inside boot.img? and then execute them inside it?
Click to expand...
Click to collapse
Why would you integrate scripts into the boot.img? The point of init.d is to be able to add things to boot without changing the boot.img. If you want to execute things from within the boot.img, then just place your scripts in it (sbin would be a good place) and execute it the same way my example executes /system/bin/sysinit.
And as for examples, it's easy. Just place your code in that section (onboot, onfs etc) where you want the code to be executed. The onboot is the default in process in most ROM's and also where regular init.d scripts is executed in this example.
dk_zero-cool said:
Why would you integrate scripts into the boot.img? The point of init.d is to be able to add things to boot without changing the boot.img. If you want to execute things from within the boot.img, then just place your scripts in it (sbin would be a good place) and execute it the same way my example executes /system/bin/sysinit.
And as for examples, it's easy. Just place your code in that section (onboot, onfs etc) where you want the code to be executed. The onboot is the default in process in most ROM's and also where regular init.d scripts is executed in this example.
Click to expand...
Click to collapse
because the point of this is to start scripts when you want.. there is a few scripts I have that can't be ran until os is loaded, there for making this a great setup for me.
init.d & boot.img runs everything at boot... not after boot.
eugene373 said:
because the point of this is to start scripts when you want.. there is a few scripts I have that can't be ran until os is loaded, there for making this a great setup for me.
init.d & boot.img runs everything at boot... not after boot.
Click to expand...
Click to collapse
The 'oncomplete' runs everything when the system is fully loaded, that's the point of this init.d system, to be able to run scripts in different ways during different stages.
dk_zero-cool said:
The 'oncomplete' runs everything when the system is fully loaded, that's the point of this init.d system, to be able to run scripts in different ways during different stages.
Click to expand...
Click to collapse
yeah I got it..... I've been having one hell of a time starting script until I cam across this...
If it starts like a normal init.d file it hangs the boot process... with this edit I can trigger it to run on bootcomplete with out hanging the service
sorry, I just noticed I quoted you and not the other guy
eugene373 said:
yeah I got it..... I've been having one hell of a time starting script until I cam across this...
If it starts like a normal init.d file it hangs the boot process... with this edit I can trigger it to run on bootcomplete with out hanging the service
sorry, I just noticed I quoted you and not the other guy
Click to expand...
Click to collapse
Yes oncomplete, oninit and onservice will not stall the process, oninit will however stall onfinalize, oncomplete and onservice. onservice will run the script in a seperate process in the background, so that will not even stall the rest of the init.d scripts while executing, making that great for scripts that should keep running, or where you don't know how long they should run.
dk_zero-cool said:
Yes oncomplete, oninit and onservice will not stall the process, oninit will however stall onfinalize, oncomplete and onservice. onservice will run the script in a seperate process in the background, so that will not even stall the rest of the init.d scripts while executing, making that great for scripts that should keep running, or where you don't know how long they should run.
Click to expand...
Click to collapse
Adding this into all my boot.img from now on & I'll be sure to link this thread...
I think this should be the new standard for all Devs, this method is not only a great idea!
But for the End User, there's so much more control over what can / should be done on starting process...
I personally want to thank you for this, as this truely is one of the better methods I've ever seen!!
~Eugene
dk_zero-cool, I'd like to ask you, why you use soft-links and not parameters?
It will remove all
Code:
symlink /system/bin/sysinit /system/bin/sysinit.*
from init.rc and you will not need to use case in sysinit.
Because this whole construction:
Code:
case $(basename $0) in
"sysinit") INIT_STATE="$1" ;;
*) INIT_STATE="`basename $0 | cut -d '.' -f2`" ;;
esac
seems to me like overload.
hashnon said:
dk_zero-cool, I'd like to ask you, why you use soft-links and not parameters?
It will remove all
Code:
symlink /system/bin/sysinit /system/bin/sysinit.*
from init.rc and you will not need to use case in sysinit.
Because this whole construction:
Code:
case $(basename $0) in
"sysinit") INIT_STATE="$1" ;;
*) INIT_STATE="`basename $0 | cut -d '.' -f2`" ;;
esac
seems to me like overload.
Click to expand...
Click to collapse
Because I have had bad experience using arguments along with the exec command, so I try to avoid that. Mostly because I can't remember the issues anymore.
As for overload, this is to small to be noticed, specially when this is only executed a couple of times during startup. If this was to be executed every couple of minute during the phone on state, then sure. But when the phone has booted, sysinit is no longer used.
Pretty neat design. I've found that having to deal with some of the escaping of an exec can be a nightmare too.
In the kernel ramdisk of my Xperia ray, there are two kinds of inits, init.rc and init.semc.rc.
The "on fs" exists in init.semc.rc (where i can see the commands to mount the partitions). In init.rc there's no "on fs" between "on early-fs" and "on post-fs".
So i've put the "on fs"-part in init.semc.rc and the rest of your fabulous work into init.rc. When i look after booting into the /system/bin/ directory i can see all the "sysinit.on........." symlinks. Is that proof that i did everything right so far? Haven't tried any script yet to be honest.
Kaskade said:
In the kernel ramdisk of my Xperia ray, there are two kinds of inits, init.rc and init.semc.rc.
The "on fs" exists in init.semc.rc (where i can see the commands to mount the partitions). In init.rc there's no "on fs" between "on early-fs" and "on post-fs".
So i've put the "on fs"-part in init.semc.rc and the rest of your fabulous work into init.rc. When i look after booting into the /system/bin/ directory i can see all the "sysinit.on........." symlinks. Is that proof that i did everything right so far? Haven't tried any script yet to be honest.
Click to expand...
Click to collapse
Yes some phones have extra init files for onfs. Mostly if they use different file system types. What you did is correct in this case.
You can check the file /sysinit.stages.prop to see if all stages was executed. If one stage is missing from that file, it was not executed.
Deleted.
hi is ths still working in android marshmallow? cant find sysinit file in system/bin/sysinit

[SCRIPT] Run init.d scripts once every N days [ZipAlign/SQLite3/others]

There are many ROMs that include the ZipAlign or SQLite3 vacuum on boot, but these command are not really needed to run on EVERY boot, once every few days can be enough, so I came out with this script.
To run it, you need to have busybox with the stat applet (should be there always), which gives information about a file, including last modification date.
This is done is by checking the last modification date on a file, which is touched or changed only when the main script is executed.
Currently I modified the ZipAlign and SQLite vacuum in my own rom to use this technique, and they seem to work fine. The monitored file is the log of the operation done, which is stored in the /data/ directory
ZipAlign on Boot:
Code:
#!/system/bin/sh
# Automatic ZipAlign by Wes Garner
# ZipAlign files in /data that have not been previously ZipAligned (using md5sum)
# Thanks to oknowton for the changes
# Changelog:
# 1.0 (11/30/09) Original
# 1.1 (12/01/09) Switched to zipalign -c 4 to check the apk instead of MD5 (oknowton)
# 1.2 (06/01/13) Run the main script only once every N days (default 7 days, 1 week) (mcbyte_it)
[COLOR="DarkRed"]LOG_FILE=/data/zipalign.log
#Interval between ZipAlign runs, in seconds, 604800=1 week
RUN_EVERY=604800
# Get the last modify date of the Log file, if the file does not exist, set value to 0
if [ -e $LOG_FILE ]; then
LASTRUN=`stat -t $LOG_FILE | awk '{print $14}'`
else
LASTRUN=0
fi;
# Get current date in epoch format
CURRDATE=`date +%s`
# Check the interval
INTERVAL=$(expr $CURRDATE - $LASTRUN)
# If interval is more than the set one, then run the main script
if [ $INTERVAL -gt $RUN_EVERY ];
then[/COLOR]
[COLOR="Green"] if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
echo "Starting Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for apk in /data/app/*.apk ; do
zipalign -c 4 $apk;
ZIPCHECK=$?;
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligning $(basename $apk) | tee -a $LOG_FILE;
zipalign -f 4 $apk /cache/$(basename $apk);
if [ -e /cache/$(basename $apk) ]; then
cp -f -p /cache/$(basename $apk) $apk | tee -a $LOG_FILE;
rm /cache/$(basename $apk);
else
echo ZipAligning $(basename $apk) Failed | tee -a $LOG_FILE;
fi;
else
echo ZipAlign already completed on $apk | tee -a $LOG_FILE;
fi;
done;
echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;[/color]
[COLOR="DarkRed"]fi[/COLOR]
SQLite3 vacuum:
Code:
#!/system/bin/sh
# ========================================
# init.d script for McByte jkSGS3
# ========================================
# SQLite database vaccum
# Frequent inserts, updates, and deletes can cause the database file to become fragmented - where data for a single table or index is scattered around the database file.
# Running VACUUM ensures that each table and index is largely stored contiguously within the database file.
# In some cases, VACUUM may also reduce the number of partially filled pages in the database, reducing the size of the database file further.
# sqlite3 binary in /system/xbin is required!
# Changelog
# v1.0 - (??/??/????) - original version
# v1.1 - (06/01/2013) - run only every X seconds, default = 1 week (mcbyte_it)
#
[COLOR="DarkRed"]# Log file location
LOG_FILE=/data/sqlite.log
#Interval between SQLite3 runs, in seconds, 604800=1 week
RUN_EVERY=604800
# Get the last modify date of the Log file, if the file does not exist, set value to 0
if [ -e $LOG_FILE ]; then
LASTRUN=`stat -t $LOG_FILE | awk '{print $14}'`
else
LASTRUN=0
fi;
# Get current date in epoch format
CURRDATE=`date +%s`
# Check the interval
INTERVAL=$(expr $CURRDATE - $LASTRUN)
# If interval is more than the set one, then run the main script
if [ $INTERVAL -gt $RUN_EVERY ];
then[/COLOR]
[COLOR="Green"]if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
echo "SQLite database VACUUM and REINDEX started at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for i in `busybox find /d* -iname "*.db"`; do
/system/xbin/sqlite3 $i 'VACUUM;';
resVac=$?
if [ $resVac == 0 ]; then
resVac="SUCCESS";
else
resVac="ERRCODE-$resVac";
fi;
/system/xbin/sqlite3 $i 'REINDEX;';
resIndex=$?
if [ $resIndex == 0 ]; then
resIndex="SUCCESS";
else
resIndex="ERRCODE-$resIndex";
fi;
echo "Database $i: VACUUM=$resVac REINDEX=$resIndex" | tee -a $LOG_FILE;
done
echo "SQLite database VACUUM and REINDEX finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;[/COLOR]
[COLOR="DarkRed"]fi;[/COLOR]
This looks like a great idea :good: is it possible to easily change the intended interval at which yo want the scripts to run though?
HTCDreamOn said:
This looks like a great idea :good: is it possible to easily change the intended interval at which yo want the scripts to run though?
Click to expand...
Click to collapse
Sure, check the examples I posted, they are well commented. Just change the value of the "RUN_EVERY".
I'll take a look
mcbyte_it said:
Sure, check the examples I posted, they are well commented. Just change the value of the "RUN_EVERY".
Click to expand...
Click to collapse
Awesome, I'll give them a go!
how can i modify this script to zimpalign /system/app too?
UnitedOceanic said:
how can i modify this script to zimpalign /system/app too?
Click to expand...
Click to collapse
There is no much sense of zipaligning system apps every x days, once they are zipaligned (when making the ROM zip), they remain zipaligned. some apks might need zip aligning if they get moved/installed as system apps after rom install.
Not to mention the stability, I don't know the exact boot mechanism of android, if you start zip aligning system apps during the init.d, it might cause instability to some system apps.
But if you mount the /system partition as read/write, do the zipaligning loop, then remount it as read-only, it should be possible.
still, I don't recommend doing so....
i pushed many apps from /data/app to /system/app.
I deleted the libs from the apks and copied them to /system/libs to saved space. however I forgot to zipalign the apks after removing the libs. I used the zipalign script from the rom toolbox app unfortunately it didn't work as expected. it just deleted the apps that should have been zipaligned.
I don't really want to zipalign /system at every boot. just once for the modified apks.
mcbyte_it said:
There are many ROMs that include the ZipAlign or SQLite3 vacuum on boot, but these command are not really needed to run on EVERY boot, once every few days can be enough, so I came out with this script.
To run it, you need to have busybox with the stat applet (should be there always), which gives information about a file, including last modification date.
This is done is by checking the last modification date on a file, which is touched or changed only when the main script is executed.
Currently I modified the ZipAlign and SQLite vacuum in my own rom to use this technique, and they seem to work fine. The monitored file is the log of the operation done, which is stored in the /data/ directory
ZipAlign on Boot:
Code:
#!/system/bin/sh
# Automatic ZipAlign by Wes Garner
# ZipAlign files in /data that have not been previously ZipAligned (using md5sum)
# Thanks to oknowton for the changes
# Changelog:
# 1.0 (11/30/09) Original
# 1.1 (12/01/09) Switched to zipalign -c 4 to check the apk instead of MD5 (oknowton)
# 1.2 (06/01/13) Run the main script only once every N days (default 7 days, 1 week) (mcbyte_it)
[COLOR="DarkRed"]LOG_FILE=/data/zipalign.log
#Interval between ZipAlign runs, in seconds, 604800=1 week
RUN_EVERY=604800
# Get the last modify date of the Log file, if the file does not exist, set value to 0
if [ -e $LOG_FILE ]; then
LASTRUN=`stat -t $LOG_FILE | awk '{print $14}'`
else
LASTRUN=0
fi;
# Get current date in epoch format
CURRDATE=`date +%s`
# Check the interval
INTERVAL=$(expr $CURRDATE - $LASTRUN)
# If interval is more than the set one, then run the main script
if [ $INTERVAL -gt $RUN_EVERY ];
then[/COLOR]
[COLOR="Green"] if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
echo "Starting Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for apk in /data/app/*.apk ; do
zipalign -c 4 $apk;
ZIPCHECK=$?;
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligning $(basename $apk) | tee -a $LOG_FILE;
zipalign -f 4 $apk /cache/$(basename $apk);
if [ -e /cache/$(basename $apk) ]; then
cp -f -p /cache/$(basename $apk) $apk | tee -a $LOG_FILE;
rm /cache/$(basename $apk);
else
echo ZipAligning $(basename $apk) Failed | tee -a $LOG_FILE;
fi;
else
echo ZipAlign already completed on $apk | tee -a $LOG_FILE;
fi;
done;
echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;[/color]
[COLOR="DarkRed"]fi[/COLOR]
SQLite3 vacuum:
Code:
#!/system/bin/sh
# ========================================
# init.d script for McByte jkSGS3
# ========================================
# SQLite database vaccum
# Frequent inserts, updates, and deletes can cause the database file to become fragmented - where data for a single table or index is scattered around the database file.
# Running VACUUM ensures that each table and index is largely stored contiguously within the database file.
# In some cases, VACUUM may also reduce the number of partially filled pages in the database, reducing the size of the database file further.
# sqlite3 binary in /system/xbin is required!
# Changelog
# v1.0 - (??/??/????) - original version
# v1.1 - (06/01/2013) - run only every X seconds, default = 1 week (mcbyte_it)
#
[COLOR="DarkRed"]# Log file location
LOG_FILE=/data/sqlite.log
#Interval between SQLite3 runs, in seconds, 604800=1 week
RUN_EVERY=604800
# Get the last modify date of the Log file, if the file does not exist, set value to 0
if [ -e $LOG_FILE ]; then
LASTRUN=`stat -t $LOG_FILE | awk '{print $14}'`
else
LASTRUN=0
fi;
# Get current date in epoch format
CURRDATE=`date +%s`
# Check the interval
INTERVAL=$(expr $CURRDATE - $LASTRUN)
# If interval is more than the set one, then run the main script
if [ $INTERVAL -gt $RUN_EVERY ];
then[/COLOR]
[COLOR="Green"]if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
echo "SQLite database VACUUM and REINDEX started at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for i in `busybox find /d* -iname "*.db"`; do
/system/xbin/sqlite3 $i 'VACUUM;';
resVac=$?
if [ $resVac == 0 ]; then
resVac="SUCCESS";
else
resVac="ERRCODE-$resVac";
fi;
/system/xbin/sqlite3 $i 'REINDEX;';
resIndex=$?
if [ $resIndex == 0 ]; then
resIndex="SUCCESS";
else
resIndex="ERRCODE-$resIndex";
fi;
echo "Database $i: VACUUM=$resVac REINDEX=$resIndex" | tee -a $LOG_FILE;
done
echo "SQLite database VACUUM and REINDEX finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;[/COLOR]
[COLOR="DarkRed"]fi;[/COLOR]
Click to expand...
Click to collapse
Thanks for this awesome script i was able to get an idea for this. I tried this two scripts but only zipalign works even though i have sqlite3 in stored in xbin.
mcbyte_it said:
There are many ROMs that include the ZipAlign or SQLite3 vacuum on boot, but these command are not really needed to run on EVERY boot, once every few days can be enough, so I came out with this script.
To run it, you need to have busybox with the stat applet (should be there always), which gives information about a file, including last modification date.
This is done is by checking the last modification date on a file, which is touched or changed only when the main script is executed.
Currently I modified the ZipAlign and SQLite vacuum in my own rom to use this technique, and they seem to work fine. The monitored file is the log of the operation done, which is stored in the /data/ directory
ZipAlign on Boot:
Code:
#!/system/bin/sh
# Automatic ZipAlign by Wes Garner
# ZipAlign files in /data that have not been previously ZipAligned (using md5sum)
# Thanks to oknowton for the changes
# Changelog:
# 1.0 (11/30/09) Original
# 1.1 (12/01/09) Switched to zipalign -c 4 to check the apk instead of MD5 (oknowton)
# 1.2 (06/01/13) Run the main script only once every N days (default 7 days, 1 week) (mcbyte_it)
[COLOR="DarkRed"]LOG_FILE=/data/zipalign.log
#Interval between ZipAlign runs, in seconds, 604800=1 week
RUN_EVERY=604800
# Get the last modify date of the Log file, if the file does not exist, set value to 0
if [ -e $LOG_FILE ]; then
LASTRUN=`stat -t $LOG_FILE | awk '{print $14}'`
else
LASTRUN=0
fi;
# Get current date in epoch format
CURRDATE=`date +%s`
# Check the interval
INTERVAL=$(expr $CURRDATE - $LASTRUN)
# If interval is more than the set one, then run the main script
if [ $INTERVAL -gt $RUN_EVERY ];
then[/COLOR]
[COLOR="Green"]if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
echo "Starting Automatic ZipAlign $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for apk in /data/app/*.apk ; do
zipalign -c 4 $apk;
ZIPCHECK=$?;
if [ $ZIPCHECK -eq 1 ]; then
echo ZipAligning $(basename $apk) | tee -a $LOG_FILE;
zipalign -f 4 $apk /cache/$(basename $apk);
if [ -e /cache/$(basename $apk) ]; then
cp -f -p /cache/$(basename $apk) $apk | tee -a $LOG_FILE;
rm /cache/$(basename $apk);
else
echo ZipAligning $(basename $apk) Failed | tee -a $LOG_FILE;
fi;
else
echo ZipAlign already completed on $apk | tee -a $LOG_FILE;
fi;
done;
echo "Automatic ZipAlign finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;[/color]
[COLOR="DarkRed"]fi[/COLOR]
SQLite3 vacuum:
Code:
#!/system/bin/sh
# ========================================
# init.d script for McByte jkSGS3
# ========================================
# SQLite database vaccum
# Frequent inserts, updates, and deletes can cause the database file to become fragmented - where data for a single table or index is scattered around the database file.
# Running VACUUM ensures that each table and index is largely stored contiguously within the database file.
# In some cases, VACUUM may also reduce the number of partially filled pages in the database, reducing the size of the database file further.
# sqlite3 binary in /system/xbin is required!
# Changelog
# v1.0 - (??/??/????) - original version
# v1.1 - (06/01/2013) - run only every X seconds, default = 1 week (mcbyte_it)
#
[COLOR="DarkRed"]# Log file location
LOG_FILE=/data/sqlite.log
#Interval between SQLite3 runs, in seconds, 604800=1 week
RUN_EVERY=604800
# Get the last modify date of the Log file, if the file does not exist, set value to 0
if [ -e $LOG_FILE ]; then
LASTRUN=`stat -t $LOG_FILE | awk '{print $14}'`
else
LASTRUN=0
fi;
# Get current date in epoch format
CURRDATE=`date +%s`
# Check the interval
INTERVAL=$(expr $CURRDATE - $LASTRUN)
# If interval is more than the set one, then run the main script
if [ $INTERVAL -gt $RUN_EVERY ];
then[/COLOR]
[COLOR="Green"]if [ -e $LOG_FILE ]; then
rm $LOG_FILE;
fi;
echo "SQLite database VACUUM and REINDEX started at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;
for i in `busybox find /d* -iname "*.db"`; do
/system/xbin/sqlite3 $i 'VACUUM;';
resVac=$?
if [ $resVac == 0 ]; then
resVac="SUCCESS";
else
resVac="ERRCODE-$resVac";
fi;
/system/xbin/sqlite3 $i 'REINDEX;';
resIndex=$?
if [ $resIndex == 0 ]; then
resIndex="SUCCESS";
else
resIndex="ERRCODE-$resIndex";
fi;
echo "Database $i: VACUUM=$resVac REINDEX=$resIndex" | tee -a $LOG_FILE;
done
echo "SQLite database VACUUM and REINDEX finished at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE;[/COLOR]
[COLOR="DarkRed"]fi;[/COLOR]
Click to expand...
Click to collapse
Hi guys! I recently installed lollipop touch wiz and installed the two scripts on the Op, managed to get the sql script to work fine but when the zip align tries to run it errors out in the log, any advice to what I've done wrong or if you guys know of a change in lollipop that doesn't play nice with zip aligning?
Starting Automatic ZipAlign 06-04-2014 15:23:01
ZipAligning *.apk
ZipAligning *.apk Failed
Automatic ZipAlign finished at 06-04-2014 15:23:01
Click to expand...
Click to collapse
All I've done as far as modify the script is I got rid of the color tags.
Also the sql log shows the correct date as well, where this script does not.
Thank you in advance guys!
Any chance to make this flasheable thx!
how to make an specific init.d script runs every x minutes?
and when unlock the screen

[TWEAK][A120][Alpha]Super battery tweaks

Please read the whole thing before deciding or asking any questions !!
This is a little script written by me to tweak the default cpu governer (hotplug) for MT6582 devices, currently tested only on A120, this script is actually programmed to set cpu power saving bias, number of cores online, and some more more attributes of our hotplug governer
Warning - flash on your own risk, i'm not responsible for any bad thing !!
Warning - this is only tested on A120 right now !!
Warning - only works on stock kitkat and cleankat for A120 !!
Warning - do give me credits if you include this in your rom !!
There are 7 different levels of power saving from 1 - 7 !!
Code:
Lvl BIAS CORES
1 150 4
2 250 4
3 150 3
4 250 3
5 100 2
6 250 2
You just have to flash any level and reboot !!
The higher level you flash, the more battery you save !!
Flash level 0 to get max perfomance with no battery saving !!
Well done brother. Now i can flash levels according to my need. There's a hell loads of difference in battery after flashing higher levels. Keep up the good work. You always come up with something remarkable.
Let us collaborate
Hi Mate,
I will message you on FB and will give you an update.
Update on script
Hi @umangleekha,
Again nice job :good:
But I have a suggestion (you can opt to take it or not). As you have mentioned the Level 0 is the stock value so you recommend us to install it whenever we want to revert. However there are a few of us who have already tweaked the values of what your script intends to change. And curious people like me would want to try your script as well. So to make things a little bit flexible and friendly, I did a little modification on your script and an uninstaller so that people can revert back to their previous settings.
I Pm'd you the scripts so you can decide if you want to update your set of installers. The uninstaller will can be applied to any of the Level installer they used.
Here's a little bit explanation of how it works, I am taking Level 6 for example:
Updated scipt
Code:
#!/system/bin/sh
#hotplug governer tweaks_umangleekha
#variables
up_threshold=/sys/devices/system/cpu/cpufreq/hotplug/up_threshold
cpu_up_threshold=/sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold
sampling_rate=/sys/devices/system/cpu/cpufreq/hotplug/sampling_rate
cpu_down_differential=/sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential
down_differential=/sys/devices/system/cpu/cpufreq/hotplug/down_differential
powersave_bias=/sys/devices/system/cpu/cpufreq/hotplug/powersave_bias
sampling_rate_min=/sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min
cpu_num_limit=/sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit
hotplugbak=/data/hotplug
hotpluglog=/data/hotplug.log
rm -f $hotpluglog
touch $hotpluglog
if [ -s $hotplugbak ] ; then
echo "hotplug original values were stored." | tee -a $hotpluglog;
else
touch $hotplugbak;
echo "#!/system/bin/sh" | tee -a $hotplugbak;
echo "# This contains the original values" | tee -a $hotpluglog;
echo "" | tee -a $hotplugbak;
echo "hotplug will run the first time..." | tee -a $hotpluglog;
#creating a backup first
echo "echo $( cat $up_threshold ) > $up_threshold" | tee -a $hotplugbak;
echo "echo $( cat $cpu_up_threshold ) > $cpu_up_threshold" | tee -a $hotplugbak;
echo "echo $( cat $sampling_rate ) > $sampling_rate" | tee -a $hotplugbak;
echo "echo $( cat $cpu_down_differential ) > $cpu_down_differential" | tee -a $hotplugbak;
echo "echo $( cat $down_differential ) > $down_differential" | tee -a $hotplugbak;
echo "echo $( cat $powersave_bias ) > $powersave_bias" | tee -a $hotplugbak;
echo "echo $( cat $sampling_rate_min ) > $sampling_rate_min" | tee -a $hotplugbak;
echo "echo $( cat $cpu_num_limit ) > $sampling_rate_min" | tee -a $hotplugbak;
fi;
# applying hotplug now
echo 95 > $up_threshold
echo 95 > $cpu_up_threshold
echo 40000 > $sampling_rate
echo 1 > $cpu_down_differential
echo 1 > $down_differential
echo 250 > $powersave_bias
echo 40000 > $sampling_rate_min
echo 2 > $cpu_num_limit
What it does is it will create a backup named "hotplug" inside /data directory. And this will not be changed and will be done once (check the IF statement). And if the backup is already there, the first IF will be bypassed and it will proceed to the changes you need. If the backup is not there, it will create the backup first. Basically that's going to be your installer.
For the Uninstaller
So the script is pretty straightforward, it will delete the existing hotplug from the init.d and then execute the shell script which was previously backed up from the installer.
Code:
#!/system/bin/sh
#
# This will revert all the changes made by the battery tweak from Umang Leekha
##################################################################################
# Let us start
#mounting /system
mount -o rw,remount /system
mount -o rw,remount /data
# Deleting the hotplug
rm -rf /system/etc/init.d/hotplug;
/system/bin/sh /data/hotplug;
# Updating the correct permission
chmod 777 /system/etc/init.d/*
I hope this helps and more power!
Thanks, i'll consider your ideas in V2
Here are the results, using my Lvl5 Super battery tweak, i'm a modeate user, brightness 22%, wifi on almost everytime when screen is on, crome and whatsapp, also one football app, played piano tiles for 15mins, it's just my first test with my tweaks, i'll release level 7 and will reach 6hrs screen time soon
umang bro, put them all inside another zip and upload it. It's annoying to download one tweak at a time. thanks !
Results after moderate usage. thanks brother, i got around 7 hours on screen. [emoji6]
Hey dev i flashed the level7 zip on my unite2 with ur cleankat v2.9 rom bt after flasbibg when i chekedout the battery stat i was shocked.it was 89% charged bt saying only 6 mins backup left why so bro tell me whats the problem.! Help
Sent from my Micromax A106 using xda app-developers app
I think you will need to recalibrate your battery dude. There are apps in Google Playstore which you can use.
Hey Umang,
So you have now Level 7 with powersave_bias=0, cpu_num_limit=2 and assigned scaling_max_freq=1040000 for all the cores, what's the effect of these changes?
scaling_max_freq path is incorrect Level7
Hey Bro,
I just checked your script for Level7, where did you checked this hotplug? I checked on my MT6582 KK version and it seems your last 4 lines' path does not exist. I checked it via ADB.
Can this work on Gionee M2?
Sent from my Gionee M2 using XDA Free mobile app
After installing on my Gionee M2, i was stuck at the Gionee Boot logo... Bootloop had to restore my backup
Sent from my Gionee M2 using XDA Free mobile app
very nice share

[MT6582][init.d Tweaks][Mix n Match]-[ALPHA version]

INTRODUCTION
I am using MTK6582 device Agua Rio (close relative of Wiko Rainbow, Explay Fresh, Blu) for 4 months now and to be honest I really enjoyed using this Android phone and so I began searching for effective init.d tweaks that will be compatible for my phone. No offense to the other developers who worked hard on building a set of tweak scripts but most of them are not compatible with my phone. It is simply because the declarations of the path is not present in my device or sometimes they are just supported by MTK6582. So I started recreating my own scripts and have been using it for weeks and works as expected.
This is still in Alpha version so I am not expecting a 360-degree change in performance but if there's one thing I can guarantee you, they are working for the devices I've mentioned above and to prove that there are log files from where you can verify if the scripts were properly executed or not.
DISCLAIMER
I will not be held liable or responsible if you brick your device after flashing this tweak. ALWAYS HAVE YOUR BACKUP READY!
FLASH AT YOUR OWN RISK!!!
FEATURES
- Battery Tweaks (a lot of things going on here like battery re-calibration which will be done every 7 days, centisecs flushing interval, WiFi Sleep from Gaurav, Entropy tweak for battery, pm.sleep_mode)
- updated Loopysmoothness for MTK (I modified the declaration of variables so that the script can be a little more flexible - Credits to [email protected])
- VM Tweaks (experimental - modified scripts to work for MTK6582 credits to [email protected] and [email protected] of Fly-on)
- GPU Rendering (Enable GPU rendering for 2D operations)
- DHCPd script to clean the DHCP leases before starting
- SDboost - (modded script to work with MTK - credits to [email protected] of Fly-on and V6 Supercharger - SD Card read-ahead cache to 2048 KB)
- IOTweaks for responsiveness
- Network tweaks - (my own mix with a touch of [email protected] network tweaks)
- Zipalign - (modded script that will zipalign any new apps in /system/app, /system/framework, /data/app every reboot)
11-DEC-2014 ALPHA 3B UPDATES
- Remount - to make your device more responsive
- zRAM - utlizing ZRAM to increase performance - http://forum.xda-developers.com/showthread.php?t=2320734
- LagBuster - Credits to [email protected] for giving me an idea to incorporate RNGD Entropy
- Props - Adding more useful prop parameters
- Looping scripts (stored in /data/Tweaks/scripts)
-- Lagfix - will run every 60min and will execute fstrim Due to bad effects in the long run I have removed this (ref: http://man7.org/linux/man-pages/man8/fstrim.8.html)
-- Defrag - will run every 12hours to execute VACUUM and REINDEX to optimize the database - credits to [email protected] of Fly-on
-- CPU Hotplug - another battery tweak which I have modified which will run specific set of hotplug depending on the needs of your device and also depending on the current capacity of your battery. Credits to [email protected]
-- Xposed Log cleaner - this is one of the scripts I initially released to temporarily fix the logging problem of the latest Xposed Installer. If you don't have the app, the script will exit - http://forum.xda-developers.com/showpost.php?p=56439074
- Added host file to block annoying phishing and ad-serving websites
- Added resolv.conf to use Google's public DNS for faster browsing
11-DEC-2014 ALPHA 3B UPDATES
- lowmemorykiller - Another rotational script that will check and update your lowmemorykiller parameters - Won't really add much value since LMK resets its value from time to time.. Thanks again bro @kermage !
- 3G Booster - I have now added in the flashable installer the 3G hack from [email protected]
- Added an uninstaller in case you don't like the tweaks. Thank you for using.
WHAT'S INSIDE
/system/etc/init.d/
- 01_BattTweaks
- 02_LoopySmoothness
- 03_VMTweaks
- 04_GPURender
- 05_DHCPD
- 06_SDBoost
- 07_IOTweaks
- 10_DONOTDELETE
- 11_Network
- 13_EXT4Remount
- 14_Zram
- 16_LagBuster
- 17_SetProps
- 51_Zipalign
/system/etc/
- hosts
- resolv.conf
/system/xbin/
- bash
- busybox
- rngd
- sqlite3
- zip
- zipalign
/data/Tweaks/scripts
- 08_LagFix.sh
- 09_Defrag.sh
- 12_CPUHotplug.sh
- 15_Mem_Tweaks
- 50_XposedCleanLog.sh
/data/Tweaks/logs
*** All logs from init.d scripts and rotational scripts (/data/Tweaks/scripts)
Click to expand...
Click to collapse
REQUIREMENTS
1. Rooted
2. Busybox
3. Kernel with init.d support
4. Custom recovery tool (CWMR, TWRP, Philz, CarlivTouch)
5. Presence of mind
6. Faith!
HOW TO INSTALL
1. Download the flashable zip file and save it to your SDcard (remember where you saved it)
2. Power off your phone
3. Press Power + Vol UP + Vol DOWN simultaneously
4. Choose Recovery mode
5. Select install from SDcard
6. Install the zip file
7. Wait until the installation is completed.
8. Reboot!
To manually Push the tweak
1. Download the zip file into your SDcard
2. Extract the files
3. Copy all the contents of init.d to your /system/etc/init.d
4. Change the permission to rwxr-xr-x or rwxrwxrwx
5. Copy all the content of net to /system/etc
6. Change the permission of "hosts" and "resolv.conf" to rw-rw-rw
7. Go to /data and add a new folder named "Tweaks"
8. Go to /data/Tweaks and add new 2 folders - "scripts" and "logs"
9. Copy all the contents from "scripts" (from the zip file) to /data/Tweaks/scripts
10. Change the permissions of all the files in /data/Tweaks/scripts to rwxr-xr-x or rwxrwxrwx
11. Reboot.
HOW TO VERIFY
With the use of Root Explorer or ES Explorer, go to /data/Tweaks/logs and you will see the log files generated by the scripts. Also if you have a Terminal Emulator, you can check that the rotational scripts are running in the background.
Oh by the way, sorry to disappoint the Antutu lovers but the scripts were not customized to satisfy your eyes with Antutu scores.
To manually Delete the Tweaks
1. Delete all the files mentioned above from your phone using Root Explorer (or any file manager like ES explorer)
2. You can leave the files added in /system/xbin/ as it may help you in the future... 'just a suggestion but you can delete it if you want.
FAQs
Q: Not working. How can I tell the scripts were actually working?
A: Check the logs stored in /data/Tweaks/logs and inspect if there are log files. And with the use of any text editor check one by one the log files for any errors.
Q: There are no files in /data/Tweaks/logs, what happened?
A: It is possible that your ROM does not have init.d support. You can try using [email protected]'s fix for that (http://forum.xda-developers.com/showthread.php?t=1933849). Then you can try using again the tweak
Q: After flashing the tweaks, I cannot connect to my VPN app like Psiphon. How to fix this?
A: To be honest, I am unsure yet why but you can try either the following:
1. Check again the permission of /system/etc/hosts, /system/etc/resolv.conf and make sure they are set to rw-rw-rw. Then reboot;
2. OR, move/delete /system/etc/init.d/11_Network, /system/etc/hosts, /system/etc/resolv.conf then reboot
Q: My Internet connection is slow.
A: You can try adding the 3G hack from [email protected] (http://forum.xda-developers.com/showpost.php?p=42185612&postcount=100)
Q: The tweak is actually useless, it is not working. Should this be the case?
A: If I was not able to help you in any way, thanks for testing and feedback. Google is our friend.
Thank you all!
Mix n Match ALPHA 3B is now available
CHANGES 11-DEC-2014:
Please refer to the notes above. for the updates .
The INSTALLER will backup your previous tweaks and any conflicting files with Mix n Match. I have also added now an UNINSTALLER in case you are not satisfied. The UNINSTALLER will revert all the changes made before you flashed the latest tweaks.
Again... Flash at your own risk!
Thank you very much​
great job man.. :good:
what version of rio you're using?
mines s5501 and running on kitkat deodexed by edmhar, is your tweaks compatible with edmhar's deodexed stock rom?
Good, i'll write governer tweaks for hotplug and post link here, i'll make different versions for more battery and more responsiveness
Agua Rio
cheeze.keyk said:
great job man.. :good:
what version of rio you're using?
mines s5501 and running on kitkat deodexed by edmhar, is your tweaks compatible with edmhar's deodexed stock rom?
Click to expand...
Click to collapse
I am using Agua Rio V2
COOL!
umangleekha said:
Good, i'll write governer tweaks for hotplug and post link here, i'll make different versions for more battery and more responsiveness
Click to expand...
Click to collapse
Cool! And good JOB as well
updated the hotplug
umangleekha said:
Good, i'll write governer tweaks for hotplug and post link here, i'll make different versions for more battery and more responsiveness
Click to expand...
Click to collapse
Hey Bro, in this release I have modified your CPU hotplug and this is a rotational shell script
Code:
#!/system/bin/sh
# Name: 12_CPUHotplug.sh
# Date: 11/03/2014
# Author: Arsie Organo Jr. - [email protected]
# Link:
# About: This is additional tweaking for MT6582 devices
# to improve battery life
# You will need your device to be:
# 1. Rooted
# 2. Busybox is installed.
# 3. hotplug
# Credits: Fly-On, Medusa, and Umang Leekha hotplug
####################################################
# START
# Logging
datalog=/data/Tweaks/logs/12_CPUHotplug.log
# Check if your device supports Hotplug
HOTPLUG=/sys/devices/system/cpu/cpufreq/hotplug
if [ -d $HOTPLUG ] ; then
echo "This device supports hotplug." | tee -a $datalog;
else
echo "No hotplug support for this device. Exiting script now!" | tee -a $datalog;
exit 0
fi;
# If device is awake, it will check current battery level and also the %usr level of the CPU (all)
a=1
sleepme=10
while [ $a -ge 0 ]
do
busybox rm -f $datalog
busybox touch $datalog
BATTSTAT=`cat /sys/class/power_supply/battery/capacity`
MAXLVL=100
USRLVL=`busybox mpstat -P ALL | grep all | awk '{print $3}'`
USRLVL=${USRLVL%.*}
GAUGE=60
ANTUTU=`ps | grep com.antutu | wc -l`
ANTUTUUSE=`busybox top -b -n10 -d3 | grep com.antutu.ABenchMark | cut -c42-45 | awk '{sum+=$0}END{print sum*10}'`
if [ $ANTUTUUSE -gt 10 ] ; then
echo "Antutu Benchmark is still running. Unable to switch to Level 5 hotplug." | tee -a $datalog;
else
killall -9 com.antutu.ABenchMark
fi;
chmod 644 /sys/devices/system/cpu/cpufreq/hotplug/*
if [ $ANTUTU -gt 0 ] ; then
echo "Level Antutu Hotplug (Pro Performance) will be applied due to Antutu - $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $datalog;
echo "Battery Level: $BATTSTAT | MPSTAT Level: $USRLVL" | tee -a $datalog;
echo 85 > /sys/devices/system/cpu/cpufreq/hotplug/up_threshold;
echo 90 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold;
echo 50000 > /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate;
echo 10 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential;
echo 15 > /sys/devices/system/cpu/cpufreq/hotplug/down_differential;
echo 0 > /sys/devices/system/cpu/cpufreq/hotplug/powersave_bias;
echo 50000 > /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min;
echo 4 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit;
echo "up_threshold: $( cat /sys/devices/system/cpu/cpufreq/hotplug/up_threshold )" | tee -a $datalog;
echo "cpu_up_threshold: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold )" | tee -a $datalog;
echo "sampling_rate: $( cat /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate )" | tee -a $datalog;
echo "cpu_down_differential: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential )" | tee -a $datalog;
echo "powersave_bias: $( cat /sys/devices/system/cpu/cpufreq/hotplug/powersave_bias )" | tee -a $datalog;
echo "sampling_rate_min: $( cat /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min )" | tee -a $datalog;
echo "cpu_num_limit: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit )" | tee -a $datalog;
echo "===== COMPLETED - $( date +"%m-%d-%Y %H:%M:%S" ) =====" | tee -a $datalog;
elif [ $USRLVL -lt $GAUGE ] || [ $BATTSTAT -lt $GAUGE ]; then
echo "Level 5 Hotplug (Battery Saver) will be applied - $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $datalog;
echo "Battery Level: $BATTSTAT | MPSTAT Level: $USRLVL" | tee -a $datalog;
echo 95 > /sys/devices/system/cpu/cpufreq/hotplug/up_threshold;
echo 95 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold;
echo 40000 > /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate;
echo 1 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential;
echo 1 > /sys/devices/system/cpu/cpufreq/hotplug/down_differential;
echo 100 > /sys/devices/system/cpu/cpufreq/hotplug/powersave_bias;
echo 40000 > /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min;
echo 2 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit;
echo "up_threshold: $( cat /sys/devices/system/cpu/cpufreq/hotplug/up_threshold )" | tee -a $datalog;
echo "cpu_up_threshold: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold )" | tee -a $datalog;
echo "sampling_rate: $( cat /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate )" | tee -a $datalog;
echo "cpu_down_differential: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential )" | tee -a $datalog;
echo "powersave_bias: $( cat /sys/devices/system/cpu/cpufreq/hotplug/powersave_bias )" | tee -a $datalog;
echo "sampling_rate_min: $( cat /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min )" | tee -a $datalog;
echo "cpu_num_limit: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit )" | tee -a $datalog;
echo "===== COMPLETED - $( date +"%m-%d-%Y %H:%M:%S" ) =====" | tee -a $datalog;
elif [ $USRLVL -ge $GAUGE ] && [ $BATTSTAT -ge $GAUGE ] ; then
echo "Level 0 Hotplug (Pro Performance) will be applied - $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $datalog;
echo "Battery Level: $BATTSTAT | MPSTAT Level: $USRLVL" | tee -a $datalog;
echo 85 > /sys/devices/system/cpu/cpufreq/hotplug/up_threshold;
echo 85 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold;
echo 30000 > /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate;
echo 15 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential;
echo 15 > /sys/devices/system/cpu/cpufreq/hotplug/down_differential;
echo 0 > /sys/devices/system/cpu/cpufreq/hotplug/powersave_bias;
echo 30000 > /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min;
echo 4 > /sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit;
echo "up_threshold: $( cat /sys/devices/system/cpu/cpufreq/hotplug/up_threshold )" | tee -a $datalog;
echo "cpu_up_threshold: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_up_threshold )" | tee -a $datalog;
echo "sampling_rate: $( cat /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate )" | tee -a $datalog;
echo "cpu_down_differential: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_down_differential )" | tee -a $datalog;
echo "powersave_bias: $( cat /sys/devices/system/cpu/cpufreq/hotplug/powersave_bias )" | tee -a $datalog;
echo "sampling_rate_min: $( cat /sys/devices/system/cpu/cpufreq/hotplug/sampling_rate_min )" | tee -a $datalog;
echo "cpu_num_limit: $( cat /sys/devices/system/cpu/cpufreq/hotplug/cpu_num_limit )" | tee -a $datalog;
echo "===== COMPLETED - $( date +"%m-%d-%Y %H:%M:%S" ) =====" | tee -a $datalog;
fi;
sleep $sleepme
done
# END
Too interested in !
But I have to ask you how to uninstall if we did not use your special one, because of I have a sad experience before...
Good question, I always make sure that anything I install I create a document or uninstaller.. however, I was too busy at work and wanted to share this to my FB friends so I published it as Alpha version and wanted to get their feedback.
Give me a few minutes and I will update the doc on how to uninstall.
Hi dhampire,
I have updated the docs for you.. in the next release I will make an backup and uninstaller so that if someone does not want this tweaks they can go back from their previous set.
Good Job ser!
Next custom rom
LOL!
petiksmode said:
Next custom rom
Click to expand...
Click to collapse
hopefully I'd be able to cook one
Will this work on leagoo lead 3? mt6582, 512m of ram
init.d support
birdsilver said:
Will this work on leagoo lead 3? mt6582, 512m of ram
Click to expand...
Click to collapse
Please wait on my next release within this week and try on your phone. But please check first if your device supports init.d.
eyesfortech said:
Please wait on my next release within this week and try on your phone. But please check first if your device supports init.d.
Click to expand...
Click to collapse
Thank you very much for your response, I'll wait. I activated init.d thanks to Ryuinferno, via the terminal support.
:good:
The main page has been updated.. check out what's new
I have re-uploaded the MixnMatch_ALPHA_3b_Installer.zip installer today (12Dec2014) to fix the Bluetooth on/off bug.
Sorry for the inconvenience guys. It should be OK now.
Thanks your job! I'm trying now.
Hi.
Thanks your job! I'm trying now.
In my device, your log said that these scripts did not work.
- 09_Defrag.sh
- 12_CPUHotplug.sh
My device Lenovo s930 (MT6582) dual sim / Kitkat 4.4.2
Regards.
Problem (Sound)
Hi. I have a report for you master.
Sound problem.
1. Telephone.
In my case, I can't hear a voice (1st call), after hang up, I can hear a voice on 2nd call with big voice.
2. Alarm
I can't hear a sound.
Common is sound problem.
Regards.
Logs
dhampire said:
Hi.
Thanks your job! I'm trying now.
In my device, your log said that these scripts did not work.
- 09_Defrag.sh
- 12_CPUHotplug.sh
My device Lenovo s930 (MT6582) dual sim / Kitkat 4.4.2
Regards.
Click to expand...
Click to collapse
Can you send me the logs from /data/Tweaks/logs ?
Or please let me know if you are familiar with ADB Shell so that I can give you the commands to check.
Thanks.
17_SetProps
dhampire said:
Hi.
Thanks your job! I'm trying now.
In my device, your log said that these scripts did not work.
- 09_Defrag.sh
- 12_CPUHotplug.sh
My device Lenovo s930 (MT6582) dual sim / Kitkat 4.4.2
Regards.
Click to expand...
Click to collapse
dhampire said:
Hi. I have a report for you master.
Sound problem.
1. Telephone.
In my case, I can't hear a voice (1st call), after hang up, I can hear a voice on 2nd call with big voice.
2. Alarm
I can't hear a sound.
Common is sound problem.
Regards.
Click to expand...
Click to collapse
Hi,
Since we have a different device, can you delete 17_SetProps from /system/etc/init.d and then reboot?
Thanks.

[TOOLS] MTKIMG : Unpack / Repack boot.img, recovery.img and logo.bin for MTK device

Hello,
For a personal project a write a simple tools to unpack/repack boot.img, recovery.img and logo.bin of Mediatek cpu based devices named MTKIMG. MTK add specific header on each blocs in image so common tools could not unpack/repack properly. Also every tools i found do not correspond to my need.
Here is the the MTKIMG characteristics :
Write in C, open-source.
Portable : Linux, Cygwin, Windows (MAC is currently under port).
Only one executable for unpack/repack.
Support unpack/repack boot.img and recovery.img.
Support unpack/repack logo.bin
Keep the original image size at repack time.
Handle kernel and ramdisk with or without MTK header.
Automatic ramdisk decompression.
Option to keep or remove MTK headers.
Check for valid "ARM Linux zImage" kernel.
Check for valid "GZIP" ramdisk.
Check for overflow if kernel or ramdisk is too big at repack time.
Option to set compression rate for ramdisk.
Easy to use, all parameters are defaulted.
Easy to build on every platform.
Got simple test-suite.
Documentation available.
Version :
Status : Bêta
Version : 0.44
Update : 2015/07/20
Source code :
https://github.com/rom1nux/mtkimg
Releases (Linux, Cygwin, Windows) :
https://github.com/rom1nux/mtkimg/tree/master/releases
OSX version are currently under port (Please, thanks sambwel)
Hope this help (Sorry for my bad english)
Hi
Did you used anything from @carliv or @bgcngm projects ( source / binarys ) ?
Or is this a full new project?
Since you didn't added any source link,,, (github / bitbucket ?)
cheers
Hello superdragonpt,
Did you used anything from @carliv or @bgcngm projects ( source / binarys ) ?
Click to expand...
Click to collapse
MTKIMG is write in C from scratch. I do not use anything other than "find", "gzip" and "cpio" utilities.
I know bgcngm's pearl scripts (mtk-tools) but it does not fit my needs.
I dont know carliv's bash scripts , i dont know if it support MTK header bloc.
Or is this a full new project?
Click to expand...
Click to collapse
Yes it's a full new project, It's write MTKIMG for my need first, but i told myself that it could help other.
Since you didn't added any source link,,, (github / bitbucket ?)
Click to expand...
Click to collapse
If MTKIMG got interests i probably create git repo.
Thanks for your remarks
rom1nux said:
Hello superdragonpt,
MTKIMG is write in C from scratch. I do not use anything other than "find", "gzip" and "cpio" utilities.
I know bgcngm's pearl scripts (mtk-tools) but it does not fit my needs.
I dont know carliv's bash scripts , i dont know if it support MTK header bloc.
Yes it's a full new project, It's write MTKIMG for my need first, but i told myself that it could help other.
If MTKIMG got interests i probably create git repo.
Thanks for your remarks
Click to expand...
Click to collapse
Thanks for answering
I have some MTK devices here, i'll test this tool Compatibility across the Mtk SoC's i own.
Keep it up
Cheers
I have some MTK devices here, i'll test this tool Compatibility across the Mtk SoC's i own.
Click to expand...
Click to collapse
Good news !
For information i put source code under GPL3 license and i create a dedicated GiHub repository as you suggest : https://github.com/rom1nux/mtkimg
Feel free to come to help
Good Work Mate ....looking forward to it
edit : any 32 bit system tool ??
Hello [email protected],
Thank for your interest.
edit : any 32 bit system tool ??
Click to expand...
Click to collapse
I got only 64bits OS but i can install Cygwin32 and VirtualBox 32 bits OS if needed but it's very easy to build.
Hello,
I test MTKIMG and it work well, but now i search information about MTK logo partition format, i see the MTK header on it but dont know how to parse images.
More preciselly i want to know information about header of the logo partition (like size of image, etc...) the header after the MTK header.
Did you have this kind of information ?
Thank in advance
Hello,
I find some information about logo.bin image :
- The first 512 bytes are the MTK header Magic (0x88168858) + Size + "LOGO"
- After, i found logo partition header is formated like :
Code:
Offset (B) | Size (B) | Description
--------------------------------------------------------
0 | 4 | Logos count
4 | 4 | Size of bloc (=MTK header image size)
8 | 4 | Logo_0 offset
12 | 4 | Logo_1 offset
8+(n*4) | 4 | Logo_n offset
... | ... | ?
--------------------------------------------------------
Logo_0 offset | Logo_1-Logo_0 offset | Logo_0 gzip content
Logo_1 offset | Logo_2-Logo_3 offset | Logo_1 gzip content
... | ... | Logo_n gzip content
--------------------------------------------------------
I dont know how to find the size of each logo, did you have this information ?
This looks great. I would love to be able to run this on my Mac. I don't think it should be hard to get it working but I'm not familiar with C so I don't know what to change to make it build. Let me know what I can do to help!
Hello sambwel,
I would love to be able to run this on my Mac. I don't think it should be hard to get it working but I'm not familiar with C so I don't know what to change to make it build. Let me know what I can do to help!
Click to expand...
Click to collapse
Happy to read this
You only need "gcc" and "make" for instance (i found this on the web) :
Installing recent XCode versions confusingly enough does not automatically install the command line tools. To install the command line tools when they're not automatically installed;
Start XCode.
Go to XCode/Preferences.
Click the "Downloads" tab.
Click "Components".
Click "Install" on the command line tools line.
That will install the command line tools and make them accessible from a regular command line.
Click to expand...
Click to collapse
Be sure gcc and make are in your PATH environment variable, and after, open a terminal on your MAC in the source folder and hit command :
Code:
make
If you get "Unsupported platform" message it's a good news, i'm going to do minor correction to the source code for this error after lunch. (Put your building log here if you want)
Thanks for your help
No worries mate, familiar with linux and building things from source, just not familiar with C code Here's the output when I try make:
Code:
sambwel:mtkimg sambwel$ make
MTKIMG LINUX MAKE by rom1nux
Create directory build ...
Building C file build/info.o ...
gcc -c -Wall src/info.c -o build/info.o
In file included from src/info.h:34,
from src/info.c:24:
src/main.h:51:3: warning: #warning "Unsupported platform !"
Building C file build/main.o ...
gcc -c -Wall src/main.c -o build/main.o
In file included from src/main.c:24:
src/main.h:51:3: warning: #warning "Unsupported platform !"
src/main.c: In function ‘main’:
src/main.c:54: error: ‘APP_PLATFORM’ undeclared (first use in this function)
src/main.c:54: error: (Each undeclared identifier is reported only once
src/main.c:54: error: for each function it appears in.)
make: *** [build/main.o] Error 1
Hello sambwel
sambwel said:
No worries mate, familiar with linux and building things from source
Click to expand...
Click to collapse
Cool, good new, I know nothing about MAC
sambwel said:
..., just not familiar with C code Here's the output when I try make:
Click to expand...
Click to collapse
OK, i'm going to add MAC platform specifics to main.h this afternoon (I have not been able to do yesterday, sorry).
I tell you when i the modification is done.
Thanks a lot for your help
superdragonpt said:
Thanks for answering
I have some MTK devices here, i'll test this tool Compatibility across the Mtk SoC's i own.
Keep it up
Cheers
Click to expand...
Click to collapse
I made a similar simple script in dash format that should work on device:
Code:
#!/sbin/sh
bootonetofive() {
busybox dd if=${1}.img of=1 bs=512 count=4 conv=notrunc
busybox dd if=${1}.img of=${1}-header bs=512 skip=4 conv=notrunc
busybox dd if=${1}-header of=2 bs=512 count=1 conv=notrunc
busybox dd if=${1}-header of=${1}-header-k_header bs=512 skip=1 conv=notrunc
initrd=`hexdump -C ${1}-header-k_header | grep -m1 "ROOTFS" | cut -d " " -f 1`
if [ -z ${initrd} ]; then
initrd=`hexdump -C ${1}-header-k_header | grep -m1 "RECOVERY" | cut -d " " -f 1`
FLSH=recovery
fi
initrdbin=`printf "%d\n" 0x${initrd}`
intrdsec=`expr ${initrdbin} / 512`
busybox dd if=${1}-header-k_header of=3 bs=512 count="${intrdsec}" conv=notrunc
busybox dd if=${1}-header-k_header of=${1}-header-k_header-kernel bs=512 skip="${intrdsec}" conv=notrunc
busybox dd if=${1}-header-k_header-kernel of=4 bs=512 count=1 conv=notrunc
busybox dd if=${1}-header-k_header-kernel of=5 bs=512 skip=1 conv=notrunc
}
AddPadd() {
if [ ${krnsz} != ${nwkrnsz} ]; then
krnsz=`du -B 1 3 | cut -f 1`
nwkrnsz=`du -B 1 3-new | cut -f 1`
if [ ${krnsz} -gt ${nwkrnsz} ]; then
pddng=`expr ${krnsz} - ${nwkrnsz}`
busybox dd if=/dev/zero of=padd bs=1 count=${pddng} conv=notrunc
cat padd >> 3-new
else
nwsz=`expr ${nwkrnsz} / 512 + 1`
busybox dd if=/dev/zero of=3 bs=512 count="${nwsz}" conv=notrunc
fi
AddPadd
else
echo "kernels are already the same size"
exit 0
fi
if [ ${pddng:-0} != "0" ]; then
if [ ${nwsz:-0} != "0" ]; then
echo "new kernel is larger"
else
echo "kernels are now the same size"
fi
exit 0
fi
}
addserialno() {
printf "androidboot.serialno=" > serno
dd if=/dev/block/mmcblk0p1 of=barcode bs=16 count=1
cat serno barcode > serialno
dd if=1 of=1_1 bs=16 count=7
dd if=1 of=1_2 bs=16 skip=7
dd if=1_2 of=1_3 bs=1 skip=37
cat 1_1 serialno 1_3 > 1_new
}
unpackramd() {
mkdir work 2> /dev/null
cd work
busybox gzip -dc ../5 2> /dev/null | cpio -i 2> /dev/null
cd ${crdr}
}
repackramd() {
cd work
find . | cpio -o -H newc 2> /dev/null | gzip -9 > ../5-new 2> /dev/null
rm -rf *
cd ${crdr}
}
bootfivetoone() {
cat 1 2 3 4 5 > new-${1:-boot}.img
}
crdr=`pwd`
bootonetofive ${1:-boot}
rm ${1:-boot}-*
if [ -f 3-new ]; then
AddPadd
cp 3-new 3
fi
if [ ${2:-NA} = "split" ]; then
unpackramd
echo "modify what you need to in ${crdr}/work then"
echo "press enter y to continue or any key to exit"
read cntn
if [ ${cntn:-n} = "y" ]; then
repackramd
cp 5-new 5
else
exit 0
fi
fi
if [ ${2-NA} = "serial" ]; then
addserialno
cp 1_new 1
fi
bootfivetoone ${1:-boot}
echo "All Done new .img created... ${crdr}/new-${1:-boot}.img"
# 1 header
# 2 k_header
# 3 kernel
# 4 r-header
# 5 ramdisk
FLSHPRT=`ls -la /dev/block/platform/mtk-msdc.0/by-name | grep ${FLSH:-boot} | awk -F " " '{print $NF}'`
if [ ${2:-no} = "flash" ]; then
dd if=${crdr}/new-${1:-boot}.img of=/dev/block/${FLSHPRT}
fi
Attached as a txt.
It just needs busybox installed. Only used it with the new MT6732/52 SoCs. I could use someone testing it with others to see if it's universal. (Only setup for gzipped ramdisks, should be able to add in the others.)
To run it is for example.
sh ./splitboot.sh boot split to split boot.img (and open ramdisk)
sh ./splitboot.sh boot flash to flash boot.img
sh ./splitboot.sh boot serial to take the barcode value from proinfo partition and uses it as serial number (only seems to work with AOSP)
It works with *.img and automatically identifies if it's a boot or recovery img.
HypoTurtle said:
I made a similar simple script in dash format that should work on device:
Code:
#!/sbin/sh
bootonetofive() {
busybox dd if=${1}.img of=1 bs=512 count=4 conv=notrunc
busybox dd if=${1}.img of=${1}-header bs=512 skip=4 conv=notrunc
busybox dd if=${1}-header of=2 bs=512 count=1 conv=notrunc
busybox dd if=${1}-header of=${1}-header-k_header bs=512 skip=1 conv=notrunc
initrd=`hexdump -C ${1}-header-k_header | grep -m1 "ROOTFS" | cut -d " " -f 1`
if [ -z ${initrd} ]; then
initrd=`hexdump -C ${1}-header-k_header | grep -m1 "RECOVERY" | cut -d " " -f 1`
FLSH=recovery
fi
initrdbin=`printf "%d\n" 0x${initrd}`
intrdsec=`expr ${initrdbin} / 512`
busybox dd if=${1}-header-k_header of=3 bs=512 count="${intrdsec}" conv=notrunc
busybox dd if=${1}-header-k_header of=${1}-header-k_header-kernel bs=512 skip="${intrdsec}" conv=notrunc
busybox dd if=${1}-header-k_header-kernel of=4 bs=512 count=1 conv=notrunc
busybox dd if=${1}-header-k_header-kernel of=5 bs=512 skip=1 conv=notrunc
}
AddPadd() {
if [ ${krnsz} != ${nwkrnsz} ]; then
krnsz=`du -B 1 3 | cut -f 1`
nwkrnsz=`du -B 1 3-new | cut -f 1`
if [ ${krnsz} -gt ${nwkrnsz} ]; then
pddng=`expr ${krnsz} - ${nwkrnsz}`
busybox dd if=/dev/zero of=padd bs=1 count=${pddng} conv=notrunc
cat padd >> 3-new
else
nwsz=`expr ${nwkrnsz} / 512 + 1`
busybox dd if=/dev/zero of=3 bs=512 count="${nwsz}" conv=notrunc
fi
AddPadd
else
echo "kernels are already the same size"
exit 0
fi
if [ ${pddng:-0} != "0" ]; then
if [ ${nwsz:-0} != "0" ]; then
echo "new kernel is larger"
else
echo "kernels are now the same size"
fi
exit 0
fi
}
addserialno() {
printf "androidboot.serialno=" > serno
dd if=/dev/block/mmcblk0p1 of=barcode bs=16 count=1
cat serno barcode > serialno
dd if=1 of=1_1 bs=16 count=7
dd if=1 of=1_2 bs=16 skip=7
dd if=1_2 of=1_3 bs=1 skip=37
cat 1_1 serialno 1_3 > 1_new
}
unpackramd() {
mkdir work 2> /dev/null
cd work
busybox gzip -dc ../5 2> /dev/null | cpio -i 2> /dev/null
cd ${crdr}
}
repackramd() {
cd work
find . | cpio -o -H newc 2> /dev/null | gzip -9 > ../5-new 2> /dev/null
rm -rf *
cd ${crdr}
}
bootfivetoone() {
cat 1 2 3 4 5 > new-${1:-boot}.img
}
crdr=`pwd`
bootonetofive ${1:-boot}
rm ${1:-boot}-*
if [ -f 3-new ]; then
AddPadd
cp 3-new 3
fi
if [ ${2:-NA} = "split" ]; then
unpackramd
echo "modify what you need to in ${crdr}/work then"
echo "press enter y to continue or any key to exit"
read cntn
if [ ${cntn:-n} = "y" ]; then
repackramd
cp 5-new 5
else
exit 0
fi
fi
if [ ${2-NA} = "serial" ]; then
addserialno
cp 1_new 1
fi
bootfivetoone ${1:-boot}
echo "All Done new .img created... ${crdr}/new-${1:-boot}.img"
# 1 header
# 2 k_header
# 3 kernel
# 4 r-header
# 5 ramdisk
FLSHPRT=`ls -la /dev/block/platform/mtk-msdc.0/by-name | grep ${FLSH:-boot} | awk -F " " '{print $NF}'`
if [ ${2:-no} = "flash" ]; then
dd if=${crdr}/new-${1:-boot}.img of=/dev/block/${FLSHPRT}
fi
Attached as a txt.
It just needs busybox installed. Only used it with the new MT6732/52 SoCs. I could use someone testing it with others to see if it's universal.
To run it is for example.
sh ./splitboot.sh boot split to split boot.img (and open ramdisk)
sh ./splitboot.sh boot flash to flash boot.img
sh ./splitboot.sh boot serial to take the barcode value from proinfo partition and uses it as serial number (only seems to work with AOSP)
It works with *.img and automatically identifies if it's a boot or recovery img.
Click to expand...
Click to collapse
Good
But for those SoC, we use the inbuilt tool.
(not for general public)
So yours and this one, is always good alternative
cheers
Hello
So yours and this one, is always good alternative
Click to expand...
Click to collapse
Yes good alternative, i take look when i can, but HypoTurtle you should probably create a dedicated thread for your tools.
sambwel,
Normally we just have to adjust "main.h" and "Makefile" for porting to OSX platform.
(I put notes in the files headers)
main.h
I add 'define' test to detect OSX platform (APP_PLATFORM/APP_OSX). I don't know if this work. I leave the APP_ARCH (32/64bits) test as-it but i don't know if this work on OSX (it's not very important for now, we can correct after)
Makefile
I add "Darwin" detection mechanism for OSX.
I start to add options to unpack/repack logo.bin, this use "zlib" and "libpng1.6", you can disable this to don't be bother with externals dependencies. In Makefile, put LOGO_SUPPORT=0 in the LINUX/CYGWIN/OSX section (Line ~92) for first build.
Big Thanks for your help
Okay, good news! mtkimg builds and runs now! I did have to put LOGO_SUPPORT=0 in the Makefile otherwise I get the error "error: png.h: No such file or directory".
So I did a quick test to see if it works. info and unpack seem to work correctly (tested on ~7mb stock boot.img). However when I repack the same image the result is a ~4.3gb boot.img!! Not sure what happened... headers are intact on the new image. No more time to test right now but I will check back here soon.
Hip Ha ! Good news !
For the size, look at the "image.cfg" if the size is right
You can use '-v' and '-d' options to see what append and look at the "layout" part display on the screen.
(Suspect image.cfg not being read correctly, i'm goind to look about "End of line" on MAC.
Many thanks for your try
Hello,
I push the MTKIMG Bêta 0.38 with compiled version for (Linux64,Cygwin64 and Windows64) that support logo unpacking. (logo repack in progres...)
Have fun.....

Categories

Resources