Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2116852
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2012-07-27 20:25:36

开发板: TQ2440

1. hello.c

点击(此处)折叠或打开

  1. #include <linux/init.h>
  2. #include <linux/module.h>

  3. MODULE_LICENSE("GPL");

  4. static int __init hello_init(void)
  5. {
  6.     printk(KERN_ALERT "my first driver\n");
  7.     return 0;
  8. }

  9. static void __exit hello_exit(void)
  10. {
  11.     printk(KERN_ALERT "goodbye my first dirver\n");
  12.     return ;
  13. }

  14. module_init(hello_init);
  15. module_exit(hello_exit);
2. Makefile

点击(此处)折叠或打开

  1. #CROSS_COMPILE=/opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-
  2. CROSS_COMPILE= /opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-
  3. ARCH:=arm
  4. CC=$(CROSS_COMPILE)gcc
  5. LD=$(CROSS_COMPILE)ld

  6. obj-m = hello.o

  7. KDIR =/root/kernel/linux-2.6.30.4
  8. PWD = $(shell pwd)
  9. default:
  10.     $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
  11. clean:
  12.     rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order
hello.rar(下载后将文件名改为hello.tar.gz)
3. 当需要在x86 和 arm上相互切换驱动时,不需要写两套Makefile,只需要加一个类型判断即可。

点击(此处)折叠或打开

  1. ARCH=x86
  2. ifeq ($(ARCH), x86)
  3. CROSS_COMPILE=
  4. KDIR = /lib/modules/$(shell uname -r)/build
  5. else
  6. CROSS_COMPILE= /opt/EmbedSky/4.3.3/bin/arm-none-linux-gnueabi-
  7. KDIR =/root/kernel/linux-2.6.30.4
  8. endif
  9. PWD = $(shell pwd)

  10. obj-m := hello.o
  11. all:
  12.     make -C $(KDIR) SUBDIRS=$(PWD) modules
  13. clean:
  14.      rm -*.ko *.*.mod.*.mod.*.symvers *.order

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