在别人板子上没问题的,拿到我板子上,做了些地址上的相应修改后,在PC上交叉编译,通过NFS,mount上去后,insmod的时候,出现如下信息:
insmod: unresolved symbol unregister_chrdev
insmod: unresolved symbol register_chrdev
insmod: unresolved symbol printk
很是纳闷,哪位兄台能帮忙解决一下,感激不尽!
我现在纳闷到底问题出在什么地方?交叉编译器?驱动本身?板子上Linux内核问题?
代码如下:
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#ifdef CONFIG_SMP
#define __SMP__
#endif
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/delay.h>
#include <asm/unistd.h>
#include <asm/fcntl.h>
#include <asm/uaccess.h>
#include <asm-arm/arch-s3c2410/s3c2410.h>
MODULE_LICENSE("GPL";
#define LED_ON 333
#define LED_OFF 555
unsigned int LED_MAJOR=251; /*static define device major number*/
static int led_open(struct inode *inode, struct file *filp);
static ssize_t led_read(struct file *filp, char *buf, size_t count,loff_t *f_pos);
static ssize_t led_write(struct file *filp, const char *buf, size_t count,loff_t *f_pos);
static int led_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg);
static int led_release(struct inode *inode, struct file *filp);
struct file_operations led_fops={
open: led_open,
read: led_read,
write: led_write,
ioctl: led_ioctl,
release: led_release,
};
int led_init()
{
int result;
result=register_chrdev(LED_MAJOR, "led",&led_fops);
if (result < 0) {
printk("<1>Sorry,I can't get major number\n";
return result;
}
if (result==0){
printk("<1>The major is:%d\n",LED_MAJOR);
printk("<1>Init LED module successful!\n";
}
return 0;
}
static void led_exit()
{
unregister_chrdev(LED_MAJOR, "led";
printk("<1>LED module has been closed already.\n";
return;
}
void led_on(unsigned long index)
{
unsigned int data=0x10;
rGPFCON=0x5500;
rGPFUP=0x0;
rGPFDAT=data<<index;
/*
*portaddr=(data<<index);
*portdata&=~(data<<index);
*printk("portaddr=%-5d ",portaddr);
*printk("portdata=%-5d index=%-5d\n",portdata,index);
*/
return;
}
void led_off(unsigned long index)
{
unsigned int data=0x10;
rGPFCON=0x5500;
rGPFUP=0x0;
rGPFDAT=~(data<<index);
/*
*portaddr=(data<<index);
*portdata|=~(data<<index);
*printk("portaddr=%-5d ",portaddr);
*printk("portdata=%-5d index=%-5d\n",portdata,index);
*/
}
static int led_open(struct inode *inode,struct file *filp)
{
return 0;
}
static int led_read(struct file *filp,char *buf,size_t count,loff_t *f_pos)
{
return 0;
}
static int led_write(struct file *filp,const char *buf,size_t count,loff_t *f_pos)
{
return 0;
}
static int led_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
{
printk("<1>rogram now in kernel space,and cmd=%ld,arg=%ld.\n",cmd,arg);
switch(cmd){
case LED_ON:
{
unsigned idx;
/*if(copy_from_user(&idx,(unsigned long*)arg,sizeof(unsigned long))){
printk("<1>Sorry,copy_from_user() error!\n";
return -1;
} */
idx=arg;
led_on(idx);
break;
}
case LED_OFF:
{
unsigned long idx;
/*if(copy_from_user(&idx,(unsigned long*)arg,sizeof(unsigned long))){
printk("<1>led_off() copy_from_user error!\n";
return -1;
}*/
idx=arg;
led_off(idx);
if(idx==7)
printk("We have already finished the work.\n";
break;
}
default:
printk("<1>Unknown cmd!\n";
break;
}
}
static int led_release(struct inode *inode,struct file *filp)
{
return 0;
}
module_init(led_init);
module_exit(led_exit);[em07]
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |