임베디드 시스템 위에서 작업을 하게 되면 욕토(Yocto) 를 다룰 일이 생긴다. 작은 IoT 디바이스 등의 임베디드 시스템에도 펌웨어로 돌리는 경우가 아니라면 OS 가 올라가게 되고 최대한 필요한 기능만 추려서 경량화된 사이즈의 OS 를 구성하게 되는데 리눅스를 기반의 OS 를 쉽게 커스터마이즈 할 수 있는 툴이 바로 욕토다. 욕토가 욕토인 이유는 욕나오고 토나와서라고..
욕토는 여러가지 장점을 가지고 있는데 간단히 요약해보면 다음과 같다.
- 크로스 플랫폼 지원: ARM, X86, MIPS 등 다양한 아키텍처를 지원함
- 커스터마이징: 원하는 모듈과 어플리케이션 등을 하드웨어 요구사항에 맞게 커스터마이징이 가능
- 모듈화 및 확장성: Layer 구조를 기반으로 기능을 쉽게 추가하거나 변경 가능
- 강력한 커뮤니티: Linux 재단이 지원해주는 프로젝트인만큼 커뮤니티 형성이 잘 되어있음
그러나 개인적으로는 다음과 같은 단점도 가지고 있는 듯 하다.
- 일반적이지 않은 빌드 시스템: BitBake 라는 욕토에서만 쓰이는 빌드시스템을 기반으로 하는데 그만큼 러닝 커브가 있다.
- 긴 빌드 시간: 작은 변경사항에도 긴 빌드과정을 수행해야 함.
- 복잡한 문서: 기능이 많고 확장이 쉬운 만큼 문서가 복잡하다.
비슷한 경쟁 프로젝트로 Buildroot 라는 프로덕트가 있는 듯 하다. Buildroot 는 Yocto 와는 다르게 친숙한 Makefile 을 기반으로 하고 러닝커브가 훨씬 낮다고 하는데 아직 사용해본 적은 없다.
먼저 Yocto 를 알아보기 위해 Yocto 를 한번 빌드하고 실행시켜 보자.
Yocto 빌드하기
먼저 시스템에 빌드에 필요한 Package 들을 설치해준다.
$ sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 python3-subunit zstd liblz4-tool file locales libacl1
$ sudo locale-gen en_US.UTF-8
이후 Yocto 프로젝트의 poky 를 clone 해준다.
$ git clone git://git.yoctoproject.org/poky
Cloning into 'poky'...
remote: Counting
objects: 432160, done. remote: Compressing objects: 100%
(102056/102056), done. remote: Total 432160 (delta 323116), reused
432037 (delta 323000) Receiving objects: 100% (432160/432160), 153.81 MiB | 8.54 MiB/s, done.
Resolving deltas: 100% (323116/323116), done.
Checking connectivity... done.
위의 git:// prefix 접속이 방화벽이나 프록시 설정 때문에 막힐 수 있다. 그런 경우 다음 명령어로 우회할 수 있다.
$ git clone https://git.yoctoproject.org/git/poky
이후 가장 최신버전의 브랜치인 `origin/styhead` 로 checkout 해주자.
$ git checkout -t origin/styhead
$ git pull
poky 프로젝트로 들어와서 oe-init-build-env 를 실행시켜주자.
$ cd poky
$ source oe-init-build-env
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.
You had no conf/bblayers.conf file. This configuration file has therefore
been created for you with some default values. To add additional metadata
layers into your configuration please add entries to conf/bblayers.conf.
The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
https://docs.yoctoproject.org
For more information about OpenEmbedded see their website:
https://www.openembedded.org/
### Shell environment set up for builds. ###
You can now run 'bitbake <target>'
Common targets are:
core-image-minimal
core-image-full-cmdline
core-image-sato
core-image-weston
meta-toolchain
meta-ide-support
You can also run generated QEMU images with a command like 'runqemu qemux86-64'
Other commonly useful commands are:
- 'devtool' and 'recipetool' handle common recipe tasks
- 'bitbake-layers' handles common layer tasks
- 'oe-pkgdata-util' handles common target package tasks
이 스크립트의 역할은 다음과 같다.
1. /build 디렉토리를 만들고 설정 파일을 생성함
2. 환경변수 설정. 특히, PATH 에 ./script 를 추가해서 자체 명령어를 실행할 수 있게 함.
3. /build 로 이동
Yocto 를 빌드하기 전에 꼭 실행시켜 주어야 하는 스크립트이다.
해당 스크립트로 이동하면 /build 폴더로 이동이 된다. 이후 bitbake 로 빌드를 진행해주자.
$ bitbake core-image-minimal
다음 명령어는 다음과 같은 의미를 가진다.
- bitbake
- 욕토의 bild 도구. 컴파일, 패키징, 이미지 생성 등의 기능을 함
- core-image-minimal
- Yocto 의 기본 recipe. Yocto 에서는 어떤 이미지를 만들 것인가를 Recipe 라는 단어로 표현한다. core-image-minimal 은 Yocto 에서 제공하는 기본 이미지 recipe 임.
빌드 과정은 굉장히 오랜 시간이 걸린다..(1시간 이상) 빌드가 완료되면 `tmp/deploy/images/<MACHINE>/` 다음 directory 에 이미지들이 생긴다.

따로 설정을 건들지 않고 build 를 하게 되면 타겟 머신이 qemux86-64 로 설정이 된다. 만약 ARM 등 다른 machine 을 타겟으로 빌드하려면 ./build/conf/local.conf 의 MACHINE 변수를 변경 후 빌드하면 된다.
이후 프로젝트 root 으로 와서 다음 명령어를 실행하면 yocto 로 생성된 OS 에 접속해서 테스트 해볼 수 있다.
$ runqemu qemux86-64
# $ runqemu qemux86-64 nographic # GUI 환경이 없으면 다음 명령어로 실행
QEMU 를 통해서 Yocto OS 의 Shell 로 접속할 수 있다.
Reference
1. https://docs.yoctoproject.org/brief-yoctoprojectqs/index.html
Yocto Project Quick Build — The Yocto Project ® 5.1.999 documentation
A Linux Foundation Collaborative Project. All Rights Reserved. Linux Foundation® and Yocto Project® are registered trademarks of the Linux Foundation. Linux® is a registered trademark of Linus Torvalds. © Copyright 2010-2024, The Linux Foundation, CC-B
docs.yoctoproject.org