2011년 6월 14일 화요일

Big Endianness / Little Endiannes Detect code


현재 개발하는 시스템이 빅엔디안인지 리틀엔디안인지 잘 모를 경우가
Embedded system 개발 중에는 자주 발생 한다....
특히 골치 아픈 mips system일 경우는 자주....
그럴 경우 사용하는 코드

#include
int main(void)
{
int i = 0x00000001;
if ( ((char *)&i)[0] )
printf("LITTLE_ENDIAN\n");
else
printf("BIG_ENDIAN\n");
}

2011년 6월 13일 월요일

Arm 에서 Profiling with Oprofile

Profiling Oprofile Cross-compile

모 업체에서 양산중인 보드의 성능 점검을 요청해 와서,
해당 타겟이 사용 중인 Board에 Oprofile로 Profiling하는 과정

기존 보드에 SD 카드를 /mnt 폴더로 mount 해서 Oprofile 추가 설치함

이번 경우엔 root 이미지를 직접 쓰기 혹은 변경 시킬 없어서 /mnt 사용

# mount /dev/mmcblk0p1 /mnt

Arm-marvell-linux-gnueabi Oprofile cross-compile 방법
Host PC로 ubuntu linux 사용하였으며 (host: i386-linux) arm-linux (build target: arm-linux) cross-compile 하였습니다.

Cross-compiler Path 지정

arm-marvell-linux-gnueabi-gcc 위치하는 폴더를 PATH 지정

# export PATH=/your path/arm-marvell-linux-gnueabi/bin:$PATH

Libpopt Cross-compiling (Oprofile에서 요구되어지는 library)

1) Popt library Download 받아 설치한다.
#./configure --prefix=/mnt/Oprofile –-build=arm-linux -–host=i386-linux -–target=arm-marvell-gnueabi

2) Make & make install

3) Add LD_LIBRARY_PATH
# export LD_LIBRARY_PATH=/mnt/Oprofile/lib:$LD_LIBRARY_PATH

4) ADD PKG_CONFIG_PATH
# export PKG_CONFIG_PATH=/mnt/Oprofile/lib:$PKG_CONFIG_PATH


Libz Cross-compiling

Libz library Download 받아 설치한다.
#./configure --prefix=/mnt/Oprofile

# Make & make install

If you use different prefix, ADD LD_LIBRARY_PATH and PKG_CONFIG_PATH (Use same path with libpopt library)

Bfd library Cross-compiling

1) Binutils 다운 받는다.
# wget
http://ftp.gnu.org/gnu/binutils/binutils-X.XX.tar.gz

2) Untar binutils
# tar xvf binutils-X.XX.tar.gz

3) Bfd 폴더로 이동한다
# cd binutils-X.XX
# cd bfd
(binutil
모든 unility들을 모두 사용할 것은 아니므로 bfd폴더에서 bfd 컴파일)

4) Bfd library 설치
# ./configure --prefix=/mnt/Oprofile/binutils --build=arm-linux --host=i386-linux --target=arm-marvell-linux-gnueabi --disable-nls --enable-install-libbfd

5) Make & make install

6) ADD LD_LIBRARY_PATH and PKG_CONFIG_PATH with installed bfd library path.
ex) # export LD_LIBRARY_PATH=/mnt/Oprofile/binutils/i386-linux/arm-marvell-linux-gnueabi/lib:$LD_LIBRARY_PATH


OProfile Cross-Compiling

1) Oprofile 다운 받는다.
# wget http://prdownloads.sourceforge.net/oprofile/oprofile-X.X.X.tar.gz

2) Untar Oprofile
# tar xvf oprofile-X.X.X.tar.gz

3) Cd Oprofile
# cd oprofile-X.X.X

4) OProfile 설치
# ./configure --prefix=/mnt/Oprofile --with-kernel-support --build=arm-linux --host=i386-linux --target=arm-marvell-linux-gnueabi

5) Make & make install

6) ADD LD_LIBRARY_PATH & PKG_CONFIG_PATH


Target 에서 OProfile 환경 설정

#export PATH=/mnt/Oprofile/bin:$PATH

# export LD_LIBRARY_PATH=/mnt/Oprofile/lib:
/mnt/Oprofile/binutils/i386-linux/arm-marvell-linux-gnueabi/lib:
$LD_LIBRARY_PATH

만일 저처럼 Root write 없는 상태가 아니라면, 아래와 같이 설정하시면 됩니다.

위에서 prefix –-prefix=/usr/local 사용한다면

#export PATH=/usr/local/bin:$PATH

# export LD_LIBRARY_PATH=/usr/local/lib:
/usr/local/binutils/i386-linux/arm-marvell-linux-gnueabi/lib:
$LD_LIBRARY_PATH