Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/build-docker-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ jobs:
- Download the `kernel-builder.zip` file.
- Unzip it.
- Install Docker if it's not already installed.
- In Ubuntu based systems, you can run:

```
sudo apt install docker.io && sudo usermod -aG docker $USER && sudo reboot
```
- **Ubuntu/Debian based systems:**

```
sudo apt install docker.io && sudo usermod -aG docker $USER && sudo reboot
```
- **Fedora/RHEL based systems:**

```
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager addrepo --from-repofile=https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
sudo reboot
```
- Run `kernel-builder.sh`, which is located inside the unzipped folder to power up the docker container :)

```
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/build-docker-minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ jobs:
- Download the `kernel-builder.zip` file.
- Unzip it.
- Install Docker if it's not already installed.
- In Ubuntu based systems, you can run:

```
sudo apt install docker.io && sudo usermod -aG docker $USER && sudo reboot
```
- **Ubuntu/Debian based systems:**

```
sudo apt install docker.io && sudo usermod -aG docker $USER && sudo reboot
```
- **Fedora/RHEL based systems:**

```
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager addrepo --from-repofile=https://download.docker.com/linux/fedora/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
sudo reboot
```
- Run `kernel-builder.sh`, which is located inside the unzipped folder to power up the docker container :)

```
Expand Down
54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,52 @@
**Requirements:**
- A working 🧠
- Patience
- A Linux-based PC/Server (Debian-based recommended)
- A x86_64 (AMD64) Linux-based PC/Server (Debian-based recommended)
- Basic knowledge of Linux commands and Bash scripting
- Basic knowledge of version control (Git)
- This is good practice when building a kernel. Imagine you edit some files and realize you've messed up the source - this one single command `git stash` can help you revert all the uncommitted changes you made. How cool is that :)

- Go [learn some Git from here](./Git-for-beginners/) **before** you start learning kernel compilation!

### 🛠 Install required dependencies for compiling kernels
- The command below only for Debian-based distros like Ubuntu, Linux Mint, Debian and etc.
- You can compile kernel with other distros, like Arch-based `(pacman)` and CentOS/RHL-based `(yay)`/`(dnf)`. **However, we won't provide it here. Please search related packages below that match with your distro!**
- Paste the code below in your terminal to start installation:


> [!TIP]
> For the most reliable and hassle-free experience, we recommend using our pre-configured Docker container which provides a stable, tested environment for kernel compilation that works on any OS. Download it from the [releases page](https://github.com/ravindu644/Android-Kernel-Tutorials/releases) and follow the included instructions.

<details>
<summary><strong>Expand to view how the Docker container looks like</strong></summary>

![Kernel Builder Docker Container](./screenshots/kernel-builder.png)

*Screenshot of the Ubuntu-based Docker container running on Fedora (click to view in full quality)*

</details>

But, if you don't want to use the Docker container, here are the commands to install the dependencies for Ubuntu/Fedora:

<details>
<summary><strong>🟧 Ubuntu/Debian-based distributions (Ubuntu, Linux Mint, Debian, etc.)</strong></summary>

```bash
sudo apt update && sudo apt install -y git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils erofs-utils \
default-jdk git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses-dev libx11-dev libreadline-dev libgl1 libgl1-mesa-dev \
python3 make sudo gcc g++ bc grep tofrodos python3-markdown libxml2-utils xsltproc zlib1g-dev python-is-python3 libc6-dev libtinfo6 \
make repo cpio kmod openssl libelf-dev pahole libssl-dev libarchive-tools zstd rsync --fix-missing && wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb
```
<br>❗The video Guide for this tutorial can be found here (outdated): Open in <a href="https://t.me/SamsungTweaks/137">Telegram</a> </h3>
<br>
</details>

> [!NOTE]
>
> - If you are not a beginner and want to build a GKI 2.0 kernel from the official Google sources, jump to the [gki-2.0](https://github.com/ravindu644/Android-Kernel-Tutorials/tree/gki-2.0) branch.
>
> - Credit to [@TheWildJames](https://github.com/TheWildJames) for the awesome tutorial!
>
<details>
<summary><strong>🟦 Fedora/Red Hat-based distributions (Fedora, CentOS, RHEL, etc.)</strong></summary>

```bash
sudo dnf group install "c-development" "development-tools" && \
sudo dnf install -y git dtc lz4 xz zlib-devel java-17-openjdk-devel python3 \
p7zip p7zip-plugins android-tools erofs-utils java-latest-openjdk-devel \
ncurses-devel libX11-devel readline-devel mesa-libGL-devel python3-markdown \
libxml2 libxslt dos2unix kmod openssl elfutils-libelf-devel dwarves \
openssl-devel libarchive zstd rsync
```
</details>

<br>

Expand All @@ -63,14 +82,21 @@ make repo cpio kmod openssl libelf-dev pahole libssl-dev libarchive-tools zstd r
10. 🟥 [Fixing the Known compiling issues](https://github.com/ravindu644/Android-Kernel-Tutorials#-fixing-the-known-compiling-issues)
11. 🟡 [Building a Signed Boot Image from the Compiled Kernel](https://github.com/ravindu644/Android-Kernel-Tutorials#-building-a-signed-boot-image-from-the-compiled-kernel)

---

> [!NOTE]
> If you are not a beginner and want to build a GKI 2.0 kernel from the official Google sources, jump to the [gki-2.0](https://github.com/ravindu644/Android-Kernel-Tutorials/tree/gki-2.0) branch.
>
> Credit to [@TheWildJames](https://github.com/TheWildJames) for the awesome tutorial!
>
> To-do:
>
> - Write a separate guide about using Samsung/Google's official GKI Build Systems (1.0 / 2.0+) to build an automated kernel with customization support.
>
> - Write a guide on wiring up and injecting the 500+ built Loadable Kernel Modules (.ko drivers) into `vendor_boot` and `vendor_dlkm` images, without causing conflicts or device crashes.

<hr>
---

<h2> ✅ Downloading the kernel source code for your device</h2>

- **⚠️ If your device is Samsung,**
Expand Down
61 changes: 42 additions & 19 deletions build_scripts/build_4.14.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@ export KERNEL_ROOT="$(pwd)"
export ARCH=arm64
export KBUILD_BUILD_USER="@ravindu644"

# Function to detect OS and install dependencies
install_dependencies() {
echo -e "\n[INFO]: Detecting OS and installing dependencies...\n"

if command -v dnf &> /dev/null; then
echo -e "[INFO]: Fedora/RHEL-based system detected, using dnf...\n"
sudo dnf group install "c-development" "development-tools" && \
sudo dnf install -y dtc lz4 xz zlib-devel java-latest-openjdk-devel python3 \
p7zip p7zip-plugins android-tools erofs-utils \
ncurses-devel libX11-devel readline-devel mesa-libGL-devel python3-markdown \
libxml2 libxslt dos2unix kmod openssl elfutils-libelf-devel dwarves \
openssl-devel libarchive zstd rsync libyaml-devel openssl-devel-engine --skip-unavailable

elif command -v apt &> /dev/null; then
echo -e "[INFO]: Ubuntu/Debian-based system detected, using apt...\n"
sudo apt update && sudo apt install -y git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils erofs-utils \
default-jdk git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses-dev libx11-dev libreadline-dev libgl1 libgl1-mesa-dev \
python3 make sudo gcc g++ bc grep tofrodos python3-markdown libxml2-utils xsltproc zlib1g-dev python-is-python3 libc6-dev libtinfo6 \
make repo cpio kmod openssl libelf-dev pahole libssl-dev libarchive-tools zstd libyaml-dev --fix-missing && wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb

else
echo -e "[ERROR]: Neither dnf nor apt package manager found. Please install dependencies manually.\n"
exit 1
fi

touch .requirements
}

# Install the requirements for building the kernel when running the script for the first time
if [ ! -f ".requirements" ]; then
sudo apt update && sudo apt install -y git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils erofs-utils \
default-jdk git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses-dev libx11-dev libreadline-dev libgl1 libgl1-mesa-dev \
python3 make sudo gcc g++ bc grep tofrodos python3-markdown libxml2-utils xsltproc zlib1g-dev python-is-python3 libc6-dev libtinfo6 \
make repo cpio kmod openssl libelf-dev pahole libssl-dev libarchive-tools zstd libyaml-dev --fix-missing && wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb && touch .requirements
install_dependencies
fi

# Create necessary directories
mkdir -p "${KERNEL_ROOT}/out" "${KERNEL_ROOT}/build" "${HOME}/toolchains"

# init clang-r383902b
Expand Down Expand Up @@ -47,27 +70,27 @@ export BUILD_CROSS_COMPILE="${HOME}/toolchains/gcc/arm-gnu-toolchain-14.2.rel1-x
export BUILD_CC="${HOME}/toolchains/clang-r383902b/bin/clang"

# Build options for the kernel
export BUILD_OPTIONS="
HOSTLDLIBS="-lyaml"
-C ${KERNEL_ROOT} \
O=${KERNEL_ROOT}/out \
-j$(nproc) \
ARCH=arm64 \
CROSS_COMPILE=${BUILD_CROSS_COMPILE} \
CC=${BUILD_CC} \
CLANG_TRIPLE=aarch64-linux-gnu- \
"
export BUILD_OPTIONS=(
HOSTLDLIBS="-lyaml"
-C "${KERNEL_ROOT}"
O="${KERNEL_ROOT}/out"
-j"$(nproc)"
ARCH=arm64
CROSS_COMPILE="${BUILD_CROSS_COMPILE}"
CC="${BUILD_CC}"
CLANG_TRIPLE=aarch64-linux-gnu-
)

build_kernel(){
# Make default configuration.
# Replace 'your_defconfig' with the name of your kernel's defconfig
make ${BUILD_OPTIONS} your_defconfig
make "${BUILD_OPTIONS[@]}" your_defconfig

# Configure the kernel (GUI)
make ${BUILD_OPTIONS} menuconfig
make "${BUILD_OPTIONS[@]}" menuconfig

# Build the kernel
make ${BUILD_OPTIONS} Image || exit 1
make "${BUILD_OPTIONS[@]}" Image || exit 1

# Copy the built kernel to the build directory
cp "${KERNEL_ROOT}/out/arch/arm64/boot/Image" "${KERNEL_ROOT}/build"
Expand Down
81 changes: 52 additions & 29 deletions build_scripts/build_4.14_aosp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@ export KERNEL_ROOT="$(pwd)"
export ARCH=arm64
export KBUILD_BUILD_USER="@ravindu644"

# Function to detect OS and install dependencies
install_dependencies() {
echo -e "\n[INFO]: Detecting OS and installing dependencies...\n"

if command -v dnf &> /dev/null; then
echo -e "[INFO]: Fedora/RHEL-based system detected, using dnf...\n"
sudo dnf group install "c-development" "development-tools" && \
sudo dnf install -y dtc lz4 xz zlib-devel java-latest-openjdk-devel python3 \
p7zip p7zip-plugins android-tools erofs-utils \
ncurses-devel libX11-devel readline-devel mesa-libGL-devel python3-markdown \
libxml2 libxslt dos2unix kmod openssl elfutils-libelf-devel dwarves \
openssl-devel libarchive zstd rsync openssl-devel-engine --skip-unavailable

elif command -v apt &> /dev/null; then
echo -e "[INFO]: Ubuntu/Debian-based system detected, using apt...\n"
sudo apt update && sudo apt install -y git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils erofs-utils \
default-jdk git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses-dev libx11-dev libreadline-dev libgl1 libgl1-mesa-dev \
python3 make sudo gcc g++ bc grep tofrodos python3-markdown libxml2-utils xsltproc zlib1g-dev python-is-python3 libc6-dev libtinfo6 \
make repo cpio kmod openssl libelf-dev pahole libssl-dev libarchive-tools zstd rsync --fix-missing && wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb

else
echo -e "[ERROR]: Neither dnf nor apt package manager found. Please install dependencies manually.\n"
exit 1
fi

touch .requirements
}

# Install the requirements for building the kernel when running the script for the first time
if [ ! -f ".requirements" ]; then
sudo apt update && sudo apt install -y git device-tree-compiler lz4 xz-utils zlib1g-dev openjdk-17-jdk gcc g++ python3 python-is-python3 p7zip-full android-sdk-libsparse-utils erofs-utils \
default-jdk git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses-dev libx11-dev libreadline-dev libgl1 libgl1-mesa-dev \
python3 make sudo gcc g++ bc grep tofrodos python3-markdown libxml2-utils xsltproc zlib1g-dev python-is-python3 libc6-dev libtinfo6 \
make repo cpio kmod openssl libelf-dev pahole libssl-dev libarchive-tools zstd --fix-missing && wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb && sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb && touch .requirements
install_dependencies
fi

# Create necessary directories
mkdir -p "${KERNEL_ROOT}/out" "${KERNEL_ROOT}/build" "${HOME}/toolchains"

#init neutron-clang
Expand Down Expand Up @@ -48,37 +71,37 @@ export BUILD_CROSS_COMPILE="${HOME}/toolchains/gcc/arm-gnu-toolchain-14.2.rel1-x
export BUILD_CC="${HOME}/toolchains/neutron-clang/bin/clang"

# Build options for the kernel
export BUILD_OPTIONS="
-C ${KERNEL_ROOT} \
O=${KERNEL_ROOT}/out \
-j$(nproc) \
ARCH=arm64 \
CROSS_COMPILE=${BUILD_CROSS_COMPILE} \
CC=${BUILD_CC} \
CLANG_TRIPLE=aarch64-linux-gnu- \
LLVM=1 \
LLVM_IAS=1 \
AR=${NEUTRON_PATH}/llvm-ar \
NM=${NEUTRON_PATH}/llvm-nm \
LD=${NEUTRON_PATH}/ld.lld \
STRIP=${NEUTRON_PATH}/llvm-strip \
OBJCOPY=${NEUTRON_PATH}/llvm-objcopy \
OBJDUMP=${NEUTRON_PATH}/llvm-objdump \
READELF=${NEUTRON_PATH}/llvm-readelf \
HOSTCC=${NEUTRON_PATH}/clang \
HOSTCXX=${NEUTRON_PATH}/clang++ \
"
export BUILD_OPTIONS=(
-C "${KERNEL_ROOT}"
O="${KERNEL_ROOT}/out"
-j"$(nproc)"
ARCH=arm64
CROSS_COMPILE="${BUILD_CROSS_COMPILE}"
CC="${BUILD_CC}"
CLANG_TRIPLE=aarch64-linux-gnu-
LLVM=1
LLVM_IAS=1
AR="${NEUTRON_PATH}/llvm-ar"
NM="${NEUTRON_PATH}/llvm-nm"
LD="${NEUTRON_PATH}/ld.lld"
STRIP="${NEUTRON_PATH}/llvm-strip"
OBJCOPY="${NEUTRON_PATH}/llvm-objcopy"
OBJDUMP="${NEUTRON_PATH}/llvm-objdump"
READELF="${NEUTRON_PATH}/llvm-readelf"
HOSTCC="${NEUTRON_PATH}/clang"
HOSTCXX="${NEUTRON_PATH}/clang++"
)

build_kernel(){
# Make default configuration.
# Replace 'your_defconfig' with the name of your kernel's defconfig
make ${BUILD_OPTIONS} your_defconfig
make "${BUILD_OPTIONS[@]}" your_defconfig

# Configure the kernel (GUI)
make ${BUILD_OPTIONS} menuconfig
make "${BUILD_OPTIONS[@]}" menuconfig

# Build the kernel
make ${BUILD_OPTIONS} Image || exit 1
make "${BUILD_OPTIONS[@]}" Image || exit 1

# Copy the built kernel to the build directory
cp "${KERNEL_ROOT}/out/arch/arm64/boot/Image" "${KERNEL_ROOT}/build"
Expand Down
Loading