Skip to content

Instantly share code, notes, and snippets.

@thinkycx
Forked from atulprak/wahoo_mybuild.sh
Last active November 1, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkycx/6de024016c03ae7a6aa6d69248263e20 to your computer and use it in GitHub Desktop.
Save thinkycx/6de024016c03ae7a6aa6d69248263e20 to your computer and use it in GitHub Desktop.
Compiling Linux Kernel for Pixel 2 devices -- Bash script
#!/bin/bash
# Purpose: Script for building AOSP code and Linux kernel for walleye using open-source toolchains.
# Author: atulp@google.com
# License: Gnu GPL v. 2
# License is same as Linux kernel license, since the code helps compile the Linux kernel for a device
# Change these directory paths to point to your aosp and NDK folders.
# reference: https://www.digitalocean.com/community/tutorials/how-to-build-android-roms-on-ubuntu-16-04
# edited by thinkycx 201809
export KERNEL=/root/AOSP/msm
export AOSP=/root/AOSP/android-8.0.0_r33
export CROSS_COMPILE=/root/AOSP/tools/aarch64-linux-android-4.9/bin/aarch64-linux-android- # ~/ndk/android-ndk-r16b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-
export USER=root # building AOSP needs USER env but in docker there is no USER env
export MAKE_NUM=80 #cpu number*2 `nproc`
export USE_CCACHE=1
export CCACHE_MEM_SIZE=100G
export ANDROID_JACK_VM_ARGS="-Xmx16g -Dfile.encoding=UTF-8 -XX:+TieredCompilation"
# Change these if you are building for something other than walleye (Pixel 2) as needed.
export KERNELNAME=wahoo
export TARGETBUILD=walleye
export ARCH=arm64
export SUBARCH=arm64
export CLANG_TRIPLE=aarch64-linux-gnu-
export CLANG_PREBUILT_BIN=$AOSP/prebuilts/clang/host/linux-x86/clang-4053586/bin
export CC_CMD=${CLANG_PREBUILT_BIN}/clang
# These likely would not have to be changed.
export PATH=$PATH:$AOSP/prebuilts/misc/linux-x86/dtc:$AOSP/prebuilts/misc/linux-x86/libufdt
build_aosp()
{
set -x
cp arch/arm64/boot/dtbo.img $AOSP/device/google/${KERNELNAME}-kernel
cp arch/arm64/boot/Image.lz4-dtb $AOSP/device/google/${KERNELNAME}-kernel
set +x
# Uncomment if other drivers need to be also updated. The following paths are specific to walleye and may need
# changes for your specific device.
cp drivers/input/touchscreen/stm/*.ko $AOSP/device/google/${KERNELNAME}-kernel
cp drivers/power/*.ko $AOSP/device/google/wahoo-kernel
cp drivers/input/touchscreen/synaptics_dsx_htc/*.ko $AOSP/device/google/${KERNELNAME}-kernel
cp drivers/input/touchscreen/lge/*.ko $AOSP/device/google/${KERNELNAME}-kernel
cp drivers/input/touchscreen/lge/lgsic/*.ko $AOSP/device/google/${KERNELNAME}-kernel
# use ccache
if [ ${USE_CCACHE} -eq 1 ];then
echo "use ccache -M ${CCACHE_MEM_SIZE}"
prebuilts/misc/linux-x86/ccache/ccache -M ${CCACHE_MEM_SIZE}
fi
echo "Running lunch and make for ${TARGETBUILD}-userdebug in the $AOSP folder"
pushd .
cd $AOSP || return 1
. build/envsetup.sh || return 1
lunch aosp_${TARGETBUILD}-userdebug || return 1
# Alternative 1: Builds everything
make -j${MAKE_NUM} || return 1
# Alternative 2: The following may work if only the kernel is being updated
# make bootimage
popd
return 0
}
flash_image()
{
echo "Attempting to flash image..."
pushd .
cd $AOSP
. build/envsetup.sh
lunch aosp_${TARGETBUILD}-userdebug || return 1
set -x
adb reboot bootloader || return 1
sleep 10
echo "fastboot flashall -w"
fastboot flashall -w || return 1
set +x
popd
echo "Attempt to flash image done..."
}
build_kernel()
{
cd ${KERNEL}
# Make walleye_defconfig or appropriate kernel configuration file
set -x
echo "Building kernel: make ${KERNELNAME}_defconfig"
make ${KERNELNAME}_defconfig
echo "apt-get install ... for kernel dependency"
apt-get install bc -y
apt-get install liblz4-tool -y
# Build the kernel, using clang if needed.
if [ -z "${CC_CMD}" ];
then
# echo "Building kernel: make V=1 -j40"
# make V=1 -j40 || exit 1
echo "Building kernel: make -j${MAKE_NUM}"
make -j${MAKE_NUM} || exit 1
else
# echo "Building kernel: make V=1 CC=${CC_CMD} -j40"
# make V=1 CC=${CC_CMD} -j40 || exit 1
echo "Building kernel: make -j${MAKE_NUM}"
make -j${MAKE_NUM} || exit 1
fi
set +x
}
build_kernel || exit 1
# Copy the kernel files to the AOSP tree and build it.
build_aosp || exit 1
# Flash the image to the connected device over adb. The device must be authorized for adb.
# flash_image || exit 1
@thinkycx
Copy link
Author

thinkycx commented Sep 14, 2018

comment

  • set -x

Prints a trace of simple commands, for commands, case commands, select commands, and arithmetic for commands and their arguments or associated word lists after they are expanded and before they are executed.

  • pushd .
  • popd
    change directory

@ssdubey
Copy link

ssdubey commented Oct 29, 2018

Hi, here you have mentioned that your Pixel was unresponsive after flashing the compiled kernel. Could you solve that problem and how? Can you help me please.

@ssdubey
Copy link

ssdubey commented Nov 1, 2018

I could solve the problem, so mentioning the solution here, in case it comes handy to anyone. So I was using the original factory image for Pixel 2 (walleye-opm2.171026.006.c1). Apparently, this image has some issue with the touchscreen, so when I was modifying the boot.img over it, the touchscreen was not responding. It was a guess work but when I flashed the new Android Pie image (walleye-ppr2.181005.003) and flashed the modified image using boot.img from this factory image, everything worked just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment