我第一次认识到:原来长途客运的服务也是可以做得这样好的.
Saturday, September 27, 2008
体验成都的长途客运服务
我第一次认识到:原来长途客运的服务也是可以做得这样好的.
Monday, September 15, 2008
address space resource
#define IORESOURCE_IO 0x00000100 /* Resource type */
#define IORESOURCE_MEM 0x00000200
#define IORESOURCE_IRQ 0x00000400
#define IORESOURCE_DMA 0x00000800
本文我主要研究IORESOURCE_IO IORESOURCE_MEM,及地址空间的管理,涉及的文件只有kernel/resource.c.
这两种资源本质上都是一段地址空间. 只是类型不一样
IORESOURCE_IO 指的是IO地址空间,这个空间从kernel编程上来看,只能通过专门的接口函数才能访问.硬件层面上,cpu需要用特殊指令才能访问或需要用特殊访问方 式才能访问,不能直接用指针来寻址.在PC机上,其指的就是PCI/CPU IO address space.在嵌入式中,基本上没有io address space.
IORESOURCE_MEM 指的是属于外设或者用于和设备通讯的支持直接寻址的地址空间.PC机上,主板上北桥上连的内存都是交给kernel直接管理,或者都是用于软件执行,所以 这部分内存不属于IORESOURCE_MEM, IORESOURCE_MEM主要是指PCI设备的 memory address space. 但在嵌入式上, 主板上的sdram一般是设备与cpu共享的. 故交给kernel直接管理的内存只是一部分.余下的内存以及寄存器空间都作为IORESOURCE_MEM来管理.
只所以需要管理,是 因为像PCI总路线设备的这些地址空间是设备向系统申请的,故是可配置的,并且设备并身可能热插拨或更换,故其变成一种可分配的资源. 故内核用算法来管理分配与释放操作,防止冲突和便于查询维护.但实际PC中,BIOS一般会做分配操作,内核需要是把分配结果添加进来,故提供了注册(或 者叫做添加)接口. 在嵌入式系统中,外设的地址也通常是固定的,只需要添加即可.
这两种资源,内核采用同样的管理算法--二叉树.相当于内核维护两个独立的二叉树. 按地址基地址与地址长度范围作为管理数据.可以添加,分配,释放节点.分配过程中可以避
免空间冲突,添加时可以识别空间冲突.根节点在kernel/resource.c中以全局变量方式定义.根节点用于限制地址空间的范围.
主要接口:
int insert_resource(struct resource *parent, struct resource *new)
int adjust_resource(struct resource *res, unsigned long start, unsigned long size)
int allocate_resource(struct resource *root, struct resource *new,
unsigned long size,
unsigned long min, unsigned long max,
unsigned long align,
void (*alignf)(void *, struct resource *,
unsigned long, unsigned long),
void *alignf_data)
int release_resource(struct resource *old)
int request_resource(struct resource *root, struct resource *new)
上面的接口对上述4种资源类型都有效,对于IORESOURCE_IO 和 IORESOURCE_MEM这两种资源,使用这两个接口更为方便
request_region(start,n,name)
release_region(start,n)
io space
request_mem_region(start,n,name)
release_mem_region(start,n)
mem space
在 /proc 文件系统中,ioports和iomem分别显示系统当前这两种资源.
嵌入式设备的外设一般先作为platform device添加到platform bus上,其主要目的就是向系统注册资源,在platform_add_devices时做,
如:
/* Watchdog timer parameters */
static struct resource wdt_resource[] = {
/* Watchdog timer only needs a register address */
[0] = {
.start = 0xFFC00008,
.end = 0xFFC00010,
.flags = IORESOURCE_MEM,
}
};
struct platform_device wdt_device = {
.name = "wdt",
.id = -1,
.num_resources = ARRAY_SIZE(wdt_resource),
.resource = wdt_resource,
};
platform_add_devices(wdt_device,1);
故如已知设备的物理地址,并不一定需要request_mem_region,因为这个操作并没有涉及到任何硬件,与软件访问也没有任何关系..但一般还是推荐做.
I/O port 访问流程( 不用mem模拟方式):
request_region() #在设备驱动模块加载或opn() 函数中进行,物理i/o port地址由pci bios模块分配
inb(),outb()等 #在设备驱动初始化,write(),red(),ioctl() 等函数中进行
relase_region #在设备驱动模块卸载或release() 函数中进行
I/O port 访问流程( 用mem模拟方式):
request_region()
ioport_map #在设备驱动模块加载或opn() 函数中进行,物理i/o port地址由pci bios模块分配
ioread8,iowrite8等 #在设备驱动初始化,write(),red(),ioctl() 等函数中进行
ioport_unmap()
relase_region #在设备驱动模块卸载或release() 函数中进行
request_mem_region
ioremap #在设备驱动模块加载或opn() 函数中进行,物理i/o port地址由pci bios模块分配
ioread8,iowrite8等 #在设备驱动初始化,write(),red(),ioctl() 等函数中进行
iounmap()
relase_region #在设备驱动模块卸载或release() 函数中进行
内核如何识别root参数所指定的根文件系统设备
root 参数的处理在是do_mount.c的prepare_namespace函数里. 基本原理为:先munt devfs到/dev目录,然后根据root参数中指定的设备文件名字,从devfs中找到设备文件对应的dev对象,这样就可以开始mount操作了. 不过devfs文件系统已被废弃了. 相应的功能由sysfs取代. 逻辑差不多.
另外 /dev/nfs 并不是实际设备文件,只是根代表文件系统为nfs文件系统. 故处理逻辑中不会用到devfs或sysfs. 所以去掉 sysfs 后,内核仍然能mount 上nfs根文件系统,而无法mount上flash mtd partition上的根文件系统.
(移动)硬盘安装fedora9
以下为笔记:
是内置硬盘,还是usb移动硬盘,方法都是一样的. 故这里不加区分.
基本原理: 开机BIOS加载硬盘上的引导程序grub,gurb从硬盘上引导一个kernel和简单安装程序. 简单安装程序启动后,此时有足够的设备驱动, 再由你来选择具体安装方式: 硬盘安装(ISO)或网络安装(NFS),并进行相应的配置.
上 面提到的安装程序的kernek和简单安装程序都在ISO文件的isolinux目录下,分别叫vmlinuz和initrd.img. 我们将其解出到硬盘的某个分区上(gurb不支持NTFS文件系统). 简单安装程序不支持NTFS文件系统,所以ISO文件要存放在非NTFS分区上.
因此第一步要安装grub.由于gurb要由 BIOS引导,故gurb要安装在任何可启动的磁盘驱动器上. 如你的内置硬盘,或USB存储介质(如BIOS支持的话). 如果电脑的内置硬盘上已经安装有windows,可以在windows里进行安装gurb. 下载WINGURB,选择grub-install,设备选你的内置硬盘即可. 由于grub支持命令行编辑启动,所以无需配置,只要安装上就行. 重启后即进入到grub启动界面,按c进入命令行模式, 用root命令设定vmlinuxz以及initrd.img所在的分区为root分区. 接着用kernel命令和initrd分别选定 vmlinuxz和initrd.img. 最后输入 boot 即可启动. 配置完语言和键盘后,即选择安装方式,选硬盘安装并且指定好ISO所在分区和目录即开始常规的安装过程.
chroot初探
这个命令的功能描述为:Run a command with a different root directory. 即在/目录理解成其它目录的环境下运行一个命令. 而我以前将其错误的理解成整个应用环境的功换. chroot下应用执行环境与原来的环境的差别只是/目录的实际物理路径不一样(当然会造成同样的路径所访问到的实际文件不一样)
不过实际使用中,一般都是这样用chroot:
chroot 目录
这 种用法后面没有跟一个命令作为参数,chroot会默认执行SHELL环境变量所保存的值作为命令来执行. 由于SHELL这个程序运行起来后不会退出,且会在终端下给出命令提示符,所以整个个命令执行起来后,即陷入,同时出现新shell的提示符,给人的感觉 是切换到新的用户环境. 由于新的shell会重新载入一些环境变量以及初始化脚本,故新环境下坏境变量与原来的环境变量还是有一些差别的.
要测试的话:
新建一个目录,把/bin以及/lib目录拷贝到新目录下,然后就可以chroot到新目录,输入exit即回到原来的环境.
openoffices tip
页面横向纵向设置:
在 Format --> Page 菜单里, 对应英文为Orientation: Portrait(纵向) Landscape(横向)
linux用电驴
安装amule:
yum install amule.
所需要做的配置:
1,更新服务器列表
http://www.emule.org.cn/server.met
2,更新 kad 网络
http://www.emule-inside.net/nodes.dat
3,更新用户名前缀
[CHN][VeryCD] 否则连不上 VeryCD 的这个服务器(no1.eserver.emule.org.cn)这 2 个服务器对于国内
用户是相当不错的选择。
浏览器关联:
在地址栏输入 about:config
新建"布尔"
名称为:network.protocol-handler.external.ed2k
值为:true
新建"字符串"
名称为:network.protocol-handler.app.ed2k
值为:/usr/bin/ed2k
shell脚本的路径问题
#! /bin/bash
echo "Path to $(basename $0) is $(readlink -f $0)"
但这种方法只适以子shell方式执行的脚本,不适用于在当前shell中执行的脚本.
难道就没有方法了吗?
Latex初探
偶然间在水木上进去到latex的版块,简单了解一下后也就有了想学的冲动. 立刻找资料.但估计这个东西和emacs一样,学习曲线都会是十分陡的. 所以学习笔记先就不在这里记了. 等以后感觉学到某个阶段,再把整理好的笔记补上.
tor
1. yum install tor
2. install foxyproxy add-on in firefox
2. restart system or start tor manually
3. configure the autoproxy(firefox add-on) to using tor with specify URL.
4. enjory
双系统共享邮件
收了,无法在另一个系统下访问到。 另外一个就是两个系统下的浏览器的bookmark需要手动去同步.
今天终于试验了一下这两者都使用跨平台的软件,分别是firefox和thunderbird. 并且把储存配置文件和数据的目录(profile)指向硬盘的同一个位置.
这里要注意两个平台下的这两个软件的版本最好一致,否则启动时老是要检果插件版本等工作,影响启动速度.
修改firefox profile 路径的方法:
Mozilla Firefox stores all your personal settings, such as bookmarks, passwords and extensions, in a profile. The profile is stored on your hard drive in a profile folder
Move an existing profile or restore a backed up profile
It's possible to move the location of a profile folder. This could be useful if you have a backed up profile folder somewhere
on your hard drive and want to tell Firefox to use that as your profile. This section explains how to do this.
1. Shut down Firefox completely (File > Exit).
2. Move the profile folder to the desired location. For example, on Windows XP, move the profile from C:\Documents and Settings\[username]\Application Data\Mozilla\Firefox\Profiles\xxxxxxxx.default to D:\Stuff\MyProfile. If you are reading these instructions because you want to restore a previously backed up profile, this step isn't necessary. Just note the current location of the profile you want to restore.
3. Open up profiles.ini in a text editor. The file is located in the application data folder for Firefox:
* On Windows Vista/XP/2000, the path is %AppData%\Mozilla\Firefox\
* On Windows 95/98/Me, the path is usually C:\WINDOWS\Application Data\Mozilla\Firefox\
* On Linux, the path is ~/.mozilla/firefox/
* On Mac OS X, the path is ~/Library/Application Support/Firefox/
4. In profiles.ini, locate the entry for the profile you've just moved. Change the Path= line to the new location. If you are using a non-relative pathname, the direction of the slashes may be relevant (this is true for Windows XP).
5. Change IsRelative=1 to IsRelative=0.
6. Save profiles.ini and restart Firefox.
修改tunderbird profile 的方法差不多.
用 firefox 保存网页中的 flash
1. Saving Flash files from Firefox
Firefox for Newbies
a. Click Tools - Page Info
b. Click the Media Tab on the Page Info Windows
c. The media tab has a complete list (with preview) of Images, CSS Files and Shockwave Flash files that were downloaded by the Firefox browser while rendering (loading) the page.
d. Scroll down the list and locate the swf file.
e. Click the "Save As" button. Select some directory on your hard drive and save the file (No need for a third-party plug-in)
Firefox for Geeks and Power Users
a. Type about:blank in the Firefox address bar
b. Now click List cache entries or directly type about:cache?device=disk (Disk cache device)
c. Press Ctrl+F and try to location the flash file by typing some part of website URL or the flash file name or just .swf. After some hit and trial, you should be able to locate the swf file URL
d. Click the SWF URL to open the Cache Entry Information page. Right click on the link and choose "Save link as"
不过Firefox for Newbies 的方法对于我所要的保存的Flash 不管用. 而for Power Users 的方法好像有点麻烦. 有个插件可以帮忙:
cacheviewer
安装完成后,在Firefox浏览器中,点击 工具->CacheViewer,打开下面的窗口,在"搜索"(search)中填入要找的flash的文件名,双击保存就可以了。
thread
When create thread with pthread_create, the attr argument can also be
NULL
, in which case default attributes are used: the created thread is joinable (not detached) and has an ordinary (not realtime) scheduling policy.关于linux 实时性的 好文章
http://blog.tom.com/blog/read.php?bloggerid=993876&blogid=57349
compile and debug directfb
[root@localhost bin]# uname -a
Linux localhost.localdomain 2.6.20-1.2952.fc6 #1 SMP Wed May 16 18:59:18 EDT 2007 i686 i686 i386 GNU/Linux
[root@localhost bin]# rpm -qa | grep gcc
libgcc-4.1.1-30
gcc-4.1.1-30
gcc-gfortran-4.1.1-30
gcc-c++-4.1.1-30
1. Enable Frame buffer device dirver in your machine.
DirectFB version: DirectFB-1.0.0 DirectFB-examples-1.0.0
2. DirectFB:
./configure --prefix=/home/dybbuk/study/DirectFB_install/ --enable-x11 --enable-debug
make
make install
3. DirectFB-examples
./configure --prefix=/home/dybbuk/study/DirectFB_install/ DIRECTFB_CFLAGS=-I/home/dybbuk/study/DirectFB_install/include/directfb/ DIRECTFB_LIBS="-L/home/dybbuk/study/DirectFB_install/lib/ -ldirectfb"
make
make install
Test(under char mode):
export $LD_LIBRARY_PATH=/home/dybbuk/study/DirectFB_install/lib/
/home/dybbuk/study/DirectFB_install/bin/df_window
4. deubg:
add a line "system=x11" in the /etc/directfbrc file.
debug directfb application under X.
For more information see the maillist below:
A copy-paste regarding X method. But I don't know a way without X, and with one machine. If u come to know, plz post it :-)
-----------
Use X
Just for the sake of development, DirectFB actually provides an X backend. In that mode, an X window is the directfb screen, and all directfb display goes to that X window. That is convenient, because- We can simultaneously work with whatever other X applications we want
- Much easier to debug,
- In situations like crashing or hanging up, you can just close the window, or in the worst case, just killall -9 program-name
Using the X backend
If you did not build directfb with --enable-x11 option, you need to rebuild it with that option(the option is given to configure script). Then, in the /etc/directfbrc file, you need to add a new line: system=x11Then you can run the same directfb application from X
For performance analysis, and final testing, I would recommend using virtual console, and not X, because thats the way directfb will finally work...
Colin Newell wrote:
What is the best way to run a debugger to debug a directfb program?
One choice is to open an xterm into the machine supporting directfb, and
run gdb in the xterm. If you can see the screen of the directfb machine,
and the Xserver's screen you can efficiently debug.
What if you only have the directfb machine to work on?
If I run gdb on a directfb program directly on the machine with
directfb, then as soon as directfb starts up, gdb loses control of the
keyboard and screen (and then I need to actually kill the program via
an xterm). Is there a clever way to allow use of gdb directly on a
machine running directfb?
Any ideas appreciated.
Regards
Colin Newell
_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users
mplayer on frame buffer
So recompile mplayer is needed.
1. enable frame buffer device driver in kernel
For FC6, only append vga=791 to kernel parameter when start kernel can enable frame buffer device driver.
run 'fbset -i' to see some infomation about current frame buffer.
[dybbuk@localhost mplayer_fc6]$ cat /proc/cmdline
ro root=LABEL=/ rhgb quiet vga=791
[dybbuk@localhost mplayer_fc6]$ /usr/sbin/fbset -i
mode "1024x768-76"
# D: 78.653 MHz, H: 59.949 kHz, V: 75.694 Hz
geometry 1024 768 1024 768 16
timings 12714 128 32 16 4 128 4
rgba 5/11,6/5,5/0,0/0
endmode
Frame buffer device information:
Name : VESA VGA
Address : 0xc0000000
Size : 3145728
Type : PACKED PIXELS
Visual : TRUECOLOR
XPanStep : 0
YPanStep : 0
YWrapStep : 0
LineLength : 2048
Accelerator : No
2. recompile mplayer
Get lattest developent version from the mplayer svn repository. when configure the source tree, check fbdev list in the enabled video output drivers.
3. test
./mplayer -vo fbdev -vf scale=1024:768 ../../The_Code-Linux.avi
Using Directfb:
1. Install directfb and driverfb-dev package
2. modify /etc/fb.modes, add the current frame buffer mode as the first mode.
3. reconfigure and recompile mplayer. make sure directfb list in the enabled video output drivers
4. ./mplayer -vo directfb -vf format=bgr16 ../../The_Code-Linux.avi
(without specify bgr16 format, the picture will all messed up with a lot of green. my graphic chipset is intel 945GM ).
RCS 使用初探
RCS 的作用管理系统文件,并保存修订历史(ps: 在服务器的管理上应该特别有用)
1. 建立RCS仓库
由于RCS将所有修订版本保存在当前目录下的RCS目录中,故要启动RCS仓库,只需创建该目录即可
mkdir RCS
2. 加入文件
仓库建立好了,就可以用了。现在把当前目录下要管理的文件加入到仓库中来
ci -i Filename
这条命令会把文件移入到RCS下,并建立这个文件的第一个版本1.1。命令会要你输入初始化说明(以C-d结束).
3. 登出文件-得到最新版本
第二条命令把文件移到RCS下了,当前目录就没有这个文件了。这可不行,那就从RCS中登出文件,即得到最新版本。
co Filename
4. 登出并锁定文件
如果登出的目的是为了要编辑,那在登出时加锁,以妨其它用户在这段时间更新文件
co -l Filename
5. 登入并解锁文件
编辑完成,更新版本吧
ci -u Filename
命令会要你加入修订说明。
6. 版本比较
编辑完成了,想回顾一下自己做了哪些修改
rcsdiff httpd.conf
这条命令也就是拿RCS中的版本和当前目录下的版本作比较
更多:
checkout时加参数-rn.n指定得到n.n版本
rcsdiff -rn.n -rn.n 比较两个指定版本
关于rcs2log的示例在fc5上有错误输出,不知道为什么
sort: invalid option -- 4
Try `sort --help' for more information.
其用法如下:
rcs2log -v Filename 查看文件的各个版本信息
rcs2log Filename 查看文件修订记录
chipset
x86体系上,其是南桥和北桥芯片的构成的,一种chipset即是一组特定的南桥和北桥的集合. 对于移动平台和x86嵌入式平台. 南桥和北桥芯片可能合到一起成为一块芯片.
硬件反向工程
硬件反向工程(Reverse Engineering RE)
包括以下几种形式:
Product tear-downs identify the product, package, internal boards, and components
System level analysis analyse operations, signal paths, and interconnections
Circuit extraction delayer to transistor level, then extract interconnections and components to create schematics
Process analysis examine the structure and materials to see how it is manufactured, and what it is made of.
第一种即常见的拆解和pcb抄板. 第二种则主要是借助逻辑分析仪来分析硬件的工作时序或协议. 第三种则主要是得到集成电路的原理图或硬件逻辑. 第四种则是深入分析晶体管的制造工艺以及进行失效分析等.
硬件反向工程领域知名公司: 国外为ChipWorks和Semiconductor Insights(SI),国内有上海圣景微电子和北京芯愿景. (行业介绍可以看:IIC-China:中国两大反向工程公司相见言欢,谜底何在)
集成电路的反向工程领域(相关介绍参见:正确实施反向工程,有利于提高芯片设计技术),通常的操作有:
常的操作有:
封装去除(decapsulate/decap):
用酸将封装去除以便提取晶粒
层次去除(delayer):
除去已分析的层或无关层
芯片染色:
为了区分器件类型,需要对衬底进行染色
芯片拍照
用光学显微镜或电子显微镜对芯片进行拍照.
电路提取
借助自动化软件对照片进行电路分析提取
封装去除的一些照片:
完全decap以后晶粒(die)放大图:
其中die所在空腔叫 cavity. die边缘连出的线上叫banding wire. die所依附的底座叫substrate. Substrate四周的片状条叫lead frame. Lead frame连到封装上的pin(这点图上没有).
(AMD AM29X305ADC MCU 图片来源于http://diephotos.blogspot.com/,该页面有更多类似精美的图片)
反向工程的全过程介绍: Safenet iKey 2032 In-depth Look Inside (该网站上还有很多类似的反射工程例子)
有关Intel's Prescott die 介绍:
见http://www.chip-architect.com/news/2003_04_20_Looking_at_Intels_Prescott_part2.html
查找资料当中遇到其它一些单词:
Epoxy 环氧树脂,在以前一般是把die直接附着在pcb上,这时用epoxy把die保护起来. 计算器pcb板上的那团黑色的物质就是(小时候我一直没想明白那里面包着的是什么东西).
Wafer 晶圆
CFI
CFI 由 jesd68 标准定义. 其标定了设备的 Query interface. 用于得到设备所支持的命令集和参数. 其并没有定义任何命令集. 从Query interface得到的信息有一个16-bit ID code(Algorithm Command Set and Control Interface ID Code),其取值和含义在JEDEC PUBLICATION: jep137b 中规定.
如:
0001 Intel/Sharp Extended Command Set
0002 AMD/Fujitsu Standard Command Set
0020 ST Advanced Architecture (这个在jep137b中没有列出)