Android
Turning an Old Android Phone into a Server (Redmi 4X [santoni])
Based on https://github.com/dreemurrs-embedded/arch-linux-santoni
Create img file
dd if=/dev/zero of=rootfs.img bs=1M count=2560
Format img file as ext4 filesystem
mkfs.ext4 rootfs.img
Mount img file
sudo mount rootfs.img /mnt/rootfs
Download Arch Linux ARM64 rootfs
wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
Extract rootfs
sudo bsdtar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C /mnt/rootfs
Install qemu-user-static
sudo pacman -S qemu-user-static
Setup DNS
sudo mv /mnt/rootfs/etc/resolv.conf /mnt/rootfs/etc/resolv.conf.ori
echo "nameserver 8.8.8.8" | sudo tee /mnt/rootfs/etc/resolv.conf
Copy qemu-user-static binary to the rootfs
sudo cp `which qemu-aarch64-static` /mnt/rootfs/sbin/
Mount dev, proc, and sys
sudo mount -o bind /dev /mnt/rootfs/dev
sudo mount -t proc proc /mnt/rootfs/proc
sudo mount -t sysfs sysfs /mnt/rootfs/sys
sudo mount -t devpts devpts /mnt/rootfs/dev/pts
Chroot to the rootfs
...Build Linux Kernel for Android Device
Download the Kernel Source Code
For example, kernel for Xiaomi Mi8937
git clone https://github.com/LineageOS/android_kernel_xiaomi_msm8937.git --depth=1
Install Cross Compiler
Arch Linux
sudo pacman -S aarch64-linux-gnu-gcc
Ubuntu
sudo apt install gcc-aarch64-linux-gnu
Compile the Kernel
Export the environment variable
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
Create the output folder
mkdir out
Locate the kernel defconfig for the device in arch/arm64/configs
, run
make O=out <defconfig>
Example for my device
make O=out vendor/msm8937-perf_defconfig
Or we can copy the defconfig file from outside kernel source code and put in the out directory
...