Author Archive

Install tokyo cabinet and python tc egg step by step

Wednesday, May 16th, 2012

1: wget 下载tokyo cabinet
2: 编译, 安装

./configure; make && make install

注:

若提示->configure:error: zlib.h is required, 安装zlib1g-dev libssl-dev
若提示->configure:error: bzlib.h is required, 安装libbz2-dev

3:安装python的egg包:

1. git clone git://github.com/rsms/tc.git
2. python setup.py install

注:

若提示->fatal error: Python.h: No such file or directory, 安装python2.6-dev

另:查看缺文件所属包使用apt-file工具(apt-file update && apt-file search xxx)

// 环境 ubuntu 10.04 && kernel 2.6.32-38-generic

设备名与文件系统结构的关系

Wednesday, March 7th, 2012

前段时间看字符设备驱动的时候,遇到了一些问题。在我们完成驱动模块开发后,将模块加入内核后,会对文件系统产生什么影响,也就是说会在哪里添加一些文件或者链接。后来查资料,做了记录。

一:主要进行的操作有:

1. 注册设备;
2. 加载模块;
3. 创建设备节点
4. 删除模块

二:主要影响的目录有以下四个:

1. /proc/devices;
2. /proc/modules;
3. /sys/modules;
4. /dev/

三:详细说明

1./proc/devices:注册设备列表.

注册设备(register_chrdev_region,allow_chrdev_region)后在此添加一行,包含两列(主设备号,设备名称)。其中的模块名称就是在调用注册函数时,形参中的设备名。

(more…)

Linux 的 I2C 总线驱动模型

Thursday, December 29th, 2011

Linux 的I2C 总线驱动架构
Bus Driver vs. Device Driver
Linux 中I2C 驱动分为两个部分,总线(BUS)和设备(DEVICE)。我把他们分别比喻为铁路和列车,相当的贴切啊!
1. 总线驱动

总线驱动是为系统中每个I2C 总线增加相应的读写方法,也包括I2C总线控制器的初始化等,但是总线驱动只提供读写函数,本身不会进行任何的通讯,因为它并不知道设备是否真正存在。这样设计也是为了减小SOC芯片驱动和外围设备驱动的耦合性。

1.2. 设备驱动

设备驱动则是与挂在I2C 总线上的具体的设备通讯的驱动。通过I2C总线驱动提供的函数,不同SOC的I2C总线控制器的差异对设备驱动透明。

在系统开机时,首先装载的是I2C总线驱动。一个总线驱动用于支持一条特定的I2C总线的读写。一个总线驱动通常需要两个模块,一个struct i2c_adapter 和一个struct i2c_algorithm 来描述。
via

Compiling directly into a kernel vs. modules

Saturday, December 10th, 2011

You have two options for adding functionality to the kernel: building functions into the kernel (making a monolithic kernel) or adding them as modules.

Monolithic kernels:

Building a function into the kernel directly ensures that that function will be available at all times. The downside is that it makes your kernel bigger, increasing boot time, and ultimately using that much more memory to hold the kernel. If you are compiling a kernel to fit on a floppy so that you can boot Linux off a rescue floppy, space will become an issue.

Modules:

Building a function as a module allows that function to be loaded into memory as needed and unloaded when it is no longer needed. This helps keep your kernel small. It is very useful if, say, you are swapping hardware in and out of your system frequently. You could compile support for a variety of, say, sound cards as modules, and your Linux system will theoretically only load the driver that is appropriate for the hardware setup at the time.

Another benefit of building functions as modules is that parameters can be passed to the modules which can be useful in debugging your system if problems occur.

There are some considerations to be made when deciding if a kernel function should be modularized. A small performance penalty is paid as it takes a little time to get the module loaded and unloaded. There are some functions that are needed at boot time and these cannot be compiled as modules — they need to be present in the kernel so your system can be loaded. For example, ext2/ext3/reiserfs file system support needs to be built into the kernel so that your partitions can be read, as you need to be able to read the filesystem to load modules. In my case, if I have PCMCIA support built into the kernel, then metworking works. If PCMCIA support is modularized, networking fails to start, probably because the PCMCIA support needs to be available very early in the boot process to set up networking.
via Gentoo Forums

以太网卡混杂模式与Sniffer程序学习

Tuesday, November 29th, 2011

Wikipedia

混杂模式(Promiscuous Mode)是计算机网络中的术语。是指一台机器的网卡能够接收所有经过它的数据流,而不论其目的地址是否是它。

一般计算机网卡都工作在非混杂模式下,此时网卡只接受来自网络端口的目的地址指向自己的数据。当网卡工作在混杂模式下时,网卡将来自接口的所有数据都捕获并交给相应的驱动程序。网卡的混杂模式一般在网络管理员分析网络数据作为网络故障诊断手段时用到,同时这个模式也被网络黑客利用来作为网络数据窃听的入口。在Liunx操作系统中设置网卡混杂模式,时需要管理员权限。在windows操作系统和Linux操作系统中都有使用混杂模式的抓包工具,比如著名的开源软件wireshark.

Linux下手动切换网卡(eth0)为(非)混杂模式。

默认为非混杂模式:

ifconfig eth0 -promisc

将eth0置为混杂(promiscuous):

ifconfig eth0 promisc

查看网卡是否混杂:

ifconfig eth0

输出若包含PROMISC则说明处于混杂模式。
例:

eth0 Link encap:以太网 硬件地址 xx:xx:xx:xx:xx:xx
inet 地址:x.x.x.x 广播:x.x.x.x 掩码:x.x.x.x
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 跃点数:1

注: (more…)

[魔都日记2]关于目前正在做的和将要做的

Wednesday, November 2nd, 2011

来到魔都的第二周。一切都比较顺利,我们部门主要做大中型交换机的研发,机体板子结构比较复杂,模块区分非常明晰,产品已经发售使用。接下来需要做的就是将板子上跑的vxworks替换成目前比较流行的Linux,说白了就是系统移植方面的东西。最近这两天都是做一些准备工作,需要对LINUX底层的API接口,设备驱动,网络协议,以及VxWORKS与底层硬件交互的驱动进行深入了解。再有就是接触宏观的一些东西,比如板子内部的信息流通,整体的架构,收发报文的流程,抓包及包内数据的具体分析。板子主要有两块NT和LT板,即通常所说的网卡与线卡。整个MDU拿起来很沉,能看到的模块除了上述两个,还有风扇模块,电源模块及trace&debug接口,adsl&vdsl接口等。 (more…)