写一个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

驱动加载和卸载成功

相关推荐
goxingman32 分钟前
在 Linux 中查看磁盘运行占用(I/O 使用率)
linux·运维·chrome
STCNXPARM32 分钟前
Linux camera之Media子系统
linux·camera·v4l2·media子系统
小天源33 分钟前
XShell一台控制多台操作详情
linux·运维·服务器
xu_yule34 分钟前
网络和Linux网络-13(高级IO+多路转接)五种IO模型+select编程
linux·网络·c++·select·i/o
夜流冰1 小时前
编程参考 - Linux kernel代码查看
linux·运维·服务器
xu_yule1 小时前
网络和Linux网络-14(IO多路转接)poll和epoll编程-服务器
linux·运维·服务器·epoll·poll
timi先生1 小时前
全新的linux如何进行远程xshell操作?
linux·运维·服务器
陌上花开缓缓归以1 小时前
OPENWRT 端口link问题
linux·arm开发
Coder个人博客1 小时前
Linux6.19-ARM64 mm ioremap子模块深入分析
linux·安全·车载系统·系统架构·系统安全·鸿蒙系统·安全架构
程序员一点1 小时前
第4章:Linux 文件系统结构与路径管理
linux·运维·服务器