Linux最小驱动与Makefile示例代码

主程序

文件名:minimum-driver.c

/* Minimum Linux Driver Demo
 *
 * This is a demo driver, which is used to demostrate Linux driver's structure
 */
 
/* Main header files, include them in all your drivers */
#include <linux/init.h>
#include <linux/module.h>
 
static int minimum_driver_init(void){
    printk(KERN_INFO "MinimumDriver: Initializing...\n");
    return 0;
}
 
static void minimum_driver_exit(void){
    printk(KERN_INFO "MinimumDriver: Exiting...\n");
    return;
}
 
/* Init function & Exit function */
module_init(minimum_driver_init);
module_exit(minimum_driver_exit);
 
/* Licenses, Authors & Descriptions */
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Picsell-Dois@SEU-BME");
MODULE_DESCRIPTION("Minimum Linux driver demo");

Makefile

文件名:Makefile

#!/bin/bash

# Specify source code
# Define object file
obj-m += minimum-driver.o

# KRNLDIR specifies source code directory
KRNLDIR := /home/picsell-dois/iTop4412/LinuxKernel/iTop4412_Kernel_3.0

# PWD specifies current working directory
PWD ?= $(shell pwd)

# Operations when calling make
all:
    rm -rf *.ko *.o *.mod.* *.order *.symvers *.cmd *.*.cmd .*.cmd .*.*.cmd .tmp_versions
    make -C $(KRNLDIR) M=$(PWD) modules

# Operations when calling make clean
clean:
    rm -rf *.o *.mod.* *.order *.symvers *.cmd *.*.cmd .*.cmd .*.*.cmd .tmp_versions

.gitignore

git使用,文件名:.gitignore

*.ko
*.o
*.mod.*
*.order
*.symvers
*.cmd
*.*.cmd
.*.cmd
.*.*.cmd
.tmp_versions
*~
*.*~

参考文献

《iTop-4412开发板实战教程》

it
除非特别注明,本页内容采用以下授权方式: Creative Commons Attribution-ShareAlike 3.0 License