Skip to content
Permalink
Browse files

Add example build/menuconfig scripts

Signed-off-by: James Christopher Adduono <jc@adduono.com>
  • Loading branch information...
jcadduono committed Mar 1, 2019
1 parent 25d28ef commit 8bddf3b8f0945856e193fcef65f54d1bd4aa050b
Showing with 233 additions and 1 deletion.
  1. +11 −1 README.md
  2. +127 −0 example_scripts/build.sh
  3. +95 −0 example_scripts/menuconfig.sh
@@ -58,4 +58,14 @@ So really all you need is a kernel image and sometimes a dtb.img to build for a

Don't forget to add your newly supported device's kernel sources to the kernels.txt file!

Sat Oct 22 21:31:18 EST 2016
## Building a kernel for your device

There are scripts in the `example_scripts` folder that you can copy to the root of your device's kernel sources.
They should be modified to match your device. It will make it easier to build your device's kernel outside of an Android source tree.

The binary output from the build will be self-contained in a `build` folder, with the kernel modules properly stripped and installed with their modprobe data in `build/lib/modules`.

Using these scripts in your source tree will make it easier for others to make modifications and update your device in the future. It will also increase the likelihood your device will be accepted into the nethunter-devices repository as an officially supported device!


Thu Feb 28 20:43:37 EST 2019
@@ -0,0 +1,127 @@
#!/bin/bash
# script for building NetHunter kernels by jcadduono

################### BEFORE STARTING ################
#
# download a working toolchain and extract it somewhere and configure this
# file to point to the toolchain's root directory.
# this file should be placed in your kernel source folder with
# the CONFIG section edited to work for your device.
#
# once you've set up the config section how you like it, you can simply run
# ./build.sh [DEVICE] [TARGET]
#
# make a copy of your device's original defconfig file.
# the new defconfig file should follow the format:
# arch/arm64/configs/nethunter_yourdevice_defconfig
#
###################### CONFIG ######################

# default device name (change this!)
DEFAULT_DEVICE=yourdevice

# default target name
DEFAULT_TARGET=nethunter

# release version (increment this with new releases)
RELEASE_VERSION=1.0

# directory containing cross-compile arm64 toolchain (change this!)
TOOLCHAIN=/opt/toolchain/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu

############## SCARY NO-TOUCHY STUFF ###############

# root directory of kernel source git repo (default is this script's location)
RDIR=$(pwd)

CPU_THREADS=$(grep -c "processor" /proc/cpuinfo)
# amount of cpu threads to use in kernel make process
THREADS=$((CPU_THREADS + 1))

ABORT() {
[ "$1" ] && echo "Error: $*"
exit 1
}

CONTINUE=false
export ARCH=arm64
export CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-gnu-

[ -x "${CROSS_COMPILE}gcc" ] ||
ABORT "Unable to find gcc cross-compiler at location: ${CROSS_COMPILE}gcc"

while [ $# != 0 ]; do
if [ "$1" = "--continue" ] || [ "$1" == "-c" ]; then
CONTINUE=true
elif [ ! "$TARGET" ]; then
TARGET=$1
elif [ ! "$DEVICE" ]; then
DEVICE=$1
else
echo "Too many arguments!"
echo "Usage: ./build.sh [--continue] [device] [target defconfig]"
ABORT
fi
shift
done

[ "$DEVICE" ] || DEVICE=$DEFAULT_DEVICE
[ "$TARGET" ] || TARGET=$DEFAULT_TARGET
DEFCONFIG=${TARGET}_${DEVICE}_defconfig

[ -f "$RDIR/arch/$ARCH/configs/${DEFCONFIG}" ] ||
ABORT "Config $DEFCONFIG not found in $ARCH configs!"

export LOCALVERSION=$TARGET-$DEVICE-$RELEASE_VERSION

CLEAN_BUILD() {
echo "Cleaning build..."
rm -rf build
}

SETUP_BUILD() {
echo "Creating kernel config for $LOCALVERSION..."
mkdir -p build
make -C "$RDIR" O=build "$DEFCONFIG" \
|| ABORT "Failed to set up build"
}

BUILD_KERNEL() {
echo "Starting build for $LOCALVERSION..."
while ! make -C "$RDIR" O=build -j"$THREADS"; do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) return 1 ;;
esac
done
}

INSTALL_MODULES() {
grep -q 'CONFIG_MODULES=y' build/.config || return 0
echo "Installing kernel modules to build/lib/modules..."
while ! make -C "$RDIR" O=build \
INSTALL_MOD_PATH="." \
INSTALL_MOD_STRIP=1 \
modules_install
do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) return 1 ;;
esac
done
rm build/lib/modules/*/build build/lib/modules/*/source
}

cd "$RDIR" || ABORT "Failed to enter $RDIR!"

if ! $CONTINUE; then
CLEAN_BUILD
SETUP_BUILD ||
ABORT "Failed to set up build!"
fi

BUILD_KERNEL &&
INSTALL_MODULES &&
echo "Finished building $LOCALVERSION!"
@@ -0,0 +1,95 @@
#!/bin/bash
# script for configuring NetHunter kernels by jcadduono

################### BEFORE STARTING ################
#
# download a working toolchain and extract it somewhere and configure this
# file to point to the toolchain's root directory.
# this file should be placed in your kernel source folder with
# the CONFIG section edited to work for your device.
#
# once you've set up the config section how you like it, you can simply run
# ./menuconfig.sh [DEVICE] [TARGET]
#
# make a copy of your device's original defconfig file.
# the new defconfig file should follow the format:
# arch/arm64/configs/nethunter_yourdevice_defconfig
#
###################### CONFIG ######################

# default device name (change this!)
DEFAULT_DEVICE=yourdevice

# default target name
DEFAULT_TARGET=nethunter

# directory containing cross-compile arm64 toolchain (change this!)
TOOLCHAIN=/opt/toolchain/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu

############## SCARY NO-TOUCHY STUFF ###############

# root directory of kernel source git repo (default is this script's location)
RDIR=$(pwd)

ABORT() {
[ "$1" ] && echo "Error: $*"
exit 1
}

export ARCH=arm64
export CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-gnu-

[ -x "${CROSS_COMPILE}gcc" ] ||
ABORT "Unable to find gcc cross-compiler at location: ${CROSS_COMPILE}gcc"

while [ $# != 0 ]; do
if [ ! "$DEVICE" ]; then
DEVICE=$1
elif [ ! "$TARGET" ]; then
TARGET=$1
else
echo "Too many arguments!"
echo "Usage: ./menuconfig.sh [device] [target defconfig]"
ABORT
fi
shift
done

[ "$DEVICE" ] || DEVICE=$DEFAULT_DEVICE
[ "$TARGET" ] || TARGET=$DEFAULT_TARGET
DEFCONFIG=${TARGET}_${DEVICE}_defconfig
DEFCONFIG_FILE=$RDIR/arch/$ARCH/configs/$DEFCONFIG

[ -f "$DEFCONFIG_FILE" ] ||
ABORT "Device config $DEFCONFIG not found in $ARCH configs!"

cd "$RDIR" || ABORT "Failed to enter $RDIR!"

echo "Cleaning build..."
rm -rf build
mkdir build
make -s -i -C "$RDIR" O=build "$DEFCONFIG" menuconfig
echo "Showing differences between old config and new config"
echo "-----------------------------------------------------"
if command -v colordiff >/dev/null 2>&1; then
diff -Bwu --label "old config" "$DEFCONFIG_FILE" --label "new config" build/.config | colordiff
else
diff -Bwu --label "old config" "$DEFCONFIG_FILE" --label "new config" build/.config
echo "-----------------------------------------------------"
echo "Consider installing the colordiff package to make diffs easier to read"
fi
echo "-----------------------------------------------------"
echo -n "Are you satisfied with these changes? y/N: "
read -r option
case $option in
y|Y)
cp build/.config "$DEFCONFIG_FILE"
echo "Copied new config to $DEFCONFIG_FILE"
;;
*)
echo "That's unfortunate"
;;
esac
echo "Cleaning build..."
rm -rf build
echo "Done."

3 comments on commit 8bddf3b

@0E800

This comment has been minimized.

Copy link

0E800 replied Mar 13, 2019

Is it futile to try to build Nethunter for Pie?
I have build kernel successfully using menuconfig.sh and build.sh but when it comes to flashing via TWRP, I am having no luck patching the bootloader.

Not sure if its a A, B issue with PixelXL or just that the current builds are for up to Marshmellow and the Meta script needs to be updated for Pie.

I was thinking I could take advantage of the Magisk module support for Nethunter, but first I would like to compile a kernel with HID and Injection support.

Thank you for your consideration.

@jcadduono

This comment has been minimized.

Copy link
Collaborator Author

jcadduono replied Mar 13, 2019

probably an A/B thing but I don't have an A/B device to test and see what problems happen when flashing
would likely be boot-patcher.sh issue.

@0E800

This comment has been minimized.

Copy link

0E800 replied Mar 15, 2019

Thank you for responding.

After adding block location to devices.cfg I was able to resolve.
Now I gotta figure out which kernel module is causing the device to boot loop during bootanim.

Ref: devices.cfg

# Google Pixel XL
[marlin]
author = "0E800"
version = "1.0"
arch = arm64
devicenames = marlin
block = /dev/block/platform/soc/624000.ufshc/by-name/boot
Please sign in to comment.
You can’t perform that action at this time.