본문 바로가기

Build/Yocto

04. Layer 추가

 
Poky 를 통해 기초 linux system 을 만들어 보았으니, 
 
이제는 자신의  target board 에 맞는 실제 linux system을 만들기 위해 필요한 절차인, 
 
Layer 추가방법에 대해 고민해 보도록 하자. 
 
 

Layer 의 구성
 
Layer 는 보통 "meta-" string 으로 시작하는데,  먼저 Yocto Project 의핵심 layer 몇 가지 를 살펴보면 다음과 같다.
 
meta : OpenEmbedded core를위한 meta data
 
meta-yocto : poky를포함한 Yocto Project를위한 meta data
 
mata-yocto-bsp : Yocto Project가지원하는 reference machine에대한 BSP를포함하는 meta data
 
Layer 는 크게 아래와 같이 두 가지로 분류할 수 있다.
 
 a) 일반(General) layer : 일반 application 의 묶음을 위한 layer 
 
 b) BSP layer : BSP(board support packages) 를 위한 layer
 
 
 
 
 

Kernel Configuration 수정
 
# 빌드 환경 설정
cd ~/poky
source oe-init-build-env
 
# Kernal Configuration UI 불러오기
 bitbake -c menuconfig virtual/kernel
    Processor type and features 에 있는 SMP 삭제
 
# 수정사항 적용 및 커널 컴파일
$ bitbake -c kernel_configme virtual/kernel
$ bitbake -C compile virtual/kernel
 
# 에뮬레이터 실행 후 멀티코어가 삭제된 것을 확인
$ runqemu qemux86 qemuparams="-smp 4"
$ cat /proc/cpuinfo | grep processor
 
 

BSP Layer 만들기
 
# 빌드 환경 설정
cd ~/poky
source oe-init-build-env
 
# 레이어 생성
yocto-layer create ypbook
 
# 생성한 레이어를 추가시킴
$ gedit ~/poky/build/conf/bblayers.conf
bblayers 는 프로젝트에 필요한 메타데이터 레이어를 열거하고 있으며
layer 관련 디렉토리 목록을 정의하고 있음
아래와 같이 추가함
 
  /home/sheen/poky/build/meta-ypbook \
 
# 생성된 레이어 확인
$ find ./ -name *ypbook*
./build/meta-ypbook
 
# 생성된 레이어에 recipe 추가
$ cd ~/poky/build/meta-ypbook
 
$ mkdir -p recipes-kernel/linux
$ mkdir -p recipes-kernel/linux/files
 
# 생성된 recipe 에 Kernel 환경구성 수정하는 파일 추가
$ gedit ~/poky/build/meta-ypbook/recipes-kernel/linux/files/smp.cfg
 
   # Disable SMP
   CONFIG_SMP=n
 
# recipe 폴더는 recipe 인 .bb 파일과 append 인 .bbappend 등으로 구성
# bbappend 는 파일을 추가하는 것을 의미
$ gedit ~/poky/build/meta-ypbook/recipes-kernel/linux/linux-yocto_4.8.12.bbappend
 
   # Include kernel configuration fragment
   FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
   SRC_URI += "file://smp.cfg"
 
#커널 폴더 확인
$ bitbake -e virtual/kernel | grep STAGING_KERNEL_DIR
#     [doc] "The location of the kernel sources. This variable is set to the value of the STAGING_KERNEL_DIR within the module class (module.bbclass)."
#     [doc] "The location of the kernel sources. This variable is set to the value of the STAGING_KERNEL_DIR within the module class (module.bbclass)."
# $STAGING_KERNEL_DIR [2 operations]
 
STAGING_KERNEL_DIR="/home/sheen/poky/build/tmp/work-shared/qemux86/kernel-source"
 
#     "${STAGING_KERNEL_DIR}"
#   "${STAGING_KERNEL_DIR}"
    kernsrc = d.getVar("STAGING_KERNEL_DIR", True)
 
/home/sheen/poky/build/tmp/work-shared/qemux86/kernel-source/
-=> 검색된 커널 폴더 위치 설정 값
 
# devshell 로 쉘에 진입
$ bitbake -c devshell virtual/kernel
 
# 커널 소스 변경
$ ls
 
$ gedit ./drivers/misc/Kconfig
 
  config YP_DRIVER
      tristate "Yocto Project Test Driver"
      help
        This dirver does nothing but print a message
 
$ gedit ./drivers/misc/Makefile
 
   obj-$(CONFIG_YP_DRIVER)        += yp-driver.o
 
$ gedit ./drivers/misc/yp-driver.c
 
   #include <linux/module.h>
 
   static int __init yocto_testmod_init(void) {
       pr_info("Hello Kernel form the Yocto Project!");
   }
 
   static void __init yocto_testmod_exit(void) {
       pr_info("Gone fishing. I'll be back ! ");
   }
 
   module_init(yocto_testmod_init);
   module_exit(yocto_testmod_exit);
 
   MODULE_AUTHOR();
   MODULE_DESCRIPTION();
   MODULE_LICENSE("GPL");
 
# 변경된 사항 확인
$ git status
 
# 변경사항 커밋
git add .
git commit -m "Added Yocto Project Driver"
 
# 커밋된 사항을 patch 로 생성
git format-patch -n HEAD^
 
# 패치 파일 확인
# 패치 파일에는 추가된 파일 및 파일 변경사항들이 적혀있음
$ ls
0001-Added-Yocto-Project-Driver.patch
...
 
# 패치 파일을 recipe 에 추가
$ mkdir ~/poky/meta/recipes-kernel/linux/files/
$ cp ./0001-Added-Yocto-Project-Driver.patch  ~/poky/build/meta-ypbook/recipes-kernel/linux/files/
 
# recipe 에 드라이버 수정사항 기록
$ gedit ~/poky/build/meta-ypbook/recipes-kernel/linux/files/yp-driver.cfg
 
   # Enable Yocto Project Driver
   CONFIG_MISC_DEVICES=y
   CONFIG_YP_DRIVER=y
 
# recipe 에 bbappend 파일 수정
$ gedit ~/poky/build/meta-ypbook/recipes-kernel/linux/linux-yocto_4.8.bbappend
 
   FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
   SRC_URI += "file://smp.cfg"
   SRC_URI += "file://yp-driver.cfg"
   SRC_URI += "file://0001-Added-Yocto-Project-Driver.patch"
 
# 수정된 kernel 테스크만 빌드 
$ cd ~/poky
$ source oe-init-build-env
$ bitbake -C compile virtual/kernel
 
# 빌드된 에뮬레이터 확인
$ runqemu qemux86
 
# 변경사항 확인 후 에뮬레이터 종료
$ dmesg | grep "Hello Kernel"
$  shutdown -h now
 
* recipe 에 추가된 패치파일 내용
 
 
From e800614192b7633a045acdcf85ce5d332826a93d Mon Sep 17 00:00:00 2001
From: OpenEmbedded <oe.patch@oe>
Date: Wed, 21 Feb 2018 16:20:26 +0900
Subject: [PATCH 1/1] Added Yocto Project Driver
 
---
drivers/misc/Kconfig     |  5 +++++
drivers/misc/Makefile    |  2 +-
drivers/misc/yp-driver.c | 18 ++++++++++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 drivers/misc/yp-driver.c
 
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index d002528..765222b 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -4,6 +4,11 @@
menu "Misc devices"
+config YP_DRIVER
+    tristate "Yocto Project Test Driver"
+    help
+        This dirver does nothing but print a message
+
config SENSORS_LIS3LV02D
    tristate
    depends on INPUT
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index fb32516..ac17244 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for misc devices that really don't fit anywhere else.
#
-
+obj-$(CONFIG_YP_DRIVER)        += yp-driver.o
obj-$(CONFIG_IBM_ASM)        += ibmasm/
obj-$(CONFIG_AD525X_DPOT)    += ad525x_dpot.o
obj-$(CONFIG_AD525X_DPOT_I2C)    += ad525x_dpot-i2c.o
diff --git a/drivers/misc/yp-driver.c b/drivers/misc/yp-driver.c
new file mode 100644
index 0000000..c15928e
--- /dev/null
+++ b/drivers/misc/yp-driver.c
@@ -0,0 +1,18 @@
+#include <linux/module.h>
+
+static int __init yocto_testmod_init(void)
+{
+    pr_info("Hello Kernel form the Yocto Project!");
+}
+
+static void __init yocto_testmod_exit(void)
+{
+    pr_info("Gone fishing. I'll be back ! ");
+}
+
+module_init(yocto_testmod_init);
+module_exit(yocto_testmod_exit);
+
+MODULE_AUTHOR();
+MODULE_DESCRIPTION();
+MODULE_LICENSE("GPL");
--
1.9.1
 
 

Layer 확인
 
# 빌드 환경 설정
cd ~/poky
source oe-init-build-env
 
# Layer 확인
$ bitbake-layers show-layers : 설정되어진 레이어들
$ bitbake-layers show-recipes : 사용가능한 레시피와 레이어
$ bitbake-layers show-overlayed : 우선 순위 높은 것에 의해 재정의된 레이어
$ bitbake-layers show-appends : 사용가능한 append 파일과 그것을 적용하는 레시피
$ bitbake-layers flatten <output_dir> : 모든 설정 레이어가 합쳐진 디렉토리가 생성된다. 덮어 쓰기 없이 모든 append 가 적용된다. 이를 비트베이크가 레시피를 찾을 때 사용한다.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

'Build > Yocto' 카테고리의 다른 글

05. Recipe  (0) 2020.01.23
03. 빌드 설정  (0) 2020.01.23
02. 빌드  (0) 2020.01.23
01. 구성  (2) 2020.01.23