linaro-swg / optee_android_manifest

Android manifest for building OP-TEE in AOSP
38 stars 34 forks source link

How to add a NW kernel driver module for AOSP+OPTEE? #13

Closed toddkuhreng closed 6 years ago

toddkuhreng commented 7 years ago

Hi @vchong

I added this line in kernel/linaro/hisilicon/drivers/Makefile:

   obj-$(CONFIG_FPGA)             += fpga/
   obj-$(CONFIG_TEE)              += tee/
 + obj-m                          += hello/

Added following in kernel/linaro/hisilicon/drivers/hello/Kconfig

config HELLO_APP
tristate "hello app for testing"
depends on ARM
default m
help
hello app

Added following in kernel/linaro/hisilicon/drivers/hello/Makefile obj-m +=hello.o

Added following in kernel/linaro/hisilicon/drivers/hello/hello.c

#include <linux/module.h>          
#include <linux/kernel.h>
#include <linux/init.h>           

static int __init enter(void)
{
     printk("hello app init");
     return 0;
}

static void __init escape(void)
{
        printk("hello app clean");
}

MODULE_VERSION("1.0");
MODULE_LICENSE("GPL");

module_init(enter);
module_exit(escape);

After compilation I only see following file in out/target/product/hikey/obj/kernel/drivers/hello: built-in.o

I can't findhello.ko or hello.o. How do I create a sample normal world hello.ko driver module in this AOSP+OPTEE repo?

vchong commented 7 years ago

depends on ARM

You're not activating your code/driver using the CONFIG_HELLO_APP flag atm? Regardless, for correctness sake, this should be ARM64.

obj-m +=hello.o

Not sure if this matters but just to be safe, have a space between "+" and "h".

I'm not really sure either but after that, try: make TARGET_BUILD_KERNEL=true BUILD_KERNEL_MODULES=true android_kernel_modules

toddkuhreng commented 7 years ago

Hi @vchong

So I just triedmake TARGET_BUILD_KERNEL=true BUILD_KERNEL_MODULES=true android_kernel_modules. It says make complete and nothing got compiled.

However,

make TARGET_BUILD_KERNEL=true BUILD_KERNEL_MODULES=true is compiling something now. This is gonna take a while now. Do you think that there is something wrong? (android_kernel_modules is not recognizing any modules?)

Now I added CONFIG_HELLO_APP=m to kernel/linaro/hisilicon/arch/arm64/configs/hikey_defconfig and changed: obj-m += hello.o toobj-$(CONFIG_HELLO_APP) += hello.o. depends on ARM to depends on ARM64 obj-m += hello/ to obj-$(CONFIG_HELLO_APP) += hello/

Then make TARGET_BUILD_KERNEL=true BUILD_KERNEL_MODULES=true Should work, isn't it?

Thank you,

toddkuhreng commented 7 years ago

Hi @vchong

I think I have to enable loadable modulesupport in the Hikey Android kernel too. Do you know how to enable it?

I tried to add CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y to linaro/hisilicon/arch/arm64/configs/hikey_defconfig. Is this the correct config file for hikey android kernel config file?

vchong commented 7 years ago

Everything looks ok to me in the 2 previous comments. Were you able to get it to work?

jbech-linaro commented 7 years ago

I'm a bit confused here, is the question how to create and compile a normal module in Linux (but using the kernel from Android)? If that is what you're asking for, then there must be tons of tutorials on the net already for that. https://hardikpatelblogs.wordpress.com/2010/11/19/8/ https://www.linuxvoice.com/be-a-kernel-hacker/ https://kernelnewbies.org/FAQ/LinuxKernelModuleCompile http://www.thegeekstuff.com/2013/07/write-linux-kernel-module/

What has this to do with OP-TEE?

zhengfish commented 6 years ago

https://abdullahyousafzaii.wordpress.com/2015/08/02/how-to-write-a-kernel-module-for-android/

vchong commented 6 years ago

@zhengfish Thanks!