Guide: How to build the kernel for your Honor 7

Search This thread

paulobrien

Senior Member
Nov 6, 2003
5,276
7,319
Norwich
www.MoDaCo.com
kernelh7.jpg

Huawei have helpfully released the kernel source for the Honor 7 on their download site. Impressively, the version posted there (3.10.86) actually matches the current release build (B330). However, the download itself is only part of the puzzle - it's important to then know how to compile it and use it. Hence this guide. :)

Some points to note first of all...
  • This guide refers to building on Linux. You can probably build on OSX or whatever too but seriously, it's less pain in the long run to spin up an Ubuntu VM.
  • There is a readme file in the kernel download with build instructions. Don't follow it... it won't work. You will end up with a built kernel, but it won't flash to your device due to the size of the file created by the 4.9 toolchain. Strange I know.
  • In the download linked above, as well as the kernel, there are some other bits and pieces (some of which are quite bizarre). I've mirrored the kernel to Bitbucket, so you don't need to grab the whole download.
Got that? OK, so here's a step by step on how to build the kernel! I strongly recommend building stock first and testing that works for you, then you can start adding your tweaks in. I'm interested to hear what you add / change!
  1. Open a terminal window on your Linux machine / in your Linux VM. No GUIs here. :) Change to the directory where you want the kernel / toolchain to live.
  2. First of all, we're going to clone the toolchain from AOSP.
    Code:
    git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8
  3. Next we're going to clone the kernel source itself from my git repo on bitbucket.
    Code:
    git clone https://bitbucket.org/paulobrien/android_kernel_honor7.git
  4. We need to add the toolchain location to the path.
    Code:
    export PATH=$(pwd)/aarch64-linux-android-4.8/bin:$PATH
  5. We need to specify that we are cross compiling for arm64.
    Code:
    export CROSS_COMPILE=$(pwd)/aarch64-linux-android-4.8/bin/aarch64-linux-android-
  6. Let's create a directory for our output to go in to.
    Code:
    mkdir out
  7. We've got the kernel downloaded, so let's change to that directory so we're ready to go.
    Code:
    cd android_kernel_honor7
  8. A bit of cleaning up before we get started...
    Code:
    make ARCH=arm64 O=../out mrproper
  9. Specify that we're building for PLK (Plank = H7)...
    Code:
    make ARCH=arm64 O=../out hw_PLK_defconfig
  10. And build it!
    Code:
    make ARCH=arm64 O=../out -j8
When this process completes, we can check the '../out' directory and you should find the file arch/arm64/boot/Image. This is the kernel that you've just built! You can't flash it as is though, you need to put it into a boot image first.

Here's how you do it...
  1. Change out of the kernel directory back to its parent.
    Code:
    cd ..
  2. Download tools for manipulating the boot image.
    Code:
    git clone https://github.com/xiaolu/mkbootimg_tools.git
  3. Download the stock boot image (actually we're using the root ready version for convenience).
    Code:
    wget -O boot.img http://nigella.modaco.com/files/boot.policypatched.b330.img
  4. Extract the boot image.
    Code:
    mkbootimg_tools/mkboot boot.img boot.extracted
  5. Copy the new kernel into the extracted boot folder.
    Code:
    cp out/arch/arm64/boot/Image boot.extracted/kernel
  6. Build a new boot image.
    Code:
    mkbootimg_tools/mkboot boot.extracted boot.newkernel.img
You now have a new boot image (boot.newkernel.img). All that's left is to flash it to your device! Reboot to bootloader (either using 'adb reboot bootloader' or by powering on with volume down held), flash using 'fastboot flash boot boot.newkernel.img' and then reboot using 'fastboot reboot'. Job done! In the About screen of settings you should see the date of the new kernel and details of your build machine.
 
Last edited:
  • Like
Reactions: FearFac

paulobrien

Senior Member
Nov 6, 2003
5,276
7,319
Norwich
www.MoDaCo.com
A quick note on building with the 4.9 toolchain - basically, the boot image that gets created is too big. This can be resolved by deleting unnecessarily PNGs in ramdisk/res/images/charger.

P
 

notthesun

Senior Member
Nov 12, 2010
142
27
Bari
hi paulobrien, i want to try to compile my own kernel, i'm not an expert of android building but i've compiled varoius linux kernel so my question is where i can find useful patch to add on my kernel? thanks for the help
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    kernelh7.jpg

    Huawei have helpfully released the kernel source for the Honor 7 on their download site. Impressively, the version posted there (3.10.86) actually matches the current release build (B330). However, the download itself is only part of the puzzle - it's important to then know how to compile it and use it. Hence this guide. :)

    Some points to note first of all...
    • This guide refers to building on Linux. You can probably build on OSX or whatever too but seriously, it's less pain in the long run to spin up an Ubuntu VM.
    • There is a readme file in the kernel download with build instructions. Don't follow it... it won't work. You will end up with a built kernel, but it won't flash to your device due to the size of the file created by the 4.9 toolchain. Strange I know.
    • In the download linked above, as well as the kernel, there are some other bits and pieces (some of which are quite bizarre). I've mirrored the kernel to Bitbucket, so you don't need to grab the whole download.
    Got that? OK, so here's a step by step on how to build the kernel! I strongly recommend building stock first and testing that works for you, then you can start adding your tweaks in. I'm interested to hear what you add / change!
    1. Open a terminal window on your Linux machine / in your Linux VM. No GUIs here. :) Change to the directory where you want the kernel / toolchain to live.
    2. First of all, we're going to clone the toolchain from AOSP.
      Code:
      git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8
    3. Next we're going to clone the kernel source itself from my git repo on bitbucket.
      Code:
      git clone https://bitbucket.org/paulobrien/android_kernel_honor7.git
    4. We need to add the toolchain location to the path.
      Code:
      export PATH=$(pwd)/aarch64-linux-android-4.8/bin:$PATH
    5. We need to specify that we are cross compiling for arm64.
      Code:
      export CROSS_COMPILE=$(pwd)/aarch64-linux-android-4.8/bin/aarch64-linux-android-
    6. Let's create a directory for our output to go in to.
      Code:
      mkdir out
    7. We've got the kernel downloaded, so let's change to that directory so we're ready to go.
      Code:
      cd android_kernel_honor7
    8. A bit of cleaning up before we get started...
      Code:
      make ARCH=arm64 O=../out mrproper
    9. Specify that we're building for PLK (Plank = H7)...
      Code:
      make ARCH=arm64 O=../out hw_PLK_defconfig
    10. And build it!
      Code:
      make ARCH=arm64 O=../out -j8
    When this process completes, we can check the '../out' directory and you should find the file arch/arm64/boot/Image. This is the kernel that you've just built! You can't flash it as is though, you need to put it into a boot image first.

    Here's how you do it...
    1. Change out of the kernel directory back to its parent.
      Code:
      cd ..
    2. Download tools for manipulating the boot image.
      Code:
      git clone https://github.com/xiaolu/mkbootimg_tools.git
    3. Download the stock boot image (actually we're using the root ready version for convenience).
      Code:
      wget -O boot.img http://nigella.modaco.com/files/boot.policypatched.b330.img
    4. Extract the boot image.
      Code:
      mkbootimg_tools/mkboot boot.img boot.extracted
    5. Copy the new kernel into the extracted boot folder.
      Code:
      cp out/arch/arm64/boot/Image boot.extracted/kernel
    6. Build a new boot image.
      Code:
      mkbootimg_tools/mkboot boot.extracted boot.newkernel.img
    You now have a new boot image (boot.newkernel.img). All that's left is to flash it to your device! Reboot to bootloader (either using 'adb reboot bootloader' or by powering on with volume down held), flash using 'fastboot flash boot boot.newkernel.img' and then reboot using 'fastboot reboot'. Job done! In the About screen of settings you should see the date of the new kernel and details of your build machine.
    1
    Well Done mate! Can we be hopefull about a sort of unoffical cm? :)

    Not sure this really helps with that. It's not something I'm looking at atm anyway I'm afraid (due to time constraints).

    P