2012年11月16日 星期五

QEMU and ARM Linux

我是以Ububtu Linux上的qemu-system-arm來進行實驗,先要安裝qemu-system-arm

sudo apt-get install qemu-user-static qemu-system

想知道支援的CPU型號列表:

qemu-system-arm -cpu ?

想知道支援的系統列表:

qemu-system-arm -machine ?

這裡用的是ARM Versatile這個系統當範例,這塊板子的CPU是ARM926EJ-S

Toolchain


首先要解決的是toolchain,這裡是直接下載現成的CodeSourcery CodeBench Lite 2012.03-57 for ARM GNU/Linux.

假設解開到~/test-qemu-arm/, 這時就需要把它的路徑加到PATH

export PATH=$PATH:~/test-qemu-arm/arm-2012.03/bin

寫個小程式來試試看QEMU, 這裡我用個老掉牙的Hello world C程式做測試

qemu-arm-static -L ~/test-qemu-arm/arm-2012.03/arm-none-linux-gnueabi/libc/ ./hello_world

Kernel


寫個script來設定編譯Linux kernel所需的環境變數:

export PATH=$PATH:/home/victor/test_qemu-arm/arm-2012.03/bin
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabi-


根據我們使用的平台,載入default config:

make versatile_defconfig

接著做個小修改:

make menuconfig

在"Kernel Features"這一頁,打開"Use the ARM EABI to compile the kernel"

離開前記得要存下設定。

接著就可以開始編譯,這個會稍微花點時間,但以現今PC的能力來說,其實才幾分鐘而已。

make uImage

檢視一下這個uImage file:

file arch/arm/boot/uImage

大致上會看到這樣的輸出:

arch/arm/boot/uImage: u-boot legacy uImage, Linux-3.6.3, Linux/ARM, OS Kernel Image (Not
compressed), 1986896 bytes, Mon Oct 22 17:52:05 2012, Load Address: 0x00008000, Entry Point:
0x00008000, Header CRC: 0x7EF0365B, Data CRC: 0xAE2513DE


現在可以用QEMU來測試kernel:

qemu-system-arm -M versatilepb -m 128M -kernel arch/arm/boot/uImage

Root Filesystem


我們借助於buildroot來建立所需要的root filesystem。
我下載的是buildroot-2012.08.tar.bz2
網址是 http://buildroot.uclibc.org/

下面是在編譯前需要做的設定:

  • Set toolchain as an External, Custom, Pre-installed toolchain.
  • Set toolchain path = ~/test_qemu-arm/arm-2012.03/
  • Set toolchain prefix = arm-none-linux-gnueabi
  • Set serial port from ttyS0 to ttyAMA0
  • Enable "cpio the root filesystem"
  • And set "Compress method" to gzip.

有些套件可能需要安裝才能順利編過
  • bison
  • flex
  • texinfo(for makeinfo)

編出來的root filesystem是在output/images/rootfs.cpio.gz

現在把kernel跟root filesystem放在一起跑:

qemu-system-arm -M versatilepb -m 128M -kernel uImage -initrd rootfs.cpio.gz -serial stdio

這套系統可以用root登入

下面是我參考的網頁:

http://www.linuxforu.com/2011/06/qemu-for-embedded-systems-development-part-1/
http://www.linuxforu.com/2011/07/qemu-for-embedded-systems-development-part-2/
http://www.linuxforu.com/2011/08/qemu-for-embedded-systems-development-part-3/
http://elasticsheep.com/2011/01/building-and-emulating-a-basic-arm-linux-system/

2012年9月29日 星期六

Sometimes the Truth Just Socks

幾天前看著公共電視台播放的怪醫豪斯,Park重擊House的後腦杓,說了這句話:

"You’ve spent your whole life looking for truth, but sometimes the truth just sucks."

是的,sometimes the truth just socks. 了解了這個世界是這麼的現實與殘酷,這就是我現在的心情。

2012年9月8日 星期六

四不像

這個中國自製的processor是在Jserv的部落格看到的,就computer architecture的角度,我想要評評這個core。

很顯然UniCore32是ARM與MIPS架構的混合,就指令集來看,它的架構應該比較貼近MIPS(不要看mnemonic code就以為它像ARM),而且還是比較陽春的MIPS。東抄西抄的結果,不小心也把缺點抄進來了。

一是register number。register多固然對於compiler optimization有幫助,但是也代表了contex switching代價高,interrupt反應時間長。另外,大的register file也比較耗電。32 registers太多了,常寫底層程式的人應該會懂。

一是code density。ARM創造了Thumb/Thumb-2,MIPS創造了MIPS16,都是為了改進code density,code density代表的是cost and performance,UniCore32竟然直接放棄。

當年凌陽自己搞了一個S+Core,君正搞了個MIPS。現在晶心搞了Andes,北大眾志搞了個UniCore32。每次都是在自吹自擂說是可以自製CPU,其實以現在技術做個CPU有何難?真的難處在於跟市場上的架構比有沒有競爭力。說難聽一點,華人世界缺乏對軟體工程師的尊重,沒有軟硬體互相激盪配合的話,是做不出個能存活的產品來的。

以前在北京跟某個科技公司的總經理碰面,一開始就吹噓其產品是在人民大會堂高調發表,某法院院長某黨校校長某某機關首長都來了。草泥馬的,這些腦滿腸肥的官懂個屁。

也難怪東西作不好只好牽拖其他的有的沒的來騙人了。

2012年7月5日 星期四

KMT跟中國共產黨

014事件正在熱頭上,KMT就拿釣魚台開始轉移注意力。幾家藍媒開始用力報導船隻衝撞,卻絕口不提人家拿的可是五星旗。
KMT跟中國共產黨越來越像了啊!

2012年7月2日 星期一

特偵組 好樣的

特偵組諸公為了護主真是不計毀譽,明明014是被檢舉的嫌疑人,竟然大張旗鼓的要去拘提檢舉人,還在媒體上放話說要羈押,實在是不知道是怎樣的邏輯。

對014的約談與搜索就可以這樣拖個幾天,難怪GGY要說台灣是鬼島,還真是大白天見鬼了。

2012年6月30日 星期六

FTP server for Ubuntu 12.04

 用Google找了一下,大多數是用vsftpd。vsftpd是"Very Secure FTP Daemon"的意思,通常提到secure的意思就是有些小地方要注意設定,不然它理都不理你。

sudo apt-get install vsftpd

安裝之後編輯/etc/vsftpd.conf來作設定。

這裡分幾個情況來說明

Anonymous Read-Only Access
編輯/etc/vsftpd.conf
anonymous_enable=YES
anon_root=/home/ftp 
要注意的是anon_home這個目錄的設定,我習慣將它設定成/home/ftp,將它的owner:group設定成ftp:ftp,mode設定成0577。這個目錄對ftp user而言一定不可以是writable,不然login時會有訊息抱怨權限錯誤。

Anonymous Read-Write Access
編輯/etc/vsftpd.conf,除了上述的兩個變數之外有一些額外的設定
write_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_upload_enable=YES

上面的設定變數如果沒有需要可以不打開,各變數的說明請man vsftpd.conf

Local User Access
編輯/etc/vsftpd.conf

local_enable=YES


Server上有帳號的人(local users)可以login,login之後是到自己的home directory。

2012年6月9日 星期六

TFTP server for Ubuntu 12.04

用apt-get直接裝TFTP server套件。

    sudo apt-get install tftpd-hpa

Default options放在 /etc/default/tftp-hpa

# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"

TFTP_DIRECTORY 是TFTP的檔案存放目錄.,我是將它改成rw for all,不知有沒有甚麼副作用?

    sudo chmod a+rw /var/lib/tftpboot

在Ubuntu上面直接裝的TFTP server套件不會在開機時執行,精確一點說應該是開機時跑了卻沒有起來。這是個老毛病,修一下就好。
編輯 /etc/init/tftpd-hpa.conf ,修改它錯誤的初始條件。

#start on runlevel [2345] # the original line which is wrong
start on (filesystem and net-device-up IFACE!=lo)