FORUMS
Remove All Ads from XDA
Honor 7x
Win an Honor 7X!

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

2,407 posts
Thanks Meter: 2,788
 
By _LLJY, Senior Member on 9th May 2017, 04:02 PM
Post Reply Email Thread
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://forum.xda-developers.com/sho....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!
The Following 6 Users Say Thank You to _LLJY For This Useful Post: [ View ] Gift _LLJY Ad-Free
 
 
9th May 2017, 04:15 PM |#2  
Member
Flag chandigarh
Thanks Meter: 7
 
More
Thanks for nice and easy guide
9th May 2017, 04:25 PM |#3  
_LLJY's Avatar
OP Senior Member
Flag Singapore
Thanks Meter: 2,788
 
More
Quote:
Originally Posted by Manjot xda

There are many great guides online on how to compile a kernel, but they often skimp on the last and most
Thanks for nice and easy guide

Thank you, and please don't quote the op, please edit and shorten your post.
Regards
-LLJY
9th May 2017, 04:30 PM |#4  
Member
Flag chandigarh
Thanks Meter: 7
 
More
Sry mostly i use other forums there is no rule like don't quote whole op so ignore that post edited. Again nice tutorial
18th August 2017, 05:05 AM |#5  
skyguy126's Avatar
Senior Member
Thanks Meter: 110
 
More
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 )!
18th August 2017, 06:02 AM |#6  
Senior Member
Thanks Meter: 10
 
More
Can you make a guide video ? And this can not work on Windows ?
18th August 2017, 06:04 AM |#7  
_LLJY's Avatar
OP Senior Member
Flag Singapore
Thanks Meter: 2,788
 
More
Quote:
Originally Posted by shinigami_tsin

Can you make a guide video ? And this can not work on Windows ?

No to both
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes