Using ARM64 cross-compile linux kernel for x86_64
contributed by < Eric Lin >
Environment
Host
- OS: ubuntu 20.04
- Arch: arm64
Target
- OS: Linux 5.10.198
- Arch: x86_64
Install dependency
Get Linix Kernel Source Code
Download archive
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/snapshot/linux-5.10.198.tar.gz
Get Busybox for building minimal file system
Download
https://busybox.net/downloads/busybox-1.32.0.tar.bz2
Config settings
Enable building static binary
A folder called _install
will be created under busybox root folder, copy it to linux-5.10.198
Copy the following context to rcS:
Change rcS permissions
Go to _install/etc
Copy following context to fstab:
Under the same path (_install/etc
):
Copy following context to inittab:
Go to _install/dev
Create initramfs file
Pack everything up as a ramdisk image. Make sure you’re inside _install
directory before running the following command:
There should be a new file initramfs_x86.cpio.gz
in your home directory.
Compile Linux Kernel
Edit defconfig
Add the following contexts in it:
Creat a specific directory for building
Build Linux Kernel
Run Linux kernel on QEMU
Troubleshooting
(.text+0x0): multiple definition of yylloc; dtc-lexer.lex.o (symbol from plugin):(.text+0x0): first defined here`
https://review.lineageos.org/c/LineageOS/android_kernel_oneplus_sm8150/+/273023/1/scripts/dtc/dtc-lexer.lex.c_shipped
scripts/selinux/mdp/mdp.c:49: ../security/selinux/include/classmap.h:251:2: error: #error New address family defined, please update secclass_map.
https://blog.csdn.net/zhangpengfei991023/article/details/109672491
fatal error: openssl/bio.h: No such file or directory
https://stackoverflow.com/questions/59016911/fatal-error-openssl-bio-h-no-such-file-or-directory
error: ‘-mindirect-branch’ and ‘-fcf-protection’ are not compatible
- change gcc version to gcc-8