Friday, 13 November 2015

How to bump yourself stock kernel, modify ramdisk to add init.d + SELinux permissive



Hello

For starters, I could not finish this topic before one or two days, so I thank you for your patience.
But I think I have already some material for the start. I will provide more detailed explanations later, when I get longer available.

I spent a lot of time searching and finding the material to understand and realize process about bump!.
After a few times shared the results of my manipulations on stock kernel, which I applied the method I'll describe here, I will try now to explain how you can make for yourself an identical result.

For starters, if you are still wondering what is Bump! I can only invite you to look for yourself, and give you the link where I tried to answer this question on the section of the G2.

The purpose of this topic is to get you to bump kernel, from a PC, Linux, or Windows, or even from the phone.
I'll try to explain as why certain steps are essential to ensure a good result, steps that, at first, did not seem obvious.

When you will try it, and will want to test the result, make sure nice to have taken the necessary precautions before: Make a backup of your current kernel foremost flashing.

Credits:
codefire team for bump!:
@thecubed , @Shelnutt2 , @IllegalArgument , @autoprime , @AnimatronicRocketReptile , @Dees_Troy
@Skin1980 for his live bump and these explanations
@osm0sis for his Android Image Kitchen - Unpack/Repack Kernel Ramdisk [Win/Android/Linux]

Now, you know what is BUMP! and why kernel must be bumped. Bump! basically involves injecting a signature in a file (boot).
This injection of the signature to be made in hexadecimal format, and immediately after the last used page of the kernel, we have to remove unnecessary bytes before doing so, and unpack/repack kernel is the easiest way to do so (http://forum.xda-developers.com/show...1&postcount=42). To do that, we need two binaries (unpackbootimg and mkbootimg). About these two binaries we can compile them ourselves, or taking already compiled bins.
@osm0sis share a super tool containing all that we need, these bins, in his Android Image Kitchen - Unpack/Repack Kernel Ramdisk [Win/Android/Linux].
So i propose to use it here.
In his thread, i gave the code for linux that can be used in a sh script (i wil attach an attachment containing file with this code to this post later) for just bumping a stock kernel without need to modify ramdisk (script sh must be in root AIK folder, kernel file can be anywere, and both can be drag and drop in an opened terminal):




Code:


#!/bin/bash
BASEDIR=$(dirname );
bin="$BASEDIR/bin";
chmod -R 755 "$bin" "$BASEDIR"/*.sh;
chmod 644 "$bin/magic";
cd "$BASEDIR";
arch=`uname -m`;

if [ ! -d "out" ];then
mkdir out
chmod 755 out
else
rm -rf out/*;
fi

if [ -e "bumped.img" ];then
rm -rf bumped.img;
fi

$bin/$arch/unpackbootimg -i -o  out;
if [ -e out/${1##*/}-ramdisk.gz ]; then
        rdcomp=out/${1##*/}-ramdisk.gz
elif [ -e out/${1##*/}-ramdisk.lz4 ]; then
        rdcomp=/out/${1##*/}-ramdisk.lz4
else
        exit 1
fi

$bin/$arch/mkbootimg --kernel  out/${1##*/}-zImage \
--ramdisk $rdcomp \
--dt out/${1##*/}-dtb \
--cmdline "$(cat out/${1##*/}-cmdline)" \
--pagesize $(cat out/${1##*/}-pagesize) \
--base $(cat out/${1##*/}-base) \
--ramdisk_offset $(cat out/${1##*/}-ramdiskoff) \
--tags_offset $(cat out/${1##*/}-tagsoff) \
--output bumped.img

printf '\x41\xA9\xE4\x67\x74\x4D\x1D\x1B\xA4\x29\xF2\xEC\xEA\x65\x52\x79' >> bumped.img





Note: bash is very important for an expected result for printf cmd. It doesn't work with sh.

Following later, namely:
- How to bump on windows
- How to change the ramdisk to put SELinux permissive and init.d before bump
- More detailed explanation and shaping the post



No comments:

Post a Comment