android驱动代码测试...

This commit is contained in:
gatieme
2017-05-06 20:42:33 +08:00
parent 3e0edb0a7f
commit 1364b409e0
18 changed files with 1862 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
#direntorys
HELLO_DIR=hello
CPLD_DIR=cpld
FPGA_DIR=fpga
TEST_MODULE_DIR=test_module
DIRS=$(HELLO_DIR) $(CPLD_DIR) $(FPGA_DIR) $(TEST_MODULE_DIR)
SUBDIRS=$(DIRS)
.PHONY:all $(SUBDIRS)
all: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
@echo "=======BUILD $@ SUCCESS======="
#all :
# for i in $(DIRS); do \
# (cd $$i && echo "making $$i" && $(MAKE) ) || exit 1; \
# done
clean:
for i in $(DIRS); do \
(cd $$i && echo "cleaning $$i" && $(MAKE) clean) || exit 1; \
done
install :
for i in $(DIRS); do \
(cd $$i && echo "install $$i" && $(MAKE) install) || exit 1; \
done
@@ -0,0 +1,85 @@
# ------------------------------------------------------------------------------
#
# 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.
#
# ------------------------------------------------------------------------------
# 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 := ccpld
ifneq ($(KERNELRELEASE),)
#CFG_FLAGS += -O2 -I./
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
RESMAIN_CORE_OBJS := cpld.o
RESMAIN_GLUE_OBJS := slaveSerial.o
ccpld-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
obj-m := $(MODULE_NAME).o
else
CURRENT_PATH ?= $(shell pwd)
ifeq ($(ARCH),arm64)
LINUX_KERNEL_PATH ?= /home/rockchip/rk3399/Android/7.1/android/kernel
else
LINUX_KERNEL ?= $(shell uname -r)
LINUX_KERNEL_PATH ?= /lib/modules/$(LINUX_KERNEL)/build
endif
modules:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
modules_install:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) 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 $(LINUX_KERNEL_PATH) M=$(PWD) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
+209
View File
@@ -0,0 +1,209 @@
/*
CPLD test
byTX
2013.1.31:add cpld_ioctl
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/module.h>
//#include <linux/serial_core.h>
//for file opration
#include <linux/fs.h>
//for cdev create
#include <linux/cdev.h>
//#include <linux/gpio.h>
//#include <linux/clk.h>
//#include <linux/delay.h>
//#include <linux/usb/ch9.h>
//#include <linux/pwm_backlight.h>
//#include <linux/spi/spi.h>
//#include <linux/gpio_keys.h>
//copy_to_user
#include <linux/uaccess.h>
//class_create
#include <linux/device.h>
//#include <asm/mach/arch.h>
//#include <asm/mach/map.h>
//#include <asm/setup.h>
//#include <asm/mach-types.h>
//ioremap defined here
#include <asm/io.h>
#include "slaveSerial.h"
//#include <plat/s5pv210.h>
#include <linux/version.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Gatieme");
MODULE_DESCRIPTION("hello world");
static void __iomem *io_base;
struct cdev *cpld_cdev;
struct class *cpld_class;
dev_t devid;
static int cpld_open(struct inode *inode, struct file *file)
{
//可配置eint18,并复位cpld
printk("cpld open\n");
return 0;
}
//read ,do not change f_pos
ssize_t cpld_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
unsigned short int tmp;
#if DEBUG_PRINT
printk("f_pos=0x%x\n",*(unsigned int*)f_pos);
#endif
tmp=ioread16(io_base+(*f_pos));
#if DEBUG_PRINT
printk("cpld read =0x%x\n",tmp);
#endif
//return copy_to_user(buf,(char *)&tmp,sizeof(unsigned short int));
*(unsigned short int*)buf=tmp;
return 2;//always read 2bytes
}
//write ,do not change f_pos
ssize_t cpld_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
{
#if DEBUG_PRINT
printk("f_pos=0x%x count=%d\n",*(unsigned int*)f_pos,count);
#endif
if(count==2)
{
iowrite16(*(unsigned short int*)buf,io_base+(*f_pos));
#if DEBUG_PRINT
printk("write data=0x%x\n",*(unsigned short int*)buf);
#endif
return count;
}
/*
else if(count==FPGA_BURST_SIZE)//多字节连续写入
{
for(i=0;i<count;i++)
{
#if DEBUG_PRINT
printk("write data=0x%x,addr=0x%x\n",*(unsigned short int*)(buf+2*i),i*2);
#endif
iowrite16(*(unsigned short int*)(buf+2*i),io_base+i*2);
}
return count;
}
*/
else
return 0;
}
//set the offset
loff_t cpld_llseek (struct file *filp, loff_t offset, int whence)
{
loff_t new_pos;
if(offset>=0 && offset<CPLD_SIZE)
new_pos=offset;
else
new_pos=0;
#if DEBUG_PRINT
printk("set cpld offset to 0x%x\n",(unsigned int)new_pos);
#endif
filp->f_pos = new_pos;
return new_pos;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
static int cpld_ioctl(struct inode *indoe, struct file *file,
unsigned int cmd, unsigned long arg)
{
#else
//long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
//long (*compat_ioctl) (struct file *file, unsigned int cmd, unsigned long arg)
static long cpld_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
//struct inode *inode = file->f_dentry->d_inode;
struct inode *inode = inode = file_inode(file);
#endif
switch(cmd)
{
case CMD_START_SHIFT:
shiftWordOut((unsigned short int)arg,io_base);
break;
case CMD_START_PROG:
set_prog_b(io_base,0); //?????? 这函数功能-设置boot值,io_base+REG_PROG_B_OFFSET
set_prog_b(io_base,0);
set_prog_b(io_base,1);
break;
case CMD_CHECK_DONE:
return check_done(io_base); //这check_done在slaveSerial.c中,检查是否下载完成
case CMD_SET_LED:
iowrite16((arg>0)?SET_LED_ON:SET_LED_OFF, io_base+REG_LED_OFFSET);
break;
case CMD_SEND_LOW_BYTE:
shiftByteOut((char)arg,io_base);
break;
case CMD_SEND_HIGH_BYTE:
shiftByteOut((char)(arg>>8),io_base);
break;
case CMD_CHECK_INIT:
return get_init_bit(io_base);
break;
case CMD_SET_CONTROL:
iowrite16((unsigned short int)arg,io_base+REG_CONTROL_OFFSET); ///?????REG_CONTROL_OFFSET在哪里定义的?arg是要设置的值,第二个参数是地址
break;
case CMD_SET_DATA:
iowrite16((unsigned short int)arg,io_base+REG_DATA_OFFSET);
break;
default:
break;
}
return 0;
}
static struct file_operations cpld_fops = {
.owner = THIS_MODULE,
.open = cpld_open,
.read = cpld_read,
.write = cpld_write,
.llseek = cpld_llseek,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
.ioctl = cpld_ioctl,
#else
.compat_ioctl = cpld_compat_ioctl,
#endif
};
static int __init cpld_init(void)
{
//创建字符设备
cpld_cdev=cdev_alloc();
cdev_init(cpld_cdev, &cpld_fops);
cpld_cdev->owner = THIS_MODULE;
alloc_chrdev_region(&devid, 0, 1, "cpld");
cdev_add(cpld_cdev,devid,1);
cpld_class = class_create(THIS_MODULE,"cpld_class");
device_create(cpld_class, NULL, devid, NULL,"cpld");
//申请内存
io_base=ioremap(CPLD_BASE,CPLD_SIZE);
if(io_base==0)
printk("failed to ioremap cpld\n");
else
printk("cpld test reg.=0x%x\n",ioread16(io_base+REG_TEST_OFFSET));
printk("CPLD initialized.\n");
return 0;
}
static void __exit cpld_exit(void)
{
unregister_chrdev_region(devid,1);
device_destroy(cpld_class , devid);
class_destroy(cpld_class);
cdev_del(cpld_cdev);
iounmap(io_base);
printk("cpld exit\n");
}
module_init(cpld_init);
module_exit(cpld_exit);
@@ -0,0 +1,110 @@
/*
2013.1.31byTX
*/
#include <linux/kernel.h>␍#include <asm/io.h>
#include "slaveSerial.h"
/*
assert cclk when value>1
*/
void set_cclk(void *io_base,int value)
{
iowrite16((value>0)?1:0,io_base+REG_CCLK_OFFSET);
}
/*
assert din when value>0
*/
void set_din(void *io_base,int value)
{
iowrite16((value>0)?1:0,io_base+REG_DIN_OFFSET);
}
/*
assert prog_b when value>0
*/
void set_prog_b(void *io_base,int value)
{
iowrite16((value>0)?1:0,io_base+REG_PROG_B_OFFSET);
}
/*
*/
unsigned short int get_stat(void *io_base)
{
return ioread16(io_base+REG_STAT_OFFSET);
}
//返回pin状态
int get_done_bit(void *io_base)
{
return ((get_stat(io_base)& STAT_DONE_BIT)>0)?1:0;
}
//返回pin状态
int get_init_bit(void *io_base)
{
return ((get_stat(io_base)& STAT_INIT_BIT)>0)?1:0;
}
int check_done(void *io_base)
{
int i;
int done=0;
int init=1;
//check init first!!
if(0==get_init_bit(io_base))
{
printk("init=0,so failed\n");
return INFOR_DONE_FAILED;
}
while((done==0) && (init==1))
{
//Apply additional CCLK pulse until DONE=1
set_cclk(io_base,0);
set_cclk(io_base,1);
done=get_done_bit(io_base);
printk("done == 0x%x\n",(unsigned int)done);
init=get_init_bit(io_base);
}
if(done>0)
{
//printk("done=1, succeed!\n");
for(i=0;i<8;i++)
{
set_cclk(io_base,0);
set_cclk(io_base,1);
}
return INFOR_DONE_SUCCEED;
}
else
{
printk("failed!done=%d,init=%d\n",done, init);
return INFOR_DONE_FAILED;
}
}
void shiftWordOut(unsigned short int data, void *io_base)
{
int i;
//low byte
for(i=0;i<8;i=i+1)␍ {
set_cclk(io_base,0);//set cclk low
set_din(io_base,(data&(0x0080>>i))?1:0);
set_cclk(io_base,1);//set cclk high
}
//high byte
for(i=0;i<8;i=i+1)
{
set_cclk(io_base,0);//set cclk low
set_din(io_base,(data&(0x8000>>i))?1:0);
set_cclk(io_base,1);//set cclk high
}
}
void shiftByteOut(char data, void *io_base)
{
int i;
for(i=0;i<8;i=i+1)␍ {
set_cclk(io_base,0);//set cclk low
set_din(io_base,(data&(0x80>>i))?1:0);
set_cclk(io_base,1);//set cclk high
}
}
@@ -0,0 +1,109 @@
/*
2013.1.31byTX
*/
#include <linux/kernel.h>␍#include <asm/io.h>
#include "slaveSerial.h"
/*
assert cclk when value>1
*/
void set_cclk(void *io_base,int value)
{
iowrite16((value>0)?1:0,io_base+REG_CCLK_OFFSET);
}
/*
assert din when value>0
*/
void set_din(void *io_base,int value)
{
iowrite16((value>0)?1:0,io_base+REG_DIN_OFFSET);
}
/*
assert prog_b when value>0
*/
void set_prog_b(void *io_base,int value)
{
iowrite16((value>0)?1:0,io_base+REG_PROG_B_OFFSET);
}
/*
*/
unsigned short int get_stat(void *io_base)
{
return ioread16(io_base+REG_STAT_OFFSET);
}
//返回pin状态
int get_done_bit(void *io_base)
{
return ((get_stat(io_base)& STAT_DONE_BIT)>0)?1:0;
}
//返回pin状态
int get_init_bit(void *io_base)
{
return ((get_stat(io_base)& STAT_INIT_BIT)>0)?1:0;
}
int check_done(void *io_base)
{
int i;
int done=0;
int init=1;
//check init first!!
if(0==get_init_bit(io_base))
{
printk("init=0,so failed\n");
return INFOR_DONE_FAILED;
}
while((done==0) && (init==1))
{
//Apply additional CCLK pulse until DONE=1
set_cclk(io_base,0);
set_cclk(io_base,1);
done=get_done_bit(io_base);
init=get_init_bit(io_base);
}
if(done>0)
{
//printk("done=1, succeed!\n");
for(i=0;i<8;i++)
{
set_cclk(io_base,0);
set_cclk(io_base,1);
}
return INFOR_DONE_SUCCEED;
}
else
{
printk("failed!done=%d,init=%d\n",done, init);
return INFOR_DONE_FAILED;
}
}
void shiftWordOut(unsigned short int data, void *io_base)
{
int i;
//low byte
for(i=0;i<8;i=i+1)␍ {
set_cclk(io_base,0);//set cclk low
set_din(io_base,(data&(0x0080>>i))?1:0);
set_cclk(io_base,1);//set cclk high
}
//high byte
for(i=0;i<8;i=i+1)
{
set_cclk(io_base,0);//set cclk low
set_din(io_base,(data&(0x8000>>i))?1:0);
set_cclk(io_base,1);//set cclk high
}
}
void shiftByteOut(char data, void *io_base)
{
int i;
for(i=0;i<8;i=i+1)␍ {
set_cclk(io_base,0);//set cclk low
set_din(io_base,(data&(0x80>>i))?1:0);
set_cclk(io_base,1);//set cclk high
}
}
@@ -0,0 +1,50 @@
/*
create 2013.1.31byTX
*/
#define CPLD_SIZE 256
#define CPLD_BASE 0x80000000
#define REG_TEST_OFFSET 0
#define REG_CCLK_OFFSET 0x2
#define REG_PROG_B_OFFSET 0x4
#define REG_DIN_OFFSET 0x6
#define REG_STAT_OFFSET 0x8
#define STAT_DONE_BIT 0x2
#define STAT_INIT_BIT 0x1
#define REG_LED_OFFSET 0xa
#define REG_CONTROL_OFFSET 0xc
#define REG_DATA_OFFSET 0x20
#define REG_FPGA_BURST_OFFSET 0x20
#define FPGA_BURST_SIZE 0x10 //words
#define INFOR_DONE_SUCCEED 0
#define INFOR_DONE_FAILED 1
#define INFOR_INIT_SUCCEED 1 //new,diff as done
#define INFOR_INIT_FAILED 0 //new
#define DEBUG_PRINT 0
#define CMD_START_PROG 0x10
#define CMD_START_SHIFT 0x11
#define CMD_CHECK_DONE 0x12
#define CMD_SET_LED 0x13
#define CMD_SEND_HIGH_BYTE 0x14 //new
#define CMD_SEND_LOW_BYTE 0x15 //new
#define CMD_CHECK_INIT 0x16
#define CMD_SET_CONTROL 0x17
#define CMD_SET_DATA 0x18
#define SET_LED_ON 0
#define SET_LED_OFF 1
void set_cclk(void *io_base,int value);
void set_din(void *io_base,int value);
void set_prog_b(void *io_base,int value);
unsigned short int get_stat(void *io_base);
int get_done_bit(void *io_base);
int get_init_bit(void *io_base);
int check_done(void *io_base);
void shiftWordOut(unsigned short int data, void *io_base);
void shiftByteOut(char data, void *io_base);
@@ -0,0 +1,79 @@
# ------------------------------------------------------------------------------
#
# 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.
#
# ------------------------------------------------------------------------------
# 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 := fpga
EXTRA_CFLAGS += -g
ifneq ($(KERNELRELEASE),) # kernelspace
obj-m += $(MODULE_NAME).o
else # userspace
CURRENT_PATH ?= $(shell pwd)
ifeq ($(ARCH),arm64)
LINUX_KERNEL_PATH ?= /home/rockchip/rk3399/Android/7.1/android/kernel
else
LINUX_KERNEL ?= $(shell uname -r)
LINUX_KERNEL_PATH ?= /lib/modules/$(LINUX_KERNEL)/build
endif
CURRENT_PATH := $(shell pwd)
modules:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
modules_install:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) 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 $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
+137
View File
@@ -0,0 +1,137 @@
/*
FPGA test
byTX
2013.1.31:create
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/module.h>
//for file opration
#include <linux/fs.h>
//for cdev create
#include <linux/cdev.h>
//copy_to_user
#include <linux/uaccess.h>
//class_create
#include <linux/device.h>
//ioremap defined here
#include <asm/io.h>
#include <linux/version.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Gatieme");
MODULE_DESCRIPTION("hello world");
#define FPGA_SIZE 1024
#define FPGA_BASE 0x80010000
#define CMD_FPGA_MODULE_RST 0x20
#define REG_RST_OFFSET 0x0006
static void __iomem *io_base;
struct cdev *fpga_cdev;
struct class *fpga_class;
dev_t fpga_devid;
static int fpga_open(struct inode *inode, struct file *file)
{
printk("fpga open\n");
return 0;
}
ssize_t fpga_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
{
*(unsigned short int*)buf=ioread16(io_base+(*f_pos));
return 2;
}
/*fpga write*/
ssize_t fpga_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
{
if(count==2)
{
iowrite16(*(unsigned short int*)buf,io_base+(*f_pos));
return 2;
}
else
return 0;
}
loff_t fpga_llseek (struct file *filp, loff_t offset, int whence)
{
loff_t new_pos;
if(offset>=0 && offset<FPGA_SIZE)
new_pos=offset;
else
new_pos=0;
filp->f_pos = new_pos;
return new_pos;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
static int fpga_ioctl(struct inode *indoe, struct file *file,
unsigned int cmd, unsigned long arg)
{
#else
//long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
//long (*compat_ioctl) (struct file *file, unsigned int cmd, unsigned long arg)
static long fpga_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
//struct inode *inode = file->f_dentry->d_inode;
struct inode *inode = inode = file_inode(file);
#endif
switch(cmd)
{
case CMD_FPGA_MODULE_RST:
iowrite16(0, io_base+REG_RST_OFFSET);
iowrite16(1, io_base+REG_RST_OFFSET);
break;
}
return 0;
}
static struct file_operations fpga_fops = {
.owner = THIS_MODULE,
.open = fpga_open,
.read = fpga_read,
.write = fpga_write,
.llseek = fpga_llseek,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
.ioctl = fpga_ioctl,
#else
.compat_ioctl = fpga_compat_ioctl,
#endif
};
static int __init fpga_init(void)
{
//创建字符设备
fpga_cdev=cdev_alloc();
cdev_init(fpga_cdev, &fpga_fops);
fpga_cdev->owner = THIS_MODULE;
alloc_chrdev_region(&fpga_devid, 0, 1, "fpga");
cdev_add(fpga_cdev,fpga_devid,1);
fpga_class = class_create(THIS_MODULE,"fpga_class");
device_create(fpga_class, NULL, fpga_devid, NULL,"fpga");
//申请内存
io_base=ioremap(FPGA_BASE,FPGA_SIZE);
if(io_base==0)
printk("failed to ioremap fpga\n");
printk("fpga initialized.\n");
return 0;
}
static void __exit fpga_exit(void)
{
unregister_chrdev_region(fpga_devid,1);
device_destroy(fpga_class , fpga_devid);
class_destroy(fpga_class);
cdev_del(fpga_cdev);
iounmap(io_base);
printk("fpga exit\n");
}
module_init(fpga_init);
module_exit(fpga_exit);
@@ -0,0 +1,82 @@
# ------------------------------------------------------------------------------
#
# 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
#MODCFLAGS:=-O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99
#EXTRA_CFLAGS += $(MODULE_FLAGS) $(CFG_INC) $(CFG_INC)
EXTRA_CFLAGS += -g -std=gnu99
ifneq ($(KERNELRELEASE),) # kernelspace
obj-m := $(MODULE_NAME).o
else # userspace
CURRENT_PATH ?= $(shell pwd)
ifeq ($(ARCH),arm64)
LINUX_KERNEL_PATH ?= /home/rockchip/rk3399/Android/7.1/android/kernel
else
LINUX_KERNEL ?= $(shell uname -r)
LINUX_KERNEL_PATH ?= /lib/modules/$(LINUX_KERNEL)/build
endif
modules:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
modules_install:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) 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 $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
@@ -0,0 +1,84 @@
# ------------------------------------------------------------------------------
#
# 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)
RESMAIN_CORE_OBJS := hello_dev.o
RESMAIN_GLUE_OBJS := hello_proc.o hello_devfs.o
hello-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
obj-m := $(MODULE_NAME).o
else
#MODULE_NAME := memory-engine
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
#KERNELDIR ?= /home/gatieme/Work/Kernel/
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
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,33 @@
#ifndef _HELLO_ANDROID_H_
#define _HELLO_ANDROID_H_
#include <linux/cdev.h>
#include <linux/semaphore.h>
/* config */
#define HELLO_DEVFS_BUILD
#define HELLO_PROC_BUILD
#define PROC_SEQ_FILE_OPERATIONS
#define HELLO_DEVICE_NODE_NAME "hello"
#define HELLO_DEVICE_FILE_NAME "hello"
#ifdef HELLO_PROC_BUILD
#define HELLO_DEVICE_PROC_NAME "hello"
#endif
#ifdef HELLO_DEVFS_BUILD
#define HELLO_DEVICE_CLASS_NAME "hello"
#endif
struct hello_android_dev
{
int val;
struct semaphore sem;
struct cdev dev;
};
#endif
Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define DEVICE_NAME "/dev/hello"
int main(int argc, char** argv)
{
int fd = -1;
int val = 0;
fd = open(DEVICE_NAME, O_RDWR);
if(fd == -1) {
printf("Failed to open device %s.\n", DEVICE_NAME);
return -1;
}
printf("Read original value:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
val = 5;
printf("Write value %d to %s.\n\n", val, DEVICE_NAME);
write(fd, &val, sizeof(val));
printf("Read the value again:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
close(fd);
return 0;
}
@@ -0,0 +1,82 @@
# ------------------------------------------------------------------------------
#
# 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 := test
#MODCFLAGS:=-O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99
#EXTRA_CFLAGS += $(MODULE_FLAGS) $(CFG_INC) $(CFG_INC)
ifneq ($(KERNELRELEASE),) # kernelspace
obj-m := $(MODULE_NAME).o
else # userspace
CURRENT_PATH ?= $(shell pwd)
ifeq ($(ARCH),arm64)
LINUX_KERNEL_PATH ?= /home/rockchip/rk3399/Android/7.1/android/kernel
else
LINUX_KERNEL ?= $(shell uname -r)
LINUX_KERNEL_PATH ?= /lib/modules/$(LINUX_KERNEL)/build
endif
modules:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
modules_install:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) 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 $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
+52
View File
@@ -0,0 +1,52 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
//#include <linux/list.h>
//#include <linux/mm.h>
//#include <linux/mm_types.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Gatieme");
MODULE_DESCRIPTION("test world");
/*
* print the module information
*/
static void print_module(void)
{
struct module *mod;
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);
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 test_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);
return 0;
}
static void test_exit(void)
{
printk(KERN_ERR"exit");
}
module_init(test_init);
module_exit(test_exit);
@@ -0,0 +1,77 @@
# ------------------------------------------------------------------------------
#
# 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.
#
# ------------------------------------------------------------------------------
# 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 := test_module
EXTRA_CFLAGS += -g -std=gnu99
ifneq ($(KERNELRELEASE),) # kernelspace
obj-m += $(MODULE_NAME).o
else # userspace
CURRENT_PATH ?= $(shell pwd)
ifeq ($(ARCH),arm64)
LINUX_KERNEL_PATH ?= /home/rockchip/rk3399/Android/7.1/android/kernel
else
LINUX_KERNEL ?= $(shell uname -r)
LINUX_KERNEL_PATH ?= /lib/modules/$(LINUX_KERNEL)/build
endif
modules:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules
modules_install:
make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) 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 $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
@@ -0,0 +1,115 @@
#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <asm/io.h>
#include <asm/uaccess.h>
static int g_testmodule_major = 0;
struct testmodule_dev{
struct cdev dev;
char buf[100];
};
struct testmodule_dev* testmodule_devp;
static ssize_t testmodule_read(struct file* filp, char __user* buf, size_t buf_size, loff_t* f_pos){
struct testmodule_dev* dev = filp->private_data;
if(copy_to_user(buf,dev->buf, 100))
{
return -EFAULT;
}
return 100;
}
static ssize_t testmodule_write(struct file* filp, const char __user* buf, size_t buf_size, loff_t* f_pos){
struct testmodule_dev* dev = filp->private_data;
if(copy_from_user(dev->buf,buf,buf_size))
{
return -EFAULT;
}
return buf_size;
}
static int testmodule_open(struct inode* node, struct file* filp){
struct testmodule_dev* dev = container_of(node->i_cdev,struct testmodule_dev, dev);
filp->private_data = dev;
return 0;
}
static long testmodule_ioctl(struct file* filp, unsigned int cmd, unsigned long arg){
struct testmodule_dev* dev = filp->private_data;
switch(cmd){
case 0:
memset(dev->buf,0,100);
printk(KERN_INFO "buf set to zero!");
break;
case 1:
memset(dev->buf,1,100);
printk(KERN_INFO "buf set to 1!");
break;
default:
break;
}
return 0;
}
static const struct file_operations testmodule_fops = {
.owner = THIS_MODULE,
.read = testmodule_read,
.write = testmodule_write,
.unlocked_ioctl = testmodule_ioctl,
.open = testmodule_open
};
void updateDev(struct testmodule_dev* dev, int index){
dev_t devno = MKDEV(g_testmodule_major, index);
int error;
cdev_init(&dev->dev, &testmodule_fops);
dev->dev.owner = THIS_MODULE;
error = cdev_add(&dev->dev, devno, 1);
if(error)
printk(KERN_NOTICE "Error %d adding testmodule %d", error, index);
}
int __init testmodule_init(void){
dev_t device_no;
/*Get Major Number*/
alloc_chrdev_region(&device_no,0,1,"testmodule");
g_testmodule_major = MAJOR(device_no);
/*Generate device struct*/
testmodule_devp = kmalloc(sizeof(struct testmodule_dev), GFP_KERNEL);
if(!testmodule_devp){
/*Generate Failed*/
int result;
result = -ENOMEM;
unregister_chrdev_region(device_no, 0);
return result;
}
memset(testmodule_devp,0,sizeof(struct testmodule_dev));
/*Update device struct*/
updateDev(testmodule_devp,MINOR(device_no));
return 0;
}
void __exit testmodule_exit(void){
cdev_del(&testmodule_devp->dev);
kfree(testmodule_devp);
unregister_chrdev_region(MKDEV(g_testmodule_major,0),1);
}
module_init(testmodule_init);
module_exit(testmodule_exit);
MODULE_LICENSE("Dual BSD/GPL");