Android Kernel Driver Builder #44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Android Kernel Driver Builder | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| android_version: | |
| description: 'Android Version (Kernel) (e.g., 14)' | |
| required: true | |
| kernel_version: | |
| description: 'Kernel Version (e.g., 6.1)' | |
| required: true | |
| driver_name: | |
| description: 'Driver Module Name (e.g., mydriver.ko)' | |
| required: true | |
| target_arch: | |
| description: 'Target Architecture (aarch64, x86_64, etc.)' | |
| required: true | |
| default: 'aarch64' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4.2.2 | |
| - name: Prepare kerneldriver directory | |
| run: | | |
| mkdir kerneldriver | |
| mv ./code/*.h ./code/*.c ./code/Makefile kerneldriver/ | |
| - name: Install repo tool | |
| run: | | |
| sudo curl -L https://storage.googleapis.com/git-repo-downloads/repo -o /usr/local/bin/repo | |
| sudo chmod a+x /usr/local/bin/repo | |
| - name: Set up Android Kernel source | |
| run: | | |
| mkdir -p android-kernel && cd android-kernel | |
| repo init -u https://android.googlesource.com/kernel/manifest -b common-android${{ github.event.inputs.android_version }}-${{ github.event.inputs.kernel_version }} | |
| repo sync -j$(nproc) -c --no-tags --optimized-fetch --force-sync | |
| - name: Copy kerneldriver | |
| run: | | |
| cd android-kernel | |
| cp -r ../kerneldriver common/drivers | |
| - name: Modify Makefile | |
| run: | | |
| cd android-kernel | |
| echo "obj-y += kerneldriver/" >> common/drivers/Makefile | |
| - name: Add module to GKI modules list | |
| if: ${{ github.event.inputs.android_version > 13 }} | |
| run: | | |
| cd android-kernel | |
| MODULE_NAME="drivers/kerneldriver/${{ github.event.inputs.driver_name }}" | |
| awk -i inplace -v module="$MODULE_NAME" ' | |
| BEGIN { added=0 } | |
| /_COMMON_GKI_MODULES_LIST = \[/ { in_list=1 } | |
| in_list && /\]/ { | |
| if (!added) { | |
| print " \"" module "\"," | |
| added=1 | |
| } | |
| in_list=0 | |
| } | |
| in_list && !added { | |
| if (module < $0) { | |
| print " \"" module "\"," | |
| added=1 | |
| } | |
| } | |
| { print } | |
| ' common/modules.bzl | |
| - name: Prepare module list for legacy builds | |
| if: ${{ github.event.inputs.android_version <= 13 }} | |
| run: | | |
| cd android-kernel | |
| echo "drivers/kerneldriver/${{ github.event.inputs.driver_name }}" >> common/android/gki_aarch64_modules | |
| - name: Increase stack frame size limit | |
| run: | | |
| cd android-kernel | |
| find . -type f -name "Makefile*" -exec sed -i 's/-Wframe-larger-than=[0-9]*/-Wframe-larger-than=4096/g' {} + | |
| grep -q "FRAME_WARN" common/Makefile || echo 'KBUILD_CFLAGS += -Wframe-larger-than=4096' >> common/Makefile | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential flex bison libssl-dev libelf-dev bc python-is-python3 | |
| - name: Build kernel module | |
| run: | | |
| cd android-kernel | |
| if [ ${{ github.event.inputs.android_version }} -le 12 ]; then | |
| BUILD_CONFIG=common/build.config.gki.${{ github.event.inputs.target_arch }} LTO=thin build/build.sh -j32 | |
| OUTPUT_PATH="out/android${{ github.event.inputs.android_version }}-${{ github.event.inputs.kernel_version }}/dist" | |
| else | |
| echo "Using Bazel build system for Android ${{ github.event.inputs.android_version }}" | |
| export BAZEL_OPTS="--host_jvm_args=-Xmx6g --jobs=$(($(nproc) - 1)) --disk_cache=./.bazel_disk_cache" | |
| echo "startup --host_jvm_args=-Xmx6g" > .bazelrc | |
| echo "build --jobs=$(($(nproc) - 1))" >> .bazelrc | |
| echo "build --local_ram_resources=HOST_RAM*0.7" >> .bazelrc | |
| echo "build --disk_cache=./.bazel_disk_cache" >> .bazelrc | |
| tools/bazel run //common:kernel_${{ github.event.inputs.target_arch }}_dist | |
| OUTPUT_PATH="out/kernel_${{ github.event.inputs.target_arch }}" | |
| fi | |
| echo "OUTPUT_PATH=$OUTPUT_PATH" >> $GITHUB_ENV | |
| continue-on-error: true | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4.6.2 | |
| with: | |
| name: kernel-driver-${{ github.event.inputs.target_arch }} | |
| path: | | |
| android-kernel/${{ env.OUTPUT_PATH }} |