Skip to content

Commit

Permalink
Update LKM build.
Browse files Browse the repository at this point in the history
  • Loading branch information
feicong committed Nov 24, 2024
1 parent aacd298 commit 07f6a44
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Upload LKM Source Code
uses: actions/upload-artifact@v4
with:
name: hello-ko-${{ matrix.tag }}-${{ matrix.arch }}
path: .github/hello-ko

- name: Run GKI Kernel Build Action
uses: ./
with:
tag: ${{ matrix.tag }}
arch: ${{ matrix.arch }}
module-path: .github/hello-ko
tag: ${{ matrix.tag }}
module-name: hello-ko
module-path: hello-ko-${{ matrix.tag }}-${{ matrix.arch }}
51 changes: 20 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Android Kernel Build Action

This GitHub Action is designed to automate the building of Android kernel modules out of the kernel source. It supports both aarch64 and x86_64 architectures, and can build kernels for different Android versions (GKI 2.0).
This GitHub Action is designed to automate the building of Android kernel modules out of the kernel source. It supports both aarch64 and x86_64 architectures, and can build kernels for different Android versions (GKI 2.0/3.0).

## Overview

Expand Down Expand Up @@ -28,20 +28,6 @@ The Android Kernel Build Action allows users to easily build kernels for Android

### Required Inputs

- kernel-url:

- Description: URL of the kernel source to be used.

- Required: true

- config:

- Description: Kernel configuration to be used for the build.

- Required: true

- Default: defconfig

- arch:

- Description: Target architecture for the kernel build.
Expand All @@ -50,24 +36,25 @@ The Android Kernel Build Action allows users to easily build kernels for Android

- Default: arm64

- android-version:
- tag:

- Description: Android version for which the kernel is being built.
- Description: Android GKI version.

- Required: true

- Default: 12
- Default: 'android13-5.15'

### Optional Inputs
- module-name:

- depth:
- Description: module name of the ko.

- Description: Depth for the kernel source git clone.
- Required: true

- Required: false
- module-path

- Default: 1
- Description: module name of the github action artifact.

- Required: true

## Usage Example

Expand Down Expand Up @@ -110,19 +97,21 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- name: Kernel Build
uses: feicong/android-kernel-build-action@main
- name: Upload LKM Source Code
uses: actions/upload-artifact@v4
with:
name: hello-ko-${{ matrix.tag }}-${{ matrix.arch }}
path: .github/hello-ko
- name: Run GKI Kernel Build Action
uses: ./
with:
arch: ${{ matrix.arch }}
tag: ${{ matrix.tag }}
module-path: .github/hello-ko
module-name: hello-ko
module-path: hello-ko-${{ matrix.tag }}-${{ matrix.arch }}
```

### Explanation of Parameters

arch: Specifies the architecture for which the kernel should be built (aarch64 or x86_64).

### Outputs

The action will upload the compiled kernel.
The action will upload the compiled kernel and module ko file.
28 changes: 18 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ branding:

inputs:
tag:
description: 'Specify the Android kernel version and tag to build for (e.g., common-android12-5.10).'
description: 'Specify the Android kernel version and tag to build for (e.g., android13-5.15).'
default: 'android13-5.15'
required: true
arch:
description: 'Specify the architecture to build for (e.g., aarch64 or x86_64).'
required: true
default: 'aarch64'
module-path:
description: 'Specify the path to the kernel module driver directory.'
description: 'Specify the name of the kernel module artifact.'
required: true
module-name:
description: 'Specify the name of the kernel module.'
Expand All @@ -23,6 +24,12 @@ inputs:
runs:
using: "composite"
steps:
- name: Download
uses: actions/download-artifact@v4
with:
name: ${{ inputs.module-path }}
path: ${{ inputs.module-name }}

- name: Validate Input
shell: bash
run: |
Expand All @@ -31,16 +38,17 @@ runs:
echo "Invalid tag specified: ${{ inputs.tag }}. Must be one of: ${VALID_TAGS[@]}"
exit 1
fi
if [ ! -d "${{ inputs.module-path }}" ]; then
echo "Invalid module-path: Directory ${{ inputs.module-path }} does not exist."
if [ ! -d "${{ inputs.module-name }}" ]; then
echo "Invalid module-name: Directory ${{ inputs.module-name }} does not exist."
exit 2
fi
if [ ! -f "${{ inputs.module-path }}/Makefile" ]; then
echo "${{ inputs.module-path }}/Makefile does not exist."
ls -l ${{ inputs.module-name }}
if [ ! -f "${{ inputs.module-name }}/Makefile" ]; then
echo "${{ inputs.module-name }}/Makefile does not exist."
exit 3
fi
if [ ! -f "${{ inputs.module-path }}/${{ inputs.module-name }}.c" ]; then
echo "Error: ${inputs.module-path}/${inputs.module-name}.c does not exist."
if [ ! -f "${{ inputs.module-name }}/${{ inputs.module-name }}.c" ]; then
echo "Error: ${inputs.module-name}/${inputs.module-name}.c does not exist."
exit 4
fi
Expand Down Expand Up @@ -82,12 +90,12 @@ runs:
GKI_ROOT=$GITHUB_WORKSPACE/android-kernel
echo "[+] GKI_ROOT: $GKI_ROOT"
echo "[+] Copy driver to $GKI_ROOT/common/drivers"
ln -sf $GITHUB_WORKSPACE/${{ inputs.module-path }} $GKI_ROOT/common/drivers/${{ inputs.module-name }}
ln -sf $GITHUB_WORKSPACE/${{ inputs.module-name }} $GKI_ROOT/common/drivers/${{ inputs.module-name }}
echo "[+] Add driver to Makefile"
DRIVER_MAKEFILE=$GKI_ROOT/common/drivers/Makefile
DRIVER_KCONFIG=$GKI_ROOT/common/drivers/Kconfig
grep -q "${{ inputs.module-name }}" "$DRIVER_MAKEFILE" || printf "\nobj-m += ${{ inputs.module-name }}/\n" >> "$DRIVER_MAKEFILE"
if [ -f $GITHUB_WORKSPACE/${{ inputs.module-path }}/Kconfig ]; then
if [ -f $GITHUB_WORKSPACE/${{ inputs.module-name }}/Kconfig ]; then
grep -q "${{ inputs.module-name }}" "$DRIVER_KCONFIG" || sed -i "/endmenu/i\\source \"drivers/${{ inputs.module-name }}/Kconfig\"" "$DRIVER_KCONFIG"
fi
# Ensure module Makefile exists
Expand Down

0 comments on commit 07f6a44

Please sign in to comment.