嵌入式 linux如何生成ko文件
2013-12-02 14:53
288 查看
hello.c文件如下
驱动程序:
#include <linux/***.h> 是在linux-2.6.29/include/linux下面寻找源文件。
#include <asm/***.h> 是在linux-2.6.29/arch/arm/include/asm下面寻找源文件。
#include <mach/***.h> 是在linux-2.6.29/arch/arm/mach-s3c2410/include/mach下面寻找源文件。
#include <linux/module.h> //最基本的文件,支持动态添加和卸载模块。Hello World驱动要这一个文件就可以了
#include <linux/fs.h> //包含了文件操作相关struct的定义,例如大名鼎鼎的struct file_operations
#include <linux/errno.h> //包含了对返回值的宏定义,这样用户程序可以用perror输出错误信息。
#include <linux/types.h> //对一些特殊类型的定义,例如dev_t, off_t, pid_t.其实这些类型大部分都是unsigned int型通过一连串的typedef变过来的,只是为了方便阅读。
#include <linux/cdev.h> //对字符设备结构cdev以及一系列的操作函数的定义。
#include <linux/wait.h> //等代队列相关头文件
应用程序:
#include <fcntl.h> //包含了open()函数的flags,mode参数的宏定义。
Linux驱动程序常用头文件列举
l #include <linux/module.h>
最基本的文件,支持动态添加和卸载模块。Hello World驱动仅需要这一个头文件即可。
l #include <linux/fs.h>
包含了struct inode 的定义、MINOR、MAJOR的定义、众所周知的文件操作结构体:struct file_operations,等文件操作相关的定义。
l #include <linux/errno.h>
包含了对返回值的宏定义,这样用户程序可以用perror输出错误信息。
l #include <linux/types.h>
对一些特殊类型的定义,例如dev_t、off_t、 pid_t。其实这些类型大部分都是unsigned int型通过一连串的typedef变过来的,这样做只是为了方便阅读。
l #include <linux/cdev.h>
对字符设备结构cdev以及一系列的操作函数的定义。包含了cdev 结构及相关函数的定义。
l #include <linux/wait.h>
等代队列相关头文件。内核等待队列,它包含了自旋锁的头文件。
l #include <linux/slab.h>
包含了kcalloc、kzalloc内存分配函数的定义。
l #include <linux/uaccess.h>
包含了copy_to_user、copy_from_user等内核访问用户进程内存地址的函数定义。
l #include <linux/device.h>
包含了device、class 等结构的定义
l #include <linux/io.h>
包含了ioremap、iowrite等内核访问IO内存等函数的定义。
l #include <linux/miscdevice.h>
包含了miscdevice结构的定义及相关的操作函数。
l #include <linux/interrupt.h>
使用中断必须的头文件
l #include <mach/irqs.h>
使用中断必须的头文件
l #include <asm/bitops.h>
包含set_bit等位操作函数,实现Input子系统时可用。
l #include <linux/semaphore.h>
使用信号量必须的头文件
l #include <linux/spinlock.h>
使用自旋锁必须的头文件
l #include <linux/sched.h>
内核等待队列中要使用的TASK_NORMAL、TASK_INTERRUPTIBLE包含在这个头文件
l #include <linux/kfifo.h>
fifo环形队列
l #include <linux/timer.h>
内核定时器
l #include <linux/input.h>
中断处理
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Xie");
MODULE_DESCRIPTION("Hello World Module");
MODULE_ALIAS("a simplest module");
static int __init hello_init()
{
printk(KERN_EMERG"Hello World!\n");
return 0;
}
static void __exit hello_exit()
{
printk("<6>hello exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile文件如下:
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KDIR :=/home/Linux_Sharing/Session1/embedded_setup/linux-2.6.24/
all:
make -C $(KDIR) M=$(PWD) modules ARCH=armCROSS_COMPILE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Xie");
MODULE_DESCRIPTION("Hello World Module");
MODULE_ALIAS("a simplest module");
static int __init hello_init()
{
printk(KERN_EMERG"Hello World!\n");
return 0;
}
static void __exit hello_exit()
{
printk("<6>hello exit\n");
}
module_init(hello_init);
驱动程序:
#include <linux/***.h> 是在linux-2.6.29/include/linux下面寻找源文件。
#include <asm/***.h> 是在linux-2.6.29/arch/arm/include/asm下面寻找源文件。
#include <mach/***.h> 是在linux-2.6.29/arch/arm/mach-s3c2410/include/mach下面寻找源文件。
#include <linux/module.h> //最基本的文件,支持动态添加和卸载模块。Hello World驱动要这一个文件就可以了
#include <linux/fs.h> //包含了文件操作相关struct的定义,例如大名鼎鼎的struct file_operations
#include <linux/errno.h> //包含了对返回值的宏定义,这样用户程序可以用perror输出错误信息。
#include <linux/types.h> //对一些特殊类型的定义,例如dev_t, off_t, pid_t.其实这些类型大部分都是unsigned int型通过一连串的typedef变过来的,只是为了方便阅读。
#include <linux/cdev.h> //对字符设备结构cdev以及一系列的操作函数的定义。
#include <linux/wait.h> //等代队列相关头文件
应用程序:
#include <fcntl.h> //包含了open()函数的flags,mode参数的宏定义。
Linux驱动程序常用头文件列举
l #include <linux/module.h>
最基本的文件,支持动态添加和卸载模块。Hello World驱动仅需要这一个头文件即可。
l #include <linux/fs.h>
包含了struct inode 的定义、MINOR、MAJOR的定义、众所周知的文件操作结构体:struct file_operations,等文件操作相关的定义。
l #include <linux/errno.h>
包含了对返回值的宏定义,这样用户程序可以用perror输出错误信息。
l #include <linux/types.h>
对一些特殊类型的定义,例如dev_t、off_t、 pid_t。其实这些类型大部分都是unsigned int型通过一连串的typedef变过来的,这样做只是为了方便阅读。
l #include <linux/cdev.h>
对字符设备结构cdev以及一系列的操作函数的定义。包含了cdev 结构及相关函数的定义。
l #include <linux/wait.h>
等代队列相关头文件。内核等待队列,它包含了自旋锁的头文件。
l #include <linux/slab.h>
包含了kcalloc、kzalloc内存分配函数的定义。
l #include <linux/uaccess.h>
包含了copy_to_user、copy_from_user等内核访问用户进程内存地址的函数定义。
l #include <linux/device.h>
包含了device、class 等结构的定义
l #include <linux/io.h>
包含了ioremap、iowrite等内核访问IO内存等函数的定义。
l #include <linux/miscdevice.h>
包含了miscdevice结构的定义及相关的操作函数。
l #include <linux/interrupt.h>
使用中断必须的头文件
l #include <mach/irqs.h>
使用中断必须的头文件
l #include <asm/bitops.h>
包含set_bit等位操作函数,实现Input子系统时可用。
l #include <linux/semaphore.h>
使用信号量必须的头文件
l #include <linux/spinlock.h>
使用自旋锁必须的头文件
l #include <linux/sched.h>
内核等待队列中要使用的TASK_NORMAL、TASK_INTERRUPTIBLE包含在这个头文件
l #include <linux/kfifo.h>
fifo环形队列
l #include <linux/timer.h>
内核定时器
l #include <linux/input.h>
中断处理
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Xie");
MODULE_DESCRIPTION("Hello World Module");
MODULE_ALIAS("a simplest module");
static int __init hello_init()
{
printk(KERN_EMERG"Hello World!\n");
return 0;
}
static void __exit hello_exit()
{
printk("<6>hello exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
Makefile文件如下:
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KDIR :=/home/Linux_Sharing/Session1/embedded_setup/linux-2.6.24/
all:
make -C $(KDIR) M=$(PWD) modules ARCH=armCROSS_COMPILE=arm-linux-
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Xie");
MODULE_DESCRIPTION("Hello World Module");
MODULE_ALIAS("a simplest module");
static int __init hello_init()
{
printk(KERN_EMERG"Hello World!\n");
return 0;
}
static void __exit hello_exit()
{
printk("<6>hello exit\n");
}
module_init(hello_init);
相关文章推荐
- [ARM-Linux开发] 嵌入式 linux如何生成ko文件
- 如何在windows编译生成嵌入式linux程序的代码
- 如何制作嵌入式Linux文件系统
- Linux下静态库_库的基本概念;如何生成静态库动态库;nm查看库中包含那些函数、ar生成静态库,查看库中包含那些.o文件、ldd查看程序依赖的.so文件;gcc/g++与库相关的参数-L,-l,-f
- 将驱动编译成.ko文件添加到嵌入式Linux系统下
- 如何查询和修改Linux操作系统生成core dump文件的默认路径?
- 如何制作嵌入式Linux文件系统
- Linux下静态库_库的基本概念;如何生成静态库动态库;nm查看库中包含那些函数、ar生成静态库,查看库中包含那些.o文件、ldd查看程序依赖的.so文件;gcc/g++与库相关的参数-L,-l,-f
- Linux下静态库_库的基本概念;如何生成静态库动态库;nm查看库中包含那些函数、ar生成静态库,查看库中包含那些.o文件、ldd查看程序依赖的.so文件;gcc/g++与库相关的参数-L,-l,-f
- 如何在Linux系统通过命令行生成随机文件
- linux中如何使用javah命令生成jni头文件
- 如何制作嵌入式Linux文件系统
- Linux如何查找某个时间点后生成的空文件
- Linux下如何生成core dump文件
- Linux下如何生成core dump文件
- 华为code craft软件精英赛笔记-如何在Linux下利用提供的shell文件生成tar.gz赛题提交压缩包
- 编写嵌入式linux驱动时,如何才能自动加载设备并生成节点
- 在嵌入式linux串口终端中,如何烧录内核和上传文件?
- 如何制作嵌入式Linux文件系统
- 【linux】如何利用mkfifo命令让程序产生的文件直接生成压缩文件