我要评分
获取效率
正确性
完整性
易理解

Compiling the ko Module

The communication between Android and Linux depends on the binder and ashmem modules. Therefore, compile and install them in the new kernel.

Two patches are required for compiling and installing the ko module. They are stored in patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder. Perform the following steps to compile them.

  1. Create a folder to store the ashmem source code.
    1
    2
    3
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/
    # mkdir -p ashmem
    # chmod -R 700 ashmem
    
  2. Copy the required files in the /usr/src/linux-kernel-5.15.98/drivers/staging/android folder in the kernel source code directory to the ashmem folder created in 1.
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/ashmem
    # cp /usr/src/linux-kernel-5.15.98/drivers/staging/android/ashmem.c ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/staging/android/ashmem.h ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/staging/android/Makefile ./
    # cp -r /usr/src/linux-kernel-5.15.98/drivers/staging/android/uapi ./
  3. Create a folder to store the binder source code.
    1
    2
    3
    4
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/
    # mkdir -p binder
    # mkdir -p binder/uapi
    # chmod -R 700 binder
    
  4. Copy the required files in the /usr/src/linux-kernel-5.15.98/drivers/android/ folder in the kernel source code directory to the binder folder created in 3.
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/binder
    # cp /usr/src/linux-kernel-5.15.98/drivers/android/binder_alloc.c ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/android/binder_alloc.h ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/android/binder.c ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/android/binder_internal.h ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/android/binder_trace.h ./
    # cp /usr/src/linux-kernel-5.15.98/drivers/android/Makefile ./
  5. Copy the required files in the /usr/src/linux-kernel-5.15.98/include/uapi/linux/android/ folder in the kernel source code directory to the uapi folder created in 3.
    1
    2
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/binder/uapi
    # cp /usr/src/linux-kernel-5.15.98/include/uapi/linux/android/binder.h ./
    
  6. Apply ashmem.patch and binder.patch.
    1
    2
    3
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/
    # patch -p1 < ashmem.patch
    # patch -p1 < binder.patch
    
  7. Compile ashmem.
    1
    2
    3
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/ashmem/
    # make KERNEL_SRC=/usr/src/linux-kernel-5.15.98 V=0 M=~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/ashmem/
    # cp ashmem_linux.ko /lib/modules/5.15.98/kernel/lib/
    
  8. Compile binder.
    1
    2
    3
    # cd ~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/binder/
    # make KERNEL_SRC=/usr/src/linux-kernel-5.15.98 V=0 M=~/dependency/patchForKernel/ubuntu_20.04/kernel_5.15.98/ashmem_binder/binder/
    # cp aosp_binder_linux.ko /lib/modules/5.15.98/kernel/lib/