[Linux] Ubuntu(16.04)에서 crosstool-ng 설치하기

728x90
반응형

Ubuntu(20.04)라는 제목으로 포스팅했던 글을 다시 작성한다.

sudo apt-get install automake bison chrpath flex g++ git gperf gawk libexpat1-dev libncurses5-dev libsdl1.2-dev libtool-bin libtool python2.7-dev texinfo help2man wget curl libisl-dev

위 명령 실행 전 반드시 sudo apt update 명령으로 패키지 목록 업데이트해야 한다. 설치할 패키지는 Ubuntu 버전마다 다를 수 있다.

ct-ng 설치는 사용자 홈 디렉터리에 설치하는 것이 일반적이다. root 디렉터리에 설치할 수 없다.

git에서 checkout받는다.

git clone http://github.com/crosstool-ng/crosstool-ng

git tag 명령으로 checkout 받을 수 있는 버전을 확인한다.

git tag
crosstool-ng-0.0.1
crosstool-ng-0.0.2
crosstool-ng-0.0.3
crosstool-ng-0.0.4
crosstool-ng-0.0.5
crosstool-ng-0.1.0
crosstool-ng-0.1.1
crosstool-ng-0.1.2
crosstool-ng-0.2.0
crosstool-ng-0.2.1
crosstool-ng-0.2.2
crosstool-ng-0.3.0
crosstool-ng-0.3.1
crosstool-ng-0.3.2
crosstool-ng-1.0.0
crosstool-ng-1.1.0
crosstool-ng-1.1.1
crosstool-ng-1.1.2
crosstool-ng-1.1.3
crosstool-ng-1.1.3a
crosstool-ng-1.10.0
crosstool-ng-1.10.1
crosstool-ng-1.11.0
.
.
.
crosstool-ng-1.9.0
crosstool-ng-1.9.1
crosstool-ng-1.9.2
crosstool-ng-1.9.3

1.22 버전으로 checkout을 받는다. crosstool-ng 버전 선택은 보드의 출시시점을 확인해 u-boot, kernel 버전등을 선정하고 여기에 가장 잘 호환되는 버전을 선택해야 한다.

git checkout crosstool-ng-1.22.0

checkout 받은 뒤 branch명령으로 현재 checkout 상태를 확인한다. git branch 명령을 입력하면 현재 branch가 나타난다.

git branch

* (HEAD detached at crosstool-ng-1.22.0)
master

crosstool-ng를 설치하기 전에 bootstrap을 실행시켜 빌드환경을 준비시켜줘야 한다. bootstrap 실행은 최초에 1회만 해주면 된다.

![[../Pasted image 20250517134954.png]]

bootstrap을 vi에디터 등으로 열어보면 내용을 확인할 수 있다.

vi bootstrap
#!/bin/sh
set -e

printf "Running autoconf...\n"
autoconf -Wall --force

printf "Done. You may now run:\n    ./configure\n"

bootstrap은 쉘스크립트 파일로 아래와 같이 실행한다.

./bootstrap

정상적으로 실행되면 아래와 같은 메시지가 출력되고 configure파일이 생성된 걸 확인할 수 있다.

Done. You may noe run:
    ./configure

![[../Pasted image 20250517140356.png]]

./configure --help 명령어를 사용하면 설정 가능한 옵션들을 확인할 수 있다. 별도의 옵션 없이 ./configure를 실행한 뒤 makemake install을 수행하면, 기본적으로 /usr/local/bin과 같은 시스템 전역 디렉터리에 ct-ng가 설치된다. 이 경우, 다른 버전의 ct-ng를 사용해야 할 때는 기존 버전을 삭제한 후 새로 설치해야 하며, 다른 빌드 시스템과 경로 충돌이 발생할 가능성도 있다. 따라서 충돌을 방지하고 버전 관리의 유연성을 높이기 위해, --enable-local 옵션을 사용하여 현재 디렉터리에 설치하거나, --prefix 옵션을 통해 사용자 지정 경로에 설치하는 것을 권장한다.

./configure --enable-local

configure가 성공하면 아래와 같은 메시지가 나오고, Makefile, Makefile.in파일이 생성된 걸 확인할 수 있다.

config.status: creating Makefile

![[../Pasted image 20250517142637.png]]

make, make install 명령으로 ct-ng 설치

make; make install

![[../Pasted image 20250517142839.png]]

./ct-ng menuconfig 명령으로 config를 변경할 수 있는데 보통은 samples 디렉터리에 미리 정의된 config를 사용한다.

cd samples
ll

![[../Pasted image 20250517150732.png]]

ct-ng가 있는 하위 디렉터리에서 arm-cortex_a8-linux-gnueabi config를 적용해 준다. ([[GNU 툴체인 타깃 트리플(target triplet), 타깃 쿼드러플(target quadruplet)]])

./ct-ng arm-cortex_a8-linux-gnueabi

위 명령으로 config를 적용해 주고 한 가지 옵션을 더 변경해 준다.

crosstool-chain build 과정에서 생성되는 toolchain 디렉터리를 read only로 생성할 것인지 결정하는 옵션을 꺼줘야 한다. build 과정에서 생성된 파일을 패치하거나 수정해야 하는 경우가 생기는데 이때 해당 옵션이 활성화돼 있으면 read only 상태기 때문에 수정이 불가능하게 된다. 또한 toolchain 내부 설정을 바꾸거나 테스트용으로 파일을 수정할 때 변경할 수 없다.

./ct-ng menuconfig -> Paths and misc options 메뉴 선택, 여기서 Render the toolchain read-only 옵션을 꺼준다.
![[../Pasted image 20250517144933.png]]

다음 명령으로 빌드를 진행한다. 소요시간은 약 30분 정도다.

./ct-ng build

빌드가 완료되면 Finishing installation (may take a few seconds)... 메시지가 출력된다. 빌드 완료된 결과물은 x-tools 디렉터리에 존재한다. 빌드된 컴파일러를 사용하기 위해서는 PATH를 등록해줘야 한다.

PATH=~/x-tools/arm-cortex_a8-linux-gnueabihf/bin:$PATH

PATH 등록 후 설치된 컴파일러의 버전을 확인할 수 있다.

$ arm-cortex_a8-linux-gnueabihf-gcc --version
arm-cortex_a8-linux-gnueabihf-gcc (crosstool-NG crosstool-ng-1.22.0) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

설치를 완료했으면 간단한 프로그램을 작성해 크로스컴파일러를 사용해서 빌드해 보자.

#include <stdio.h>

int main(void)
{
    printf("Hello embedded world\n");
    return 0;
}
arm-cortex_a8-linux-gnueabihf-gcc helloworld.c -o helloworld

빌드에 성공하면 helloworld 실행파일이 생성된다. file 명령어를 통해 파일 정보를 확인해 보면 ARM 용 실행파일임을 확인할 수 있다.

file helloworld
helloworld: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 4.3.0, not stripped

build error

라이브러리의 압축파일은 .build/tarballs 에 다운로드되기 때문에 해당 경로에서 아래 명령을 실행해야 한다.

  1. isl-0.14.tar.gz 파일을 받지 못하는 경우
    isl-0.14 는 sourceforge에 있는데 해당경로가 변경되거나 접속이 불가능한경우 받아오지 못한다. [[명령어/wget|wget]] 명령을 사용해서 직접 받아와야 한다.
cd .build/tarballs
wget -O isl-0.14.tar.xz [다운로드 주소]
wget -O isl-0.14.tar.xz https://sourceforge.net/projects/libisl/files/isl-0.14.tar.xz/download
  1. libelf-0.8.13
    cd .build/tarballs
    wget -O libelf-0.8.13.tar.gz [다운로드 주소]
    wget -O libelf-0.8.13.tar.gz https://sourceforge.net/projects/rtesberemizpackage/files/libelf-0.8.13.tar.gz/download
  2. expat-2.1.0
    cd .build/tarballs
    wget -O expat-2.1.0.tar.gz [다운로드 주소]
    wget -O expat-2.1.0.tar.gz https://repository.timesys.com/buildsources/e/expat/expat-2.1.0/expat-2.1.0.tar.gz
728x90
반응형