出现这种情况:
1 ) no newline at end of the file!
一般要在程序出现的错误一行加上一个"回车"就OK!(GCC中)
以前在51中一般是不会有这种问题出现的!
2 )还有一个是Linvale 左值问题!在3.4.1交叉编译器中,一般开始我们都有这种错的!
像这种错误是编译器造成的!不过,我们在将寄存器地址,强制转换再加上指针,最后用变成指针变量就可以
了!
如: #define GPF0 (*(volital unsigned *)56000060) .
3) Section fail (分割块出错)
(一)、一般可能是地址错误,引起MMU的问题!因为在ARM9下面工作的方式是虚拟地址映射到内存物理地址的!这就是会引起地址的分割出错!此时,我们应该查一下,地址的问题,及指针的问题的!以下是一个空指针引起的错误/内存越界!
这下面的东西,见了就头痛!这时我们要借助工具OOPES分析器!
例如:
scankey: module license 'KEY_INTERRUPT' taints kernel.
Unable to handle kernel paging request at virtual address 56000050
pgd = c3780000
[56000050] *pgd=00000000
Internal error: Oops: 5 [#1]
Modules linked in: scankey s3c2410mci clk
CPU: 0
PC is at key_init+0x50/0x1c4 [scankey]
LR is at sys_init_module+0x14a0/0x1600
pc : [<bf007050>] lr : [<c005f8ac>] Tainted: P
sp : c3c09e44 ip : 56000000 fp : c3c09e64
r10: c39e6600 r9 : c39e6624 r8 : c4a90938
r7 : bf0059b0 r6 : bf0059b0 r5 : bf0059b0 r4 : bf0059a0
r3 : 02000500 r2 : 00100554 r1 : f0e00010 r0 : 00000005
Flags: Nzcv IRQs on FIQs on Mode SVC_32 Segment user
Control: C000717F Table: 33780000 DAC: 00000015
Process insmod (pid: 420, stack limit = 0xc3c08194)
Stack: (0xc3c09e44 to 0xc3c0a000)
9e40: c0069320 c02c8948 bf005a40 bf005a40 c02c8938 c3c09fa4 c3c09e68
9e60: c005f8ac bf007010 00000000 000002a8 bf005a4c 00000200 00000028 c3c09f68
9e80: 38ec24c0 00000010 0000000c c0089308 bf005824 00000000 0000003f c3bafa80
9ea0: 00000044 00000040 0000002c bf007000 00000000 00000000 00000000 00000007
9ec0: 00000000 0000000b 00000000 00000000 00000000 00000011 00000010 c4a91278
9ee0: c4a908a4 c4a90000 c3c08000 bf000000 00000000 00000000 c00720dc c006d6ac
9f00: c3bd51e8 000000d1 c3bd5908 c3c09f70 c3c09f1c c00736e4 c0071bf0 c3bd51e8
9f20: 00000000 c3b4b5a0 00000000 00000000 00000002 00000000 00000000 c3bd51e8
9f40: c3bd51f0 c3bd51d0 c3c08000 c3c08000 00000001 40015000 c3b4b5a0 00000000
9f60: 000013e5 c3c09fa4 c3c09f74 c0032ed8 c00802d4 00000001 00000000 00000004
9f80: 00000000 00000000 00000080 c002f004 c3c08000 00000000 00000000 c3c09fa8
9fa0: c002ee80 c005e41c 00000000 00000000 00900080 40015000 000013e5 001cb028
9fc0: 00000004 00000000 00000000 bedfad54 001cb018 001cb008 00000000 00000000
9fe0: bedf88a4 bedf8898 000444e0 40199ac0 60000010 00900080 f737b333 7f7f1f3f
Backtrace:
[<bf007000>] (key_init+0x0/0x1c4 [scankey]) from [<c005f8ac>] (sys_init_module+0
x14a0/0x1600)
r7 = C02C8938 r6 = BF005A40 r5 = BF005A40 r4 = C02C8948
[<c005e40c>] (sys_init_module+0x0/0x1600) from [<c002ee80>] (ret_fast_syscall+0x
0/0x2c)
Code: e3a0c456 e3833402 e2030cff e1a00440 (e79c2200)
Segmentation fault
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(二)、Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = c2dc4000
[00000000] *pgd=3360b031, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1]
Modules linked in: adc s3c2410mci clk
CPU: 0
PC is at open+0x10/0x44 [adc]
LR is at chrdev_open+0x14c/0x164
pc : [<bf005010>] lr : [<c00888cc>] Not tainted
sp : c3c09ed4 ip : c3c09ee8 fp : c3c09ee4
r10: 4013d180 r9 : c3c08000 r8 : c3e179e0
r7 : 00000000 r6 : 00000000 r5 : c0013c54 r4 : c3b91240
r3 : bf005000 r2 : 00000000 r1 : c3e179e0 r0 : c0013c54
Flags: NzCv IRQs on FIQs on Mode SVC_32 Segment user
Control: C000717F Table: 32DC4000 DAC: 00000015
Process run_adc (pid: 422, stack limit = 0xc3c08194)
Stack: (0xc3c09ed4 to 0xc3c0a000)
9ec0: c3b91240 c3c09f0c c3c09ee8
9ee0: c00888cc bf005010 00000000 c3e179e0 c0013c54 c03e59c0 c37a508c 00000000
9f00: c3c09f30 c3c09f10 c007e668 c0088790 00000002 00000003 00000002 c3439000
9f20: c002f004 c3c09f84 c3c09f34 c007e7e0 c007e574 c37a508c c03e59c0 00000003
9f40: c03f1ba0 c3c08000 00000101 00000001 00000000 4013d180 c3c09f84 c3c09f68
9f60: c007e83c c009aaa8 bea2cd6c 00000003 bea2cd6c bea2cd6c c3c09fa4 c3c09f88
9f80: c007e99c c007e7ac bea2cd64 4001bd80 000085b0 00000005 00000000 c3c09fa8
9fa0: c002ee80 c007e968 bea2cd64 c0035788 00008694 00000002 bea2cd6c 00000000
9fc0: bea2cd64 4001bd80 000085b0 00000001 4013f430 00008490 4013d180 bea2cd34
9fe0: 00000000 bea2cb80 00003c00 400e0c40 60000010 00008694 f737b733 7f7f1f3f
Backtrace:
[<bf005000>] (open+0x0/0x44 [adc]) from [<c00888cc>] (chrdev_open+0x14c/0x164)
r4 = C3B91240
[<c0088780>] (chrdev_open+0x0/0x164) from [<c007e668>] (dentry_open+0x104/0x238)
r8 = 00000000 r7 = C37A508C r6 = C03E59C0 r5 = C0013C54
r4 = C3E179E0
[<c007e564>] (dentry_open+0x0/0x238) from [<c007e7e0>] (filp_open+0x44/0x4c)
r8 = C002F004 r7 = C3439000 r6 = 00000002 r5 = 00000003
r4 = 00000002
[<c007e79c>] (filp_open+0x0/0x4c) from [<c007e99c>] (sys_open+0x44/0x88)
r4 = BEA2CD6C
[<c007e958>] (sys_open+0x0/0x88) from [<c002ee80>] (ret_fast_syscall+0x0/0x2c)
r7 = 00000005 r6 = 000085B0 r5 = 4001BD80 r4 = BEA2CD64
Code: e1a0c00d e92dd810 e24cb004 e3a02000 (e5923000)
Segmentation fault
以上为错误消息!!
以下为错误代码!
/* file name : "adc"
*
*
* author : "kang"
*
*
* date :"2009 01 03"
*
*/
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/arch/hardware.h>
#include <asm/arch-s3c2410/regs-adc.h>
#define MAJOR_ID 109
#define DEV_NAME "adc"
#define ADC_CON (*(volatile unsigned *)S3C2410_ADCCON)
#define ADC_DAT0 (*(volatile unsigned *)S3C2410_ADCDAT0)
static int adc_open(struct inode * inode, struct file * file)
{ int ADC_MAX_FREQ=2500000;
int PCLK=50000000;
int ADC_PRSCVL;
ADC_PRSCVL=PCLK/ADC_MAX_FREQ -1;
ADC_CON=(ADC_CON|(S3C2410_ADCCON_PRSCEN)|(S3C2410_ADCCON_PRSCVL(ADC_PRSCVL))|(S3C2410_ADCCON_SELMUX(0))|(S3C2410_ADCCON_STDBM));
mdelay(200);
return 0;
}
static int adc_read(struct file * file, char __user * userbuf, size_t count, loff_t * off)
{
ADC_CON=(ADC_CON|0x01); /*开始启动转换*/
if (ADC_CON&0x01); /*开始使能变为低电平?同时读取转换的数据,把数据读写到ADT1与DAT0中*/
if (ADC_CON&0x8000); /*AD转换结束?*/
*userbuf=ADC_DAT0;
return count;
}
static int adc_close(struct inode * inode, struct file * file)
{ ADC_CON=0x3cf4;
return 0;
}
static struct file_operations adc = {
.open = adc_open,
.read = adc_read,
.release = adc_close,
};
static int __init adc_init(void)
{ int result;
result=register_chrdev(MAJOR_ID,DEV_NAME,&adc);
if (result<0)
{printk ("the drives registre is fail!!n");
return result;
}
else
{printk ("the drives registre is success!!n");
devfs_mk_cdev(MKDEV(MAJOR_ID,0),S_IFCHR | S_IRUSR | S_IWUSR,"adc");
return result;
}
return 0;
}
static void __exit adc_exit(void)
{ unregister_chrdev(MAJOR_ID,DEV_NAME);
devfs_remove(DEV_NAME);
}
module_init(adc_init);
module_exit(adc_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("kang");
MODULE_DESCRIPTION("ADC");
原因分析:
首先看到错误消息提示:PC is at open+0x10/0x44 [adc]是在OPEN里面出错了!
继续再找,那个地方出现空指针!再到地址链接的宏里面去找!看到底是那个地方的链接断了,或者出现错误.打开<asm/arch-s3c2410/regs-adc.h>这个里面的宏原来是这样的----如下:
#define S3C2410_ADCREG(x) (x)
#define S3C2410_ADCCON S3C2410_ADCREG(0x00)问题就出来了,0x00如果映射到内存肯定是要出错的,会造成内存混乱的,再看一下本空间的ARM MMU原理,肯定会内存混乱.
解决方法:重新做虚拟地址映射!
#define ADCCON 0x58000000
#define ADCDAT0 0x5800000c
static void *ADC_CON;
static void *ADC_DAT0;
虚拟地址映射如下:
ADC_CON=ioremap(ADCCON,0x00000004);
ADC_DAT0=ioremap(ADCDAT0,0x00000004);
ADC_CON=(ADC_CON|0x01);对寄存器这样操作不是标准的赋值.应该要用writel(0x01,ADC_CON)
修改正确代码如下:
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/io.h>
#include <asm/arch/hardware.h>
#include <asm/arch-s3c2410/regs-adc.h>
#define MAJOR_ID 109
#define DEV_NAME "adc"
#define ADCCON 0x58000000
#define ADCDAT0 0x5800000c
static void *ADC_CON;
static void *ADC_DAT0;
static int adc_open(struct inode * inode, struct file * file)
{ int ADC_MAX_FREQ=2500000;
int PCLK=50000000;
int ADC_PRSCVL,ADC_CMD;
ADC_CON=ioremap(ADCCON,0x00000004); /*虚拟地址映射或者因为在宏里面地址链接断了要不然可以用(*(volitle unsigned *)S3C2410-ADCCON)*/
ADC_DAT0=ioremap(ADCDAT0,0x00000004);
ADC_PRSCVL=(PCLK/ADC_MAX_FREQ)-1;
ADC_CMD=((S3C2410_ADCCON_PRSCEN)|(S3C2410_ADCCON_PRSCVL(ADC_PRSCVL))|(S3C2410_ADCCON_SELMUX(0))|(S3C2410_ADCCON_STDBM));
writel(ADC_CMD,ADC_CON);
mdelay(200);
return 0;
}
static int adc_read(struct file * file, char __user * userbuf, size_t count, loff_t * off)
{
writel(0x01,ADC_CON); /*开始启动转换*/
if (readl(ADC_CON)&0x01); /*开始使能变为低电平?同时读取转换的数据,把数据读写到ADT1与DAT0中*/
if (readl(ADC_CON)&0x8000); /*AD转换结束?*/
*userbuf=readl(ADC_DAT0);
return count;
}
static int adc_close(struct inode * inode, struct file * file)
{ writel(0x3cf4,ADC_CON); /*关ADC转换器*/
return 0;
}
static struct file_operations adc = {
.open = adc_open,
.read = adc_read,
.release = adc_close,
};
static int __init adc_init(void)
{ int result;
result=register_chrdev(MAJOR_ID,DEV_NAME,&adc);
if (result<0)
{printk ("the drives registre is fail!!n");
return result;
}
else
{printk ("the drives registre is success!!n");
devfs_mk_cdev(MKDEV(MAJOR_ID,0),S_IFCHR | S_IRUSR | S_IWUSR,"adc");
return result;
}
return 0;
}
static void __exit adc_exit(void)
{ unregister_chrdev(MAJOR_ID,DEV_NAME);
devfs_remove(DEV_NAME);
}
module_init(adc_init);
module_exit(adc_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("kang");
MODULE_DESCRIPTION("ADC");
====================================================
三、poll驱动测试!
Unable to handle kernel NULL pointer dereference at virtual address 00000004
pgd = c2d80000
[00000004] *pgd=33724031, *pte=00000000, *ppte=00000000
Internal error: Oops: 817 [#3]
Modules linked in: poll s3c2410mci clk
CPU: 0
PC is at add_wait_queue+0x30/0x44
LR is at signel_poll+0x90/0xc8 [poll]
pc : [<c00592d8>] lr : [<bf0052dc>] Not tainted
sp : c3e6ff2c ip : a0000013 fp : c3e6ff38
r10: 7fffffff r9 : c3ea0dc8 r8 : 00000001
r7 : c3e6e000 r6 : c3b59aa0 r5 : c3b59aa0 r4 : c3e6ff70
r3 : c3b8f018 r2 : 00000000 r1 : c3b8f00c r0 : bf005ac0
Flags: NzCv IRQs off FIQs on Mode SVC_32 Segment user
Control: C000717F Table: 32D80000 DAC: 00000015
Process read (pid: 437, stack limit = 0xc3e6e194)
Stack: (0xc3e6ff2c to 0xc3e70000)
ff20: c3e6ff50 c3e6ff3c bf0052dc c00592b8 00000145
ff40: c3ea0dc0 c3e6ffa4 c3e6ff54 c0093458 bf00525c c3ea0dc8 00000001 c3ea0dc0
ff60: fffffff4 bed23d24 00000000 c3e6ff70 c0092928 c3b8f000 00000000 ffffffff
ff80: 00000001 bed23d24 000000a8 c002f004 c3e6e000 4013d180 00000000 c3e6ffa8
ffa0: c002ee80 c009324c ffffffff c0035a74 bed23d24 00000001 ffffffff 00000154
ffc0: ffffffff 00000001 bed23d24 00000001 4013f430 00008490 4013d180 bed23d44
ffe0: 40140d80 bed23d0c 00000000 400e5558 60000010 bed23d24 b332a233 3bab0b3b
Backtrace:
[<c00592a8>] (add_wait_queue+0x0/0x44) from [<bf0052dc>] (signel_poll+0x90/0xc8
[poll])
[<bf00524c>] (signel_poll+0x0/0xc8 [poll]) from [<c0093458>] (sys_poll+0x21c/0x3
cc)
r5 = C3EA0DC0 r4 = 00000145
[<c009323c>] (sys_poll+0x0/0x3cc) from [<c002ee80>] (ret_fast_syscall+0x0/0x2c)
Code: e121f003 e5902000 e281300c e581200c (e5823004)
Segmentation fault
/*
* file name: "signel"
*
* author : "kang"
*
*
* data : 2009-3-11
*/
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/wait.h>
#include <linux/errno.h>
#include <linux/poll.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/semaphore.h>
#include <asm/uaccess.h>
#define DEV_NAME "signel"
#define DEV_ID 110
struct signel {
int arry;
wait_queue_head_t read_Monitor;
wait_queue_head_t write_Monitor;
struct semaphore sem;
}signel_buff;
static int signel_write(struct file *filp,const char __user * buf,size_t count,loff_t *off)
{ printk("%i,%sn",current->pid,current->comm);
if(down_interruptible(&signel_buff.sem))
{ return -ERESTARTSYS;
}
printk("write data....!!!n");
if(copy_from_user(&signel_buff.arry,buf,count))
{ up(&signel_buff.sem);
return -EFAULT;
}
up(&signel_buff.sem);
return count;
}
static int signel_read(struct file *filp,char __user * buf,size_t count,loff_t *off)
{ printk ("%i,%sn",current->pid,current->comm);
if(down_interruptible(&signel_buff.sem))
{ return -ERESTARTSYS;
}
printk("read data....!!!n");
if(copy_to_user(buf,&signel_buff.arry,count))
{ up(&signel_buff.sem);
return -EFAULT;
}
up(&signel_buff.sem);
signel_buff.arry=0;
return count;
}
static unsigned int signel_poll(struct file *filp, struct poll_table_struct *wait)
{ unsigned int masker=0;
printk("mode=%sn",(filp->f_mode & FMODE_WRITE)? "write" : "read");
printk ("%i,%sn",current->pid,current->comm);
if(down_interruptible(&signel_buff.sem))
{return -ERESTARTSYS;
}
if(filp->f_mode & FMODE_WRITE)
{poll_wait(filp,&signel_buff.write_Monitor,wait);
if(signel_buff.arry==0)
{ masker=POLLOUT | POLLWRNORM;
}
}
if(filp->f_mode & FMODE_READ)
{ poll_wait(filp,signel_buff.read_Monitor,wait);
if(signel_buff.arry!=0)
{ masker=POLLIN | POLLRDNORM;
}
}
up(&signel_buff.sem);
return masker;
}
static struct file_operations signel_test = {
.write = signel_write,
.read = signel_read,
.poll = signel_poll,
};
static int __init init_signel(void)
{ int ret;
sema_init(&signel_buff.sem,1); /* 或者用init_MUTEX(&dev->sem) 初始化并声明为互斥(实际上也就是将信号量为“1”也就是它互斥模式)*/
ret=register_chrdev(DEV_ID,DEV_NAME,&signel_test);
if(ret<0)
{ printk("registre is fail!!n");
return ret;
}
else
{ printk("registre is scuss!!n");
devfs_mk_cdev(MKDEV(DEV_ID,0),S_IFCHR | S_IRUSR | S_IWUSR,"signel");
return 0;
}
return 0;
}
static void __exit exit_signel(void)
{ unregister_chrdev(DEV_ID,DEV_NAME);
devfs_remove(DEV_NAME);
}
module_init(init_signel);
module_exit(exit_signel);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("KANG");
MODULE_DESCRIPTION("SIGNE");
要改成:
wait_queue_head_t *read_Monitor;
wait_queue_head_t* write_Monitor;
poll_wait(filp,signel_buff.write_Monitor,wait);