hello world 简单的驱动

#include<linux/init.h>

#include<linux/module.h>

//#include < linux/config.h>

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);

MODULE_LICENSE("Dual BSD/GPL");

Makefile

obj-m := hello.o

KDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)

default:

$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:

rm -rf *.mode.o

rm -rf *.ko

rm -rf *.mod.c

rm -rf *.o.cmd

rm -rf *.ko.cmd.tmp_versions

KERNELDIR = /home/kernel/linux-2.6.22.2

    # The current directory is passed to sub-makes as argument

PWD := $(shell pwd)

INSTALLDIR = /home/tekkaman/working/rootfs/lib/modules

CROSS_COMPILE    =/home/arm/3.4.1/bin/arm-linux-

CC    = $(CROSS_COMPILE)gcc

obj-m := hello.o

modules:

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

modules_install:

    cp hello.ko $(INSTALLDIR)

clean:

     rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

2.6的内核

makefile 中要有 obj-m:= hello.o

  然后:

  make -C /usr/src/linux- 2.6.22 SUBDIRS=$PWD modules (当然简单的 make 也可以)


你可能感兴趣的:(shell,Module,makefile)