I created 2 files: hello.c, Android.bp
This is code of Hello.c
// hello.c
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void) {
printk(KERN_INFO "Hello, kernel!\n");
return 0;
}
void cleanup_module(void) {
printk(KERN_INFO "Goodbye, kernel!\n");
}
This is code of Android.bp
cc_library {
name: "hello_kernel_module",
srcs: [
"hello.c",
],
arch: ["x86_64"],
}
Then I used mm to make file but it didn'n success.
I try alternative way by Makefile, but I think my Makefile is not true.
this is Makefile and Hello.c
Hello.c
//kernel/hello_module/hello.c
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
///< The license type -- this affects runtime behavior
MODULE_LICENSE("GPL");
///< The author -- visible when you use modinfo
MODULE_AUTHOR("ABC");
///< The description -- see modinfo
MODULE_DESCRIPTION("Hello World");
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);
This is Makefile
obj-m += hello.o
PWD := $(shell pwd)
CLANG := /opt/prebuilt-android-clang/clang-r450784e/bin
KERNEL := /home/ubuntu/android_build/out/target/product/evk_8mq/obj/KERNEL_OBJ
LD = /opt/prebuilt-android-clang/clang-r450784e/bin/ld.lld
all:
make LD=$(LD) ARCH=arm64 CC=$(CLANG) -C $(KERNEL) M=$(PWD) modules
clean:
make -C $(KERNEL) M=$(PWD) clean
When i used Makefile, i didn't know what is tool to compile, that's reason Makefile error.
The first, i want to compile Hello.c, with output have Hello.ko
Then I want insmod Hello.ko to kernel through adb. Can you help me?