针对nanopi2的hello word 驱动

一、环境

1.本机

虚拟机搭建ubuntu140.4 64bit

2.目标板

Debian

3.交叉编译器

arm-linux-gcc

友善版本为4.9.3

git clone https://github.com/friendlyarm/prebuilts.git
sudo mkdir -p /opt/FriendlyARM/toolchain
sudo tar xf prebuilts/gcc-x64/arm-cortexa9-linux-gnueabihf-4.9.3.tar.xz -C /opt/FriendlyARM/toolchain/

二、步骤

1.确定本机版本

$ uname -r
3.16.0-30-generic

2.确定目标板版本

$ uname -r
3.4.39-s5p4418

3.下载源码树

git clone https://github.com/friendlyarm/linux-3.4.y.git
cd linux-3.4.y
git checkout nanopi2-lollipop-mr1

4.编译源码树

make nanopi2_linux_defconfig
touch .scmversion
make uImage
的这之前可能需要准备mkimage

5.编写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"); 
} 


module_init(hello_init); 
module_exit(hello_exit); 

6.编写Makefile

obj-m := hello.o 
KERNELDIR := /home/inmen/FriendlyARM/linux-3.4.y
PWD := $(shell pwd) 


modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

其中KERNELDIR需要修改,定位到本机的源码树目录

7.生成ko文件

执行make

8.检查ko文件信息

$ modinfo hello.ko
filename:       /home/inmen/nanopi2Driver/hello.ko
license:        Dual BSD/GPL
depends:        
vermagic:       3.4.39-s5p4418 SMP preempt mod_unload ARMv7 p2v8 

注意:vermagic中信息应与目标板信息一致,否则不能挂载

9.在目标板挂载驱动模块


三、参考资料

友善官司方资料

64位unbun下的hello驱动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值