• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root [Development] Unofficial TWRP - K2_CL

I feel like everyday you release a new version of recovery lol

This should honestly be the last one lol. Don't really need to do anything else for the recovery. It's where it needs to be now and completely stabilized.

I'm actually working on a kernel completely separate from this project right now.
 
Thank you for all your hard work. Greatly appreciated.

I tried to "fastboot boot TWRP.img" this version. Still doesn't work that way-still need to flash it to recovery. Any ideas why?

It's the bootloader. Not the recovery. Have to boot it another way using a different command which specifies the kernel, however, I havent figured out the precise command yet. When I do, I will share it. One if the Nexus devices has the same issue but they already figured out the command to get around the problem.
 
It's the bootloader. Not the recovery. Have to boot it another way using a different command which specifies the kernel, however, I havent figured out the precise command yet. When I do, I will share it. One if the Nexus devices has the same issue but they already figured out the command to get around the problem.
Is that something inside the TWRP image file, or is that a parameter we must put in the fastboot command line?
 
Well, I put your latest TWRP release through unpackbootimg and then tried fastboot boot /path/to/zImage /path/to/ramdisk.gz but all that did was freeze the device, requiring a battery pull. The boot command's parameters are:
Code:
 boot <kernel> [ <ramdisk> ]              download and boot kernel
 
Well, I put your latest TWRP release through unpackbootimg and then tried fastboot boot /path/to/zImage /path/to/ramdisk.gz but all that did was freeze the device, requiring a battery pull. The boot command's parameters are:
Code:
 boot <kernel> [ <ramdisk> ]              download and boot kernel

You will need to specify the kernel command-line using -c.

The Nexus 4 has to use this one in order to boot vice flash.
Code:
fastboot -c "lge.kcal=0|0|0|x" boot customrecovery.img

That won't work for us so don't bother lol. Ours is obviously different.
 
I'm gonna be working on getting this sent to TeamWin for official support. My battery is acting up and I may be forced to get a new phone and leave the community. Was showing signs earlier today which means future problems are to come.

Want to get official support so this way if I do leave and there are any updates by TeamWin this variant will be up to tune with it. :-)
 
Need some assistance possibly... From someone who is really good with scripts? I have been working on a small project which pretty much works now with the exceptions of calling the unmkbootimg binary I have. Keeps giving me problems in my script. Here is what I am working with below. I can also zip it all up and send it your way assuming you know what you are doing. The recovery makes it a pain to use a binary haha.

PHP:
#!/system/bin/sh
#
# This script has six optional parameters:
#



tools=/data/tmp/tools;
binaries=/data/tmp/binaries;
scripts=/data/tmp/tools/scripts;
working=/data/tmp/prebuilt/working_folder;
prebuilt=/data/tmp/prebuilt/kernel;

chown -R root root /data/tmp
chmod -R 0775 /data/tmp

# Get the file descriptor for output
# to communicate back to the recovery

OUTFD=$($tools/busybox ps | $tools/busybox grep -v "grep" | $tools/busybox grep -o -E "updater(.*)" | $tools/busybox cut -d " " -f 3);

# Same as the ui_print command in updater_script, for example:
#
# ui_print "hello world!"
#
# will output "hello world!" to recovery, while
#
# ui_print
#
# outputs an empty line

ui_print() {
  if [ $OUTFD != "" ]; then
    echo "ui_print ${1} " 1>&$OUTFD;
    echo "ui_print " 1>&$OUTFD;
  else
    echo "${1}";
  fi;
}


#
# Check for strange boot.img header
#

check_header=`$tools/busybox od -A n -h -j 0 -N 8 $working/boot.img | sed 's/ //g'`

if [ "$check_header" != "4e415244494f2144" ]
then

  ui_print;
  ui_print "Android 'magic' header not found at start of boot.img";
  ui_print "Checking if it exists elsewhere ...";

  # Searching for the headers hex offset
  hex_offset=`$tools/busybox od -x -A x $working/boot.img | grep -m 1 "4e41 [ ]*5244 [ ]*494f [ ]*2144" | sed -e 's/ .*//'`

  if [ "$hex_offset" != "" ]
  then

    #
    # Remove leading bytes before the Android header 
    #

    dec_offset=`printf "%d" 0x$hex_offset`
    ui_print "Android header found at offset $dec_offset";
    ui_print "Removing extra stuff before it so boot.img can be read properly ...";

    dd if=$working/boot.img of=$working/modboot.img bs=1 skip=$dec_offset
    rm -f $working/boot.img
    mv $working/modboot.img $working/newboot.img
    ui_print;

dump_boot() {
    cd $working;
    $binaries/unmkbootimg -i $working/newboot.img >> $working/repackbootimg.txt;
    rm $working/kernel;
    rm $working/newboot.img;
    mv $prebuilt/zImage $working/kernel;
}

prep_boot() {
    echo \#!/sbin/sh > $working/createnewboot.sh;
    sed -n 5,10p $working/repackbootimg.txt >> $working/createnewboot.sh;
    chown root root $working/createnewboot.sh;
    chmod 775 $working/createnewboot.sh;
    sh $working/createnewboot.sh;
}

dump_boot;
prep_boot;
return $?
    exit 0

  else
    ui_print "Warning: Android header not found in boot.img (unsupported format)";
return $?
    exit 1
  fi
fi

    
    mv $working/boot.img $working/newboot.img
    rm -f $working/boot.img

dump_boot() {
    cd $working;
    $binaries/unmkbootimg -i $working/newboot.img >> $working/repackbootimg.txt;
    rm $working/kernel;
    rm $working/newboot.img;
    mv $prebuilt/zImage $working/kernel;
}

prep_boot() {
    echo \#!/sbin/sh > $working/createnewboot.sh;
    sed -n 5,10p $working/repackbootimg.txt >> $working/createnewboot.sh;
    chown root root $working/createnewboot.sh;
    chmod 775 $working/createnewboot.sh;
    sh $working/createnewboot.sh;
}

dump_boot;
prep_boot;
return $?
exit 0

Below is the code that is screwing me up. The binary is called but gives me a segmentation fault :-P

Code:
$binaries/unmkbootimg -i $working/newboot.img >> $working/repackbootimg.txt;

The concept is similar to Koushes Anykernel but his doesn't work so I am redesigning pretty much the whole concept and by also adding in that the boot.img is checked to see if it can be read and if not then it is fixed before proceeding. Need this to work so I can use it for my kernels :-) as a flashable zip.
 
Need some assistance possibly... From someone who is really good with scripts? I have been working on a small project which pretty much works now with the exceptions of calling the unmkbootimg binary I have. Keeps giving me problems in my script. Here is what I am working with below. I can also zip it all up and send it your way assuming you know what you are doing. The recovery makes it a pain to use a binary haha.

PHP:
#!/system/bin/sh
#
# This script has six optional parameters:
#



tools=/data/tmp/tools;
binaries=/data/tmp/binaries;
scripts=/data/tmp/tools/scripts;
working=/data/tmp/prebuilt/working_folder;
prebuilt=/data/tmp/prebuilt/kernel;

chown -R root root /data/tmp
chmod -R 0775 /data/tmp

# Get the file descriptor for output
# to communicate back to the recovery

OUTFD=$($tools/busybox ps | $tools/busybox grep -v "grep" | $tools/busybox grep -o -E "updater(.*)" | $tools/busybox cut -d " " -f 3);

# Same as the ui_print command in updater_script, for example:
#
# ui_print "hello world!"
#
# will output "hello world!" to recovery, while
#
# ui_print
#
# outputs an empty line

ui_print() {
  if [ $OUTFD != "" ]; then
    echo "ui_print ${1} " 1>&$OUTFD;
    echo "ui_print " 1>&$OUTFD;
  else
    echo "${1}";
  fi;
}


#
# Check for strange boot.img header
#

check_header=`$tools/busybox od -A n -h -j 0 -N 8 $working/boot.img | sed 's/ //g'`

if [ "$check_header" != "4e415244494f2144" ]
then

  ui_print;
  ui_print "Android 'magic' header not found at start of boot.img";
  ui_print "Checking if it exists elsewhere ...";

  # Searching for the headers hex offset
  hex_offset=`$tools/busybox od -x -A x $working/boot.img | grep -m 1 "4e41 [ ]*5244 [ ]*494f [ ]*2144" | sed -e 's/ .*//'`

  if [ "$hex_offset" != "" ]
  then

    #
    # Remove leading bytes before the Android header 
    #

    dec_offset=`printf "%d" 0x$hex_offset`
    ui_print "Android header found at offset $dec_offset";
    ui_print "Removing extra stuff before it so boot.img can be read properly ...";

    dd if=$working/boot.img of=$working/modboot.img bs=1 skip=$dec_offset
    rm -f $working/boot.img
    mv $working/modboot.img $working/newboot.img
    ui_print;

dump_boot() {
    cd $working;
    $binaries/unmkbootimg -i $working/newboot.img >> $working/repackbootimg.txt;
    rm $working/kernel;
    rm $working/newboot.img;
    mv $prebuilt/zImage $working/kernel;
}

prep_boot() {
    echo \#!/sbin/sh > $working/createnewboot.sh;
    sed -n 5,10p $working/repackbootimg.txt >> $working/createnewboot.sh;
    chown root root $working/createnewboot.sh;
    chmod 775 $working/createnewboot.sh;
    sh $working/createnewboot.sh;
}

dump_boot;
prep_boot;
return $?
    exit 0

  else
    ui_print "Warning: Android header not found in boot.img (unsupported format)";
return $?
    exit 1
  fi
fi

    
    mv $working/boot.img $working/newboot.img
    rm -f $working/boot.img

dump_boot() {
    cd $working;
    $binaries/unmkbootimg -i $working/newboot.img >> $working/repackbootimg.txt;
    rm $working/kernel;
    rm $working/newboot.img;
    mv $prebuilt/zImage $working/kernel;
}

prep_boot() {
    echo \#!/sbin/sh > $working/createnewboot.sh;
    sed -n 5,10p $working/repackbootimg.txt >> $working/createnewboot.sh;
    chown root root $working/createnewboot.sh;
    chmod 775 $working/createnewboot.sh;
    sh $working/createnewboot.sh;
}

dump_boot;
prep_boot;
return $?
exit 0

Below is the code that is screwing me up. The binary is called but gives me a segmentation fault :-P

Code:
$binaries/unmkbootimg -i $working/newboot.img >> $working/repackbootimg.txt;

The concept is similar to Koushes Anykernel but his doesn't work so I am redesigning pretty much the whole concept and by also adding in that the boot.img is checked to see if it can be read and if not then it is fixed before proceeding. Need this to work so I can use it for my kernels :-) as a flashable zip.

What exactly are you trying to do with this?

EDIT: After reading through the script, I notice that you define both dump_boot() and prep_boot() twice and call both of them twice
 
What exactly are you trying to do with this?

EDIT: After reading through the script, I notice that you define both dump_boot() and prep_boot() twice and call both of them twice

They are defined twice because in the beginning of the script the boot image is checked for the android header. If the android header is not found at the beginning of the boot.img it begins the process of locating that header and removing everything before that.

If the android header is found at the beginning like it should be then it skips all of that and proceeds towards the end of the script to finish it's tasks so it has to be included again by that reasoning. However, if you look closely the two are slightly different due to whether or not the boot.img can be read or not.

With that said, my goal is to take my built kernel and modules and add it to my zip.

The updater-script will then push all folders and files to the /tmp directory of the recovery.

It will then run the check_bootimg_header.sh and modclean.sh

The modclean.sh basically removes the old modules so the updater-script can push the new modules.

The check_bootimg_header.sh will take your current boot.img from your phone which has already been dumped prior too and see if it has the 256 bit signature prior to the android header. If it does then it will remove it and continue to proceed forward. If it doesn't then it will proceed forward.

It will use my unmkbootimg binary to unpack the boot.img now that it can be read properly and swap out the old kernel with the new kernel. The binary will give an output of how to rebuild the boot.img which is saved into a text file called repackbootimg.txt.

I use sed to pull the strings from the repackbootimg.txt file in to another file called, createnewboot.sh.

I then run createnewboot.sh which will use my mkbootimg binary plus the needed parameters to properly rebuild the newboot.img.

when done the updater_script will write the newboot.img to the boot partition.

after that, you reboot.
 
I notice the script doesn't make the directories defined in the variables at the top; is that something to be done by the updater-script or some other script and how would I go about testing this.
 
I notice the script doesn't make the directories defined in the variables at the top; is that something to be done by the updater-script or some other script and how would I go about testing this.

In the updater-script I have it as follows:

package_extract_dir("", "/tmp");

The quotes in the first argument will drop the directories from the zip to the /tmp directory. So it's not needed to make them.

I can zip it up and pm it to you.
 
On a side note, ADB doesn't seem to be working in TWRP (the device isn't detected and the output of lsusb indicates that the device is in "charge mode" which will make it difficult for me to test this at the moment)

EDIT: Flashed version d of this recovery and suddenly adb works
 
On a side note, ADB doesn't seem to be working in TWRP (the device isn't detected and the output of lsusb indicates that the device is in "charge mode" which will make it difficult for me to test this at the moment)

Well, technically, it is in charge mode lol. You have it plugged up to a power source.

I will have to checkout adb on my end to confirm that part.
 
Well, technically, it is in charge mode lol. You have it plugged up to a power source.

I will have to checkout adb on my end to confirm that part.

See my edit :)

On a side note, how long should it take for the removal of everything before the Android header?

EDIT: Output of the check_bootimg_header.sh script:

PHP:
/tmp/tools/scripts # ./check_bootimg_header.sh ../boot.img 
chown: root: No such file or directory
chown: /data/tmp: No such file or directory
chmod: /data/tmp: No such file or directory
ash: : unknown operand

ash: : unknown operand
Android 'magic' header not found at start of boot.img
ash: : unknown operand
Checking if it exists elsewhere ...
ash: : unknown operand
Android header found at offset 256
ash: : unknown operand
Removing extra stuff before it so boot.img can be read properly ...
16776960+0 records in
16776960+0 records out
16776960 bytes (16.0MB) copied, 272.457806 seconds, 60.1KB/s
ash: : unknown operand

./check_bootimg_header.sh: line 87: /tmp/binaries/unmkbootimg: not found
rm: can't remove '/tmp/prebuilt/working_folder/kernel': No such file or directory
chown: root: No such file or directory
/tmp/tools/scripts #
 
See my edit :)

On a side note, how long should it take for the removal of everything before the Android header?

It takes a bit because it has to use the dd command to remove them.

And yea, adb works lol, I think you used the wrong command initially. :-)

adb sideload filename.zip
 
It takes a bit because it has to use the dd command to remove them.

And yea, adb works lol, I think you used the wrong command initially. :-)

adb sideload filename.zip

Oh, I just flashed it with TWRP, I was just looking to use adb shell so I could do this from my computer. On a side note, the results of my run are in my previous post
 
Oh, I just flashed it with TWRP

Fair warning, WiFi will be broken because the modules will be pushed successfully but the kernel will not due to the current issue I mentioned previously. To fix it you will need to push back your originally modules or simply restore your /system alone.

The new modules need the new kernel in order for it all to work properly. Hence why I am tackling this flashable zip ;-)
 
Back
Top Bottom