Last active
January 30, 2025 09:56
-
-
Save ericdennisforever/34f32cb2a1b4fc90353e1a08e3d439a0 to your computer and use it in GitHub Desktop.
How to compile a Linux kernel module for Android Emulator(LDPLAYER/NOX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- LDPlayer ver 9.0.45(9) | |
Android version 9 | |
Kernel 4.4.146 #1 Thu Apr27 10:42:33 (ST 2023) | |
Build Number PQ3A 190705.003 release keys | |
$modinfo vboxsf.ko | |
vermagic: 4.4.146 SMP preempt mod_unload modversions | |
- To compile a linux kernel module: | |
git clone https://android.googlesource.com/kernel/goldfish/ -b android-goldfish-4.4-dev | |
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9 | |
cd x86_64-linux-android-4.9 | |
git checkout pie-b4s4-release | |
cd goldfish | |
export CROSS_COMPILE=x86_64-linux-android- | |
export ARCH=x86_64 | |
export PATH=$PATH:/path/to/x86_64-linux-android-4.9/bin | |
make x86_64_ranchu_defconfig | |
make menuconfig # enable overlayfs and namespaces support here | |
make -j8 | |
- hello.c | |
#include <linux/module.h> /* Needed by all modules */ | |
#include <linux/kernel.h> /* Needed for KERN_ALERT */ | |
#include<linux/init.h> | |
MODULE_LICENSE("GPL"); | |
MODULE_AUTHOR("dambo, 2023"); | |
MODULE_DESCRIPTION("Demo module"); | |
static int __init hello_start(void) | |
{ | |
printk("hello to the world from module"); | |
return 0; | |
} | |
static void __exit hello_end(void) | |
{ | |
printk("hello exit"); | |
} | |
module_init(hello_start); | |
module_exit(hello_end); | |
-Makefile | |
KDIR=~/Workspace/android-sdks/goldfish-4.4-dev/ | |
PWD := $(shell pwd) | |
obj-m += hello.o | |
CCPATH := ~/Workspace/android-sdks/x86_64-linux-android-4.9/bin/ | |
CCPATH_EXT := $(CCPATH)x86_64-linux-android- | |
ARCH=x86_64 | |
default: | |
make -C $(KDIR) CFLAGS_MODULE=-fno-pic ARCH=$(ARCH) CROSS_COMPILE=$(CCPATH_EXT) $(KERNEL_DIR) M=$(PWD) modules | |
clean: | |
make -C $(KERNEL_DIR) M=$(PWD) clean | |
- compile | |
$ make | |
- outputs | |
make -C ~/Workspace/android-sdks/goldfish-4.4-dev/ CFLAGS_MODULE=-fno-pic ARCH=x86_64 CROSS_COMPILE=~/Workspace/android-sdks/x86_64-linux-android-4.9/bin/x86_64-linux-android- M=/home/ubuntu/Workspace/android-sdks/custom_modules/hello modules | |
make[1]: Entering directory '/home/ubuntu/Workspace/android-sdks/goldfish-4.4-dev' | |
Building modules, stage 2. | |
MODPOST 1 modules | |
LD [M] /home/ubuntu/Workspace/android-sdks/custom_modules/hello/hello.ko | |
- adb shell | |
/data/local/tmp # modinfo hello.ko | |
modinfo hello.ko | |
filename: hello.ko | |
author: dambo, 2023 | |
license: GPL | |
depends: | |
vermagic: 4.4.302+ SMP preempt mod_unload modversions | |
- goldfish/Makefile | |
VERSION = 4 | |
PATCHLEVEL = 4 | |
SUBLEVEL = 146 | |
EXTRAVERSION = | |
make -j8 LOCALVERSION="" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi my friend :) i can't run hello on ld 9.0.45(9)
can u help me? and i can't undestand that u use git checkout pie-b4s4-release branch :)