Friday, July 22, 2011

SAS - Zone configuration

From SAS2r16 Spec. page 120

Zoning expander devices implement a lock to coordinate zoning configuration by zone manager(s).
There are four steps in the zone configuration process:

1) lock

2) load

3) activate
The activate step:
a) copies the zoning expander shadow register values to the current values
b) saves the zoning expander shadow values, if saving was requested.

4) unlock
The unlock step ensures that:
a) the active zone manager unlocks the locked zoning expander devices; or
b) if the zone manager fails, then the zone lock inactivity timer expires, and the
zoning expander devices unlock.

The management device server in a zoning expander device only accepts
1-SMP zone configuration function requests
The SMP zone configuration functions are:
a) SMP CONFIGURE ZONE PHY INFORMATION
b) SMP CONFIGURE ZONE PERMISSION TABLE
c) SMP ENABLE DISABLE ZONING
2-SMP ZONE ACTIVATE requests
3-SMP ZONE UNLOCK requests
while it is locked

It only accepts SMP zone configuration function requests from the zone manager that locked the zoning expander device (i.e., the active zone manager).

SMP zone configuration functions change zoning expander shadow values.

When changes are complete, the zone manager activates the changes and
the zoning expander device sets the zoning expander current values equal to the zoning expander shadow values.

The zone manager then unlocks the zoning expander devices.

For a ZPSDS to function correctly, all zoning expander devices within the ZPSDS are required to have identical values in their zone permission tables.

To change zone permission tables, a zone manager device locks all zoning expander devices in a ZPSDS.

To change zone phy information, a zone manager locks only the zoning expander devices containing the phys to be changed.

When a zoning expander device with zoning disabled is being added to a ZPSDS or two or more ZPSDSes are being merged, the zone manager locks all of the zoning expander devices that are to be included in the final ZPSDS.

The zone manager configures the zone phy information in each zoning expander device
(e.g., sets the REQUESTED INSIDE ZPSDS bit to one for phys inside the final ZPSDS) and configures all of the zone permission tables to be identical.

If the zone lock inactivity timer expires, then the zoning expander device performs the unlock step.
The zoning expander device is unlocked and the zoning expander shadow values are not activated.

Monday, July 04, 2011

U8150 IDEOS 刷機

過年前買了一支 Android 手機

因為對手機的需求不高, 基本上只是拿來試用看看 Android 的

所以特別選了比較便宜的機種, 挑來挑去最後以 4300 大洋空機價買了華為出的 U8150 IDEOS 手機

雖然用 U8150 的人沒有那些大廠牌的多, 不過在 XDA forum 依然還是有一些人在開發 ROM

買了一個多月後準備拿來刷機了, 最後刷了 FUSIONideos 的 ROM, 可以到這邊下載
http://ideos.accentiweb.it/

超頻到 710MHz 用到目前還沒有任何異狀, 而且可以降頻到 30MHz 待機時間更持久

手寫輸入法則是安裝了 "國比輸入法" 和 "HTC CIME"

目前用起來還蠻順手的

最近 U8150 已有 multi touch support 的 ROM 出來了

不過目前只有 synaptics touch panel 會 work

melfas touch panel 的就殘念了

詳細刷機步驟請望友們自己去 XDA forum 多爬爬文吧

Friday, April 15, 2011

Compile kernel for Kurobox HG

又是寫筆記的一篇文章

記得這台 Kurobox HG 已經買了至少 五六年以上了

kernel 從早期內建的 2.4.17_mvl-sandpoint 幾年之間一直不斷的升級到現在已經 2.6.32.28
(註:要使用自己的kernel必須先將機器的 bootloader
刷成 uboot,但是刷 bootloader有一定程度的風險,
不確定的朋友請勿輕易嘗試,以免機器變成磚頭)

機器上的系統也從

Debian 3.0 (woody) -> Debian 4.0 (etch) -> Debian 5.0 (lenny) -> Debian 6.0 (squeeze)
(註: Debian 的套件管理真的做的很好, 一路這樣升級都沒出什麼大問題)

年紀大了
每次 compile 新 kernel 都還要去看網頁
Compile a uBoot Kernel

記不了那麼多, 而且本人很懶也沒設 bookmark, 所以乾脆寫編文章也方便自己參考


1. Get the kernel source

# cd /usr/src
# wget http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-2.6.35.12.tar.bz2
# tar xjvf linux-2.6.35.12.tar.bz2


2. Compile your kernel
直接拿前一版的config來用比較快,而且我是 native compile 所以 ARCH=powerpc 就省了

# cp /boot/config-2.6.32.28 .config
# make oldconfig
...
...
# make uImage && make modules && make modules_install

通常我都從外面用 ssh 連回家而且開 screen 讓, 開始 make 後就 detach 了
沒意外的話應該是不會出什麼差錯

3. Backup your old kernel and dtb file

# cp /boot/uImage /boot/uImage.bak
# cp /boot/kuroboxHG.dtb /boot/kuroboxHG.dtb.bak


前面的步驟跟一般x86上 make kernel 的步驟都一樣, 讓我老是記不起來的是關於 dtb file
這些步驟, 如下

4. Compile the dtb file

# cp kuroboxHG.dtb /tmp/
# cd /usr/src/linux/arch/powerpc/boot/dts
# dtc -I dts -O dtb -V 16 -o /tmp/kuroboxHG.dtb kuroboxHG.dts
# cp /tmp/kuroboxHG.dtb /boot/kuroboxHG.dtb


5. Install the kernel & enable modules

# cp /usr/src/linux/arch/powerpc/boot/uImage /boot/uImage
# cd /lib/modules/2.6.35.12/
# depmod


6. Reboot

# reboot


7.Troubleshooting
如果不幸開不了機的話 XD
只好進去 EM mode 把剛剛備份的舊 kernel 和 dtb file copy 回來

# cp /boot/uImage.bak /boot/uImage
# cp /boot/kuroboxHG.dtb.bak /boot/kuroboxHG.dtb


(註:dtb file 是 uboot 使用的, 但是 uboot 必須要在某個版本以上才有支援(版本忘記了)
所以如果 Kurobox HG bootloader 沒刷機成 uboot 的朋友, 是不需要做出 dtb file 的)

Tuesday, April 12, 2011

Fedora - Build rpm package from src.rpm

參考
http://fedoraproject.org/wiki/Docs/CustomKernel

以下所有命令都是在非 root 下運行

在開始之前,先確保系統已安裝下列必要的包:

yum-utils
rpmdevtools


可通過下面的命令來安裝:
su -c 'yum install yum-utils rpmdevtools'

其中 yum-utils 包提供 yumdownloader 和 yum-builddep 這兩個命令,

rpmdevtools 包提供 rpmdev-setuptree 這個命令

獲得 Source
1. 首先建立 RPM 的打包環境目錄,運行下列命令:
rpmdev-setuptree

該命令會在用戶的 HOME 目錄下建立 rpmbuild/{SOURCES,SPECS,BUILD,RPMS,SRPMS} 這5個目錄,
以及一個 .rpmmacros 文件,該文件定義了一些 rpm 打包的環境變數。

2. 下載 kernel source src.rpm package。
可以直接到 fedora 的官方源上去下載,也可以用下列命令下載:
yumdownloader --source kernel

3. 安裝編譯內核所需要的包,運行下列命令:
su -c 'yum-builddep kernel-.src.rpm'

4. 安裝 kernel source src.rpm 包,運行下列命令:
rpm -Uvh kernel-.src.rpm

準備 kernel source tree
1. 運行下列命令來建立 kernel source tree:

cd ~/rpmbuild/SPECS
rpmbuild -bp --target=`uname -m` kernel.spec

現在kernel source tree位於
~/rpmbuild/BUILD/kernel-/linux-. 目錄。

2. 如果還需要修改kernel source的話(可選),可按如下步驟操作:

cp -a ~/rpmbuild/BUILD/kernel-2.6.$ver/linux-2.6.$ver.$arch ~/rpmbuild/BUILD/kernel-2.6.$ver.orig
cp -a ~/rpmbuild/BUILD/kernel-2.6.$ver.orig ~/rpmbuild/BUILD/kernel-2.6.$ver.new
在 ~/rpmbuild/BUILD/kernel-2.6.$ver.new 中對 source 作修改,然後作成 patch:
cd ~/rpmbuild/BUILD
diff -uNrp kernel-2.6.x.orig kernel-2.6.x.new > ../SOURCES/linux-2.6-my-new-patch.patch


配置內核選項(可選)
如果需要修改內核的編譯選項的話,按如下操作:
1. 進入內核源代碼樹

cd ~/rpmbuild/BUILD/kernel-/linux-./


2. 從 configs 目錄中挑選一個基於其修改的 config 檔,把它複製成內核源代碼樹中的 .config 文件

cp configs/ .config


3. 配置內核編譯選項

make oldconfig
make menuconfig


4. 在新生成的 .config 檔的第一行添加一行指定硬體平臺的標識(uname -i 的輸出),以 # 號開頭,例如:

# i386


5. 把 .config 檔複製到 ~/rpmbuild/SOURCES/ 目錄下,並命名成 config-,例如 config-i686

cp .config ~/rpmbuild/SOURCES/config-


準備 spec 文件
進入 ~/rpmbuild/SPECS 目錄,編輯 kernel.spec 文件:
1. 定義 buildid 為一個唯一的標識,以區別不同的 kernel rpm 包。把
#% define buildid .local
改成
%define buildid .
注意去掉 % 和 define 之間的空格

2. 如果之前有生成 patch ,把 patch 加到 kernel.spec 文件中。一般放在所有已有的 patch 最後,並注明注釋。例如:

# cputime accounting is broken, revert to 2.6.22 version
Patch2220: linux-2.6-cputime-fix-accounting.patch
Patch9999: linux-2.6-samfw-test.patch

另外在打 patch 那一段也要補上:

ApplyPatch linux-2.6-cputime-fix-accounting.patch
ApplyPatch linux-2.6-samfw-test.patch

編譯新的內核
用 rpmbuild 命令來編譯 kernel rpm 包,默認的命令為:
rpmbuild -bb --target=`uname -m` kernel.spec
這個命令可能會編譯好幾遍 kernel,生成不同類型的 kernel image,
例如支援 xen、smp 等的 kernel。

可以通過添加 --without

Friday, April 01, 2011

load storage adapter driver 遇到的問題

今天成功的將 CentOS 5.5 機器的 kernel更新成了 Fedora Core 14 x86 64 bits 的 kernel,

因為CentOS 5.5 的 kernel實在太老舊了,

不過在開機過程 load SAS adapter driver, 發現 driver load 完, init 仍然繼續往前執行,

如果這時有設定 LVM/MD之類的東西就會發生錯誤,

後來拜Google大神找到一個類似的問題
rc.sysinit does not wait for udev loaded scsi adapters to finish scanning their busses

應該跟 rc.sysinit 有關係, 因為筆者使用 Fedora Core 14時並沒有這個現象,
索性就直接去比較 CentOS 5.5 和 Fedora Core 14 rc.sysinit 的差別
結果發現了, Fedora Core 14 裡面有一段

# Sync waiting for storage.
{ rmmod scsi_wait_scan ; modprobe scsi_wait_scan ; rmmod scsi_wait_scan ; } >/dev/null 2>&1

加到 CentOS 5.5 rc.sysinit 後, 一切 OK, 果然如 module name scsi_wait_scan 一樣
至於為什麼要先 rmmod -> modprobe -> rmmod 就再研究了

SCSI adapter driver initial 完會call scsi_scan_host 來 scan device
為了 async scan device 會 create 一個名為 "scsi_scan_x" 的 kernel thread 來執行 do_scan_async
詳細看 void scsi_scan_host(struct Scsi_Host *shost) source code

do_scan_async() 呼叫 do_scsi_scan_host() 開始啟動 scan,
呼叫 scsi_finish_async_scan() 來通知系統 scan 完成

從source code 可以得知如果是 async scan的話, scan到一個lun的時候並不會馬上註冊device name
device name的註冊是在scsi_finish_async_scan()裡面完成的

基本上這次遇到的問題是 async scan 造成的...

scsi_wait_scan module source code 很短, 主要應該是 scsi_complete_async_scans(void)
基本上作法就是 create 一個假的 "async_scan_data" insert 到
scanning_hosts list 的尾巴, 然後就等 wait_for_completion(&data->prev_finished);

int scsi_complete_async_scans(void)
{
struct async_scan_data *data;
...
...
data = kmalloc(sizeof(*data), GFP_KERNEL);
...
init_completion(&data->prev_finished);
...
...
list_add_tail(&data->list, &scanning_hosts);
...
printk(KERN_INFO "scsi: waiting for bus probes to complete ...\n");
wait_for_completion(&data->prev_finished);
...
return 0;
}


如果沒理解錯誤的話, 應該是會在
void scsi_finish_async_scan(struct async_scan_data *data) 中
被 complete(&next->prev_finished);

也因此 scsi_wait_scan module return 時只保證在它之前就啟動的scan

已經結束, 若是在它之後才啟動的scan 則有可能已經結束或未結束

Tuesday, March 29, 2011

客製 Fedora Core 14 initramfs


cp /boot/initramfs-2.6.35.6-45.fc14.x86_64.img .
mkdir ./temp
cd ./temp
gunzip < ../initramfs-2.6.35.6-45.fc14.x86_64.img | cpio -i


修改完後, 重新打包出新的 initramfs

find | cpio -H newc -o | gzip -9 > ../initramfs-2.6.35.6-45.fc14.x86_64-XXXX.img

Friday, March 18, 2011

CentOS 5.5 自己 build kernel

由於CentOS 5.5的kernel實在太舊了 (Version 2.6.18-194, 沒記錯的話是 2007年2月)
紀錄一下升級kernel的步驟
1. 安裝build kernel所需的套件

#yum groupinstall “Development Tools” && yum install ncurses-devel


2. 抓取要使用的kernel source

#cd /usr/src
#wget “http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-2.6.35.11.tar.bz2″
#bunzip2 linux-2.6.35.11.tar.bz2
#tar xf linux-2.6.35.11.tar
#ln -s linux-2.6.35.11 linux
#cd linux


3. 利用舊的kernel config來build kernel

#cp /boot/config-`uname -r` /usr/src/linux/.config
#cd /usr/src/linux
#make menuconfig

選取 'Load an alternate Configuration File' 將 .config load 進來

在 'General Setup' 選取
'enable deprecated sysfs features to support old userspace tools'

不選的話會在開機過程 switchroot 的時候 fail, 選取之後 save config


4. build kernel

#make rpm

如果過程沒問題的話, 等一段時間後 rpm 會被做出來,

5. install kernel

#rpm -ivh /usr/src/redhat/RPMS/i386/kernel-2.6.35.11-1.i386.rpm

rpm檔的名字不一定跟上面相同 (depend on 你的機器), 安裝完後我們檢查一下

#rpm -qa | grep -i kernel


6. build initrd image

#mkinitrd /boot/initrd-2.6.35.11.img 2.6.35.11


7. 修改 grub

#vim /boot/grub/menu.lst


剩下就不多說了