Chinaunix首页 | 论坛 | 博客
  • 博客访问: 458060
  • 博文数量: 134
  • 博客积分: 3056
  • 博客等级: 中校
  • 技术积分: 1150
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-14 15:53
文章分类
文章存档

2013年(1)

2010年(133)

我的朋友

分类: LINUX

2010-07-21 11:17:06

1. 我的开发环境:
主机:ubuntu9.04+mips交叉编译工具(mipsel-linux-gcc是v3.6的)+IP地址为:192.168.1.222
目标板:mips开发板(系统是uclinux,内核linux-2.4.x)+uclinux安装了tftp命令+IP地址为:192.168.1.20

2. 一个最简单的驱动程序示例程序hello world,源码如下:


#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/config.h>

MODULE_LICENSE("GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, Michael Yao\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye,\nLove you!\n");
}

module_init(hello_init);
module_exit(hello_exit);


2. 我的Makefile文件如下:

TARGET    := helloworld
INCLUDE    := -I/home/michael/work/project/org_source/linux-2.4.x/include/ #开发板内核源码所在目录

CFLAGS    := -O2 -Wall -DMODULE -DUSEFIFO -D__KERNEL__ -DLINUX\
     -mno-abicalls -fno-pic -mips32 -DMODULE -mlong-calls
CC    := /opt/buildroot-gdb/bin/mipsel-linux-gcc #交叉编译器所在位置


${TARGET}.o: ${TARGET}.c
    $(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.c

install:
    $(shell cp ./helloworld.o /tftpboot) #我已经安装并启动tftp系统服务


clean:
    rm -rf *.o *~core .depend .*.cmd *.ko *.mod.c .tmp_versions



3. 在开发板/tmp目录下,在minicom中输入命令'tftp -gr helloworld.o 192.168.1.222'

4. 在minicom输入命令'insmod helloworld.o',打印'hello, Michael Yao'。

5. done

6. 说明:
  1) 编译选项:'-mno-abicalls -fno-pic'必须加上,不然insmod模块的时候会出现:'insmod:unresolved symbol _gp_disp'的错误。
  1) 编译选项:'-mips32 -DMODULE -mlong-calls'必须加上,不然insmod模块的时候会出现:'

insmod:Relocation overflow of type 4 for printk'的错误。


参考:

1. 一个简单的基于mips的驱动例子

2. Linux Device Driver
(Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartma著)

阅读(1246) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~