2008年3月31日 星期一

Input parameter check of udelay

使用udelay只有在傳入的參數是constant時才會檢查大小,成功就call __const_udelay
若不是constant則不會檢查大小,直接call __udelay(n),但delay的時間就不一定對了(算完後可能會overflow)
include/asm-arm/delay.h


#define MAX_UDELAY_MS 2

#define udelay(n) \
(__builtin_constant_p(n) ? \
((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
__const_udelay((n) * 0x68dbul)) : \
__udelay(n))

implementations is in linux/arch/arm/lib/delay.S


__builtin_constant_p: from GCC 4.3.0 Manual 5.49 Other built-in functions provided by GCC
— Built-in Function: int __builtin_constant_p (exp)

You can use the built-in function __builtin_constant_p to determine if a value is known to be constant at compile-time and hence that GCC can perform constant-folding on expressions involving that value. The argument of the function is the value to test. The function returns the integer 1 if the argument is known to be a compile-time constant and 0 if it is not known to be a compile-time constant. A return of 0 does not indicate that the value is not a constant, but merely that GCC cannot prove it is a constant with the specified value of the -O option.

2008年3月30日 星期日

大嘴鳥結束主題曲 - キョロちゃん絵描き歌

from 歌詞帝國
聽歌(不完整)
聽歌(要登入)【ニコニコ動画】キョロちゃんの絵かき歌 フル(full) ver

キョロちゃん絵(え)か描(き)歌(うた)

詞:ほんごうみつる
曲:栗原正巳
歌:さねよしいさ子

編曲:栗原正己 、近藤研二

天気(てんき)がいいね 絵(え)でも描(か)きたい…
何(なに) 描(か)こうかな どうしようかな?

丸(まる)描(か)いて 丸(まる)描(か)いて
丸(まる)描(か)いて 丸(まる)描(か)いて

中(なか)の二(ふたつ)つを黒(くろ)くぬり 三角(さんかく)帽子(ぼうし)をかぶせたら
ながー い丸(まる)でつつみます

アンテナ二本(にほん)立(た)てまして
棒(ぼう)を一本(いっぽん)引(ひ)きまして

                   
おなかにギザギザかいちゃって クルッと回(まわ)して ツルッとすべって
一度もどして あら、これは!
キョロちゃん キョロちゃん
キョロ キョロ キョロ キョロ キョロちゃん
バビドゥ ミレドゥ ヘレヒレ ホレモニ
キョロちゃん キョロちゃん

                            
雨(あめ)が降(ふ)ってる ゆううつだな 今(いま) したいこと 落書(らくか)きかな
棒(ぼう)ひいて 棒(ぼう)ひいて 棒(ぼう)ひいて 棒(ぼう)ひいて

上(うえ)に花瓶(かびん)をのせたなら 草(くさ)がニョロッと生(は)えちゃった
舌(した)を出(だ)したら湯(ゆ)気(げ)がでて お日様(ひさま)にっこり雲(くも)ひとつ

パタパタ羽(はね)に中(なか)四角(しかく) ギザギザタマゴにのせたなら
右足(みぎ)出(だ)して 左(ひだり)も出(だ)して クチバシつけたら  あら、これは!

ミッケン ミッケン
ミッケ ミッケ ミッケ ミッケ ミッケンくん
シャバドゥ ドゥビドゥ
スットロロット ハットロロット
ミッケンくん ミッケンくん

夜(よる)になっても 眠(ね)たくないよ
布団(ふとん)の中(なか)で 絵(え)でも描(か)こうか

ABCのA描(か)いて A描(か)いて A描(か)いて A描(か)いて
橋(はし)を二本(にほん)かけまして 中(なか)に線路(せんろ)が走(はし)ります
大(おお)きな口(くち)にあごつけて 上(うえ)にMの字(じ)のせまして
豆(まめ)がつにゴマつ でっかい饅頭(まんじゅう)つぶれてる
チクチクチクチク チクチクチクチク

クルッと回(まわ)して キャー、これは!
シババ シババ
シシシシ ババババ シバシバ
シババ シババ シシシシ ババババ
シバ シバ
キョロちゃん キョロちゃん
キョロ キョロ キョロ キョロ キョロちゃん
キョロちゃん キョロちゃん
キョロちゃん キョロちゃん
キョロ キョロ キョロ キョロ 
キョロ キョロ キョロ キョロ
キョロ キョロ キョロ キョロ
キョロちゃん キョロちゃん

描(か)いたらちょっと 幸(しあわ)せになったよ


〈畫大嘴鳥之歌〉
詞:本鄉滿
曲:栗原正巳
歌:實吉伊沙子


天氣真好 好想畫圖……
要畫什麼呢 要怎麼畫呢?
畫一個圓 畫一個圓 畫一個圓 畫一個圓
裡面的兩個要塗黑 三角形的帽子加上去
長長的圓要圍起來 兩隻天線直直地加上去
拉出一隻棒子 在肚子那畫出鋸齒的樣子
一起轉一轉 一起滑一圈 再一次轉回來
哎呀、這是!
大嘴鳥 大嘴鳥
大嘴 大嘴 大嘴 大嘴 大嘴鳥
啪皮肚 咪勒肚
嘿啦西勒 好哇摩你 大嘴鳥
大嘴鳥 大嘴鳥
大嘴 大嘴 大嘴 大嘴
大嘴 大嘴 大嘴 大嘴 大嘴鳥
大嘴鳥
畫完之後就稍微幸福點……
那就好囉


http://www.sonymusic.co.jp/Animation/kyoro/animation/song/ed/isako/index.html


大嘴鳥的由來


大嘴鳥雖然在1967年就在日本森永製果誕生(比凱蒂貓還老),但是到1999年才被製作成動畫。而剛誕生的大嘴鳥就像醜小鴨一樣,一開始並不被日本森永製果看好,然而後來卻大受小朋友們的歡迎。


大嘴鳥又稱巨嘴鳥,有著漂亮鮮黃色的大嘴巴。小時候第一次看到這種鳥是在南投的鳳凰谷鳥園,只記得這是一種嘴巴很大,顏色很鮮豔的鳥;和牠很像的還有一種巨犀鳥,頭上多頂了一頂帽子


將繪圖與歌曲配合成一首適合小朋友活動的兒歌,在我小時候還沒有遇過;滿有趣的,所以特別把這首歌記下來,有空自己畫!但是邊聽邊畫之後卻變成一隻鬥雞眼的大嘴鳥,滑鼠實在太難控制了

2008年3月29日 星期六

網站抓圖

無名
WretchXD v1.6.0.26
http://soft.ccn.tw/
我的W2k不能跑,用XP ok

2008年3月27日 星期四

Building OCF-linux and openswan

  1. download packages
    ocf-linux (current release 20071215) http://ocf-linux.sourceforge.net/
    crypto-tools-20071215.tar.gz
    ocf-linux-20071215.tar.gz
    ocf-linux-24-20071215.patch.gz
    ocf-linux-26-20071215.patch.gz
    ocf-openswan-2.4.11-20071215.patch.gz
    linux kernel (2.4 and 2.6 kernels up to and include 2.4.34 and 2.6.23)
    openssl-0.9.8g (or e)
    openswan-2.4.11
  2. build ocf-linux
    • patch linux kernel source with ocf-linux-26-20071215.patch.gz
    • change kernel config
      Cryptographic options  --->
      OCF Configuration --->
      <*> OCF (Open Cryptograhic Framework)
      <*> cryptodev (user space support)
      <*> cryptosoft (software crypto engine)
      <*> safenet (HW crypto engine)
    • build kernel
    • install cryptodev.h
      mkdir include/crypto;
      ln -s crypto/ocf/cryptodev.h include/crypto/cryptodev.h;
      or install it at /usr/include/crypto/cryptodev.h
  3. build openssl-ocf
    patch openssl-0.9.8g (or e) with openssl-0.9.8g.patch (or e) in ocf-linux-20071215.tar.gz, then build it.
  4. build crypto-tools-20071215.tar.gz
    ensure crypto/cryptodev.h is installed somewhere
  5. build openswan-ocf
    patch openswan-2.4.11 with ocf-openswan-2.4.11-20071215.patch.gz and build it

    However, building KLIPS module doesn't use OCF crypto by default. (?)
    Because there is a default config included in the Makefile(linux/net/ipsec/defconfig) and it doesn't include CONFIG_KLIPS_OCF=y.

    Adding "CONFIG_KLIPS_OCF=y" do cause ipsec_ocf.o compiled, but still failed because CONFIG_KLIPS_OCF is not defined. Additional flags "-DCONFIG_KLIPS_OCF" should be added when CONFIG_KLIPS_OCF is required while compiling.
    Index: packaging/makefiles/module26.make
    ===================================================================
    --- packaging/makefiles/module26.make (revision 96)
    +++ packaging/makefiles/module26.make (working copy)
    @@ -50,7 +50,12 @@
    include ${OPENSWANSRCDIR}/packaging/makefiles/module.defs
    ifneq ($(strip $(MODULE_DEFCONFIG)),)
    include ${MODULE_DEFCONFIG}
    +
    +ifneq ($(strip $(CONFIG_KLIPS_OCF)),)
    +EXTRA_CFLAGS += -DCONFIG_KLIPS_OCF
    endif
    +
    +endif
    include ${KLIPSSRC}/Makefile.fs2_6


    Index: linux/net/ipsec/defconfig
    ===================================================================
    --- linux/net/ipsec/defconfig (revision 96)
    +++ linux/net/ipsec/defconfig (working copy)
    @@ -1,3 +1,4 @@
    +CONFIG_KLIPS_OCF=y

    #
    # RCSID $Id: defconfig,v 1.28.2.1 2006-10-11 18:14:33 paul Exp $
Testing
  1. according to ./crypto/ocf/README,enable debug option of ocf/cryptodev/safe/cryptosoft
  2. use cryptotest/openssl command to test, and there should be debug message from ocf modules printed.
  3. use openswan to get connected, and there should be debug message from ocf modules printed.

2008年3月26日 星期三

Ascii Table

blogger的"撰寫"會自動吃掉用ascii code 的&#60; 用<取代 ,於是若是你這次用&#60;發佈文章 會ok,下一次修改的時候&#60;就會變成<,再 發佈文章 時就會出現tag錯誤。

所以要用named entity的方式, ref RFC1866 ch14, or Special Characters
&yen; ¥
&lt; <
&gt; >
&nbsp (no-break space)
http://www.asciitable.com/

2008年3月25日 星期二

openswan 雜記

开源Linux VPN解决方案 - OpenSWan安装配置指南
HOWTO OpenSwan 2.6 kernel


Configure-NETKEY

Networking --->
Networking Options --->
(M) PF_KEY sockets
(M) IP: AH transformations
(M) IP: ESP transformations
(M) IP: IPComp transformations
(M) IP: tunnel transformations
(M) IPsec user configuration interface
Cryptographic options --->
<*> MD5 digest algorithm
<*> SHA1 digest algorithm
<*> DES and Triple DES EDE cipher algorithms
<*> AES cipher algorithms
Cryptographic options要注意,否則後來出問題的時候根本看不出來是沒有選的原因:
pluto[12237]: ASSERTION FAILED at kernel_alg.c:264: buflen>0
看source code也看不出個所以然,google了才知道

Configure-OCF-linux
Cryptographic options  --->
[*] Cryptographic API
[*] HMAC support
OCF Configuration --->
<*> OCF (Open Cryptograhic Framework)
<*> cryptodev (user space support)
<*> cryptosoft (software crypto engine)
<*> safenet (HW crypto engine)

openswan psk config
ipsec.conf
# /etc/ipsec.conf - Openswan IPsec configuration file
# RCSID $Id: ipsec.conf.in,v 1.13 2004/03/24 04:14:39 ken Exp $

# This file: /usr/share/doc/openswan/ipsec.conf-sample
#
# Manual: ipsec.conf.5


version 2.0 # conforms to second version of ipsec.conf specification

# basic configuration
config setup
# Debug-logging controls: "none" for (almost) none, "all" for lots.
# klipsdebug=none
plutodebug=all
nat_traversal=yes
interfaces="%defaultroute"

# Add connections here

# sample VPN connection
conn test
authby=secret
left=172.20.6.2
leftsubnet=192.168.2.0/24
right=172.20.6.3
rightsubnet=192.168.3.0/24
auto=add
#Disable Opportunistic Encryption
#include /etc/openswan/ipsec.d/examples/no_oe.conf
include /etc/ipsec.d/examples/no_oe.conf
ipsec.secrets
: PSK "1234567890"

/etc/init.d/ipsec start
ipsec auto --up <config_name>
ipsec auto --status

script
host=a;
or
host=b;

/etc/init.d/ipsec stop;rmmod ipsec ;
eth0=eth0
eth1=eth1
case "$host" in
l|L|left|LEFT|a|1)
a=2;b=3;echo host a config...;;
r|R|right|RIGHT|b|2)
a=3;b=2;echo host b config...;;
*)
esac

echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig $eth0 down
ifconfig $eth1 down
ifconfig $eth0 hw ether 00:$a$a:$a$a:$a$a:$a$a:00
ifconfig $eth1 hw ether 00:$a$a:$a$a:$a$a:$a$a:1

while [ $? = 0 ] ; do route del default 1>/dev/null 2>&1; done

ifconfig $eth1 172.200.6.$a
ifconfig $eth0 192.168.$a.1
route add default gw 172.200.6.$b

/etc/init.d/ipsec start

generate key by /dev/urandom, faster than /dev/random
ipsec rsasigkey --verbose --random /dev/urandom 2192 >> /tmp/k

2008年3月18日 星期二

PCI LA analysis - 080321

Address Phase

  • PCICLK=rising edge
  • CBE=X
  • AD[31:16]=XXXX
  • AD[15:0]=XXXX
  • FRAMEN=Low
Data Phase
  • PCICLK=rising edge
  • IRDY=Low
  • TRDY=Low
  • AD[31:16]=XXXX
  • AD[15:0]=XXXX
LA sample的訊號有時會看到CLK的rising edge在訊號轉變的中間,要怎麼決定它的值呢?
因為PCI有定義setup/hold time,所以舊的值(應該)至少要在CLK的sample event前維持Tsu,在CLK的sample event後維持Th這段時間
PCI bus spec v2.2 Tsu=min 7ns, Th=min 0ns


Setup and Hold Times for Latches
  • Setup Time (Tsu) is the minimum time interval for which the input signal must be stable (unchanging) prior to the sampling event of the clock for the input signal to be recognized correctly.
  • Hold Time (Th) is the minimum time interval for which the input signal must be stable (unchanging) following the sampling event of the clock for the input signal to be recognized correctly.



日本的『燒き』

2008/02/28 - 上野 秋葉原

日文所謂的"お好み燒"(okonomiyaki)
原本是泛指麵糊煎成的各種餅
現在則比較是指我們今天吃的這種圍成大圓形、多次翻面的廣島燒(中日文大致同義)
"モダン燒き"則是有加炒麵的廣島燒

日文的"大阪燒"則是形狀像我們的大車輪餅、但內容物和味道類似廣島燒
(所以是鹹的而不是甜的)
台灣的大阪燒好像都是做成正方形,就我在台灣夜市看的印象

而東京月島地區盛行的"もんじゃ燒"也就是台灣翻成的文字燒
是潑在鐵板上,不成形狀的麵糊
可以照你喜歡的焦度,刮來吃

至於台灣人很愛的車輪餅/紅豆餅,在日文是叫今川燒/大判燒

粉物ジャンクフード大別(XX junk food分類)
各種『燒き』的圖文解說

ウェブ - web
メリケン - アメリカン(American)の転
メリケン粉(こ) - 小麦粉の俗称

Bash Command substitution & Subshell - 080320

Command substitution
$(...) or `...`

Subshell
(...)

Nested command substitution
ls -al $(echo $(ls $(pwd)))


the following is ok...

C2QSERVER lsdk # echo $(a=b;echo $a)=c;echo $b
b=c
but the following failed...
C2QSERVER lsdk # $(a=b;echo $a)=c;echo $b
bash: b=c: command not found

C2QSERVER quicksec # $($(a=b;echo $a)=c);echo $b
bash: b=c: command not found
while the following will work..
C2QSERVER quicksec # eval $(a=b;echo $a)=c;echo $b
c

why?
bash shell只有認是直接的 a=b 這種語法是變數設定
所以 a 是變數可以變動的話,請愛用 eval 代為帶入展開即可
eval $(a=b;echo $a)=c;echo $b
a=b; b=c; echo $b=$(eval echo \$$a)

h

2008年3月17日 星期一

retty : 攔截終端機輸出的工具

retty : 攔截終端機輸出的工具



我只能在同機器上開的兩個terminal上作retty
由ssh連接的不能攔截其他終端機,也沒辦法被攔截?
ssh用的是pts
而retty只能處理tty(?)

2008年3月15日 星期六

Papago R12 vs R15/VROne

話說我用GPS導航由來。工作上的原因拿到了一台Acer N300的Engineer sample,WLAN不能用,使用上也不太穩定。某天心血來潮,跑去NOVA買了papago r12和ㄧ支bluetooth GPS,就這麼用了好一陣子。不過過年前某天N300突然變ㄟ告,突然發現沒有語音提示,就得不時注意PDA,對行車安全影響很大,因此才打算再買一台導航機。自從買了A800以後,出去就幾乎都用A800,灌了多選單以後,仍然是比較常用papago。

基本上R15和VROne應該是同樣的東西,UI介面上只有些微的差別。使用上UI變漂亮了,有了複雜路口的實境圖(可是我只有模擬導航的時候才看過,我實際使用上還沒看過),地圖資訊較豐富。不過說老實話,實際使用上並沒有太大的改進,反倒是遇上一些缺點,實在是不吐不快

首先,我沒辦法把我R12的我的最愛匯入到R15或VROne,這絕對是一個很重大的缺失。連R12選單上都有匯入匯出的選項,R15和VROne竟然都沒有,這樣我還得一個一個建回來。怎麼建? 自己key經緯度ㄚ! 我是沒什麼耐心一個一個key....

另外是地圖上顯示的資訊,一些銀行郵局飯店等等的景點更多了,是好處沒錯,但是地圖上可能不能顯示那麼多文字,於是問題出來了,它會給你ㄧ個圖示,讓你知道那裡有個什麼類型的景點,但是如果你對那個景點有興趣,糟了,不知道怎麼點....

還有就是在高速公路上的時候,R12在行進過程中會有接下來兩三個出口的資訊和距離,所以你一眼就能看出來你在哪裡、下一個出口是什麼。缺點是不會顯示收費站,我本來還以為之後可能會加上去吧! 沒想到R15/VROne更扯,根本沒有這些資訊,平常地圖就顯示 "國道三號",一直到接近出口時才有一個小小的綠標指名出口名稱。我知道是國道三號,但是是國道三號的哪邊,還要多久到下一個出口,通通不知道。

不知道是不是PND與PPC的介面不一樣,雖然papago是有名的操作介面複雜(這點在R15/VROne上的確是有改進),但感覺上R15/VROne就是介面更fancy,功能更爛。寫軟體寫成這樣真是不容易,寫到沒東西寫了嗎? 明明還是有很多可以改進的,卻去改進UI。說真的,要不是我的R12沒辦法在A800上灌,我還真寧可用R12就好

2008年3月14日 星期五

FPGA測試不穩定的狀況

狀況:

測試約在1-20個round內會fail,先是Packet Engine(PE)停了,不再處理packet,(過了幾個round)然後可能PCI interrupt會一直asert清不掉(Linux會因為處理interrupt沒有反應)。最後Linux會整個hang住(即使把FPGA端電源關掉也不會有任何反應)。

另外在測試的整個過程中,爾而會觀察到INT_EN或PE_PDR_BASE/PE_RDR_BASE等等register會讀到不正常的值。更甚者連reserved的欄位都會出現值。

有時候PE停掉是因為PDR中的entry值不正常,看起來是被overwrite過。有時候則是因為PE_PDR_BASE被overwrite導致PE去錯誤的addr抓資料。

處理:

其次,利用AxD在可以讀到PCI Memory或I/O位址確定軟體讀的值是正確的。

利用Logic Analyzer(LA)攔截PCI bus的訊號,確定不是軟體(host)端寫入的。另外,出問題時PCI端有時會對host端很奇怪的位置作寫入或讀取。

結果:
問題確認是因為EIP94原來的設計會使用PCI configuration register中的BAR0,1,2,但是PCI bridge只會request BAR0,因此BAR1和BAR2值都會是0x0,PCI loopback (bridge?)會decode addr當看到BAR1/BAR2(?)的addr就會作(loopback),因此會overwrite PCI or host memory上的register/memory值(?)
因為NonOS的驗證用的Memory都是在0x20xxxxxx,所以不會遇到這個問題

反省:

其實我這邊的驗證是應該要能驗出來的,只是礙於alloc memory的位置不知道要怎麼去固定它
1. 如何在Linux裡alloc固定位置的memory
2. PCI 的運作方式?

2008年3月12日 星期三

Debian/Ubuntu Kernel Compile Howto (Kernel 2.6) - 081209

debian/ubuntu 的 update-alternatives 指令

  1. install gcc-2.95, gcc-3.4
  2. update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3 52
  3. update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-2.95 53
  4. update-alternatives --config gcc


Debian-Kernel-Compile-Howto (Kernel 2.6)
  1. apt-get build-dep linux-headers-`uname -r`;
  2. apt-get install kernel-package ncurses-dev fakeroot wget bzip2 module-init-tools procps initrd-tools
    Use "initramfs-tools" instead of "initrd-tools" on Squeeze(6.0).
  3. download, uncompress, and config linux kernel source somewhere, e.g. /usr/src
  4. make-kpkg clean
  5. fakeroot make-kpkg --revision=custom.1.0 linux-image
    fakeroot make-kpkg --revision=custom.1.0 linux-image -j4
    CONCURRENCY_LEVEL=4 fakeroot make-kpkg --revision=custom.1.0 linux-image
    開始build kernel,通常會很久,因為有很多module要build。build完後在上一層(linux-src/../)下會產出一個linux-image-2.6.8.1_custom.1.0_i386.deb
  6. dpkg -i linux-image-2.6.8.1_custom.1.0_i386.deb
  7. Make initrd by
    cd /boot/;mkinitrd -o /boot/initrd.img-2.6.8.1 2.6.8.1;
    Use "mkinitramfs" instead of "mkinitrd" on Squeeze(6.0)
    cd /boot/;mkinitramfs -o /boot/initrd.img-3.2.0+ 3.2.0+;

  8. Grub, Edit /boot/grub/menu.lst, add the following line to the new item
    initrd /boot/initrd.img-2.6.8.1
    LILO
    initrd=/boot/initrd.img-2.6.8.1

    Or simply "update-grub"

http://www.howtoforge.com/kernel_compilation_ubuntu
http://www.howtoforge.com/kernel_compilation_ubuntu_p2
  1. apt-get install kernel-package libncurses5-dev fakeroot wget bzip2
  2. download, uncompress, and config linux kernel source in /usr/src
  3. make-kpkg clean
  4. fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
    CONCURRENCY_LEVEL=4 fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
  5. dpkg -i linux-image-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb
    dpkg -i linux-headers-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb
  6. vi /boot/grub/menu.lst
    title           Ubuntu, kernel 2.6.18.1-custom
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.18.1-custom root=/dev/sda1 ro quiet splash
    initrd /boot/initrd.img-2.6.18.1-custom
    savedefault
    boot

    title Ubuntu, kernel 2.6.18.1-custom (recovery mode)
    root (hd0,0)
    kernel /boot/vmlinuz-2.6.18.1-custom root=/dev/sda1 ro single
    initrd /boot/initrd.img-2.6.18.1-custom
    boot


080815
Debian 2.6.24的linux-image不能開機
連linux-source-2.6.24按照上述程序也不能開機,似乎找不到initrd
2.6.18的就ok

ERROR: Documentation/lguest: No such file or directory
20120315 - linux-3.2.0 w/ Squeeze (6.0)
#638012 - error compiling(make: *** Documentation/lguest: No such file or directory. Stop) - Debian Bug report logs
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=638012

As a workaround simply linking the virtual/lguest/ directory from the Documentation folder of the source tree will solve the problem.
cd ./Documentation
ln -s virtual/lguest/

2008年3月11日 星期二

錄螢幕與聲音

最近聽了一些Webinar, 想把內容抓起來, 於是想找些錄螢幕與聲音的工具
免費螢幕錄製工具:Freez Screen Video Capture 1.2
簡單好用, 一看到就上手

由於我還要錄對方講話的聲音,所以只要到Windows的RecordingControl選擇WaveOutMix (Freez -> Options -> Audio -> Volumn ) 即可錄製PC喇叭聽到的聲音

CamStudio也能用,就是複雜了點

2008年3月9日 星期日

Debug FPGA through PCI

1. use Logic Analyzer (LA)
2. use ICE

2008年3月7日 星期五

Trace32 Installation & Using - 080710

Note:

  • Trace32 要先(於target)開 後(於target)關
  • on Ubuntu, refer to Trace32 在 Ubuntu 上執行的問題 there is no hotplug package available and t32usbchecker always report no debuger found.
  • on Debian(icewm/xfce4)/Ubuntu8.04, after running t32(t32marm), the console shows:
    Warning: String to TranslationTable conversion encountered errors
    Warning: translation table syntax error: Unknown keysym name: osfPrimaryPaste
    Warning: ... found while parsing ':m osfPrimaryPaste:cut-primary()'
    Warning: String to TranslationTable conversion encountered errors
    (................same message repeat a couple of times................)
    all text field can't input text, click on any drop down list would halt all window action, until you kill the t32(t32marm) in other console.
    Solution
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=1196039
    Warning: translation table syntax error: Unknown keysym name: osfActivate

    The problem is actually that the display-machine (5.3) doesn't have the
    XKeysymDB file that defines the special Motif virtual keysyms (osf*).
    This is NOT a java/AWT bug.

    You need to get a /usr/openwin/lib/XKeysymDB file installed on the
    display system that defines these keysyms (not sure which Solaris release
    this file shipped wi).
    http://linux.chinaunix.net/bbs/viewthread.php?tid=898502
    一个十分棘手的问题,请兄弟们给予指点

    export XKEYSYMDB=/usr/share/X11/XKeysymDB
    By my collegue, Scott Shu,
    # mkdir -p /usr/X11R6/lib/X11
    # cd /usr/X11R6/lib/X11
    # ln -s /usr/share/X11/XKeysymDB
  • Also by Scott Shu,
    # t32marm
    FATAL ERROR from X-windows: font not found: t32-lsys-16
    CONFIG: config.t32
    Program stops with message 'font xxxx not found'
    Do fonts appear in the 'xlsfonts' command?
    Can one font (e.g. t32-lsys-16) be displayed by 'xfd -fn t32-lsys-16'?

    Install fonts (options)
    # yum install xorg-x11-fonts-75dpi
    # yum install xorg-x11-fonts-ISO8859-1-75dpi
    # cd /opt/t32/fonts
    # mkfontdir .
    # xset fp+ /opt/t32/fonts
    # xset fp rehash

Installing Trace32
  1. mkdir /home/t32/bin -p
    mount /dev/cdrom /media/cdrom
    cp -r /mnt/cdrom/files/* /home/t32
    cp -r /mnt/cdrom/bin/pc_linux /home/t32/bin;
    chmod -R u+w *
  2. mv /home/t32/bin/pc_linux/config.t32 /home/t32/
    or run t32 by
    t32marm -c/home/t32/bin/pc_linux/config.t32
  3. converts all filenames to lower case and files into UNIX format
    bin/pc_linux/filecvt .
  4. Add the following script at /home/t32
    #!/bin/sh

    export T32SYS=/home/t32
    export T32TMP=/tmp
    export T32ID=T32

    cd /home/t32/fonts
    mkfontdir .
    xset +fp /home/t32/fonts
    xset fp rehash

    cd /home/t32
    ./bin/pc_linux/t32marm

  5. vi config.t32, uncomment the following lines:
    PBI=
    USB
  6. if Ubuntu is used, refer to Trace32 在 Ubuntu 上執行的問題
    else {
    package hotplug required

    grep -iq trace32 /etc/hotplug/usb.usermap || cat /home/t32/bin/pc_linux/usb.usermap.trace32 >>/etc/hotplug/usb.usermap
    install -m 0755 trace32 /etc/hotplug/usb/
    }
  7. use t32usbchecker to verify proper USB operation



Using Trace32
  1. add debug info to image, rebuild the kernel
    Edit arch/arm/Makefile
    CFLAG+=-gdwarf-2
  2. Runing Trace32
    1. [CPU] -> [System Settings] CPU => FA526
    2. [Break]->[OnChip Trigger] (TrOnChip) turn off DABORT, PABORT
  3. Add breakpoint
    1. Get the address of the first breakpoint by:
      grep start_kernel System.map
    2. [Break] -> [Set...] -> [fill address 0xC0XXXXXX] -> [implementation: Onchip] -> [Set] -> [OK]
To load kernel image
  1. Let device boot as normal (load from flash, or tftp). CPU would be trapped when the breakpoint is reached.
  2. Use the Load function
    1. [File] -> [Load: vmlinux]
    2. [Run] -> [Go (F7)]
? How to debug modules?

用AxD debug Linux

只能看Assembly, 不過可以看reg, PCI的IO register,

1. Run AxD directly, load CPU only
2. [Option] -> [Config Target] 選FA5
3. [Option] -> [Config Processor] Clear all Vector catch 與 semihosting
4. 打開Register View, 選 [Current] -> [pc] 設定為0x0 (reboot)
(..............)
5. 在要debug時選 [Execute] -> [Stop]
6. 由於Linux有用MMU,知道virtual address可直接
7. 若是只知道physical address, 要先把MMU關掉才能存取
disable [Register View] -> [CP15] -> [Control] 的m bit (bit 0)
8. 若是要繼續run, 要先打開mmu才能開始run

2008年3月5日 星期三

Linux Memory - 080408

findout:

kernel module memory location
kernel memory alloc location
kernel's data/text/bss segment, stack addresses

dma_map_single / pci_map_single
dma_sync_single / pci_dma_sync_single
copy_from_user / copy_to_user
vmalloc/kmalloc/pci_alloc_consistent


http://en.wikipedia.org/wiki/CPU_cache
(?)how kernel alloc NCNB (non-cacheable, non-bufferable) buffer
dma_is_consistent在arm沒辦法知道mem是不是consistent/NCNB
linux/include/asm-arm/dma-mapping.h
static inline int dma_get_cache_alignment(void)
{
return 32;
}
static inline int dma_is_consistent(dma_addr_t handle)
{
return 0;
}
CONFIG_GROCX_CONSISTENT_DMA_16M
CONSISTENT_DMA_SIZE
(2.6.23.9) arch/arm/mm/consistent.c
/* Sanity check size */
#if (CONSISTENT_DMA_SIZE % SZ_2M)
#error "CONSISTENT_DMA_SIZE must be multiple of 2MiB"
#endif

#define CONSISTENT_END (0xffe00000)
#define CONSISTENT_BASE (CONSISTENT_END - CONSISTENT_DMA_SIZE)

#define CONSISTENT_OFFSET(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PAGE_SHIFT)
#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PGDIR_SHIFT)
#define NUM_CONSISTENT_PTES (CONSISTENT_DMA_SIZE >> PGDIR_SHIFT)




L1_CACHE_ALIGN, L1_CACHE_BYTES
How to Align Data Structures on Cache Boundaries
syn_str * align_p = (syn_str *)( (((int) p) + 127) & -128 );
Linux source
./include/linux/cache.h
#define L1_CACHE_ALIGN(x) ALIGN(x, L1_CACHE_BYTES)
./include/linux/kernel.h
#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
./include/asm-arm/cache.h, depend on the architecture.
#define L1_CACHE_SHIFT 5
#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)


to alloc a buf for DMA uses
  • kmalloc (n, (in_interrupt () ? GFP_ATOMIC : GFP_KERNEL) | GFP_DMA)
  • align the virtual addr by L1_CACHE_ALIGN
  • get the physical addr by
    phy_addr=dma_map_single (dma->pdevice, dma->virt_addr, len, DMA_BIDIRECTIONAL);


user space local variable 的位置大約是在
0xbebc8e00
user space global varialbe 的位置大約是在
0x000108e0
kernel space static link
kernel space module
oxbf015f60

kernel kmalloc
c3751000(va)
kmalloc (GFP_KERNEL|GFP_DMA);
0xbf01677c

2008年3月3日 星期一

微處理機

[轉貼]HAL, D-bus, udev間的關係

from ivman 與 HAL

上篇文章中提到,可能需要去寫 HAL 的程式,不過發現 2 個問題:
1. libhal 是 GNU GPL 授權
2. HAL 實在很有難度阿..... = =

不過不用擔心,我找到解決方案了,那就是 ivman。
下面把我目前對 HAL、ivman、d-bus、udev 間的關聯、理解貼上來,原則上都是 google 來的。

==================================
HAL、D-bus、ivman、udev心得:

一直以來我對udev、HAL、D-bus的角色一直不很了解,
一直到最近桌機安裝Ubuntu之後,在前陣子要修改預設的影片播放器,
那時候才稍微知道HAL的功用。

在Windows當中,每當我們插入光碟、隨身碟時,系統就會自動開啟檔案總管,
如果是DVD影片,則會自動開啟播放程式,當然了~預設就是Windows Media Player。
正因為這樣的設計,讓M$立於不敗之地,畢竟習慣是很可怕的,
當預設的播放環境習慣之後,要選擇其他的播放環境,那麼就要有十足的說服力來說明新的播放環境比較好。

在Linux上,我一直認為沒有很好的自動判斷機制,雖然Unix一直是device file的機制,這也許是原因之一,
也許Unix一直以來都有許多的歷史包袱,但沒有就是沒有,不方便就是不方便~

Linux並不是不希望改善,所以有automount這樣的機制,現在也是內建措施之一,
但是automount實在是不怎麼樣,它很單純的設計成:
當執行『cd /media/nfs』時,自動 mount 這個目錄。
當超過一定時間時,自動 unmount 這個目錄。

這樣的設計顯然不怎麼聰明,但它的確是 Linux/FreeBSD 上常見的設計。

現在 Linux 的 GNOME 很聰明了,它已經能夠做到 Windows 這樣的能力,透過的是甚麼?
透過的是 HAL 的技術。

在 Linux 上,HAL 全名是 Hardware Abstraction Layer,
雖然 Windows 上也有相同的名稱,但就 google 的說法,是不同的東西。

HAL 的設計其實頗複雜,我們可以從
http://people.freedesktop.org/~david/hal-spec/hal-spec.html

裡面的圖


看出來。

這張圖相對來說,是比較清楚的,不然找到的經常是UML,那種就不是很容易看懂了..... = =||

從下列網頁中可以找到比較詳細些的關係說明:
http://Linux.chinaitlab.com/driver/40018.html

要實現 Linux 上的 automount,Linux 設計了一套架構,如下:
=================================================
hotplug 是內核的一部分,在設備插入或拔出時,自動進行配置內核狀態。udev 是 hotplug 的一部分,負責維護動態的 /dev 目錄,使 /dev 目錄的內容與當前系統狀態一致。D-BUS 可以在應用程序之間傳送消息,例如可以把「連接上一台打印機」的消息發送給 HAL。HAL 可以集成多種來源的信息,包括內核消息,配置文件等等,然後根據 D-BUS 的消息進行操 作。gamin 是改進的文件狀態監視程序。
例如插 入優盤。hotplug 自動加載需要的模塊,udev 創建相應的 /dev/sda1 等等節點,hotplug 向 HAL 發消息,HAL 收到消息後,根據配置文件,它運行 fstab-sync 來修改 fstab,創建 /media 的子目錄作為掛載點。gamin 檢測到 fstab 發生變化之後,通知桌面系統。桌面系統在 「計算機」 項目中建立驅動器圖標。
在拔出優盤時,與上面的過程類似,模塊被卸載,設備文件被刪除,fstab 中相應條目被刪除,/media 目錄下的掛載點也被刪除了。

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

上述這段是直接轉貼的,簡單的說:
1. Linux 2.6 kernel 包含 hotplug,來判斷硬體的插入、移除。

2. Linux OS 透過 udev 來搭配 hotplug,專門維護 /dev 下的 device file,
這也就是我之前在摩托學園發的問題的所在點,它會動態的建立出各種裝置的 device file。

3. Linux OS 透過 D-BUS 來轉發系統訊息,告知 HAL 硬體的插入、拔出動作。

4. HAL 則呼叫相對應的應用程式來執行相對應的操作。


整個 auto mount 或 auto umount 就是上述的流程,實際上 HAL 還是一組 library,
除非應用程式以 HAL 的 library 來開發,否則應用程式通常無法直接收到 HAL 的消息,
簡單的說,HAL 還太低階,雖然他能夠直接操作特定的系統消息(像 DVD影片 插入時),
但彈性不足(設定煩雜,不容易設定、修改),因此通常還需要一個 manager 來進行真正的 HAL 操作。
這在 GNOME 就是 Gnome Volume Manager。

將整個堆疊以文字分層來表示,大致如下:

GNOME Volume Manager
HAL(Hardware Abstraction Layer)
D-Bus
udev

kernel hotplug

上述這些部分,除了 kernel hotplug 之外,全部都是以 daemon 的型式,一直常駐在系統中,
所以每個程式都需要持續的執行。

因為整個架構的複雜,就某方面來說,幾乎獨占了整個 Linux 的 automount 設計,
每個部分的可以用的程式選擇都很少。

目前的情況是,以 HAL 以上,整個架構相容性最好的是 GNOME,
其他 桌面系統(包括 KDE),似乎都沒有很好的相容性。
icewm 相關的設計更是嚴重缺乏。

所以目前可以知道的是,儘管所有 Linux(Debian、Ubuntu、Fedora) 幾乎都直接使用 udev、d-bus 甚至 HAL,
幾乎每個 Linux 上都可以看到 hald、udev 在執行中,大部分人卻不知道也不敢動這幾個東西,
有點冒險精神的人,會嘗試把它關掉,結果可能會從 try & error 中發現,這會導致系統完全無法開機..... :p
偏偏這整套東西,沒有 GNOME 時,通常沒有 Volume Manager,
然後就是大部分 Linux User 覺得它一直在跑也不知道在幹嘛,扒著資源不放。
另一部分來說,非 GNOME 的 桌面系統,要使用 HAL,經常不知道怎麼使用,
這造成了有 Linux 發行套件,使用 KDE 作為 桌面系統,卻使用 GNOME Volume Manager 這種不協調的情況。

幸好我們還有 ivman,ivman 全名 Ikke's Volume Manager
它的身分基本上等於 GNOME Volume Manager,它可以接收各種 HAL 發出的訊息,
最棒的是,ivman 不是 桌面系統 的一部份,也不是 GUI程式,
它的設定都是以 xml設定檔 方式定義,執行的程式完全由我們自己定義,
這表示它應該有不錯的彈性,儘管看起來,
它的相容性似乎不很好,而且當選擇太多時,我們反而會不知道該怎麼選擇。

ivman 要安裝,我覺得 man ivman 是最好的主意,網路上找的資料,幾乎沒辦法協助我排除安裝的問題,
後來看了 man ivman 之後,問題就解決了~

1. 在 Debian 上,ivman 直接是套件,安裝即可

2. ivman 要正常動作,要確定 udev、d-bus、hald 這幾個 daemon 都正常運作中,
這部分我相信只要沒漏裝,都是 ok 的
要測試,在 Debian 上我認為執行
/etc/init.d/dbus restart

似乎不錯,當執行 dbus(也就是 D-bus daemon) 的重新起動時,它會一併重新起動 hald(HAL Daemon)、ivman,
整個內容如下:
media [/root] -root- /etc/init.d/dbus restart
Stopping Hardware abstraction layer: hald.
Stopping Avahi mDNS/DNS-SD Daemon: avahi-daemon.
Stopping ivman: ivman.
Stopping System Tools Backends: system-tools-backends.
Stopping system message bus: dbus.
Starting system message bus: dbus.
Starting System Tools Backends: system-tools-backends.
Starting ivman: manager.c:1387 (do_startup_configure) Directory /etc/ivman/ will be used for configuration files.
ivman.
Starting Avahi mDNS/DNS-SD Daemon: avahi-daemon.
Starting Hardware abstraction layer: hald.


udev 的部分,我相信如果有問題,可能連開機都會有問題的,除非你的 Linux 不是使用 udev。

3. 執行 ivman
這部分需要『特別注意』,我之前就是這地方沒弄好,一直一直沒弄成功。
在 man ivman 中有下面這段話:
For automount purposes, Ivman should be run once from a system-wide init script and once per user session (e.g., create a link to /usr/bin/ivman in ~/.kde/Autostart or put an entry for /usr/bin/ivman in gnome-session-manager).

這句話是關鍵,它說,如果你要正常使用 ivman,你必須要執行『2 次』ivman,一次執行在 OS 開機時,
以 Debian 來說,就是
/etc/init.d/ivman

指令執行的。

另一次則要在使用者進入 桌面系統 時執行。

以我來說,我把它加入
~/.xsession

中,類似如下:
.....
icewm-session-lite &
/usr/bin/ivman &
.....



至於其他部分,就是 lirc、mythfrontend、scim,所以我就沒列出來了。

而從前面說明中,它則建議加入到 KDE 的 Autorun 或 GNOME 的 session-manager,這都是起動 X-win 時自動執行的方式,
我加入到 .xsession,實在是因為我基本上是沒用 桌面系統 的,硬要說,也就是 icewm-lite,
主要是因為我整個系統只執行 mythtv,加了大型的 桌面系統 沒有意義。

4. 設定 ivman
ivman 的設定和上面一樣,也是『2 份』,一份放 /etc/ivman/,另一份則是 ~/.ivman/ 下。
原則上,/etc/ivman/ 下的設定檔不需要動,所有使用者都只要設定 ~/.ivman/ 下的設定檔即可,
這點讓 ivman 可以根據不同的使用者,定義不同的 automount 設定,相當不錯。

當使用者執行過 ivman 後,~/.ivman/ 下的設定檔就會自動產生,基本上和系統的相同,
都是 4 個檔案,分別是:
IvmConfigActions.xml
IvmConfigConditions.xml
IvmConfigBase.xml
IvmConfigProperties.xml


其中比較重要的是『IvmConfigActions.xml』,這檔案負責所有訊息的動作,
目前的進度是,我將 IvmConfigActions.xml 中的 autoplay video DVD 部分註解去除,如下:
.....
<!-- autoplay video DVDs in Xine (change PLAYER and PLAYEROPT to use a different media player -->
<ivm:Match name="hal.volume.disc.is_videodvd" value="true">
<ivm:Option name="exec" value="PLAYER='xine'; PLAYEROPT='-f dvd://'; pumount '$hal.volume.mount_point$' && ${PLAYER} ${PLAYEROPT}$hal.block.device$" />
</ivm:Match>
.....


在 DVD影片光碟 插入時,已經能夠正常使用 xine 播放。
目前正在設定當 檔案光碟 插入時的動作,目前預設是只會 automount。

附帶一點:
在設定中可以注意到,『volume.disc.is_videodvd』這個參數,這個參數是 HAL 的參數,
也就是說 ivman 會監視 HAL(或說 HAL 會發出通知),當參數改變時,ivman 就會有相對應的動作。
關鍵點,要如何知道 HAL 的參數呢?
可以執行:
> lshal
==================================