Sunday 12 December 2021

Compiling Kernel For Android ARM With Ender-3 Pro ch341 Driver (Galaxy S3 i9300)

Kernel Driver Support to Connect to Ender

For any rom, if you want to connect it to Ender 3, you need "ch341" driver added/activated in the kernel or you need a custom implementation of it (look for octo4a program). You could understand it by connecting the phone with a USB OTG cable to your printer and execute command "ls /dev | grep tty". If  there is "ttyusb" or "ttyacm" , it means that kernel has the driver. If kernel does not have the driver you have two options: 
  1. You need to compile a kernel with driver support. Also keep in mind that kernel needs to support "loopback" functionality to host a virtual linux system and accept/direct connections to that virtual linux over its loopback.
  2. You can install octo4a, which installs custom a ch34x driver. and you need to mount the serial pipe of the octo4a (you can check that part from: https://github.com/d4rk50ul1/klipper-on-android




Compiling Kernel for ARM (Galaxy S3 i9300)

If you do not want to bother with all compiling, just download the boot.img that i compiled. It is for  CrDroid LineageOS rom install Galaxy s3 i9300s. 

I will be telling the procedure for Samsung galaxy s3 but it should be generally applicable to any ARM (not ARM64) android phone:

So i searched for Lineage os based 7.x kernels on github and found a one with "ch341" driver already included in its folders. 
Good part is that this kernel supports many phones, loopback and usb audio/dock station mode. You need a linux environment to compile kernel (might be possible on windows too). First you need to download the kernel and a toolchain (Google) to compile it. 

We need programs/files listed below: 
  • AIK KITCHEN folder (to split and merge new kernel into boot.img file) 
  • arm-eabi folder (google toolchain to compile kernel) 
  • Kernel folder (new kernel source code)
  • boot.img file (we will replace the kernel in this original image file taken from firm zip file) 
1. Installing prerequisites 
sudo apt-get install libncurses5 libncurses5-dev
sudo apt-get install make
sudo apt-get install git

2. Install google toolchain

cd /home/ercin
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8 

3. Download Android image kitchen  and extract it to a folder. (/home/ercin/Downloads/AIK-Linux)

4. Download CrDroid rom and extract boot.img file

At the end you will have a Download folder  with folders and images like below: 



5. Edit kernel configuration file to include ch341 driver  (you need to find the defconfig file for your phone type, which is generally under /arch/arm/configs folder inside kernel folder)


6. Compile New Kernel
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=/home/ercin/Downloads/arm-eabi-4.8/arm-eabi-
cd /home/ercin/Downloads/elite-boeffla-kernel-lineage14.1-i9300-master/
make clean
make mrproper
make lineageos_i9300_defconfig
make -j$(nproc --all)
7.Now you have the kernel with name Zimage under arch/arm/boot folder: 
/home/ercin/downloads/elite-boeffla-kernel-lineage14.1-i9300-master/arch/arm/boot/Zimage
8. Unpack boot.img (taken from crdroid zip file) and change old kernel with newly compiled one. 

cd /home/ercin/Downloads/AIK-Linux/
./unpackimg.sh /home/ercin/Downloads/boot.img 
cd /home/ercin/Downloads/AIK-Linux/split_img/
rm boot.img-zImage
cp  /home/ercin/downloads/elite-boeffla-kernel-lineage14.1-i9300-master/arch/arm/boot/Zimage boot.img-zImage
cd /home/ercin/Downloads/AIK-Linux/
./repackimg.sh 

Now you have image-new.img file under folder /home/ercin/Downloads/AIK-Linux

8. Install image-new.img file to phone boot section using TWRP

2 comments:

Honor said...

I just have to add only command in kernel then compile?

Erçin TORUN said...

Hello Honor,

Basically yes, if the kernel you are using has already ch341 but not enabled, the only thing you need to is enabling it. If it does not have it, you need to find another kernel compatible with your device that has ch341 driver inside.

If you can't compile it or can't find a suitable kernel, there is an alternative way. You can install octo4a, which installs custom a ch34x driver. and you need to mount the serial pipe of the octo4a (you can check that part from: https://github.com/d4rk50ul1/klipper-on-android)