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 : [
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:
[
x14a0/0x1600)
r7 = C02C8938 r6 = BF005A40 r5 = BF005A40 r4 = C02C8948
[
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 : [
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:
[
r4 = C3B91240
[
r8 = 00000000 r7 = C37A508C r6 = C03E59C0 r5 = C0013C54
r4 = C3E179E0
[
r8 = C002F004 r7 = C3439000 r6 = 00000002 r5 = 00000003
r4 = 00000002
[
r4 = BEA2CD6C
[
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
#include
#include
#include
#include
#include
#include
#include
#include
#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里面出错了!
继续再找,那个地方出现空指针!再到地址链接的宏里面去找!看到底是那个地方的链接断了,或者出现错误.打开
#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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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");