Skip to content

Building FrancoKernel from source

Dmitry Gruzd edited this page Jun 7, 2019 · 4 revisions

I'm writing this as a newbie to building Linux kernels. This is the first kernel I've ever built but not before failing miserably for a considerable while. I'm not going to try and reinvent the wheel here, mostly just an outline of what worked for me and the sources that helped me along.

Build environment

I first attempted to build on Mac OS X and ran into enough problems that I decided to try a Linux virtual machine. This guide assumes you are working on Ubuntu 14.04 64-bit, but should work on other versions and distributions. If you're a Mac user, consider installing VirtualBox as your virtualization software with Ubuntu 14.04 as your guest machine.

Build prerequisites

  1. Update installed packages
    sudo apt-get update && sudo apt-get dist-upgrade
    
  2. Install required packages (source)
    sudo apt-get install build-essential kernel-package libncurses5-dev bzip2
    
  3. Download a prebuilt toolchain (source)
    git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8
    
  4. Download the kernel source (source)
    git clone [email protected]:franciscofranco/hammerhead.git
    

Building

Much of the below is borrowed from here

  1. Expose you prebuilt toolchain. You'll need the path the "arm-eabi-4.8" directory, but we'll assume it's in your home folder
    export PATH=~/arm-eabi-4.8/bin:$PATH
    
  2. You can probably get away without these variables since the default config seems to define them, but just in case
    export ARCH=arm
    export CROSS_COMPILE=arm-eabi-
    
  3. Change directory into the kernel source folder (assuming it's in your home folder)
    cd ~/hammerhead
    
  4. (Optionally) Customize your kernel config using GUI (source)
    • make xconfig or via text editor vi arch/arm/config/franco_defconfig
  5. Create the build config file:
    make defconfig franco_defconfig
    
  6. Build with your desired number of concurrent threads make -j4
  7. On my quad core i7, it takes about 10 minutes to build and you'll know it's successful when the last messages tell you where to find zImage and zImage-dtb.

Packaging for flashing

You probably want to install this on your phone now. For this, we can use Franco's builds as a template for packaging a zip to be installed via TWRP or a similar recovery.

  1. Download a Franco build to use as a template
    wget https://kernels.franco-lnx.net/Nexus5/6.0.1/anyKernel/fk-r106-anykernel2.zip
    
  2. Unzip the archive for editing
    unzip fk-r106-anykernel2.zip -d fk-r106-anykernel2
    
  3. Place your newly built kernel into the template. Pay particular attention that we're copying zImage-dtb as zImage
    cp -f arch/arm/boot/zImage-dtb fk-r106-anykernel2/zImage
    
  4. Change directory into the template
    cd fk-r106-anykernel2
    
  5. Zip it up
    zip -r9 custom-fk-r106-anykernel2.zip *
    

And there you have it, custom-fk-r106-anykernel2.zip is your zip to flash in recovery. Nice work!