一个简单的内核驱动程序,编译出错了,请大家进来看看

内核编译和嵌入式产品的设计与开发
回复
freeubuntu
帖子: 35
注册时间: 2007-04-12 17:18
送出感谢: 0
接收感谢: 0

一个简单的内核驱动程序,编译出错了,请大家进来看看

#1

帖子 freeubuntu » 2007-05-09 11:52

先是驱动程序源码
test.c
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif



#include <linux/module.h>
#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
#include <linux/init.h>



static int test_open(struct inode *inode, struct file *filp);
static int test_release(struct inode *inode, struct file *filp);
static int test_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
unsigned long param);
static int check_test_change(kdev_t dev);
static int test_revalidate(kdev_t dev);
int test_init(void);
void test_cleanup(void);


#define MAJOR_NR 125
#define DEVICE_NAME "test" /* name for messaging */
#define DEVICE_NR(device) MINOR(device)
#define DEVICE_NO_RANDOM
#define DEVICE_OFF(d)

module_init(test_init);
module_exit(test_cleanup);

#include <linux/blk.h>


/********************************************************************************************************/



static struct block_device_operations test_fops = /* driver info */
{
owner: THIS_MODULE,
open: test_open,
release: test_release,
ioctl: test_ioctl,
check_media_change: check_test_change,
revalidate: test_revalidate,
};

static int test_open(struct inode *inode, struct file *filp)
{
MOD_INC_USE_COUNT;
return 0; /* success */
}

static int test_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
return(0);
}

static int test_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
return 0;
}

static int check_test_change(kdev_t dev)
{
return 0;
}

static int test_revalidate(kdev_t dev)
{

return 0;
}

int test_init(void)
{
int result;

result = register_blkdev(MAJOR_NR, DEVICE_NAME, &test_fops);
if (result < 0)
{
printk(KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR );
return(result);
}

printk(KERN_ERR DEVICE_NAME ": init OK\n");
return(0);
}

void test_cleanup(void)
{
unregister_blkdev(MAJOR_NR, DEVICE_NAME);
}

再是Makefile
EXEC =test

OBJS =test.o

SRC =test.c



INCLUDE = /usr/src/uClinux-dist/linux-2.4.x/include

CC = arm-elf-gcc

LD = arm-elf-ld

MODCFLAGS = -D__KERNEL__ -I$(INCLUDE) -Wall -O2 -fno-strict-aliasing -fno-common -pipe -fno-builtin -D__linux__ -g -DNO_MM -mapcs-32 -march=armv4 -mtune=arm7tdmi -mshort-load-bytes -msoft-float -nostdinc -iwithprefix include

LDFLAGS = -m armelf -r



all: $(EXEC)



$(EXEC): $(OBJS)

$(LD) $(LDFLAGS) -o $@ $(OBJS)



%.o:%.c

$(CC) $(MODCFLAGS) -mapcs -c $< -o $@



clean:

-rm -f $(EXEC) *.elf *.gdb *.o

make

{standard input}: Assembler messages:
{standard input}:5686: Fatal error: Symbol sequence already defined.
test.c:36: output pipe has been closed
make: *** [test.o] 错误 1
回复

回到 “内核及嵌入式开发”