顯示具有 arm 標籤的文章。 顯示所有文章
顯示具有 arm 標籤的文章。 顯示所有文章

2010年4月14日 星期三

cross compile ssh daemon(dropbear) for arm

1. Get zlib(included by dropbear)
#wget http://www.zlib.net/zlib-1.2.3.tar.gz
#tar zxvf zlib-1.2.3.tar.gz
#mkdir zlib
#cd zlib-1.2.3/
#CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/zlib
#make
#make install

2. Get dropbear source
#wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.51.tar.gz
#tar zxvf dropbear-0.51.tar.gz
#mkdir dropbear-build
#cd dropbear-build/
#mkdir build
#../dropbear-0.51/configure --prefix=/build/ \
--with-zlib=/zlib/ CC=arm-none-linux-gnueabi-gcc --host=arm-none-linux-gnueabi LDFLAGS=-static
#make
#sudo make install

3. Copy dbclient, dropbearconvert, dropbearkey, and dropbear binarys to your file system and generate the cpio.gz file(Under build/bin and build/sbin, if you are not using a emulator, do not generate cpio.gz file :))

4. In target,
#cd /etc
#mkdir dropbear
#cd dropbear
#dropbearkey -t rsa -f dropbear_rsa_host_key

if indicate "Exited: couldn't open random device", do the following
#mknod -m=666 /dev/random c 1 8
#mknod -m=666 /dev/urandom c 1 9

#dropbear(assume the binary is under /sbin)

5. Done, you should be able to run ssh client to access this machine.
(May add password if it's originally none, otherwise ssh will complain permission denied)

PS. If you encountered the following error when ssh to the target.
"PTY allocation request failed on channel 0"
"shell request failed on channel 0"
do the following:

# mkdir /dev/pts
# mknod /dev/ptmx c 5 2
# mount -t devpts devpts /dev/pts

2010年4月9日 星期五

Cross Compile gdb for x86 and gdbserver for ARM

1. Download GDB source code
2. Download toolchain. ex, you can download the toolchain binary from codesourcery.
3. you will have GDB for x86 host machine after the following:
#./configure --target=arm-none-linux-gnueabi LDFLAGS=-static --with-build-libsubdir=/usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib --disable-werror
#make
4. enter gdb/gdbserver, you will have gdbserver for ARM after the following:
#./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi LDFLAGS=-static --with-build-libsubdir=/usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib --disable-werror
#make

ps.
If make complains about no termcap library, do the following
1. Download ncurses (search the web)
2. Do the following
#./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi --prefix="$HOME/install"
#make && make install
#sudo cp ~/install/lib/libncurses.a /usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib
#sudo cp ~/install/include/ncurses/ /usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/include -rf

Beaware that this is because that the toolchain is not aware of the libncurses.a library though you've probably install it in the regular path. We need it for the toolchain and which is for ARM machine.
You can do
#file libncurses.a
to check if it's for your machine or for the target. The format should match to cease the complaining.

2009年10月6日 星期二

ARM BL instruction

syntax:
   bl function_A;
簡單說就是把下一個要執行的位置(i.e. the return address),
存到LR(r13)之後,
把function_A的位置,
存到PC中。
這樣就會跳到callee function
然後把return address存給caller function。

2009年9月29日 星期二

防止資料被初始化 in ARM environment

有的時候,資料並不想被初始化,這時候我們需要特別的指定section。在code裡面我們可以用
#pragma arm section zidata = "non_init"
int i, j;    //uninit (in non_init section)
#pragma arm section zidata   //back to default (.bss section)
int k=0, l=0;  //zero-init (in .bss section)
這樣我們就會有一個自己的section名子叫做non_init。之後在execution region中我們可以把它指定成UNINIT,好比說

LOAD_1 0x0{

EXEC_1 +0


{



* (+RO)


* (+RW)


* (+ZI) ;ZI data will be initialized to zero



}



EXEC_2 +0 UNINIT


{



* (non_init) ;ZI data will not be initialized to zero



}



}

這樣我們的i和j就不會就算不給值也不會被初始成0了。

ARM assembly 範例 and 解說

   AREA ARMex, CODE, READONLY ;Name this block of code ARMex
   ENTRY ;Mark first instruction to execute
start
   MOV r0, #10 ; Set up parameters
   MOV r1, #3
   ADD r0, r0, r1 ; r0 = r0 + r1
stop
   MOV r0, #0x18 ; angel_SWIreason_ReportException
   LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
   SVC #0x123456 ; ARM semihosting (formerly SWI)
END ; Mark end of file

我們可以發現第一行就指定了這個section的名子,叫做ARMex。第一個AREA的意思是表示一個section
的開始,除了明子以外,還會設定這個section的屬性。名子基本上可以隨便取,可是如果不是英文字母開頭的話,就要用兩個bar把它包起來,好比說|1_DataArea|。不然的話會有AREA name missing的錯誤。


ENTRY跟AREA一樣,都是directive,顧名思義是說明一個section的開始,後面的END相對應的就是說明一個section的結束。

start和stop都是function的label。

如果是在C code裡面的話
就是 #pragma arm section [code、rwdata、rodata、zidata] = "label"