mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-23 13:13:40 +08:00
测试的proc_test驱动包括只读proc_entry, 只写proc_entry和可读写proc_entry...
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.ko
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/driver/hello/hello.o
|
||||
@@ -1,19 +1,78 @@
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := hello.o
|
||||
|
||||
else
|
||||
|
||||
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
KERNELDIR ?= /usr/src/linux-headers-3.14.0
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# 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 := hello
|
||||
|
||||
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 :
|
||||
sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
rm -f modules.order Module.symvers Module.markers
|
||||
|
||||
.PHNOY:
|
||||
modules modules_install clean
|
||||
|
||||
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -1,43 +1,76 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
/*
|
||||
* "Hello, world!" minimal kernel module - /proc version
|
||||
*
|
||||
* Valerie Henson <val@nmt.edu>
|
||||
*
|
||||
*/
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/proc_fs.h>
|
||||
|
||||
/*
|
||||
* print the module information
|
||||
* Write "Hello, world!" to the buffer passed through the /proc file.
|
||||
*/
|
||||
static void print_module(void)
|
||||
|
||||
static int
|
||||
hello_read_proc(char *buffer, char **start, off_t offset, int size, int *eof,
|
||||
void *data)
|
||||
{
|
||||
struct module *mod;
|
||||
char *hello_str = "Hello, world!\n";
|
||||
int len = strlen(hello_str); /* Don't include the null byte. */
|
||||
/*
|
||||
* We only support reading the whole string at once.
|
||||
*/
|
||||
if (size < len)
|
||||
return -EINVAL;
|
||||
/*
|
||||
* If file position is non-zero, then assume the string has
|
||||
* been read and indicate there is no more data to be read.
|
||||
*/
|
||||
if (offset != 0)
|
||||
return 0;
|
||||
/*
|
||||
* We know the buffer is big enough to hold the string.
|
||||
*/
|
||||
strcpy(buffer, hello_str);
|
||||
/*
|
||||
* Signal EOF.
|
||||
*/
|
||||
*eof = 1;
|
||||
|
||||
printk(KERN_ALERT "this module: %p==%p\n", &__this_module, THIS_MODULE);
|
||||
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state);
|
||||
printk(KERN_ALERT "module name: %s\n", THIS_MODULE->name);
|
||||
return len;
|
||||
|
||||
list_for_each_entry(mod, *(&THIS_MODULE->list.prev), list);
|
||||
printk(KERN_ALERT "module name: %s\n", mod->name);
|
||||
printk(KERN_ALERT "module state: %d\n", THIS_MODULE->state);
|
||||
}
|
||||
|
||||
|
||||
static int hello_init(void)
|
||||
static int __init
|
||||
hello_init(void)
|
||||
{
|
||||
print_module( );
|
||||
|
||||
printk(KERN_ALERT "run in cpu %d\n", get_cpu());
|
||||
|
||||
printk(KERN_ALERT "PAGE_OFFSET : 0x%lx, TASK_SIZE : 0x%lx", PAGE_OFFSET, TASK_SIZE);
|
||||
|
||||
/*
|
||||
* Create an entry in /proc named "hello_world" that calls
|
||||
* hello_read_proc() when the file is read.
|
||||
*/
|
||||
if (create_proc_read_entry("hello_world", 0, NULL, hello_read_proc,
|
||||
NULL) == 0) {
|
||||
printk(KERN_ERR
|
||||
"Unable to register \"Hello, world!\" proc file\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
module_init(hello_init);
|
||||
|
||||
|
||||
static void hello_exit(void)
|
||||
static void __exit
|
||||
hello_exit(void)
|
||||
{
|
||||
remove_proc_entry("hello_world", NULL);
|
||||
}
|
||||
|
||||
|
||||
module_init(hello_init);
|
||||
module_exit(hello_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Valerie Henson <val@nmt.edu>");
|
||||
MODULE_DESCRIPTION("\"Hello, world!\" minimal module");
|
||||
MODULE_VERSION("proc");
|
||||
Reference in New Issue
Block a user