Skip to content

Latest commit

 

History

History
218 lines (166 loc) · 9.77 KB

README.md

File metadata and controls

218 lines (166 loc) · 9.77 KB
banner

Build Your Own Kernel with Github Action

English | 中文

License Language Issues Pull Requests

This Github Action helps you build kernels. It reads multiple kernel sources from a configuration file and builds them using different toolchains. Additionally, it supports patching the kernel with KernelSU and uploading the built kernel image.



  Configure  

  Quick Start  

  Local testing  


Github Action

This action contains two jobs: Set-repos and Build-Kernel.

The Set-repos job reads the kernel sources from the configuration file and outputs them to the Build-Kernel job. The Build-Kernel job uses the outputted kernel sources to build the kernels and upload the built kernel images.

Trigger

Event name Description
workflow_dispatch Manually run

Workflow

Build Step Description
Checkout Check out code
Generate Matrix Generate kernel source matrix from config file
Create working dir Create working directory
Install prerequisites Install necessary dependencies for build
Clone kernel source Clone kernel source code
Get toolchains Get toolchains
Set args Set build arguments
Update KernelSU (optional) Patch kernel with KernelSU
Make defconfig Generate kernel configuration file
Build kernel Build kernel
Upload Image Upload kernel image
Upload Image.gz Upload compressed kernel image
Upload dtb Upload device tree blob file
Upload dtbo.img Upload device tree overlay file

Configuration File Syntax

Here is an example configuration file:

[
  {
    "kernelSource": {
      "name": "DogDayAndroid",
      "repo": "https://codeberg.org/DogDayAndroid/android_kernel_xiaomi_thyme",
      "branch": "lineage-20.0",
      "device": "thyme"
    },
    "withKernelSU": false,
    "toolchains": [
      {
        "repo": "https://android.googlesource.com/platform/prebuilts/gas/linux-x86",
        "branch": "master",
        "name": "gas"
      },
      {
        "repo": "https://gitlab.com/ThankYouMario/android_prebuilts_clang-standalone/",
        "branch": "11",
        "name": "clang"
      }
    ],
    "params": {
      "ARCH": "arm64",
      "CROSS_COMPILE": "aarch64-linux-gnu-",
      "CROSS_COMPILE_ARM32": "arm-linux-gnueabi-",
      "CROSS_COMPILE_COMPAT": "arm-linux-gnueabi-",
      "CLANG_TRIPLE": "aarch64-linux-gnu-",
      "AR": "",
      "CC": "clang"
    }
  },
  {
    "kernelSource": {
      "name": "DogDay-KernelSU",
      "repo": "https://codeberg.org/DogDayAndroid/android_kernel_xiaomi_thyme",
      "branch": "lineage-20.0",
      "device": "thyme"
    },
    "withKernelSU": true,
    "toolchains": [
      {
        "repo": "https://android.googlesource.com/platform/prebuilts/gas/linux-x86",
        "branch": "master",
        "name": "gas"
      },
      {
        "repo": "https://gitlab.com/ThankYouMario/android_prebuilts_clang-standalone/",
        "branch": "11",
        "name": "clang"
      }
    ],
    "params": {
      "ARCH": "arm64",
      "CROSS_COMPILE": "aarch64-linux-gnu-",
      "CROSS_COMPILE_ARM32": "arm-linux-gnueabi-",
      "CROSS_COMPILE_COMPAT": "arm-linux-gnueabi-",
      "CLANG_TRIPLE": "aarch64-linux-gnu-",
      "AR": "",
      "CC": "clang"
    }
  }
]

This JSON code describes a build configuration that includes the following:

Field Name Description
kernelSource Information about the kernel source code, including its name, repository URL, branch, and device.
withKernelSU A boolean value indicating whether the KernelSU kernel patch tool was used.
toolchains An array containing information about the required toolchains, including the repository URL, branch, and name.
params An object containing information about the build parameters, including architecture type, cross-compiler, and compiler information.

Here's a table of the parameters in the params object:

Parameter Name Description
ARCH The architecture type, in this case arm64.
CROSS_COMPILE The cross-compiler prefix, in this case aarch64-linux-gnu-.
CROSS_COMPILE_ARM32 The cross-compiler prefix for 32-bit compatibility support, in this case arm-linux-gnueabi-.
CROSS_COMPILE_COMPAT The cross-compiler prefix for 32-bit compatibility support, in this case arm-linux-gnueabi-.
CLANG_TRIPLE The clang compiler's triple, in this case aarch64-linux-gnu-.
AR The archiving program for static libraries, which is empty in this case.
CC The C compiler, which is clang in this case.

These configuration details will be used in the build process to automate the creation of specific kernel image files.

How to use

This project's basic usage is as follows:

  1. Fork this project on GitHub.

  2. Modify the repos.json file through the Github website or pull it to your local machine and commit the changes.

  3. Go to the Action page on Github and find Build kernels, then Run workflow.

  4. Wait for the compilation to finish, then download the compiled product from the corresponding page.

  5. Use your preferred packaging software to package the kernel (AnyKernel3, Android-Image-Kitchen, MagiskBoot, etc.)

Artifacts

Local testing

If you don't want to run the action on Github, you can use nektos/act to test this workflow locally and output the files.

Normal local build (kernel source code is fetched using Git)

This is the recommended local testing process. Simply install nektos/act and run the following command:

# Collect artifacts to /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts

If you want to store the artifacts in a different location, change /tmp/artifacts to your preferred directory.

If there are errors, use the -v flag to generate an error report and submit an issue. Here's the command:

# Collect artifacts to /tmp/artifacts folder:
act --artifact-server-path /tmp/artifacts -v

Full local build (kernel source code is stored locally)

If you need to perform a completely local build, consider building as follows:

  1. Set up a local Gitea or Gitlab Git service and modify the configuration file address to point to the local service address.

  2. Use git daemon to create a secondary image locally.

This is just a suggestion, and we do not provide a specific guide.

Acknowledgments

Contributor

contributors

Star history

Star History

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.