[HOW TO] Build custom stock kernel with Linaro GCC 4.9.1

Search This thread

AndroPlus

Senior Member
Mar 13, 2013
1,898
4,155
Kyoto
androplus.org
Lenovo P11
Xiaomi Mix Fold 2
I'm making AndroPlus Kernel but when you want to build custom stock kernel for Lollipop, you'll need some changes.
So I'm sharing my how to:)
If you want to build with other toolchain, just read ramdisk changes in 4. and cmdline changes in 7.

First of all, this official tutorial will help you a lot.

Prerequisites
You are running Linux or Mac with git commands
FTF for the version you want to build
* If your system doesn't contain commands in my tutorial, please search and install.

1. Put toolchain to your home
Download Linaro GCC 4.9.1-2014.04 Toolchains (A15) from this thread
and copy arm-cortex_a15-linux-gnueabihf-linaro_4.9.1-2014.04.tar.xz to your home,
then run these commands:
Code:
cd ~
tar Jxvf arm-cortex_a15-linux-gnueabihf-linaro_4.9.1-2014.04.tar.xz
* You can change location to everywhere you like

2. Download the kernel source
Sony has official Github but they are too slow to update kernel source...
Download kernel source from here and run these commands:
Code:
mkdir /custom_kernel && cd /custom_kernel
mkdir /final_files
mkdir /kernel_src && cd /kernel_src
bzip2 -dc 23.1.A.0.690.tar.bz2 | tar xvf -
* Change dir name and file name to extract

3. Prepare ramdisk
Make ramdisk_pack dir in home and extract kernel.sin from FTF to ramdisk_pack dir.
Download this scripts and mkbootimg,
then extract them and set 755 (rwxr-xr-x) permission.

4. Unpack ramdisk
Run runme_1unpack.sh to unpack ramdisk.
Code:
./runme_1unpack.sh
It will create kernel.sin-ramdisk dir and some files.

5. Repack ramdisk
Run runme_2repack_mod.sh.
Code:
./runme_2repack_mod.sh
This will patch and repack your ramdisk.
In my script, I'm disabling sony_ric and change some lines to fix unknown baseband.
Code:
# Disable sony_ric
sed -i -e "s/write \/sys\/kernel\/security\/sony_ric\/enable 1/# write \/sys\/kernel\/security\/sony_ric\/enable 0/g" init.sony-platform.rc
sed -i -e "s/mount securityfs securityfs \/sys\/kernel\/security nosuid nodev noexec/# mount securityfs securityfs \/sys\/kernel\/security nosuid nodev noexec/g" init.sony-platform.rc
sed -i -e "s/service ric \/sbin\/ric/service ric \/sbin\/ric\n    disabled/g" init.sony-platform.rc

# Fix for Lollipop kernel
sed -i -e "s/chown tad tad \/dev\/block\/mmcblk0p1/chown root root \/dev\/block\/mmcblk0p1/g" init.sony-platform.rc
sed -i -e "s/chmod 0770 \/dev\/block\/mmcblk0p1/chmod 0777 \/dev\/block\/mmcblk0p1/g" init.sony-platform.rc
sed -i -e "s/user tad/user root/g" init.sony-platform.rc
sed -i -e "s/group tad root/group root root/g" init.sony-platform.rc
After that, you'll get [name]-ramdisk.cpio.gz.
Rename it to ramdisk.cpio.gz.

6. Prepare kernel build tools
Copy ramdisk.cpio.gz to ~/custom_kernel/final_files dir,
then download dtbToolCM from here and mkbootimg from here
and put them in ~/custom_kernel/final_files dir and set 755 (rwxr-xr-x) permission.

7. Patch some files to build with Linaro GCC 4.9.1
Open terminal in ~/custom_kernel/kernel_src, then run
Code:
git init
git remote add AndroPlus https://github.com/WedyDQ10/android_kernel_sony_msm8974ac.git
git fetch AndroPlus
git cherry-pick 3fdc1afb44e469417a9885138acfdf1ed356c8ca
git cherry-pick 488cfa625e0402e7c819a9e6240c349ed7bf5b9f
git cherry-pick b0fa0eee571e4587d0a2e256061532158b852253
git cherry-pick 116a674042845179e9ef2d7c2708db0c53e5e605
8. Build kernel
Download build script from here and set 755 (rwxr-xr-x) permission.
This script is for building Z3 (leo), so please change words
msm8974pro-ac-shinano_leo.dtb
shinano_leo_defconfig
boot_Z3.img
to something you want to build.
You can find defconfig in /arch/arm/configs.

In my script, I set cmdline
"androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x3b7 ehci-hcd.park=3 androidboot.bootdevice=msm_sdcc.1 vmalloc=300M dwc3.maximum_speed=high dwc3_msm.prop_chg_detect=Y".
This fix unknown baseband on Lollipop kernel.

After modifying script, run
Code:
./build_it4_leo
9. Done!
If build goes well, you'll get boot_Z3.img.
Flash it with
Code:
fastboot flash boot boot_Z3.img
If you get some error, please search with error message.

Credits:
Sony
DooMLoRD
Cyanogenmod
Christopher83
russel5
and other people involved
 
Last edited:

Gustavo RD78

Senior Member
May 19, 2011
1,723
2,400
Maringá - PR
my building with GCC 4.6
work now!
the problem was with cmdline!
Thanks for sharing!

jnw5mDVPWzOH3.png


Att GustavoRD78
 
  • Like
Reactions: eduardkdrv

naitik2012

Senior Member
Oct 30, 2012
875
259
Hi @AndroPlus

your build_it4_leo scripts shows that ........ramdisk ../final_files/ramdisk.cpio.gz but i got boot.img-ramdisk.gz (something) do i need to unpack and repack it to get ramdisk.cpio.gz ? or just replace ramdisk.cpio.gz with boot.img-ramdisk.gz in script ...

and one more thing i got zImage and zImage-dtb .. can u please explain what is zImage-dtb ? :)

Thanks
 
Last edited:

AndroPlus

Senior Member
Mar 13, 2013
1,898
4,155
Kyoto
androplus.org
Lenovo P11
Xiaomi Mix Fold 2
Hi @AndroPlus

your build_it4_leo scripts shows that ........ramdisk ../final_files/ramdisk.cpio.gz but i got boot.img-ramdisk.gz (something) do i need to unpack and repack it to get ramdisk.cpio.gz ? or just replace ramdisk.cpio.gz with boot.img-ramdisk.gz in script ...

and one more thing i got zImage and zImage-dtb .. can u please explain what is zImage-dtb ? :)

Thanks

Please rename boot.img-ramdisk.cpio.gz to ramdisk,cpio.gz, or replace ramdisk,cpio.gz in script.
dtb is "Device Tree Blob" and used to make kernel more generic.
In short, zImage-dtb is device specific zImage.
 
  • Like
Reactions: naitik2012

naitik2012

Senior Member
Oct 30, 2012
875
259
Please rename boot.img-ramdisk.cpio.gz to ramdisk,cpio.gz, or replace ramdisk,cpio.gz in script.
dtb is "Device Tree Blob" and used to make kernel more generic.
In short, zImage-dtb is device specific zImage.

Thanks for you help ...
i have one more question
i have compile kernel and got zImage and zImage-dtb .. if i use zImage-dtb then i dont need to create dt.img ? and what command to use to build boot.img (i think i have to only remove dt dt.img part or something )

Thanks :)

btw i got boot.img-ramdisk.gz it doesnt have .cpio.gz only .gz
 

AndroPlus

Senior Member
Mar 13, 2013
1,898
4,155
Kyoto
androplus.org
Lenovo P11
Xiaomi Mix Fold 2
Thanks for you help ...
i have one more question
i have compile kernel and got zImage and zImage-dtb .. if i use zImage-dtb then i dont need to create dt.img ? and what command to use to build boot.img (i think i have to only remove dt dt.img part or something )

Thanks :)

btw i got boot.img-ramdisk.gz it doesnt have .cpio.gz only .gz

dt.img is automatically created if you use my build_it4_leo script. (Step 8)
kernel for my device (Z3) generates .cpio.gz, but maybe it's OK to use .gz for your device.
 
  • Like
Reactions: naitik2012

naitik2012

Senior Member
Oct 30, 2012
875
259
Hi @AndroPlus
need your help

I can build CM12.1 Kernel using Christopher83's latest GCC 4.9.3 for my Xperia Z1 but when i make CM12.1 kernel for my Xperia Z2 it stuck on CM logo and phone rebooted it self but i can build kernel with DooMLoRD's prebuild toolchain 4.9.1 without any issues .... tried so many times , also used justarchi's GCC 4.9.3 toolchain but same result ..

should i use this(which m using to build Z1 & Z2 Kernel) > .. /bin/arm-eabi- or this > ... bin/arm-linux-gnueabihf-

Any help would be appreciated ,,

i haven't applied any flags or anything ... everything is default .. just building from source..

Source - https://github.com/naitikshah2015/android_kernel_sony_msm8974
 

rajit

Senior Member
Oct 13, 2012
895
853
kolkata
geek2gyaan.blogspot.com
Hi @AndroPlus
need your help

I can build CM12.1 Kernel using Christopher83's latest GCC 4.9.3 for my Xperia Z1 but when i make CM12.1 kernel for my Xperia Z2 it stuck on CM logo and phone rebooted it self but i can build kernel with DooMLoRD's prebuild toolchain 4.9.1 without any issues .... tried so many times , also used justarchi's GCC 4.9.3 toolchain but same result ..

should i use this(which m using to build Z1 & Z2 Kernel) > .. /bin/arm-eabi- or this > ... bin/arm-linux-gnueabihf-

Any help would be appreciated ,,

i haven't applied any flags or anything ... everything is default .. just building from source..

Source - https://github.com/naitikshah2015/android_kernel_sony_msm8974

Open the bin fine as u mentioned then see therir is many files which start with something. Like file 1 name - xdatool- blabla, file name 2- xdatool-bla222bla .. So the prefix should be "xdatool-"
 

Top Liked Posts

  • There are no posts matching your filters.
  • 23
    I'm making AndroPlus Kernel but when you want to build custom stock kernel for Lollipop, you'll need some changes.
    So I'm sharing my how to:)
    If you want to build with other toolchain, just read ramdisk changes in 4. and cmdline changes in 7.

    First of all, this official tutorial will help you a lot.

    Prerequisites
    You are running Linux or Mac with git commands
    FTF for the version you want to build
    * If your system doesn't contain commands in my tutorial, please search and install.

    1. Put toolchain to your home
    Download Linaro GCC 4.9.1-2014.04 Toolchains (A15) from this thread
    and copy arm-cortex_a15-linux-gnueabihf-linaro_4.9.1-2014.04.tar.xz to your home,
    then run these commands:
    Code:
    cd ~
    tar Jxvf arm-cortex_a15-linux-gnueabihf-linaro_4.9.1-2014.04.tar.xz
    * You can change location to everywhere you like

    2. Download the kernel source
    Sony has official Github but they are too slow to update kernel source...
    Download kernel source from here and run these commands:
    Code:
    mkdir /custom_kernel && cd /custom_kernel
    mkdir /final_files
    mkdir /kernel_src && cd /kernel_src
    bzip2 -dc 23.1.A.0.690.tar.bz2 | tar xvf -
    * Change dir name and file name to extract

    3. Prepare ramdisk
    Make ramdisk_pack dir in home and extract kernel.sin from FTF to ramdisk_pack dir.
    Download this scripts and mkbootimg,
    then extract them and set 755 (rwxr-xr-x) permission.

    4. Unpack ramdisk
    Run runme_1unpack.sh to unpack ramdisk.
    Code:
    ./runme_1unpack.sh
    It will create kernel.sin-ramdisk dir and some files.

    5. Repack ramdisk
    Run runme_2repack_mod.sh.
    Code:
    ./runme_2repack_mod.sh
    This will patch and repack your ramdisk.
    In my script, I'm disabling sony_ric and change some lines to fix unknown baseband.
    Code:
    # Disable sony_ric
    sed -i -e "s/write \/sys\/kernel\/security\/sony_ric\/enable 1/# write \/sys\/kernel\/security\/sony_ric\/enable 0/g" init.sony-platform.rc
    sed -i -e "s/mount securityfs securityfs \/sys\/kernel\/security nosuid nodev noexec/# mount securityfs securityfs \/sys\/kernel\/security nosuid nodev noexec/g" init.sony-platform.rc
    sed -i -e "s/service ric \/sbin\/ric/service ric \/sbin\/ric\n    disabled/g" init.sony-platform.rc
    
    # Fix for Lollipop kernel
    sed -i -e "s/chown tad tad \/dev\/block\/mmcblk0p1/chown root root \/dev\/block\/mmcblk0p1/g" init.sony-platform.rc
    sed -i -e "s/chmod 0770 \/dev\/block\/mmcblk0p1/chmod 0777 \/dev\/block\/mmcblk0p1/g" init.sony-platform.rc
    sed -i -e "s/user tad/user root/g" init.sony-platform.rc
    sed -i -e "s/group tad root/group root root/g" init.sony-platform.rc
    After that, you'll get [name]-ramdisk.cpio.gz.
    Rename it to ramdisk.cpio.gz.

    6. Prepare kernel build tools
    Copy ramdisk.cpio.gz to ~/custom_kernel/final_files dir,
    then download dtbToolCM from here and mkbootimg from here
    and put them in ~/custom_kernel/final_files dir and set 755 (rwxr-xr-x) permission.

    7. Patch some files to build with Linaro GCC 4.9.1
    Open terminal in ~/custom_kernel/kernel_src, then run
    Code:
    git init
    git remote add AndroPlus https://github.com/WedyDQ10/android_kernel_sony_msm8974ac.git
    git fetch AndroPlus
    git cherry-pick 3fdc1afb44e469417a9885138acfdf1ed356c8ca
    git cherry-pick 488cfa625e0402e7c819a9e6240c349ed7bf5b9f
    git cherry-pick b0fa0eee571e4587d0a2e256061532158b852253
    git cherry-pick 116a674042845179e9ef2d7c2708db0c53e5e605
    8. Build kernel
    Download build script from here and set 755 (rwxr-xr-x) permission.
    This script is for building Z3 (leo), so please change words
    msm8974pro-ac-shinano_leo.dtb
    shinano_leo_defconfig
    boot_Z3.img
    to something you want to build.
    You can find defconfig in /arch/arm/configs.

    In my script, I set cmdline
    "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x3b7 ehci-hcd.park=3 androidboot.bootdevice=msm_sdcc.1 vmalloc=300M dwc3.maximum_speed=high dwc3_msm.prop_chg_detect=Y".
    This fix unknown baseband on Lollipop kernel.

    After modifying script, run
    Code:
    ./build_it4_leo
    9. Done!
    If build goes well, you'll get boot_Z3.img.
    Flash it with
    Code:
    fastboot flash boot boot_Z3.img
    If you get some error, please search with error message.

    Credits:
    Sony
    DooMLoRD
    Cyanogenmod
    Christopher83
    russel5
    and other people involved
    1
    my building with GCC 4.6
    work now!
    the problem was with cmdline!
    Thanks for sharing!

    jnw5mDVPWzOH3.png


    Att GustavoRD78
    1
    Hi @AndroPlus

    your build_it4_leo scripts shows that ........ramdisk ../final_files/ramdisk.cpio.gz but i got boot.img-ramdisk.gz (something) do i need to unpack and repack it to get ramdisk.cpio.gz ? or just replace ramdisk.cpio.gz with boot.img-ramdisk.gz in script ...

    and one more thing i got zImage and zImage-dtb .. can u please explain what is zImage-dtb ? :)

    Thanks

    Please rename boot.img-ramdisk.cpio.gz to ramdisk,cpio.gz, or replace ramdisk,cpio.gz in script.
    dtb is "Device Tree Blob" and used to make kernel more generic.
    In short, zImage-dtb is device specific zImage.
    1
    Thanks for you help ...
    i have one more question
    i have compile kernel and got zImage and zImage-dtb .. if i use zImage-dtb then i dont need to create dt.img ? and what command to use to build boot.img (i think i have to only remove dt dt.img part or something )

    Thanks :)

    btw i got boot.img-ramdisk.gz it doesnt have .cpio.gz only .gz

    dt.img is automatically created if you use my build_it4_leo script. (Step 8)
    kernel for my device (Z3) generates .cpio.gz, but maybe it's OK to use .gz for your device.