[Tutorial]Kernel Post Compilation Guide; how to turn kernel into img

Search This thread

_LLJY

Senior Member
Jun 28, 2015
2,448
3,039
Singapore
There are many great guides online on how to compile a kernel, but they often skimp on the last and most important part, how to get it into a working img. Therefore, without further ado, these are the steps

Prerequisites:
-Linux
-Good-ish command line experience
-Mkbootimg https://github.com/Team-DevElite/mkbootimg-python3
-you will need this https://xdaforums.com/showthread.php?t=2073775
-Python 3

Step 1:
-Extract image kitchen
-Download a working kernel and extract boot image
-Place it into image kitchen's folder

-Type this into the terminal(of course, set permissions first)
Code:
./unpackimg.sh <boot image>

You will now get something similar to this.
Code:
BOARD_KERNEL_CMDLINE androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff coherent_pool=2M enforcing=0
BOARD_KERNEL_BASE 80000000
BOARD_NAME 
BOARD_PAGE_SIZE 4096
BOARD_HASH_TYPE sha1
BOARD_KERNEL_OFFSET 00008000
BOARD_RAMDISK_OFFSET 02200000
BOARD_SECOND_OFFSET 00f00000
BOARD_TAGS_OFFSET 02000000
SAVE THE OUTPUT INTO A TEXT FILE

Step 2: Getting the Ramdisk
-Go to the folder, split_img
-Copy ramdisk.cpio.gz into a conveinient folder

Step 3:
Now, get the values from Step 1
-Seperate them like this and get rid of whitespace between the \s
Code:
--ramdisk <ramdisk location> \
--cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff coherent_pool=2M enforcing=0" \
--base 0x80000000 \
--pagesize 4096 \
--ramdisk_offset 0x02200000 \
--tags_offset 0x02000000 \
Now Figure out the directory of your compiled kernel
64bit
Code:
arch/arm64/boot/

32bit
Code:
arch/arm/boot
Depending on your kernel, the kernel file will either be image-gz.dtb or zImage.
Either way its the same step.


Next, add this argument to the one we made above
Code:
--kernel <path to kernel output file>

Step 4 FINAL:
-Set the permissons for mkbootimg
-add this argument to the one above
Code:
--output boot.img
Now your arguments list should look something like this
Code:
--kernel <kernel file> \
--ramdisk <ramdisk file> \
--cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff
coherent_pool=2M enforcing=0" \
--base 0x80000000 \
--pagesize 4096 \
--ramdisk_offset 0x02200000 \
--tags_offset 0x02000000 \
--output boot.img \
-cd into the directory containing mkbootimg
-Now add ./mkbootimg to the front of it and execute!

-Check that it looks something like this
Code:
./mkbootimg \
--kernel <kernel file> \
--ramdisk <ramdisk file> \
--cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff coherent_pool=2M enforcing=0" \
--base 0x80000000 \
--pagesize 4096 \
--ramdisk_offset 0x02200000 \
--tags_offset 0x02000000 \
--output boot.img \

you should now see a boot.img generated

HIT Thanks if I helped
thanks to @osm0sis for his awesome tools!
 
Last edited:

skyguy126

Senior Member
Sep 17, 2014
454
110
github.com
Missed the ramdisk flag while building the new image and my device failed to boot multiple times. Thanks for the detailed guide (pressed the button :D)!
 
I know this is a rather old thread, but I just wanted to say thank you for this. I do a lot of modding and other tricks and hacks on Amazon Fire HD 10 (we were just recently able to unlock them) and it was nice to read a small and straight forward guide without anything being deleted or commented out. As such, I was able to use this method to make a fresh boot.img and it booted the very first time. It's an awesome feeling when that happens, given we often do more unintentional (or intentional) destruction to them.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 7
    There are many great guides online on how to compile a kernel, but they often skimp on the last and most important part, how to get it into a working img. Therefore, without further ado, these are the steps

    Prerequisites:
    -Linux
    -Good-ish command line experience
    -Mkbootimg https://github.com/Team-DevElite/mkbootimg-python3
    -you will need this https://xdaforums.com/showthread.php?t=2073775
    -Python 3

    Step 1:
    -Extract image kitchen
    -Download a working kernel and extract boot image
    -Place it into image kitchen's folder

    -Type this into the terminal(of course, set permissions first)
    Code:
    ./unpackimg.sh <boot image>

    You will now get something similar to this.
    Code:
    BOARD_KERNEL_CMDLINE androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff coherent_pool=2M enforcing=0
    BOARD_KERNEL_BASE 80000000
    BOARD_NAME 
    BOARD_PAGE_SIZE 4096
    BOARD_HASH_TYPE sha1
    BOARD_KERNEL_OFFSET 00008000
    BOARD_RAMDISK_OFFSET 02200000
    BOARD_SECOND_OFFSET 00f00000
    BOARD_TAGS_OFFSET 02000000
    SAVE THE OUTPUT INTO A TEXT FILE

    Step 2: Getting the Ramdisk
    -Go to the folder, split_img
    -Copy ramdisk.cpio.gz into a conveinient folder

    Step 3:
    Now, get the values from Step 1
    -Seperate them like this and get rid of whitespace between the \s
    Code:
    --ramdisk <ramdisk location> \
    --cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff coherent_pool=2M enforcing=0" \
    --base 0x80000000 \
    --pagesize 4096 \
    --ramdisk_offset 0x02200000 \
    --tags_offset 0x02000000 \
    Now Figure out the directory of your compiled kernel
    64bit
    Code:
    arch/arm64/boot/

    32bit
    Code:
    arch/arm/boot
    Depending on your kernel, the kernel file will either be image-gz.dtb or zImage.
    Either way its the same step.


    Next, add this argument to the one we made above
    Code:
    --kernel <path to kernel output file>

    Step 4 FINAL:
    -Set the permissons for mkbootimg
    -add this argument to the one above
    Code:
    --output boot.img
    Now your arguments list should look something like this
    Code:
    --kernel <kernel file> \
    --ramdisk <ramdisk file> \
    --cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff
    coherent_pool=2M enforcing=0" \
    --base 0x80000000 \
    --pagesize 4096 \
    --ramdisk_offset 0x02200000 \
    --tags_offset 0x02000000 \
    --output boot.img \
    -cd into the directory containing mkbootimg
    -Now add ./mkbootimg to the front of it and execute!

    -Check that it looks something like this
    Code:
    ./mkbootimg \
    --kernel <kernel file> \
    --ramdisk <ramdisk file> \
    --cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=16M@0-0xffffffff coherent_pool=2M enforcing=0" \
    --base 0x80000000 \
    --pagesize 4096 \
    --ramdisk_offset 0x02200000 \
    --tags_offset 0x02000000 \
    --output boot.img \

    you should now see a boot.img generated

    HIT Thanks if I helped
    thanks to @osm0sis for his awesome tools!