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  

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值