2010年12月31日 星期五

取消剛剛的patch動作

有時候...會發生patch錯diff檔的事 :p
patch的雙向動作:

[Do It] patch -p0 < xxx.diff
[Undo] patch -p0 -R < xxx.diff

2010年12月14日 星期二

How to link pre-built kernel module

有些情況下
你會希望額外寫的kernel module會用到另一個pre-built好的ko
可是在原先build procedure裡頭
linux並不知道你事先pre-built好的module symbol
因此它在link之前會發現symbol undefine
WARNING: "abc_xxx_yyy_set" [drivers/net/abc/xxx.ko] undefined!

比較簡單的解決方法如下:
在linux-2.6.x/scripts/Makefile.modpost裡頭
加上
KBUILD_MODPOST_WARN := 1

這樣還是會出現原先那些WARNING
因為在這次的build procedure它的確還是不知道這幾個symbol在哪
但是它可以讓你繼續編過

詳細的部分可以參考linux文件目錄下面的Document/kbuild/kbuild.txt

165 KBUILD_MODPOST_WARN
166 --------------------------------------------------
167 KBUILD_MODPOST_WARN can be set to avoid errors in case of undefined
168 symbols in the final module linking stage. It changes such errors
169 into warnings.
170
171 KBUILD_MODPOST_NOFINAL
172 --------------------------------------------------
173 KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
174 This is solely useful to speed up test compiles.
175
176 KBUILD_EXTRA_SYMBOLS
177 --------------------------------------------------
178 For modules that use symbols from other modules.
179 See more details in modules.txt.


2010年12月1日 星期三

header file開頭的#ifndef也要留意

當程式碼越來越多
常常在加加減減和copy and paste的過程中
容易造成新copy的header file開頭的#ifndef忘了跟著改

這個情況常讓工作者抓不著頭緒
在開發工具上看著只是一些簡單的定義明明都有宣告
在相對應的程式碼中也有正確include需要的header path
可是compiler一直抱怨
error: `XXXXX' undeclared (first use in this function)

這個時候應該可以先檢查看看
是不是自己顧著快速copy and paste code卻忘了修改一些定義
常見的就是copy a new header
然後卻忘了改開頭的
#ifndef __MY_HEADER_H__
#define __MY_HEADER_H__
........
#endif /* __MY_HEADER_H__ */

2010年8月20日 星期五

Canon 鏡頭編號

1.第一個字母代表鏡頭的生產工廠︰U=Utsunomiya 日本宇都宮廠房

2.第二個字母代表生產年份︰
A 1986 J 1995 S 2004
B 1987 K 1996 T 2005
C 1988 L 1997 U 2006
D 1989 M 1998 V 2007
E 1990 N 1999 W 2008
F 1991 O 2000 X 2009
G 1992 P 2001 Y 2010
H 1993 Q 2002 Z 2011
I 1994 R 2003

3.後面4位數字:鏡頭生產月份和日期
如果鏡頭編號為UY0601:該鏡頭是日本宇都宮廠房2010年6月份生產的.

=================================================
生產工廠代號︰

O︰大分工廠
K︰大分杵築工廠
U︰宇都宮工廠
F︰福島工廠
T︰台灣工廠
S︰滋賀長 工廠
M︰宮崎

2010年8月6日 星期五

Compare two binary

有時候我們會需要比較兩個binary是否相同
可以用:

hexdump -C xxx.bin > file1
hexdump -C yyy.bin > file2
diff -y file1 file2 | more

2010年7月15日 星期四

remount的意義

Controlling and Querying Mounts

int mount (const char *special_file, const char *dir, const char *fstype, unsigned long int options, const void *data)

For a remount, dir specifies the mount point where the filesystem to be remounted is (and remains) mounted and special_file is ignored. Remounting a filesystem means changing the options that control operations on the filesystem while it is mounted. It does not mean unmounting and mounting again.

Mount, Unmount, Remount

2010年6月7日 星期一

如何修改Firefox Plug-in的語系

有時候找了幾個好用的Plug-in
明明以為是英文語系
但他安裝過程會自動幫你安裝成簡體中文
如果還是習慣看英文介面怎麼辦?

我的方法是,直接去改firefox的config =_=
  1. 在URL欄敲 about:config
  2. 進去後在Filter欄找general.useragent.locale
  3. 把原本的zh-TW改成en-US
  4. restart firefox

2010年6月4日 星期五

Catching Integer Overflows in C

Integer Overflows are arithmetic errors. Integers have finite ranges in computers, for example a 32-bit unsigned integer goes from 0 to 0xffffffff. If you add one to 0xffffffff, you get 0 again.

Since the addition operation in the CPU is agnostic to whether the integer is signed or unsigned, the same goes for signed integers. For 32-bit signed integers, the minimum value is 0x80000000 (-2147483648) and the maximum value is 0x7fffffff (2147483647). Note that there is no value than can hold 2147483648, so if you negate (int)0x80000000, you get (int)0x80000000 again. That is something to look out for, because it means abs() returns a negative value when fed -2147483648.

原文出處: http://www.fefe.de/intof.html


2010年6月3日 星期四

拍出不再淺景深的食物

拉高ISO + 縮光圈(F4~F6.3)
調成手動模式, 快門速度設在安全快門附近

如果食物太大又不想拍得後方糊掉
相機拿高一點拍俯角試看看 <-- 從側邊拍因為焦平面問題通常都會部分糊

另外的重點是拍時不要離主體太近拍
回去再裁圖處理即可

2010年6月1日 星期二

[HowTo] SVN rollback

網路上看到一段話寫著:

SVN 的設計原則就是鼓勵程序員瘋狂 commit,不用怕 commit 有 bug 的程式碼,SVN 記錄整個專案的變動歷程,而不是單一程式碼的變動,所以他的版次是整個專案在計算的。因此在版次之間的切換很方便,今天改錯了,那就回到先前沒錯的版本就 好。也就是因為這樣,他的 check-in check-out 速度飛快無比。為什麼要瘋狂 commit 呢,

Merge early, Merge often, Merge always…

寫了 code 就 commit,改得越少,Merge 越自動,比兩個人坐在隔壁寫程式還要寫得快。而且可以一起改同一支程式,而不用 Lock 程式。這是 SVN 的基本設計理念。如果要把某個時間點的程式碼狀態記下來,那就做一個標註(Tag) 在某個版號上就可以了。

===================

回到主題,話雖如此,但應該不少朋友沒親自做過version rollback的動作
這邊分享一下,下回可以試試看:

假設新的版本是888,舊的版本是777
可以下 svn merge -r 888:777
就可以rollback到777版本了

有人或許會聯想到,這和svn up -r 777不同的是???

用merge的方式,會連888版本的log history都保留,因為你想做的是commit之後會是889之類
但如果你是直接update成777版本,這個時候你的local copy是777,且log history也是777
這個時候即使你想要commit,server應該也會報錯的喔~

常見的Coding Style

下面列出一些網路上的coding style,有興趣可以參考一下:

Linux Coding Style

Android Code Style Guildlines

C++ Programming/Code/Style Conventions

Mozilla Coding Style

Code Conventions for the Java Programming Language

Object Pascal Style Guide


要記得errno的存在!!

不知道是沒睡醒還是在恍神
compile總是出現warning
直說我的func_xxx不是prototype

突然看到密密麻麻的func param當中出現了一個很閃的字眼 errno
OMG....趕快改掉吧 XD

2010年5月27日 星期四

165反詐騙網站的daily report

不想接某些電話的時候
可以順便search一下是不是已經出現在報表裡頭了

話說這幾天常常被同一支號碼煩
查了一下,竟然是最近被檢舉次數第一名的門號,還真有點準.....

報表網址:http://net165.erufa.com/outtext.php

Roomba Life

這篇主要紀錄著Roomba相關的網路資訊


2010年5月26日 星期三

Test harness/Test stubs/Test instrumentation的區別

* Test harness " a contrived code that executes the test cases which are invented to test the unit under test

* Test stubs " optional functions (or macros) created to replace functions (or macros) called from the unit under test (UUT) to abstract from the actual behaviors of the real functions.

* Test instrumentation " code plugged into the UUT to expose its behaviors normally not visible from the outside and to output "documentable" traces of execution.

參考文章:http://www.embedded.com/design/201805598

=================================================

In software testing, a test harness or automated test framework is a collection of software and test data configured to test a program unit by running it under varying conditions and monitoring its behavior and outputs.

It has two main parts: the Test execution engine and the Test script repository.


DUT, UUT, SUT的區別

DUT: device under test
UUT: unit under test
SUT: system under test

Device under test (DUT), also known as unit under test (UUT), is a term commonly used to refer to a manufactured product undergoing testing.

System under test (SUT) refers to a system that is being tested for correct operation. The term is used mostly in software testing. The term SUT means also a stage of maturity of the software, because a system test is the successor of integration test in the testing cycle.

2010年5月20日 星期四

Word也可以用滑鼠放大縮小頁面比例

剛剛無意中發現
慣用了MAC的滑鼠放大縮小功能
在Word上也可以
很簡單,按著CTRL再滾動滑鼠滾輪就可以了

一個方向是比例放大
另一個方向是縮小,到後來是變成一個螢幕show出多張page
對我來說還蠻方便的

2010年5月7日 星期五

[MAC] 常常滑到Expose設定的四個角落怎辦?

Expose很好用很實用
但....有些時候滑鼠太靈活會不小心滑到四個角落
而造成工作突然中斷一下也不是很好
後來發現....

Expose的設定是可以加上特定按鍵的
譬如說,可以在進行Expose設定的同時
先按住command,再去下拉式選單選擇你想要的功能即可


[MAC] 如何快速關閉螢幕

快速關閉螢幕 Shift + Control + Eject
快速進入睡眠 Option + Command + Eject
快速進行關機 Control + Option + Command + Eject

另外
如果離開座位有習慣鎖定螢幕的朋友
可以先在System Preference --> Security --> General去設定
然後可以用快速關閉螢幕 or Expose去做鎖定


2010年4月15日 星期四

Configuration of NFS Server and Client

[NFS Server]

Server端的部分有幾種選擇:
  1. pure Linux server
  2. Windows host with Cygwin
  3. Windows host with FreeNFS

(1)
pure Linux Server的部分大家應該都很熟悉
如果有點忘了也可以參考這邊
另外就是,有時候Linux server是共用的,你不見得擁有root權限
所以提供其他選擇讓大家參考

(2)
Cygwin也是很多人使用的環境
要架設NFS server你需要額外的packages
  • Net :: nfs-server
  • Libs :: sunrpc
  • Admin :: cygrunsrv
install完成之後,執行/usr/bin/nfs-server-config
接下來都回答yes,並提供user/passwd供windows services使用
接著cygwin會自動幫你install mountd/nfsd/portmap

上述動作都跑完之後,接著就是去修改/etc/exports來決定你想分享的目錄和權限

再來就是mountd/nfsd/portmap的使用,有兩種方式:

1. 從Windows的控制台->系統管理工具->服務
找到這三個,然後決定自動/手動/停用等選項

2. 從cygwin裡頭去下 /bin/cygrunsrv --stop/start/remove ....

Stop the services:

 cygrunsrv --stop mountd
cygrunsrv --stop nfsd
cygrunsrv --stop portmap

Remove the services:

 cygrunsrv --remove mountd
cygrunsrv --remove nfsd
cygrunsrv --remove portmap
最後就是記得把Windows防火牆針對這些app ports打開

更多內容請參考: 文章一 文章二

(3)
最後來介紹最簡單的設定工具
直接下載sourceforge上的這個freenfs project來用
馬上執行馬上通,很適合不想被眾多設定搞得一頭霧水的朋友們使用

下載點: FreeNFS

=================================================
[NFS Client]

這邊client的部分主要針對embedded target board上的設定
主要要改的有三大部分:
  1. Kernel
  2. uClibc
  3. mount (or busybox)
(1)
首先,要使用NFS是需要kernel的幫忙的
所以在menuconfig中,先找到

(1.1)
Networking --->
Networking support
Networking options --->
TCP/IP networking
[*] IP: kernel level configuration (把底下DHCP和BOOTP都選起來,RARP選起來也safe)

(1.2)
File systems --->
Network File Systems --->
<*>NFS file system support
[*] Provide NFSv3 client support
然後底下
[*]Root file system on NFS (如果你要做的是nfsroot,這邊一定要記得選)

(1.3)
如果是uClinux,在General Setup --->
可以把Initramfs source file設成empfs

(2)
uClibc的部分要支援
Networking Support --->
[*] Remote Procedure Call(RPC) support
[*] Full RPC support

(3)
mount的部分要支援
[*]mount: support NFS mounts

-------------
mount NFS有兩種case
  • mount any directory exported from nfs server
  • mount nfsroot at kernel booting
第一種直接在target shell下
mount -t nfs -o nolock 192.168.1.1:/pub /mnt/nfs

第二種需要傳入一些參數給kernel
方法也有兩種:
  • 直接在kernel menuconfig去寫command string要為何
Kernel command line: root=/dev/nfs rw nfsroot=192.168.0.17:/rootfs,nfsvers=3 ip=192.168.0.15:192.168.0.17:192.168.0.1:255.255.255.0:1:eth0:off
  • 從u-boot下去設環境變數
+ uboot> setenv ipaddr 192.168.1.254
+ uboot> setenv serverip 192.168.1.1
+ uboot> setenv bootargs root=/dev/nfs nfsroot=/tftpboot/rootfs ip=192.168.1.254:192.168.1.1::::eth0:off

參考網址:
uclinux-dist:nfs
[Buildroot] [PATCH] docs/howto: add howto for nfsroot
SkyEye: BootfromNFS
root_file_system_structure

======================================
[Buildroot]
要支持NFS,除了busybox的mount命令要支持NFS外,buildroot需要添加如下设置:
Toolchain----->[*]Enable RPC
Package Selection----->Networking----->[*]portmap

http://buildroot.busybox.net/buildroot.html

2010年3月10日 星期三

System Spec and Software Spec

What is the difference between a System Specification and a Software Specification?

Very often we find that companies do not understand the difference between a System specification and a Software Specification. Important issues are not defined up front and Mechanical, Electronic and Software designers do not really know what their requirements are.

The following is a high level list of requirements that should be addressed in a System Specification:

  • Define the functions of the system
  • Define the Hardware / Software Functional Partitioning
  • Define the Performance Specification
  • Define the Hardware / Software Performance Partitioning
  • Define Safety Requirements
  • Define the User Interface (A good user’s manual is often an overlooked part of the System specification. Many of our customers haven’t even considered that this is the right time to write the user’s manual.)
  • Provide Installation Drawings/Instructions.
  • Provide Interface Control Drawings (ICD’s, External I/O)

One job of the System specification is to define the full functionality of the system. In many systems we work on, some functionality is performed in hardware and some in software. It is the job of the System specification to define the full functionality and like the performance requirements, to set in motion the trade-offs and preliminary design studies to allocate these functions to the different disciplines (mechanical, electrical, software).

Another function of the System specification is to specify performance. For example, if the System is required to move a mechanism to a particular position accurate to a repeatability of ± 1 millimeter, that is a System’s requirement. Some portion of that repeatability specification will belong to the mechanical hardware, some to the servo amplifier and electronics and some to the software. It is the job of the System specification to provide that requirement and to set in motion the partitioning between mechanical hardware, electronics, and software. Very often the System specification will leave this partitioning until later when you learn more about the system and certain factors are traded off (For example, if we do this in software we would need to run the processor clock at 40 mHz. However, if we did this function in hardware, we could run the processor clock at 12 mHz). [This implies that a certain level of research or even prototyping and benchmarking needs to be done to create a System spec. I think it is useful to say that explicitly.]

However, for all practical purposes, most of the systems we are involved with in small to medium size companies, combine the software and the systems documents. This is done primarily because most of the complexity is in the software. When the hardware is used to meet a functional requirement, it often is something that the software wants to be well documented. Very often, the software is called upon to meet the system requirement with the hardware you have. Very often, there is not a systems department to drive the project and the software engineers become the systems engineers. For small projects, this is workable even if not ideal. In this case, the specification should make clear which requirements are software, which are hardware, and which are mechanical.

原文出處: How to write a software requirements specification



2010年2月24日 星期三

different memory address

kernel logical address: These addresses map most or all of main memory.and are often treated as if they were physical addresses. On most architectures, logical addresses and their associated physical addresses differ only by a constant offset.
内核逻辑地址和物理地址之间只有一个偏移量的差别。而且内核在启动时就是根据这种逻辑地址和物理地址的对应关系给896MB以下内存建立了页表。virt_to_phys只接受这种直接映射的虚拟地址作为参数。

kernel virtual address: ioremap返回的就是这种地址。它在VMALLOC_START和VMALLOC_END之间搜索到一块空闲的虚拟地址空间,把它和物理地址 (ioremap的参数)建立联系,并建立页表。VMALLOC_START是根据最大内存地址的虚拟地址(kernel logical address)计算出来的,如在i386中:
#define VMALLOC_START (((unsigned long) high_memory + 2*VMALLOC_OFFSET-1) & ~(VMALLOC_OFFSET-1))

可见kernel logical address和kernel virtual address 是不一样的,而且在值上是不会重叠的。对kernel virtual address调用virt_to_phys也是没有意义的。
===================================
一种就是在引导时预留RAM,如设置MEM=31M,阻止内核使用最顶部的1M字节,然后用:
dmabuf=ioremap(0x1F00000 /* 31M */, 0x100000 /* 1M */ );

我觉得你这里传给DMA的应该就是0x1F00000, 这就是物理地址,DMA所需要的。ioremap后的到的地址dmabuf是虚拟地址,是给程序用的。DMA操作完后,0x1F00000处就应该有了你要的数据,然后你就可以通过:
memcpy(dest, dmabuf, size)
操作从0x1F00000把数据复制到你想要放的地方。

你这里讲的预留1M的空间实际上已经变成了外设地址空间,因为kmalloc无法分配这块地方。


對I/O memory region寫值

Q: 假設有一個I/O addr和一個value,請說明將value寫進addr的步驟?

A:用 check_mem_region(mem_addr, mem_size) 函数来检查该内存地址有没有被用到, 可以用的话调用函数 request_mem_region(mem_addr, mem_size, "设备名称") 申请该内存,成功的话, 调用 writeb(values, mem_addr),或者 writew(values, mem_addr),writel(values, mem_addr), 来在 mem_addr 地址 写入 value 值,三个函数分别为写入 8位,16位和32位的值。 最后需要调用 release_mem_region(mem_addr, mem_size) 函数来…

I/O Resource Management

Functions (Detailed Description)

struct resource * request_region (unsigned long start, unsigned long n, const char *name)

Allocate I/O port region.
struct resource * request_mem_region (unsigned long start, unsigned long n, const char *name)

Allocate I/O memory region.
void release_region (unsigned long start, unsigned long n)

Release I/O port region.
void release_mem_region (unsigned long start, unsigned long n)

Release I/O memory region.
int release_resource (struct resource *res)

Release any resource.
int check_region (unsigned long start, unsigned long n)

Check I/O port region availability.
int check_mem_region (unsigned long start, unsigned long n)

Check I/O memory region availability.
void * ioremap (unsigned long phys_addr, unsigned long size)

Remap I/O memory into kernel address space.
void * ioremap_nocache (unsigned long phys_addr, unsigned long size)

Remap I/O memory into kernel address space (no cache).
void iounmap (void *addr)

Unmap I/O memory from kernel address space.

[新手入門] C for embeded world

if you know C, you are 50 % embedded capable. In this article, I will share a few tips that will make you an embedded qualified programmer.

1. Understand Memory Segments

Memory where the code runs can come one or more different areas called segments. These areas are simply the logical divisions that can contain suitable physical memory. To understand C code better, you need to be aware of a few common memory segments. Users can always define their segments in assembly code.


-------------------
| Text segment |
| |
|-------------------|
| Data segment |
| |
|-------------------|
| symbol table |
| |
|-------------------|
| Stack |
| |
|-------------------|
| HEAP |
| |
-------------------

1.a. Text (instructions)

This segment contains execution instructions. Normally, this segment is Read only. Programs are not generally allowed to modify the text segment. The code below will reside in the text segment.

int f() {
return 1;
}

1.b. Data Segment

This segment is used to hold global and static variables in a program. static variable, in a way, is a global variable except with limited visibility scope. A global variable/function normally has visible entry in the symbol table, whereas the static does not have an entry in the symbol table.

The globalCount variable below will reside in the data segment. Any change in its value anywhere will be effective.

int globalCount = 0;

void increment()
{
globalCount++;
}

1.c. Symbol Table

When the compiler compiles code, it puts all named entries (functions, global variables), into symbol table. The debugger uses this symbol table to go between an address and a function name. Its main purpose is for debugging/tracing.

1.d. Stack

Stack is where automatic variables stored when exceeding the number of register profile. Each program will have a default stacksize which is set by linker/compiler tool. In the example below, variable array will be allocated on the stack, whereas variable i is likely to be assigned with a register.

void functionF()
{
int array[20];
int i;
for (i = 0; i < 20; i++)
array[i] = i*i;
….
}

1.e. Heap

Heap is where operation like malloc and free operate on. It provides dynamic memory for the program. Heap is normally used for big memory buffer.

2. Know important keyword implications

When C programming was taught in school, there was little mentioning about implications of using different keywords. But rather, the coursework was probably focusing on the code construct, logic, etc… These are of course very essential for programming C, but little extra understanding would make any C course twice beneficial. Here are a few import keywords that an embedded software engineer needs to be aware of.

2.a. static keyword

static key word when combined with the variable tells the compiler to put the variable in the data segment, but limits the access scope to either a file or a function. In the code below, fileStatic variable sits in the data segment, and its scope is file meaning that any function within the same file can access to it. On the other hand, variable funcStatic is only available with functionF. funcStatic also sits in the global data segment.

static int fileStatic = 2;
void functionF()
{
int funcStatic = 1;
int array[20];
int i;
}

static is normally used by internal functions of a module. A typical use of static is shown in the snippet below

/* internal functions ... */
static void _internal1();
static void _internal2();
...
/* public functions */
int module1_function1();
int module2_function2();

2.b. volatile keyword

volatile keyword tells the compiler to use the variable from memory and not to optimize it with a register. It is typically used when the variable is shared between modules or it can be changed at anytime. Hence, any variable representing a memory location should be declared with volatile keyword.

volatile unsigned int * HardWareAddr = 0xFF00AABB;
/* read hardware register */
unsigned int a = *HardwareAddr;
/* write register */
*HardwareAddr = 0xABCDEF00;

3. Pointers and Function Pointers

Have a really good understanding about pointer and memory will take care of most of the embedded issues for you.

Pointers allow you to quickly access data at certain memory location direction, as seen in the section 2.b.

Function pointer (or also refered as function callback) is another important element of embedded world. Function pointers allow code to easily jump back and forth between functions. Most of the low level OS facilities involve function callback: Interrup Service Routine (ISR), OS context switch, user hook to OS facilities.

4. Closing

I hope that this little short article gives you some useful introduction to applying C to writing embedded applications.

參考: 原文出處

memory barrier

memory barrier 長這樣 __asm__ __volatile__("": : :"memory")

首先gcc對於匯編語言(組合語言),是使用AT&T的語法,不同於INTEL的組合語言語法

格式 : __asm__(組合語言:輸出:輸入:修飾詞")
__volatile__ 代表這行指令(這些組合語言),不和前面的指令一起最佳化
"memory" 告訴GCC這些組合語言會改變所有的RAM的資料
因為沒組合語言,又告訴gcc所有RAM的內容都改變,
所以這個memory barrier的效用,
會讓這行之前被gcc所cache到暫存器的資料通通寫回RAM裡面
也告訴gcc會讓之後讀取RAM的資料,必須再從RAM裡讀取出來

參考:原文出處

在asm裡面是說這個東西compiler時,gcc不要雞婆作optimized,因為 最佳化的結果,compiler會把code按照他想的方法放到記憶體裡, 但是有的code我們需要特定指定他一定要在某個記憶體上, 在kernel裡常有這樣情形發生,我們可以用 __asm__ __volatile__宣告一段assembly的code是不要做最佳化的。 例如cli sti
#define disable() __asm__ __volatile__ ("cli");
#define enable() __asm__ __volatile__ ("sti");