Linux 多个文件.c 一个模块


test.h
--------------------------------------------
#define BUF_SIZE 100

typedef struct {
    void * base_addr;
    int    buf_size;
} buf_info;

extern buf_info skb_info;
void init_buf(buf_info * skb_info);

test.c
--------------------------------------------
#include "test.h"
buf_info skb_info;

void init_buf(buf_info * skb_info)
{
    skb_info->base_addr = 0;
    skb_info->buf_size  = BUF_SIZE;
}

hello.c
--------------------------------------------
#include <linux/module.h> 
#include <linux/kernel.h>
#include <asm/param.h>
#include "test.h"

static int __init hello_init(void)
{
    printk("<1>Hello world 1.\n");
    printk("<1>HZ = %d\n", HZ);
    init_buf(&skb_info);
    return 0;
}

static void __exit hello_exit(void)
{
    printk(KERN_ALERT "Goodbye world 1.\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("zengxiaolong ");
MODULE_DESCRIPTION("A sample driver");
MODULE_SUPPORTED_DEVICE("testdevice");

Makefile
--------------------------------------------
KERNEL_LOCATION := /home/zengxiaolong/soft/s3c2410/linux-2.6.24
obj-m += helloworld.o
helloworld-y += hello.o
helloworld-y += test.o


all:
    make -C $(KERNEL_LOCATION) M=`pwd` modules
clean:
    make -C $(KERNEL_LOCATION) M=`pwd` clean

相关内容