Linux设备驱动学习-Davinci开发板上运行的hello模块
Linux设备驱动学习-Davinci开发板上运行的hello模块
看了很多个hello world了,自己来写一个在davinci板块上跑的吧。
主体很简单,就是一个C文件hello_davinci.c。
/*================hello_davinci.c==============*/
#include <linux/module.h> /*所有模块都需要的头文件*/
#include <linux/kernel.h>
#include <linux/init.h> /* init和exit相关宏*/
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("lintax");
static int hello_init(void)
{
printk(KERN_ALERT " Hello Davinci!\n");
return 0;
}
static void hello_exit(void)
{
printk( KERN_ALERT " Goodbye, Davinci.\n ");
}
module_init(hello_init);
module_exit(hello_exit);
/*================hello_davinci.c end===========*/
给其配个Makefile文件:
/*================Makefile==================*/
obj-m := hello_davinci.o
KERNELDIR := /opt/ti-davinci/
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
/*================Makefile end===============*/
好了,编译吧。
我的好心情立马被扑灭了,error,又见error:
说找不到/opt/ti-davinci/include/asm/ 下的某个头文件,查了一下,没这个目录嘛,当然找不到了。记得以前是看见过的,并且与asm-arm是一样的,应该是编译时复制的一份。不巧我前几天觉得硬盘空间有些不够,就把好几个内核都
make clean了一次。那就再make一次嘛,ok,生成了hello_davinci.ko。
转移到davinci开发板上,执行插入模块命令:
insmod hello_davinci.ko
输出信息:
Hello Davinci!
通过lsmod查看,也有了hello_davinci 模块。
然后执行移除模块命令:
rmmod hello_davinci
输出信息:
Goodbye Davinci.
再用lsmod来查看,就找不到hello_davinci了。
有以下几点要注意:
1,所使用的内核环境必须是编译过的,否则,就等着重蹈我的覆辙吧。
2,对于编译过程中类似于:不能创建hello_davinci.o.tmp文件的错误。说明权限不够,可更改hello_davinci.c Makefile文件所在目录的属性,或者是sudo到根用户。
3,hello_davinci.c文件中调用的头文件的作用:
&n
相关文档:
Linux启动时,第一个必须挂载的是根文件系统;若系统不能从指定设备上挂载根文件系统,则系统会出错而退出启动。之后可以自动或手动挂载其他的文件系统。因此,一个系统中可以同时存在不同的文件系统。不同的文件系统类型有不同的特点,因而根据存储设备的硬件特性、系统需求等有不同 ......
ls
ls 命令可以说是linux下最常用的命令之一。它有众多的选项,其中有很多是很有用的,你是否熟悉呢?下面列出了 ls 命令的绝大多数选项。
-a 列出目录下的所有文件,包括以 . 开头的隐含文件。
-b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出。
-c 输出文件的 i 节 ......
from:http://blog.chinaunix.net/u2/62281/showart_1096746.html
sock_raw原始套接字编程可以接收到本机网卡上的数据帧或者数据包,对与监听网络的流量和分析是很有作用的.一共可以有3种方式创建这种socket
1.socket(AF_INET, SOCK_RAW, IPPROTO_TCP|IPPROTO_UDP|IPPROTO_ICMP)发送接收ip数据包
2.socket(PF_PACK ......
Linux Execution and Virtual Memory Utilization
Linux执行以及虚拟内存之用
When Linux boots, it starts with the MMU disabled, so initially it deals only with physical
memory. The kernel image is copied to physical address 0x8000 in DRAM and executed. First a master page table is created ......