TQ2440驱动-hello world 模块
来源:互联网 发布:单片机课设 编辑:程序博客网 时间:2024/05/16 11:38
TQ2440驱动-hello world 模块
http://blog.csdn.net/dg1683wen/article/details/6861044?userName=wlxf9999&userInfo=RCDraL3gzBmi9UU3YpiXPhwmS8CrmIvVXTjMnFaBY%2FxLEBUICPxQZpkLdD4cjm%2Fuyi%2FEobsC4KK3aeEeKIjbwQKG2%2BfbVIMYXRlZmad6Lh0LNhggF%2Fd9IizBQRyqEGHUxmEEJOIljjFxTa8wzYNADw%3D%3D
开发平台:
ubuntu10.04,内核版本2.6.32-33-generic,交叉编译器:天嵌公司提供的arm-linux-gcc 4.3.3,
内核树:/opt/EmbedSky/linux-2.6.30.4/
目标平台:
天嵌公司的TQ2440开发板ARM9,内核版本2.6.30.4
1. 首先解压天嵌公司提供的内核源码包linux-2.6.30.4_20100531.tar.bz2,
tar xvfj linux-2.6.30.4_20100531.tar.bz2 –C /-C是指定解压目录,后面的/代表在根目录解压归档文件。
之后内核树会被解压到/opt/EmbedSky/linux-2.6.30.4/
编译内核:
cd /opt/EmbedSky/linux-2.6.30.4cp config_EmbedSky_W35 .configmake zImage在此,config_EmbdeSky_W35为天嵌公司提供的内核配置文件,开始时可暂时拿来用。
至此,内核树已经准备好了,这是编译内核驱动模块的前提工作,如果在自己的文件系统中没有准备好内核树,则无法构造可装载的模块。
2. 安装交叉编译器4.3.3
解压天嵌公司提供的EABI-4.3.3_EmbedSky_20100610.tar.bz2,
tar xvfj EABI-4.3.3_EmbedSky_20100610.tar.bz2 –C /之后交叉编译器会被解压到/opt/EmbedSky/4.3.3/,
修改环境变量配置文件/etc/environment,
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/EmbedSky/4.3.3/bin"
LANGUAGE="zh_CN:zh:en_US:en"
LANG="zh_CN.utf8"
或
使用命令
export PATH=$PATH:/opt/EmbedSky/4.3.3/bin保存重启即生效,若不想重启可使用
source /etc/environment但是此命令只对该终端生效,所以若没其他问题,推荐重启
3.编写hello world 驱动模块
cd /home/shanks/modulesmkdir hellocd hello驱动模块不一定要放在内核树里,只要你的Makefile指定了内核树的路径就没问题,所以我这里在/home/shanks/里建立了一个modules目录专门用来开发驱动模块
hello.c 源码:
#include <linux/init.h>#include <linux/module.h>MODULE_LICENSE("Dual BSD/GPL");static int hello_init(void){ printk(KERN_ALERT "Hello, world\n"); return 0;} static void hello_exit(void){ printk(KERN_ALERT "Goodbye, cruel world\n"); return 0;}module_init(hello_init);module_exit(hello_exit);
Makefile:
KERNELDIR=/opt/EmbedSky/linux-2.6.30.4 PWD:=$(shell pwd) INSTALLDIR=$(PWD) CC=arm-linux-gcc obj-m := hello.o modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf *.o *.ko *.mod.c *.markers *.order *.symvers .PHONY:modules clean这里有必要解释一下驱动模块的Makefile编写方法,需要注意的是:
obj-m := hello.o
扩展语法,说明有一个模块需要从目标文件hello.o中构造,模块名称为hello.ko
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules上述命令首先改变目录到-C选项指定位置(即目录源代码目录),其中保存有内核的顶层文件。M=选项让内核顶层的Makefile在构造modules目标之前返回到模块源代码目录。然后,开始第二次读取PWD中的Makefile,modules目标指向obj-m变量中设定的模块,而内核的Makefile负责真正构造模块。
然后,
make
生成了几个文件,其中hello.ko就是我们需要的用来加载的模块文件。
这里注意,make之前必须要先准备好内核树,否则make会出错。
连上开发板,这里我把PC的根目录挂载到板子的/mnt下,
cp /mnt/home/shanks/modules/hello/hello.ko/tmpcd /tmp好了,加载模块!
[root@EmbedSky /tmp]# insmod hello.ko
Hello, world
[root@EmbedSky /tmp]# rmmod hello
Goodbye, cruel world
完成!
insmod时可能出现的错误:
I.
hello: version magic '2.6.30.4 mod_unload ARMv4 ' should be'2.6.30.4-EmbedSky mod_unload ARMv4 '
insmod: cannot insert 'hello.ko': invalid module format
出错原因:模块版本与内核版本不匹配!
解决办法:导入预设配置信息,进入menuconfig 继续配置General config ->( )Local version -> 括号中加入如下内容:“-EmbedSky”退出保存为 .config ,重新编译内核、驱动模块,再来加载模块
ii.
hello: Unknown symbol__aeabi_unwind_cpp_pr0
insmod: cannot insert 'hello.ko': unknown symbol in module, or unknown
parameter
出错原因:模块和内核镜像不匹配
解决方法:尽量用和你同时用来编译驱动而生成的内核镜像zImage,zImage烧到板子上。Ldd3上有句话:尽管并不是必需的,但最好运行和模块对应的内核。
这是学习驱动的一小步,但是对我来说却是一大步!
ubuntu下编译时出现“make: arm-linux-gcc:命令
http://blog.csdn.net/lifengxun20121019/article/details/21332805
1,进入linux-2.6.32.2这个目录,从终端输入命令:
2.执行以下命令来使用缺省配置文件 config_w35
3.然后执行“sudo make menuconfig“,出现配置内核界面,并且这时不用做任何更改,在主菜单里选择<Exit>退出,这样做是为了生成相应配置的头文件。
4.输入以下命令,开始编译内核:
make zImage (有可能加sudo)
这时出现如下错误:
这时出现如下错误:
# make zImage
make: arm-linux-gcc:命令未找到
scripts/kconfig/conf -s arch/arm/Kconfig
make: arm-linux-gcc:命令未找到
make[1]: “include/asm-arm/mach-types.h”是最新的。
/bin/sh: arm-linux-gcc: not found
make[1]: *** [kernel/bounds.s] 错误 127
make: *** [prepare0] 错误 2
即出现make: arm-linux-gcc:命令未找到的错误提示。
我开始检查如下:
1,终端输入gedit /etc/profile
在出现的配置文件中,可以看到环境变量(在最后一行)为
export PATH=$PATH:/usr/local/arm/4.4.3/bin
环境变量的设置没错。
2. 之前arm-linux-gcc.4.3.3的编译器都安装好了的,在终端输入 arm-linux-gcc -v
arm-linux-gcc -v
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /opt/FriendlyARM/mini2440/build-toolschain/working/src/gcc-4.4.3/configure --build=i386-build_redhat-linux-gnu --host=i386-build_redhat-linux-gnu --target=arm-none-linux-gnueabi --prefix=/opt/FriendlyARM/toolschain/4.4.3 --with-sysroot=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --enable-languages=c,c++ --disable-multilib --with-arch=armv4t --with-cpu=arm920t --with-tune=arm920t --with-float=soft --with-pkgversion=ctng-1.6.1 --disable-sjlj-exceptions --enable-__cxa_atexit --with-gmp=/opt/FriendlyARM/toolschain/4.4.3 --with-mpfr=/opt/FriendlyARM/toolschain/4.4.3 --with-ppl=/opt/FriendlyARM/toolschain/4.4.3 --with-cloog=/opt/FriendlyARM/toolschain/4.4.3 --with-mpc=/opt/FriendlyARM/toolschain/4.4.3 --with-local-prefix=/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi//sys-root --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-c99 --enable-long-long --enable-target-optspace
Thread model: posix
gcc version 4.4.3 (ctng-1.6.1)
以上说明4.4.3的编译器已经成功安装好。
以上说明4.4.3的编译器已经成功安装好。
以上说明4.4.3的编译器已经成功安装好。
后来发现原因如下:
exportPATH=$PATH:/usr/local/arm/4.4.3/bin
是设置当前用户的PATH,而sudo执行make的时候,使用的是超级用户权限,那也就使用了超级用户的PATH(但是这个PATH里,并没有/usr/local/arm/4.4.3/bin)
解决方法:
1.先打开一个超级用户权限的shell:
2.在当前shell下,设置环境变量:
在文件末端加上 export PATH=$PATH:/usr/local/arm/4.4.3/bin,并保存。
3. 执行source /etc/profile
再进入到/opt/FriendlyARM/mini2440/linux-2.6.32.2
- TQ2440驱动-hello world 模块
- TQ2440驱动-hello world 模块
- TQ2440驱动-hello world 模块
- TQ2440驱动-hello world 模块
- 加载TQ2440驱动-hello world 模块
- 加载TQ2440驱动-Hello World 模块
- 加载TQ2440驱动-Hello World 模块
- 加载TQ2440驱动-Hello World 模块
- 《TQ2440加载Hello world驱动模块》
- 加载TQ2440驱动-hello world 模块
- TQ2440加载Hello world驱动模块
- hello world!(驱动模块)
- TQ2440驱动-hello world(入门,注意事项)
- TQ2440驱动-hello world(入门,注意事项)
- 编写 Hello world 模块驱动
- 驱动学习,hello world模块
- 编写 Hello world 模块驱动
- linux下hello world驱动模块
- java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
- 猴子吃桃(递归)
- 使用分水岭算法对图像进行分割
- java生成和读取文本文件(text)
- Node
- TQ2440驱动-hello world 模块
- Mysql列转行
- 解决位图失真-SetStretchBltMode
- Ural 1550 Dean's Pyramid 3
- socket与http的区别
- 界面跳转类似于qq音乐刚开始登录时跳出的图标
- Spring 框架的设计理念与设计模式分析
- Locks and Unindexed Foreign Keys
- Flex实例【Shangle.net】解析【二】