안드로이드 와 디바이스 드라이버 적용 기법

  • Upload
    chon2010

  • View
    17.982

  • Download
    5

Embed Size (px)

DESCRIPTION

안드로이드 와 디바이스 드라이버 적용 기법

Citation preview

  • 1. 2010. 09

2. 3. 2.6.29 2.6.33 ? ? http://android.git.kernel.org/ 2.6.292.6.29 2.6.332.6.33 ?? ?? http://android.git.kernel.org/http://android.git.kernel.org/ 4. insmodinsmod module_init( fabase_init )module_init( fabase_init ) fabase_init()fabase_init() platform_driver_register(&fabase_driver) struct platform_driver fabase_driverstruct platform_driver fabase_driver .probe = fabase_probe .remove = fabase_remove .suspend = fabase_suspend .resume = fabase_resume .driver = { .name = FABASE_DEVICE_DRIVER_NAME, } platform_device_register_simple( FABASE_DEVICE_DRIVER_NAME fabase_probe()fabase_probe() 5. rmmodrmmod module_exit(fabase_exit)module_exit(fabase_exit) fabase_exit()fabase_exit() platform_device_unregister(fabase_device) struct platform_driver fabase_driverstruct platform_driver fabase_driver .probe = fabase_probe .remove = fabase_remove .suspend = fabase_suspend .resume = fabase_resume .driver = { .name = FABASE_DEVICE_DRIVER_NAME, } fabase_remove()fabase_remove() 6. struct platform_device *platform_device_register_simple ( const char *name, int id, struct resource *, unsigned int ); void platform_device_unregister( struct platform_device *pdev ); 7. int platform_device_register( struct platform_device * pdev ); void platform_device_del( struct platform_device *pdev ); 8. [root@falinux nfs]$ insmod fa_virtual.ko IORESOURCE_MEM 0 -> [10000000:1FFFFFFF] IORESOURCE_MEM 1 -> [20000000:2FFFFFFF] IORESOURCE_IRQ 0 -> [00000003:00000004] IORESOURCE_IRQ 1 -> [00000005:00000006] [root@falinux nfs]$ lsmod Module Size Used by Not tainted fa_virtual 2140 0 [root@falinux nfs]$ rmmod fa_virtual.ko 9. struct file_operations xxx_fop = { open : xxx_open, read : xxx_read, write : xxx_write, ioctl : xxx_ioctl, release : xxx_release }; xxx_exit( . . . ) { : } open( . . . ) read( . . . ) write( . . . ) ioctl( . . . ) close( . . . ) insmod rmmod Hardware interrupt xxx_init( . . . ) { : } xxx_interrupt( . . . ) { : } xxx_open( . . . ) { : } xxx_read( . . . ) { : } xxx_write( . . . ) { : } xxx_ioctl( . . . ) { : } xxx_release( . . . ) { : } 10. (1) JNI (1) JNI(1) JNI H/WH/W JAVA JAVA JNIJNI 11. (2) (2)(2) H/WH/W JAVA JAVA C C LOCAL NETWORK (127.0.0.1) TCP or UDP LOCAL NETWORK (127.0.0.1) TCP or UDP 12. NDK NDKNDK Java C/C++ JavaJava C/C++C/C++ 13. NDK NDKNDK Bionic LIBCBionic LIBCBionic LIBC BIONIC LIBCBIONIC LIBC GNU LIBCGNU LIBC Bionic LIBCBionic LIBC {ANDROID_SROUCE}/ bionic/libc/SYSCALLS.txt{ANDROID_SROUCE}/ bionic/libc/SYSCALLS.txt 14. NDK NDKNDK 15. NDK NDKNDK NDK $ mkdir arm-eabi-4.2.1 $ cd arm-eabi-4.2.1 $ cp a {NDK_DIR}/build/prebuilt/linux-x86/arm-eabi-4.2.1/* . $ cp a {NDK_DIR}/build/platform/android-5/arch-arm/usr/include ./arm-eabi/. $ cp a {NDK_DIR}/build/platform/android-5/arch-arm/usr/lib ./arm-eabi/. $ mkdir arm-eabi-4.2.1 $ cd arm-eabi-4.2.1 $ cp a {NDK_DIR}/build/prebuilt/linux-x86/arm-eabi-4.2.1/* . $ cp a {NDK_DIR}/build/platform/android-5/arch-arm/usr/include ./arm-eabi/. $ cp a {NDK_DIR}/build/platform/android-5/arch-arm/usr/lib ./arm-eabi/. Get Android toolchain from NDKGet Android toolchain from NDK 16. NDK NDKNDK NDK 17. C CC service mydemon /usr/bin/mydemon oneshot service mydemon /usr/bin/mydemon oneshot Android demon script sample init.rcAndroid demon script sample init.rc 18. JNI JNIJNI Build the Hello-JNI $ cd {NDK_DIR}/samples/hello-jni $ {NDK_DIR}/ndk-build $ cd {NDK_DIR}/samples/hello-jni $ {NDK_DIR}/ndk-build Change directory to hello-jni in NDKChange directory to hello-jni in NDK $ cd ~/project/android-ndk-r4//samples/hello-jni $ ~/project/android-ndk-r4/ndk-build Gdbserver : [arm-eabi-4.4.0] /home/hyowon/project/android-ndk-r4/samples/hello- jni/libs/armeabi/gdbserver Gdbsetup : /home/hyowon/project/android-ndk-r4/samples/hello-jni/libs/armeabi/gdb.setup Gdbsetup : + source directory /home/hyowon/project/android-ndk-r4/samples/hello-jni/jni Compile thumb : hello-jni /home/hyowon/project/android-ndk-r4/samples/hello- jni/libs/armeabi $ cd ~/project/android-ndk-r4//samples/hello-jni $ ~/project/android-ndk-r4/ndk-build Gdbserver : [arm-eabi-4.4.0] /home/hyowon/project/android-ndk-r4/samples/hello- jni/libs/armeabi/gdbserver Gdbsetup : /home/hyowon/project/android-ndk-r4/samples/hello-jni/libs/armeabi/gdb.setup Gdbsetup : + source directory /home/hyowon/project/android-ndk-r4/samples/hello-jni/jni Compile thumb : hello-jni /home/hyowon/project/android-ndk-r4/samples/hello- jni/libs/armeabi Succeed message from NDKSucceed message from NDK 19. JNI JNIJNI Hello-JNI Create project from existing sourceCreate project from existing source Project TreeProject Tree 20. JNI JNIJNI Hello-JNI Screenshot of Hello-JNI sampleScreenshot of Hello-JNI sample 21. JNI JNIJNI hello-jni.c #include #include /* HelloJni.java JNI */ jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject this ) { return (*env)->NewStringUTF(env, "Hello from JNI !"); } #include #include /* HelloJni.java JNI */ jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject this ) { return (*env)->NewStringUTF(env, "Hello from JNI !"); } 22. JNI JNIJNI HelloJni.java package com.example.hellojni; import android.app.Activity; import android.widget.TextView; import android.os.Bundle; public class HelloJni extends Activity { /* */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* TextView . stringFromJNI() JNI . */ TextView tv = new TextView(this); tv.setText( stringFromJNI() ); setContentView(tv); } /* 'hello-jni' . */ public native String stringFromJNI(); public native String unimplementedStringFromJNI(); /* hello-jni . */ static { System.loadLibrary("hello-jni"); } } package com.example.hellojni; import android.app.Activity; import android.widget.TextView; import android.os.Bundle; public class HelloJni extends Activity { /* */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* TextView . stringFromJNI() JNI . */ TextView tv = new TextView(this); tv.setText( stringFromJNI() ); setContentView(tv); } /* 'hello-jni' . */ public native String stringFromJNI(); public native String unimplementedStringFromJNI(); /* hello-jni . */ static { System.loadLibrary("hello-jni"); } } 23. Binder - IPC ashmem - Android shared memory pmem - Process memory allocator logger - system logging facilit wakelock - used for power management oom handling - lowmem notifications alarm paranoid network security timed gpio - Generic gpio is a mechanism to allow programs to access and manipulate gpio registers from user space RAM_CONSOLE http://elinux.org/Android_Kernel_Features#Important_update BinderBinder -- IPCIPC ashmemashmem -- Android shared memoryAndroid shared memory pmempmem -- Process memory allocatorProcess memory allocator loggerlogger -- system logging facilitsystem logging facilit wakelockwakelock -- used for power managementused for power management oom handlingoom handling -- lowmem notificationslowmem notifications alarmalarm paranoid network securityparanoid network security timed gpiotimed gpio -- Generic gpio is a mechanismGeneric gpio is a mechanism to allow programs to access andto allow programs to access and manipulate gpio registers frommanipulate gpio registers from user spaceuser space RAM_CONSOLERAM_CONSOLE http://elinux.org/Android_Kernel_Features#Important_updatehttp://elinux.org/Android_Kernel_Features#Important_update 24. Binder drivers/android/binder.c include/linux/binder.h drivers/android/binder.cdrivers/android/binder.c include/linux/binder.hinclude/linux/binder.h 25. ashmem mm/ashmem.c ioctl * ASHMEM_SET_NAME * ASHMEM_GET_NAME * ASHMEM_SET_SIZE * ASHMEM_GET_SIZE * ASHMEM_SET_PROT_MASK * ASHMEM_GET_PROT_MASK * ASHMEM_PIN * ASHMEM_UNPIN * ASHMEM_GET_PIN_STATUS * ASHMEM_PURGE_ALL_CACHES mm/ashmem.cmm/ashmem.c ioctlioctl * ASHMEM_SET_NAME* ASHMEM_SET_NAME * ASHMEM_GET_NAME* ASHMEM_GET_NAME * ASHMEM_SET_SIZE* ASHMEM_SET_SIZE * ASHMEM_GET_SIZE* ASHMEM_GET_SIZE * ASHMEM_SET_PROT_MASK* ASHMEM_SET_PROT_MASK * ASHMEM_GET_PROT_MASK* ASHMEM_GET_PROT_MASK * ASHMEM_PIN* ASHMEM_PIN * ASHMEM_UNPIN* ASHMEM_UNPIN * ASHMEM_GET_PIN_STATUS* ASHMEM_GET_PIN_STATUS * ASHMEM_PURGE_ALL_CACHES* ASHMEM_PURGE_ALL_CACHES 26. pmem large (1-16+MB) physically contiguousregions of memory shared between userspace and kernel drivers drivers/misc/pmem.c include/linux/android_pmem.h large (1large (1--16+MB) physically16+MB) physically contiguousregions of memorycontiguousregions of memory shared between userspace andshared between userspace and kernel driverskernel drivers drivers/misc/pmem.cdrivers/misc/pmem.c include/linux/android_pmem.hinclude/linux/android_pmem.h 27. logger drivers/android/logging.c 'logcat' command drivers/android/logging.cdrivers/android/logging.c 'logcat' command'logcat' command 28. wakelock drivers/android/power.c ioctl * WAKE_LOCK_IDLE * WAKE_LOCK_SUSPEND drivers/android/power.cdrivers/android/power.c ioctlioctl * WAKE_LOCK_IDLE* WAKE_LOCK_IDLE * WAKE_LOCK_SUSPEND* WAKE_LOCK_SUSPEND 29. oom handling drivers/misc/lowmemorykiller.c security/lowmem.c drivers/misc/lowmemorykiller.cdrivers/misc/lowmemorykiller.c security/lowmem.csecurity/lowmem.c 30. 31. - . . , , . . 32. - User Level User Level /LCD /LCD /LCD /LCD /dev/fb0 : /dev/fb0 : ioctl open Cable I/F mmap VFS memory direct access BUS I/F () : : 33. FBIOGET_VSCREENINFO - struct fb_var_screeninfo FBIOPUT_VSCREENINFO - struct fb_var_screeninfo , , FBIOGET_FSCREENINFO - struct fb_fix_screeninfo FBIOGETCMAP - struct fb_cmap_user FBIOPUTCMAP - struct fb_cmap_user IOCTL 34. - ioctlioctl FBIOPUT_VSCREENINFO - struct fb_var_screeninfoFBIOPUT_VSCREENINFO - struct fb_var_screeninfo int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) ret = info->fbops->fb_check_var(var, info); info->fbops->fb_set_par(info); fb_pan_display(info, &info->var); Int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)Int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var) err = info->fbops->fb_pan_display(var, info) 35. (kbd) (mousedev, mic) (joydev) (tsdev) (evdev) 36. input Kbd mousedev, mice joydev tsdev evdev touch screen device driver keyboard device driver mouse device driver keyboard api mouse api Joystick api toutch screen api event api application Kernel 2.6.24 tsdev linux/driver/char/keyboard.c 37. INPUT : linux/include/linux/input.h static inline void init_input_dev(struct input_dev *dev); dev . void input_register_device(struct input_dev *); . void input_unregister_device(struct input_dev *); . void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value); . static inline void input_report_key(struct input_dev *dev, unsigned int code, int value); input_event . 38. static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value); input_event . static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value); input_event . static inline void input_sync(struct input_dev *dev); input_event . static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat); . 39. . ..