九鼎创展论坛中文版English
登录 | 立即注册 设为首页收藏本站 切换到宽版
查看: 1375|回复: 0
打印 上一主题 下一主题

添加新的内核驱动模块报错等问题

[复制链接]
跳转到指定楼层
楼主
发表于 2021-11-16 13:42:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
第一个问题:
Android8
目的:以模块的形式添加新的驱动。
新的内核文件:makefile  up.c
描述:添加一个新的内核驱动模块  发现makefile报错 报错信息如下:
root@work00:/px30/source/px30_android8_20210926/code# make
make -C /px30/source/px30_android8_20210926/px30_oreo M=/px30/source/px30_android8_20210926/code modules
make[1]: Entering directory '/px30/source/px30_android8_20210926/px30_oreo'
build/core/product_config.mk:227: *** Can not locate config makefile for product "rk3326".  Stop.
09:52:14 Error dumping make vars: exit status 2
build/core/main.mk:21: recipe for target 'run_soong_ui' failed
make[1]: *** [run_soong_ui] Error 1
make[1]: Leaving directory '/px30/source/px30_android8_20210926/px30_oreo'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2

makefile:
obj-m := up.o
        PWD := $(shell pwd)
        KERNELDIR := /px30/source/px30_android8_20210926/px30_oreo
all:
        make -C $(KERNELDIR) M=$(PWD) modules

.PHONY: clean
clean:
        rm -rf *.o *~ core *.ko *.mod.c modules.order Module.symvers
up.c
很简单没报错。

第二个问题:
Android8
目的:以内核源码的形式添加一个新的驱动
文件:up.c makefile
描述:在kernel/drivers目录中添加uplooking文件夹,将上诉两个文件添加进去。 编译后没报错 在开机中能看到up.c中XXX_init函数打印出来的信息。烧录进去后在设备中/dev中没有查看到设备号。  但是在cat proc/devices中能看到新驱动的设备号。在sys/各个目录中也没有查到。请问一下这个怎么回事?

kernel/drivers/uplooking/makefile:
obj-y = up.o
在kernel/drivers/makefile 也添加了。



这是up.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/ide.h>
#include <linux/cdev.h>
#include <linux/device.h>

static int chrtest_open(struct inode *inode, struct file *filp);
static ssize_t chrtest_read(struct file *filp, char __user *buf,size_t cnt, loff_t *offt);
static ssize_t chrtest_write(struct file *filp,const char __user *buf,size_t cnt, loff_t *offt);
static int chrtest_release(struct inode *inode, struct file *filp);

/* uplooking设备结构体 */
struct uplooking_dev{
        dev_t devid;                        /* 设备号          */
        struct cdev cdev;                /* cdev         */
        struct class *class;        /* 类                 */
        struct device *device;        /* 设备          */
        int major;                                /* 主设备号          */
        int minor;                                /* 次设备号   */
        struct device_node        *nd; /* 设备节点 */
        int uplooking_gpio;                        /* beep所使用的GPIO编号                */
};

struct uplooking_dev uplooking;                /* beep设备 */

static struct file_operations test_fops = {
.owner = THIS_MODULE,
.open = chrtest_open,
.read = chrtest_read,
.write = chrtest_write,
.release = chrtest_release,
};
static int chrtest_open(struct inode *inode, struct file *filp)
{
/* 用户实现具体功能 */
printk("uplookinglooking open\n");
return 0;
}

/* 从设备读取 */
static ssize_t chrtest_read(struct file *filp, char __user *buf,size_t cnt, loff_t *offt)
{
/* 用户实现具体功能 */
printk("uplookinglooking read\n");
return 0;
}
/* 向设备写数据 */
static ssize_t chrtest_write(struct file *filp,const char __user *buf,size_t cnt, loff_t *offt)
{
/* 用户实现具体功能 */
printk("uplookinglooking write\n");
return 0;
}
/* 关闭/释放设备 */
static int chrtest_release(struct inode *inode, struct file *filp)
{
/* 用户实现具体功能 */
printk("uplookinglooking release\n");
return 0;
}



static __init int test_init(void)
{
        int i=0;
        int retvalue = 0;
        for(i=0;i<10;i++)
        {
        printk("hello uplookinglooking\n");
        }
/* 注册字符设备驱动 */
retvalue = register_chrdev(232, "uplookinglooking", &test_fops);
if(retvalue < 0){
/* 字符设备注册失败,自行处理 */
     printk("uplookinglooking err!!!!\n");
}
uplooking.cdev.owner = THIS_MODULE;
cdev_init(&uplooking.cdev, &test_fops);


cdev_add(&uplooking.cdev, 232, 1);

uplooking.class = class_create(THIS_MODULE, "uplookinglooking");
        if (IS_ERR(uplooking.class)) {
                 printk("uplooking.class err!!!!\n");
                return PTR_ERR(uplooking.class);
        }

uplooking.device = device_create(uplooking.class, NULL, 232, NULL, "uplookinglooking");
        if (IS_ERR(uplooking.device)) {
                printk("uplooking.device err!!!!\n");
                return PTR_ERR(uplooking.device);
        }
return 0;
}
static __exit int test_exit(void)
{
        unregister_chrdev(232, "uplookinglooking");

        return 0;
}

module_init(test_init);
module_init(test_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("zhangcheng");
MODULE_DESCRIPTION("This is the first driver.");

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳市九鼎创展科技官方论坛 ( 粤ICP备11028681号-2  

GMT+8, 2024-4-20 15:15 , Processed in 0.016979 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表