Skip to content

Instantly share code, notes, and snippets.

@calebccff
Created November 1, 2021 16:47
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 calebccff/9444e896d8befeb0f9a772d28480d38d to your computer and use it in GitHub Desktop.
Save calebccff/9444e896d8befeb0f9a772d28480d38d to your computer and use it in GitHub Desktop.
Bash function to copy kernel artifacts to AOSP device project
#!/bin/bash
##############
## WARNING: This script uses `rm -rf` with variables, make sure you know what it's doing before running it
## and don't hold me accountable if you accidentally delete important stuff.
## Whilst I have tested it, your setup will be different and you should edit this to match.
## See more details at the bottom.
ANDROID_MAINLINE_DIR="/PATH/TO/AOSP/SOURCE"
# $1: vendor
# $2: device
# $3: optional kernel dir
function copymainlinekernel() {
VENDOR="$1"
DEVICE="$2"
DEVICE_KERNEL=${3:-$DEVICE/prebuilt-kernel}
_ANDROID_PREBUILT_KERNEL_DIR="$ANDROID_MAINLINE_DIR/device/$VENDOR/$DEVICE_KERNEL/android-mainline"
echo $_ANDROID_PREBUILT_KERNEL_DIR
[[ -z "$_ANDROID_PREBUILT_KERNEL_DIR" ]] && echo "_ANDROID_PREBUILT_KERNEL_DIR not found" && return
rm -rf --interactive=never "$ANDROID_MAINLINE_DIR/out/target/product/$DEVICE/ramdisk/lib/modules/*" && \
rm -rf --interactive=never "$_ANDROID_PREBUILT_KERNEL_DIR"/*
find $KERNEL_OUTDIR/modules/ -type f -name "*.ko" -exec cp {} "$_ANDROID_PREBUILT_KERNEL_DIR/" \; && \
cp -v $KERNEL_OUTDIR/arch/arm64/boot/Image.gz "$_ANDROID_PREBUILT_KERNEL_DIR/" && \
# For non-sdm845 devices this will need to be changed
cp -v $KERNEL_OUTDIR/arch/arm64/boot/dts/qcom/sdm845-*.dtb "$_ANDROID_PREBUILT_KERNEL_DIR/" && \
echo "Copied kernel and modules to android-mainline"
}
# Example
# copymainlinekernel linaro dragonboard dragonboard-kernel # copies to device/linaro/dragonboard-kernel/android-mainline
# copymainlinekernel generic sdm845 # copies to device/generic/sdm845/prebuilt-kernel/android-mainline
#
# This script is designed to be hacked on, it probably won't work out of the box.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment