树莓派内核模块交叉编译
来源:互联网 发布:2017中国机电贸易数据 编辑:程序博客网 时间:2024/04/28 08:51
一、 获得ARM GCC 交叉编译器
官网下载可能比较慢,可以csdn资源下载 为 bcm2708hardfp编译器,和官方一样的
http://download.csdn.net/detail/canyue102/6725615
安装该编译器,把编译器路径加入到环境变量中:
gedit ~/.bashrc
在最后一行添加:
export PATH=$PATH:/your_dir/tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/
然后终端查看
arm-bcm2708hardfp-linux-gnueabi-gcc -v
然后就安装好交叉编译器了.
二、获取树莓派官方内核
使用git下载,我的板子使用的内核版本是3.18,因此我下载的版本就是rpi-3.18.y-rebase版本
mkdir raspeberrypi_srccd raspberrypi_srcgit clone -b rpi-3.18.y-rebase --single-branch git://github.com/raspberrypi/linux.git
如果上面的命令中–single-branch 识别不了,升级你的git版本即可
进入内核目录:
编辑根目录下的Makefile文件,找到下面相似语句,修改为下面:
ARCH ?= arm
CROSS_COMPILE ?= arm-bcm2708hardfp-linux-gnueabi-
获得内核配置文件
在运行的树莓派中运行:
ls /proc/
可看到一个叫config.gz的文件,他是当前的树莓派配置选项记录文件,我们将他拷出
在linux内核源码下执行:
zcat config.gz > .config
然后只需要make就开始编译内核了,时间会有点长,先睡一觉
三、编写驱动代码
我们在上位机编写hello world的代码:
#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.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"); } module_init(hello_init); module_exit(hello_exit);
相应的makefile代码:
ifneq ($(KERNELRELEASE),) obj-m := hello.o else KDIR := /home/hcx/work/boards/RPi/kernel/linux-rpi-3.6.y all: make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/home/hcx/work/boards/RPi/kernel/RpiTools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi- clean: rm -f *.ko *.o *.mod.o *.mod.c *.symvers modul* endif
进入此目录直接make即可
编译完成后,我们通过U盘将hello.ko文件拷贝到树莓派中,然后通过insmod插入模块
0 0
- 树莓派内核模块交叉编译
- Linux 交叉编译内核模块
- 交叉编译内核模块的Makefile范本
- 如何编译/交叉编译内核模块, Linux 2.6.
- 交叉编译mini2440内核模块的注意点
- linux 模块交叉编译
- 交叉编译helloword模块
- 树莓派内核(Kernel)的交叉编译
- 交叉编译内核
- s3c2440 内核交叉编译
- 交叉编译linux内核
- 交叉编译Linux内核
- 树莓派编译内核(编译模块)
- 内核编译 & 模块编译
- 两个编译2.4与2.6内核模块的Makefile 模板(支持交叉编译)
- 建立树莓派raspberry交叉编译环境以及编译内核
- 树莓派交叉编译工具的创建与内核编译
- 如何利用交叉编译工具为树莓派编译linux内核
- android学习笔记(六)——数据库操作
- MyBatis数据持久化(八)sql复用
- get whole screen size;add background
- Leetcode#6 ZigZag Conversion
- RulingSite-S 系统漏洞 (台湾大学居多)
- 树莓派内核模块交叉编译
- Android RecyclerView 使用详解
- Huffman编码用MTLAB的实现及编码注释----------Matlab
- log4j.properties配置生成log文件路径问题
- Archlinux设置静态固定IP
- LintCode-简化路径
- Cocos2dx多线程与异步加载
- SVN命令的使用(Ubuntu)
- The connection to adb is down, and a severe error has occured