RK3399 驱动开发 _ 03 - Android8.1编译自己驱动到内核


前言

在Android系统开发中,经常需要编译自己的驱动到内核。
以helloworld为例,分为以下步骤:

  • 添加驱动文件
  • 关联上下级驱动编译文件
  • 重新编译内核

一、添加驱动文件

  1. 在/kernel/drivers/char/目录下,新建helloworld目录
  2. 在helloworld目录下新建helloworld.c文件:
#include <linux/module.h>
#include <linux/kernel.h> 
static int helloworld_init(void)        
{
    
    
	printk("helloworld_init\r\n");
	return 0;
}
static void helloworld_exit(void)    
{
    
    
	printk("helloworld_exit\r\n");
}

module_init(helloworld_init);    
module_exit(helloworld_exit); 
  1. 在helloworld目录下新建Kconfig文件:
config helloworld
        bool "hellworld support"
        default y
        help
                helloworld Kconfig
  1. 在helloworld目录下新建Makefile文件
obj-$(CONFIG_helloworld)        += helloworld.o 
  1. 编译内核kernel,观察.config文件,会出现:
    在这里插入图片描述

二、关联上下级驱动编译文件

  1. 在char目录下Kconfig文件里添加:
source "drivers/char/helloworld/Kconfig"
  1. 在char目录下Makefile文件里添加:
obj-$(CONFIG_helloworld)        += helloworld.o 

三、重新编译内核

make distclean
make ARCH=arm64 rockchip_defconfig -j8
make ARCH=arm64 rk3399-xxxx.img -j8  

猜你喜欢

转载自blog.csdn.net/chenkanuo/article/details/130576130