Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
Add example build/menuconfig scripts
Browse files Browse the repository at this point in the history
Signed-off-by: James Christopher Adduono <[email protected]>
  • Loading branch information
jcadduono committed Mar 1, 2019
1 parent 25d28ef commit 8bddf3b
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
127 changes: 127 additions & 0 deletions example_scripts/build.sh
Original file line number Diff line number Diff line change
@@ -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!"
95 changes: 95 additions & 0 deletions example_scripts/menuconfig.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link

@0E800 0E800 commented on 8bddf3b Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator Author

@jcadduono jcadduono commented on 8bddf3b Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@0E800 0E800 commented on 8bddf3b Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.