写一个rv1106的led驱动1-整体架构

创建工程文件夹

在sysdrv/drv_ko/创建led文件夹

修改Makefile

在led文件夹的同级Makefile添加上led文件夹

bash 复制代码
ifeq ($(SYSDRV_PARAM), )
	SYSDRV_PARAM:=../../Makefile.param
	include $(SYSDRV_PARAM)
endif

CURRENT_DIR := $(shell pwd)
M_OUT_DIR ?= ../out

MODULE_NAME := led

build_target := modules

all: $(build_target)
	@echo "build $(MODULE_NAME) done"

.PHONY: modules clean

$(MODULE_NAME)-objs := led.o
obj-m := $(MODULE_NAME).o

modules:
	$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL_DIR) M=$(shell pwd) $@ -j12
	cp $(shell pwd)/led.ko $(M_OUT_DIR)
	@rm -rf *.o *~ .depend .*.cmd  *.mod.c .tmp_versions *.symvers modules.order *.mod

clean:
	@rm -rf *.o *~ .depend .*.cmd  *.mod.c .tmp_versions *.ko *.symvers modules.order *.mod

创建源文件led.c

c 复制代码
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/clk.h>
#include <linux/pwm.h>
#include <linux/file.h>
#include <linux/list.h>
#include <linux/gpio.h>
#include <linux/time.h>
#include <linux/hrtimer.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/debugfs.h>
#include <linux/kthread.h>
#include <linux/mempolicy.h>
#include <linux/miscdevice.h>
#include <linux/interrupt.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/module.h>





static int led_probe(struct platform_device *pdev)
{


	printk("%s enter\n", __func__);


	printk("%s leave\n", __func__);
	return 0;
}

static int led_remove(struct platform_device *pdev)
{
	printk("led_remove\n");
	return 0;
}

struct of_device_id of_match_table = {
	.compatible = "led"
};

static struct platform_driver led_platform_driver = {
	.probe = led_probe,
	.remove = led_remove,
	.driver = {
		.name = "led",
		.owner = THIS_MODULE,
		.of_match_table = &of_match_table,
	}
};

static int __init led_init(void)
{
	int ret;
	ret = platform_driver_register(&led_platform_driver);
	return ret;
}

static void __exit led_exit(void)
{
	platform_driver_unregister(&led_platform_driver);
}

module_init(led_init);
module_exit(led_exit);

MODULE_LICENSE("GPL");

这个文件只是把整个架构做出来,没有什么功能。

修改dts

在根节点添加led节点

bash 复制代码
led: led{
		compatible = "led";
		status = "okay";
	};

编译

在sdk的根目录下,通过命令编译

bash 复制代码
./build.sh kernel
./build.sh driver

更新下位机的boot.img

测试

把sysdrv/drv_ko/out/led.ko 复制到下位机/oem/usr/ko文件夹中

bash 复制代码
insmod ./led.ko
rmmod led.ko

得到输出

bash 复制代码
[   97.620096] led_probe enter
[   97.620123] led_probe leave
[  149.878684] led_remove

驱动加载和卸载成功

相关推荐
A小辣椒1 天前
TShark:Wireshark CLI 功能
linux
A小辣椒1 天前
TShark:基础知识
linux
AlfredZhao1 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao2 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334662 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪2 天前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠3 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush43 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5203 天前
Linux 11 动态监控指令top
linux
不会C语言的男孩3 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言