1 / 12

Cross-Compiler 설치

Cross-Compiler 설치. Ch.5 Cross-compiler. Cross-compiler. Cross-compiler

zuzana
Download Presentation

Cross-Compiler 설치

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cross-Compiler 설치 Ch.5 Cross-compiler

  2. Cross-compiler • Cross-compiler • 컴파일러는 고급 언어로 작성된 소스 파일을 실행 파일로 작성하기 위한 프로그램이다. i386 환경의 PC에서 C 코드로 작성한 소스 파일을 호스트 컴퓨터에서 실행 가능한 파일로 만들기 위해서 사용하는 것을 컴파일러라고 한다. 그러나 컴파일이 이루어지는 호스트는 i386이고 실행하는 환경은 Xscale인 PXA 255 CPU 경우에는 다른 형태의 컴파일러가 필요하다. 이러한 컴파일러를 크로스 컴파일러라고 한다. • Toll chains • gcc: gnu C compiler • binutils: binary utilities 구성 (assembler, loader 등) • glibc: C library (크로스 컴파일 구축을 위한 라이브러리) • linux kernel: 리눅스 커널

  3. Installation of Cross-compiler • Cross-compiler source를 직접 설치하는 방법 • GNU cross-compiler 소스를 다운로드 받아서 컴파일 과정을 통해 Linux PC에 tool chain 환경을 구축 • 소스 설치 순서 • 1. binutilis, 2. glib, 3. gcc, 4. linux kernel • Sources • ftp://sources.redhat.com/pub/binutilis/releases/binutils-2.11.2.yar.bz • ftp://ftp.gnu.org/gnu/glibc/glibc-2.2.3.tar.gz • ftp://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.2.3.tar.gz • ftp://ftp.gnu.org/gnu/gcc/gcc-2.95.3/gcc-core-2.95.3.tar.gz • ftp://ftp.gnu.org/gnu/gcc/gcc-2.95.3/gcc-g++-2.95.3.tar.gz • Linux-2.4.19-rmk4-pxa2-empx1.tar.bz2 • EMPOS II CD 에서 다운로드 가능 • 리눅스 커널 위치 (/mnt/cdrom/Source/kernel/linux-2.4.19-rmk4-pxa2-empx1.tar.gz) • 크로스 컴파일러 소스 위치 (/mnt/cdrom/Tools/toolchain/SRC/*)

  4. Installation of Cross-compiler • 반드시 설치 순서를 지킬 것! < 소스 파일을 작업할 디렉터리로 이동 > # mkdir –p /tmp/source # cp * /tmp/source # cd /tmp/source < 압축 해제 > - linux kernel – # tar xvfz linux-2.4.19-rmk4-pxa2-empx1.tar.gz - binutils - # tar xvfj binutils-2.11.2.tar.bz2 - gcc - # tar xvfz gcc-core-2.95.3.tar.gz - g++ - # tar xvfz gcc-g++-2.95.3.tar.gz - glibc - # tar xvfz glibc-2.2.3.tar.gz # cd glibc-2.2.3 # tar xvfz ../glibc-linuxthreads-2.2.3.tar.gz

  5. Installation of Cross-compiler • 소스 컴파일 • 정상적으로 컴파일이 완료되면 /tmp/cross-tools 디렉터리 생성됨 • 다음 과정에서 사용하기 위해 경로에 추가 • 해당 명령어들을 어디에서나 사용 가능하도록 함 (arm-linux-* 명령어) • 로그오프 후 로그인하거나 재 부팅하면 다시 경로를 추가해줘야 함 • 경로 환경변수에 등록 • 로그오프 후 로그인하거나 재 부팅해도 경로 유지 # mkdir -p /tmp/build/binutils # cd /tmp/build/binutils # /tmp/source/binutils-2.11.2/configure --prefix=/tmp/cross-tools --target=arm-linux # make # make install < 경로 추가 과정 > # export PATH=/tmp/cross-tools/bin:$PATH < 경로 추가 과정 > # vi ~/.bash_profile # 맨 아래 줄에 export PATH=/tmp/cross-tools/bin:$PATH 추가 # source ~/.bash_profile

  6. Installation of Cross-compiler • 소스 컴파일 • 커널 소스가 있는 디렉토리로 이동 후 다음과 같이 수행 • 커널 소스를 binutils 패키지 다음에 설치하는 이유는 헤더 파일 때문 • 컴파일러 설치 목적이 ARM용 리눅스라면 커널 소스는 ARM 패치까지 수행되어 있어야 하며, 본 교재에서 사용하는 커널 소스는 ㈜한백전자에서 제공한 커널 소스로써 EMPOS II 보드 패치까지 완료된 커널임 # cd /tmp/source/linux-2.4.19-rmk4-pxa2-empx1 # make empos_config (arm-linux-gcc가 없다고 메시지가 나와도 무시하고 진행) # make oldconfig < 컴파일 에러 방지를 위해 ‘unistd.h’ 파일의 아래 두 줄을 변경 # vi /tmp/source/linux-2.4.19-rmk4-pxa2-empx1/include/asm/unistd.h <수정 전> #define __NR_pread64 (__NR_SYSCALL_BASE+180) #define __NR_pwrite64 (__NR_SYSCALL_BASE+181) <수정 후> #define __NR_pread (__NR_SYSCALL_BASE+180) #define __NR_pwrite (__NR_SYSCALL_BASE+181)

  7. Installation of Cross-compiler • gcc 를 컴파일 해야 함 (gcc는 glibc를 컴파일 하기 위한 컴파일러) • Glibc 컴파일이 완료되면 glibc를 이용하여 gcc를 다시 만들어야 함. gcc를 만들기 위해서는 리눅스 커널의 헤더 파일이 필요하므로 configure 시 커널 헤더가 있는 디렉토리를 명시해 주도록 함 • t-linux 파일 수정: gcc 생성시 리눅스 커널의 헤더 파일이 필요하므로 configure시 커널 헤더가 있는 디렉터리 명시 • 컴파일할 디렉토리 생성과 설정 # vi /tmp/source/gcc-2.95.3/gcc/config/arm/t-linux <수정 전> TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer –fPIC <수정후> TARGET_LIBGCC2_CFLAGS = -fomit-frame-pointer –fPIC –Dinhibit_libc –D__gthr_posix_h T_CFLAGS = -Dinhibit_libc –D__gthr_posix_h # mkdir -p /tmp/build/gcc # cd /tmp/build/gcc # /tmp/source/gcc-2.95.3/configure --target=arm-linux --prefix=/tmpcross-tools --with-headers=/tmp/source/linux-2.4.19-rmk4-pxa2-empx1/include --disable-shared --disable-threads --enable-languages=“c” –nfp --without-fp --with-softfloat-support=internal

  8. Installation of Cross-compiler • 컴파일 진행 • 컴파일 도중 오류가 발생하더라도 실제 필요한 파일은 이미 생성 되었으므로 문제되지 않는다. • glibc 설치 # make # ./gcc/xgcc -dumpmachine <- arm-linux라고 나오면 정상임 # make install # mkdir -p /tmp/build/glibc # cd /tmp/build/glibc 다음의 stdio.texi 소스를 수정하여 패치를 하도록 한다. (코드가 길기 때문에 검색하여 찾는다.) # vi /tmp/source/glibc-2.2.3/manual/stdio.texi <수정 전> @code{scanf}. For more information about these tools, see @ref{, , , flex.info, Flex: The Lexical Scanner Generator}, and @ref{, , , bison.info, The Bison Reference Manual}. <수정 후> @code{scanf}. For more information about these tools,

  9. Installation of Cross-compiler • glibc 설치 • gcc 삭제 후 재설치 glibc를컴파일 하기 위해서는 커널 소스와 version.h 파일이 필요함. version.h 파일은 커널 소스에서 make dep 명령을 통해 얻을 수 있다. # cd /tmp/source/linux-2.4.19-rmk4-pxa2-empx1 # make dep # find ./ -name version.h <glibc 컴파일> # cd /tmp/build/glibc # /tmp/source/glibc-2.2.3/configure arm-linux --build=i686-pc-linux-gnu --with-headers=/tmp/source/linux-2.4.19-rmk4-pxa2-empx1/include --enable-add-ons --enable-shared --prefix=/tmp/cross-tools/arm-linux --without-fp --enable-kernel=2.4.19 에러가 발생하여 Makefile이 생성되지 않으면 에러 메시지에 나온 옵션을 추가로 적고 다시 실행한다. # make (시간이 오래 걸리니 잠시 기다린다.) # make install # cd /tmp/build/gcc # rm -rf * # /tmp/source/gcc-2.95.3/configure --target=arm-linux --prefix=/tmp/cross-tools --with-headers=/tmp/source/linux-2.4.19-rmk4-pxa2-empx1/include --with-softfloat-support=internal --enable-languages=c,c++ -nfp # make # make install

  10. Cross-compiler Test • Test program coding: hello.c • Cross-compile • 표준 gcc 컴파일 방식과 동일하며 ARM processor용 컴파일러를 사용 • Program Execusion • Target board에 다운로드 한 후 실행 #include <stdio.h> int main(void) { printf(“Hello World!\n”); return 0; } # gcc –o hello-x86 hello.c # arm-linux-gcc –o hello-arm hello.c < 아래 명령어 실행시와 같은 메시지 나오면 설치 성공> # file hello-arm hello: ELF 32-bit LSB executable, ARM, version 1 (ARM), dynamically linked (uses shared libs), not stripped # ./hello-arm

  11. Cross-compiler Files • 생성된 tool chains 확인: /usr/cross-tools/bin

  12. 실습내용 • 1. • ‘hello-world’ 작성 후, target board에서 실행 여부 확인 • tftp를 통한 file 전송 후 실행 • NFS를 통한 file 공유 후 실행

More Related