首页 > 嵌入式/内核开发 > 嵌入式/内核开发 > i.MX8MP开发板移植驱动全过程
forlinx@ubuntu:~$ cd /home/forlinx/work/OK8MP-linux-sdk/OK8MP-linux-kernel/driversforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$mkdir hello
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$ cd helloforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ vi hello.c
#include <linux/init.h>#include <linux/module.h>static int hello_init(void){printk(KERN_ALERT "Hello world\n");return 0;}static void hello_exit(void){printk(KERN_ALERT "Goodbye world\n");}module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("Dual BSD/GPL");
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ vi Kconfig
config HAVE_HELLOtristate "hello driver"helpThis hello driver is just to show how to develop driver process.This driver can also be built as a module. If so, the module will be called .default y#endmenu
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ vi Kconfig
obj-$(CONFIG_HAVE_HELLO) += hello.o
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ chmod 777 hello.cforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ chmod 777 Kconfigforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ chmod 777 Makefile
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ cd ..forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$ vi Kconfig
source "drivers/counter/Kconfig"source "drivers/mxc/Kconfig"source "drivers/hello/Kconfig" //在endmenu前添加hello文件夹的配置文件解析endmenu
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$ vi Makefile
obj-$(CONFIG_COUNTER) += counter/obj-y += mxc/obj-$(CONFIG_HAVE_HELLO) += hello/ //在Makefile最后加入这一句
forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/$ ls drivers/hellohello.c hello.ko hello.mod hello.mod.c hello.mod.o hello.o Kconfig Makefile modules.order
root@OK8MP:~# cd /run/media/sda1/ //进入U盘的路径下root@OK8MP:/run/media/sda1# insmod hello.ko //挂载hello.ko[ 138.679964] Hello world //挂载驱动打印信息root@OK8MP:/run/media/sda1# rmmod hello.ko //卸载hello.ko[ 142.022115] Goodbye world //卸载驱动打印信息root@OK8MP:/run/media/sda1#
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69989353/viewspace-2921866/ ,如需转载,请注明出处,否则将追究法律责任。