linux 驱动开发

如何编译驱动

obj-m obj-y: 目标定义是Kbuild Makefile的主要部分,也是核心部分。主要是定义了要编 译的文件,所有的选项,以及到哪些子目录去执行递归操作。 最简单的Kbuild makefile 只包含一行: 例子: obj-y += foo.o 该例子告诉Kbuild在这目录里,有一个名为foo.o的目标文件。foo.o将从foo.c 或foo.S文件编译得到。 如果foo.o要编译成一模块,那就要用obj-m了。所采用的形式如下: 例子: obj-$(CONFIG_FOO) += foo.o $(CONFIG_FOO)可以为y(编译进内核) 或m(编译成模块)。如果CONFIG_FOO不是y 和m,那么该文件就不会被编译联接了

 

驱动代码编译需要写makefile。make -C ~/kernel-2.6 M=`pwd` modules

This command starts by changing its directory to the one provided with the -C
option (that is, your kernel source directory). There it finds the kernel’s top-level
makefile. The M= option causes that makefile to move back into your module source
directory before trying to build the modules target

# Makefile2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax. dependency relationshsip of files and target modules are listed here.

mymodule-objs := hello.o
  obj-m := hello.o

else
PWD := $(shell pwd)

KVER ?= $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build #KDIR目录其实是链接到上面那个Makefile中的那个/usr/src/linux-source-2.6.15/*中
all:
  $(MAKE) -C $(KDIR) M=$(PWD)

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

endif

或者make -C ~/linux-3.16.1 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- M=`pwd` modules Makefile:obj-m:= hello.o

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值