mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-25 14:53:35 +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");
|
||||
|
||||
@@ -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 := pcie_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,89 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/slab.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/seq_file.h>
|
||||
|
||||
// http://blog.csdn.net/wealoong/article/details/7992071
|
||||
|
||||
struct dentry *pcie_file = NULL;
|
||||
static int pcie0_linked = 1;
|
||||
|
||||
static int pcie_debugfs_read(struct seq_file *s, void *data)
|
||||
{
|
||||
seq_printf(s, "pcie0_link status : %s\n", pcie0_linked == 1 ? "Enable": "Disable");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pcie_single_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
//return single_open(file, pcie_reg_open, NULL);
|
||||
return single_open(file, pcie_debugfs_read, inode->i_private);
|
||||
}
|
||||
|
||||
static ssize_t pcie_debugfs_write(struct file *file,
|
||||
const char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buff[20];
|
||||
int iRet;
|
||||
|
||||
if(count <= 1)
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
memset(buff, '\0', sizeof(buff));
|
||||
if (copy_from_user(buff, userbuf, count))
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
printk("[%s, %d] : %s \n", __FUNCTION__, __LINE__, buff);
|
||||
|
||||
iRet = sscanf(buff, "%d", &pcie0_linked); // 将读出来的数据sPid赋值给模块的全局变量pid
|
||||
if(iRet != 1)
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
pcie0_linked = !!pcie0_linked;
|
||||
printk("[%s, %d] : pcie0_linked = %d\n", __FUNCTION__, __LINE__, pcie0_linked);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct file_operations pcie_ios_fops = {
|
||||
.open = pcie_single_open,
|
||||
.read = seq_read,
|
||||
.write = pcie_debugfs_write,
|
||||
.lseek = seq_lseek,
|
||||
.release = single_release,
|
||||
};
|
||||
|
||||
|
||||
static int __init pcie_debugfs_init(void)
|
||||
{
|
||||
pcie_file = debugfs_create_file("gatieme_debugfs_file3", 0644, NULL, NULL, &pcie_ios_fops);
|
||||
if(pcie_file == NULL)
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void __exit pcie_debugfs_exit(void)
|
||||
{
|
||||
printk(KERN_INFO "mydebugfs_exit\n");
|
||||
debugfs_remove_recursive(pcie_file);
|
||||
//debugfs_remove(pcie_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
module_init(pcie_debugfs_init);
|
||||
module_exit(pcie_debugfs_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
@@ -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,75 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/debugfs.h> /* this is for DebugFS libraries */
|
||||
#include <linux/fs.h>
|
||||
|
||||
// http://opensourceforu.com/2010/10/debugging-linux-kernel-with-debugfs/
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Surya Prabhakar <surya_prabhakar@dell.com>");
|
||||
MODULE_DESCRIPTION("sample code for DebugFS functionality");
|
||||
|
||||
#define len 200
|
||||
|
||||
u64 intvalue,hexvalue;
|
||||
struct dentry *dirret,*fileret,*u64int,*u64hex;
|
||||
char ker_buf[len];
|
||||
int filevalue;
|
||||
|
||||
|
||||
/* read file operation */
|
||||
static ssize_t myreader(struct file *fp,
|
||||
char __user *user_buffer,
|
||||
size_t count,
|
||||
loff_t *position)
|
||||
{
|
||||
return simple_read_from_buffer(user_buffer, count, position, ker_buf, len);
|
||||
}
|
||||
|
||||
/* write file operation */
|
||||
static ssize_t mywriter(struct file *fp, const char __user *user_buffer,
|
||||
size_t count, loff_t *position)
|
||||
{
|
||||
if(count > len)
|
||||
return -EINVAL;
|
||||
|
||||
return simple_write_to_buffer(ker_buf, len, position, user_buffer, count);
|
||||
}
|
||||
|
||||
static const struct file_operations fops_debug = {
|
||||
.read = myreader,
|
||||
.write = mywriter,
|
||||
};
|
||||
|
||||
static int __init init_debug(void)
|
||||
{
|
||||
/* create a directory by the name dell in /sys/kernel/debugfs */
|
||||
dirret = debugfs_create_dir("gatieme_mydebug", NULL);
|
||||
|
||||
/* create a file in the above directory
|
||||
This requires read and write file operations */
|
||||
fileret = debugfs_create_file("text", 0644, dirret, &filevalue, &fops_debug);
|
||||
|
||||
/* create a file which takes in a int(64) value */
|
||||
u64int = debugfs_create_u64("number", 0644, dirret, &intvalue);
|
||||
if (!u64int) {
|
||||
printk("error creating int file");
|
||||
return (-ENODEV);
|
||||
}
|
||||
/* takes a hex decimal value */
|
||||
u64hex = debugfs_create_x64("hexnum", 0644, dirret, &hexvalue );
|
||||
if (!u64hex) {
|
||||
printk("error creating hex file");
|
||||
return (-ENODEV);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
module_init(init_debug);
|
||||
|
||||
static void __exit exit_debug(void)
|
||||
{
|
||||
/* removing the directory recursively which
|
||||
in turn cleans all the file */
|
||||
debugfs_remove_recursive(dirret);
|
||||
}
|
||||
module_exit(exit_debug);
|
||||
@@ -0,0 +1,37 @@
|
||||
You-Get--基于Python3的开源网络视频下载工具
|
||||
=======
|
||||
|
||||
| CSDN | GitHub |
|
||||
|:----:|:------:|
|
||||
| [You-Get--基于Python3的开源网络视频下载工具](http://blog.csdn.net/gatieme/article/details/61623891) | [`AderXCoding/system/tools/you-get`](https://github.com/gatieme/AderXCoding/tree/master/system/tools/you-get) |
|
||||
|
||||
<br>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>
|
||||
本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a>进行许可, 转载请注明出处, 谢谢合作
|
||||
<br>
|
||||
|
||||
|
||||
[Linux内核里的DebugFS](http://www.cnblogs.com/wwang/archive/2011/01/17/1937609.html)
|
||||
|
||||
[Debugging the Linux Kernel with debugfs](http://opensourceforu.com/2010/10/debugging-linux-kernel-with-debugfs/)
|
||||
|
||||
[debugfs-seq_file](http://lxr.free-electrons.com/source/drivers/base/power/wakeup.c)
|
||||
|
||||
|
||||
[Linux Debugfs文件系统介绍及使用](http://blog.sina.com.cn/s/blog_40d2f1c80100p7u2.html)
|
||||
|
||||
[Linux 文件系统:procfs, sysfs, debugfs 用法简介](http://www.tinylab.org/show-the-usage-of-procfs-sysfs-debugfs/)
|
||||
|
||||
[用户空间与内核空间数据交换的方式(1)------debugfs](http://www.cnblogs.com/hoys/archive/2011/04/10/2011124.html)
|
||||
|
||||
|
||||
[Linux 运用debugfs调试方法](http://www.xuebuyuan.com/1023006.html)
|
||||
|
||||
|
||||
误删恢复
|
||||
----
|
||||
[linux 删除文件和目录与恢复详解](http://www.111cn.net/sys/linux/47629.htm)
|
||||
|
||||
<br>
|
||||
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>本作品采用<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a>进行许可, 转载请注明出处, 谢谢合作.
|
||||
Reference in New Issue
Block a user