mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-21 03:43:38 +08:00
kernel debug tools...
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for the LDD-LinuxDeviceDrivers.
|
||||
#
|
||||
# Author: gatieme
|
||||
# Create: 2016-07-29 15:50:46
|
||||
# Last modified: 2016-07-29 16:10:29
|
||||
# Description:
|
||||
# This program is loaded as a kernel(v2.6.18 or later) module.
|
||||
# Use "make install" to load it into kernel.
|
||||
# Use "make remove" to remove the module out of kernel.
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
ROOT=..
|
||||
#PLATFORM=$(shell $(ROOT)/systype.sh)
|
||||
#include $(ROOT)/Make.defines.$(PLATFORM)
|
||||
|
||||
# my driver description
|
||||
DRIVER_VERSION := "1.0.0"
|
||||
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
|
||||
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
|
||||
DRIVER_LICENSE := "Dual BSD/GPL"
|
||||
|
||||
|
||||
MODULE_NAME := my_debugfs
|
||||
MODCFLAGS:=-O6 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99
|
||||
|
||||
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
#CFG_FLAGS += -O2 -I./
|
||||
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
|
||||
|
||||
|
||||
|
||||
obj-m := $(MODULE_NAME).o #print_vmarea.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
modules:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
modules_install:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules_install
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
reinsmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
sudo insmod $(MODULE_NAME).ko
|
||||
|
||||
github:
|
||||
cd $(ROOT) && make github
|
||||
|
||||
rmmod:
|
||||
sudo rmmod $(MODULE_NAME)
|
||||
|
||||
test :
|
||||
cat /sys/kernel/debug/mydebug/a
|
||||
cat /sys/kernel/debug/mydebug/b
|
||||
cat /sys/kernel/debug/mydebug/subdir/c
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
rm -f modules.order Module.symvers Module.markers
|
||||
|
||||
.PHNOY:
|
||||
modules modules_install clean
|
||||
|
||||
|
||||
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
// http://files.cnblogs.com/wwang/debugfs.zip
|
||||
|
||||
struct dentry *my_debugfs_root;
|
||||
|
||||
u8 a = 0;
|
||||
char hello[32] = "Hello world!\n";
|
||||
struct debugfs_blob_wrapper b;
|
||||
|
||||
static int c_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
filp->private_data = inode->i_private;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t c_read(struct file *filp, char __user *buffer,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
if (*ppos >= 32)
|
||||
return 0;
|
||||
if (*ppos + count > 32)
|
||||
count = 32 - *ppos;
|
||||
|
||||
if (copy_to_user(buffer, hello + *ppos, count))
|
||||
return -EFAULT;
|
||||
|
||||
*ppos += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t c_write(struct file *filp, const char __user *buffer,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
if (*ppos >= 32)
|
||||
return 0;
|
||||
if (*ppos + count > 32)
|
||||
count = 32 - *ppos;
|
||||
|
||||
if (copy_from_user(hello + *ppos, buffer, count))
|
||||
return -EFAULT;
|
||||
|
||||
*ppos += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
struct file_operations c_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = c_open,
|
||||
.read = c_read,
|
||||
.write = c_write,
|
||||
};
|
||||
|
||||
static int __init mydebugfs_init(void)
|
||||
{
|
||||
struct dentry *sub_dir, *r_a, *r_b, *s_c;
|
||||
|
||||
printk(KERN_INFO "mydebugfs_init\n");
|
||||
|
||||
my_debugfs_root = debugfs_create_dir("gatieme_mydebug", NULL);
|
||||
if (!my_debugfs_root)
|
||||
return -ENOENT;
|
||||
|
||||
r_a = debugfs_create_u8("a", 0644, my_debugfs_root, &a);
|
||||
if (!r_a)
|
||||
goto Fail;
|
||||
|
||||
b.data = (void *)hello;
|
||||
b.size = strlen(hello) + 1;
|
||||
r_b = debugfs_create_blob("b", 0644, my_debugfs_root, &b);
|
||||
if (!r_b)
|
||||
goto Fail;
|
||||
|
||||
sub_dir = debugfs_create_dir("subdir", my_debugfs_root);
|
||||
if (!sub_dir)
|
||||
goto Fail;
|
||||
|
||||
s_c = debugfs_create_file("c", 0644, sub_dir, NULL, &c_fops);
|
||||
if (!s_c)
|
||||
goto Fail;
|
||||
|
||||
return 0;
|
||||
|
||||
Fail:
|
||||
debugfs_remove_recursive(my_debugfs_root);
|
||||
my_debugfs_root = NULL;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static void __exit mydebugfs_exit(void)
|
||||
{
|
||||
printk(KERN_INFO "mydebugfs_exit\n");
|
||||
debugfs_remove_recursive(my_debugfs_root);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
module_init(mydebugfs_init);
|
||||
module_exit(mydebugfs_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
Reference in New Issue
Block a user