Nhân build YOCTO - Build SDK
1. Mục tiêu
- Bình thường chúng ta cần phải download source của kernal về và một số BSP để build OS. Thay vì vậy mình sử dụng yocto project để build SDK cho đồng bộ
2. Build SDK
vbuser@Ubuntu18:~/Desktop/selfstudy/poky/build$ bitbake core-image-minimal -c populate_sdk
Loading cache: 100% |#############################################################################################################################| Time: 0:00:00
Loaded 1306 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies
Build Configuration:
BB_VERSION = "1.44.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "universal"
TARGET_SYS = "i686-poky-linux"
MACHINE = "qemux86"
DISTRO = "poky"
DISTRO_VERSION = "3.0.4"
TUNE_FEATURES = "m32 core2"
TARGET_FPU = ""
meta
meta-poky
meta-yocto-bsp
meta-skeleton = "zeus:daf096e295121ea49ebf21f8070e9a6e28f5d46c"
Initialising tasks: 100% |########################################################################################################################| Time: 0:00:01
Sstate summary: Wanted 352 Found 0 Missed 352 Current 472 (0% match, 57% complete)
NOTE: Executing Tasks
NOTE: Setscene tasks completed
NOTE: Tasks Summary: Attempted 3058 tasks of which 2051 didn't need to be rerun and all succeeded.
3. Run SDK installer
- Đầu tiên chúng ta cần cài đặt SDK vào host (cái máy dùng để build kernel). Cái SDK installer này là mấy file .sh (shell script), nó sẽ được tìm thấy trong "build/tmp/deploy/sdk" ở đây mình sử dụng "core-image-minimal" nên mọi người có thể sử dụng "poky-glibc-x86_64-core-image-minimal-core2-32-qemux86-toolchain-3.0.4.sh" để cài đặt SDK.
vbuser@Ubuntu18:~/Desktop/selfstudy/poky/build$ cd tmp/deploy/sdk
vbuser@Ubuntu18:~/Desktop/selfstudy/poky/build/tmp/deploy/sdk$ tree -L 1 .
.
├── poky-glibc-x86_64-core-image-minimal-core2-32-qemux86-toolchain-3.0.4.host.manifest
├── poky-glibc-x86_64-core-image-minimal-core2-32-qemux86-toolchain-3.0.4.sh
├── poky-glibc-x86_64-core-image-minimal-core2-32-qemux86-toolchain-3.0.4.target.manifest
└── poky-glibc-x86_64-core-image-minimal-core2-32-qemux86-toolchain-3.0.4.testdata.json
0 directories, 4 files
vbuser@Ubuntu18:~/Desktop/selfstudy/poky/build/tmp/deploy/sdk$ ./poky-glibc-x86_64-core-image-minimal-core2-32-qemux86-toolchain-3.0.4.sh
Poky (Yocto Project Reference Distro) SDK installer version 3.0.4
=================================================================
Enter target directory for SDK (default: /opt/poky/3.0.4): /home/vbuser/Desktop/selfstudy/SDK
You are about to install the SDK to "/home/vbuser/Desktop/selfstudy/SDK". Proceed [Y/n]? Y
Extracting SDK.............................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
$ . /home/vbuser/Desktop/selfstudy/SDK/environment-setup-core2-32-poky-linux
4. Using the SDK
- Chúng ta có thể sử dụng cái SDK để dev application
4.1. Run SDK environment setup script
vbuser@Ubuntu18:~/Desktop/selfstudy$ mkdir App_Workspace
vbuser@Ubuntu18:~/Desktop/selfstudy$ cd App_Workspace/
vbuser@Ubuntu18:~/Desktop/selfstudy/App_Workspace$ source ../SDK/
environment-setup-core2-32-poky-linux site-config-core2-32-poky-linux sysroots/ version-core2-32-poky-linux
vbuser@Ubuntu18:~/Desktop/selfstudy/App_Workspace$ source ../SDK/environment-setup-core2-32-poky-linux
4.2. Bây giờ chúng ta tạo hello world bằng code C thôi
vbuser@Ubuntu18:~/Desktop/selfstudy/App_Workspace$ cat helloworld.c
#include <stdio.h>
void main()
{
printf("Hello world \r\n");
}
vbuser@Ubuntu18:~/Desktop/selfstudy/App_Workspace$ cat Makefile
all: helloworld
$(CC) helloworld.c -o helloworld
clean:
rm helloworld
vbuser@Ubuntu18:~/Desktop/selfstudy/App_Workspace$ make
i686-poky-linux-gcc -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/vbuser/Desktop/selfstudy/SDK/sysroots/core2-32-poky-linux -O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z,relro,-z,now helloworld.c -o helloworld
i686-poky-linux-gcc -m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/vbuser/Desktop/selfstudy/SDK/sysroots/core2-32-poky-linux helloworld.c -o helloworld