2/26/2018

Raspberry-Pi3 와 Linux Yocto 기본구성 과 이해

1. Yocto 구성설명 

Yocto의 Quick Build 방법과 기존에 존재하는 Layer를 쉽게 추가하는 방법을 아래의 링크에서 쉽게 설명을 해주고 있으므로, 반드시 알아두자

  • Yocto의 사용법 (Cookbook)
Yocto에 대한 현재 Quick Guide / Reference Manul 와 Cookbook Topics 에서 쉽게확인
  https://wiki.yoctoproject.org/wiki/Cookbook

  • OS Image에 추가하는 방법 (Cookbook Topics)
아래의 구성할 문서의 순서랑 거의 동일하며 Layer 추가하는 방법 및 수정방법이 괜찮다
  https://wiki.yoctoproject.org/wiki/Cookbook:Example:Adding_packages_to_your_OS_image

  • Application 개발관련내용(Cookbook Topics) 
기존의 bitbake-layers 와 다르게 devtool 을 이용한 recipe 추가방법이 새로움
  https://wiki.yoctoproject.org/wiki/Application_Development_with_Extensible_SDK


  • Yocto 기본사용법확인
이전에 Yocto Reference Manual 기반으로 필요한 환경변수 및 구조설명
  https://ahyuo79.blogspot.com/2015/10/yocto.html


https://yoctoproject.org/docs/2.7/mega-manual/mega-manual.html#what-is-the-yocto-project

  • Layer 의 우선순위 (Layer Priority)
이전에 $ bitbake-layers show-layers 명령으로 우선순위를 보기는 했지만 우선순위 동작원리를 미쳐 파악을 못했다.

$ bitbake-layers show-layers  // Layer Priority 확인 및 구성확인 

$ bitbake-layers layerindex-show-depends meta-raspberrypi    // meta-raspberrypi의 의존성 확인, Layer를 추가할 때 의존성을 확인필요 

$ bitbake-layers -h 
usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h]  ...

BitBake layers utility

optional arguments:
  -d, --debug           Enable debug output
  -q, --quiet           Print only errors
  -F, --force           Force add without recipe parse verification
  --color COLOR         Colorize output (where COLOR is auto, always, never)
  -h, --help            show this help message and exit

subcommands:
  
    add-layer           Add one or more layers to bblayers.conf.
    remove-layer        Remove one or more layers from bblayers.conf.
    flatten             flatten layer configuration into a separate output
                        directory.
    show-layers         show current configured layers.
    show-overlayed      list overlayed recipes (where the same recipe exists
                        in another layer)
    show-recipes        list available recipes, showing the layer they are
                        provided by
    show-appends        list bbappend files and recipe files they apply to
    show-cross-depends  Show dependencies between recipes that cross layer
                        boundaries.
    layerindex-fetch    Fetches a layer from a layer index along with its
                        dependent layers, and adds them to conf/bblayers.conf.
    layerindex-show-depends
                        Find layer dependencies from layer index.
    create-layer        Create a basic layer

Use bitbake-layers  --help to get help on a specific command


https://dornerworks.com/blog/building-linux-with-yocto
상위 사이트에서 Layer의 우선순위에 대해서 너무 쉽게 그림으로 설명을 해주었지만,궁금한 사항이 두 가지가 더 생겼다.

  • 궁금사항 
  1. Layer의 우선순위는 어떻게 정해지는 것인가? 
  2. Recipe의 우선순위는 어떻게 정해지는가? 

1번째의 질문의 답은 처음 conf/bblayers.conf에서 정해지는 것으로 착각했으나,  각 개별 Layer의 conf에  BBFILE_PRIORITY_xxx , suffix는 layer 이름에 의해 정해진다.


  • meta-oe Layer 의 예제 (oe는 open embedded 약어)
$ vi meta-openembedded/meta-oe/conf/layer.conf    // 각 Layer의 conf에 의해 정의됨

BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_PRIORITY_openembedded-layer = "6"        // openembedded layer 우선순위 

LAYERDEPENDS_openembedded-layer = "core"        //의존성 

LAYERSERIES_COMPAT_openembedded-layer = "thud warrior zeus"  // Yocto version 호환성 


  • meta-networking Layer 예제
$ vi meta-openembedded/meta-networking/conf/layer.conf 

BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \              // 등록되는 순서에 의해 동작될것이라고 생각 
            ${LAYERDIR}/recipes-*/*/*.bbappend"


BBFILE_PRIORITY_networking-layer = "5"     //networking layer의 우선순위 (같은 meta-openembdedded에 속해있지만 다름)

LAYERDEPENDS_networking-layer = "core"                // 의존성이 상당함 
LAYERDEPENDS_networking-layer += "openembedded-layer"
LAYERDEPENDS_networking-layer += "meta-python"

LAYERSERIES_COMPAT_networking-layer = "thud warrior zeus"


2번째의 질문의 답은 처음 Layer의 conf에서 BBFILES의 등록되는 순서가 아닐까 역시 잠시 착각 했는데, BBFILES은 등록만 할뿐 모든 Recipe는 사용하지 않는다는 사실을 깜빡했다.
잘 생각을 해보면, 최종 target image.bb파일이 존재하여, IMAGE_INSTALL에 들어간 Package들만을 설치진행한다.
기본으로 설치되는 부분은 class라는 공유개념이 존재하며,모든 recipe들은 사용하지 않는다.
즉  image -> core-image ->  include ***.bb 확장되어가는 구조


2. Raspberry Pi  개발환경 구성

  1. OS: Ubuntu 16.04_LTS 64bit 
  2. Window 기반의 Virtual Box 사용 

  • 기본설치 
$ sudo apt install chrpath  diffstat gawk libncurses5-dev texinfo  

makeinfo -> texinfo 변경


2.1 Raspberry PI 관련사항 

  • Raspberry PI 설정 및 전체문서   
  https://wikidocs.net/book/483

  • Raspberry PI Kernel 
  https://wikidocs.net/3243
  https://wikidocs.net/3244

  • Raspberry Android Build 
  http://airpage.org/xe/project_data/25990


2.2  Raspberry Pi Yocto 전체구성 


상위 Raspberry PI Yocto 구성 를 보면  사용할 GIT는 아래와 같이 세개로 구성이 된다.

  • 기본 Yocto 시스템  및 추가 metalayer들 
  1. git://git.yoctoproject.org/poky       // 기본 Yocto System 인 Poky
  2. git://git.openembedded.org/meta-openembedded  // Yocto의 meta-layer (meta-oe) 추가 
  3. https://github.com/agherzan/meta-raspberrypi  // Yocto의 meta-layer (meta-raspberrypi) 추가 

  • Raspberry Pi Yocto 기본사용법 참고 사이트 
  http://www.jumpnowtek.com/rpi/Raspberry-Pi-Systems-with-Yocto.html
  http://www.yocto.co.kr/2016/01/yocto-project-2.html
  http://kernelhacks.com/raspberry-pi-3-with-yocto/


2.3 Yocto 구성 및 meta layer 추가 

Yocto의 Reference Manual에 Reference Distribution Layer인 Poky를 구성한 후 각 필요한 meta layer들을 각각 추가하여 구성한다.

  1. 필요한 Raspberry Pi를 위한 BSP Layer 추가 
  2. Emdedded 관련된 기본인 Base Layer 추가

  • Yocto의 기본인 Poky (Reference Distribution Layer) 구성 

Yocto의 기본시스템이 Pocky를 git로 download하여 아래와 같이 구성을 확인하자

$ mkdir raspberrypi
$ cd raspberrypi
$ git clone -b master  git://git.yoctoproject.org/poky

$ tree poky -L 1
poky
├── bitbake   // bin에 bitbake , bitbake-layers 가 존재하므로 중요   
├── contrib
├── documentation
├── LICENSE
├── LICENSE.GPL-2.0-only
├── LICENSE.MIT
├── meta
├── meta-poky
├── meta-selftest
├── meta-skeleton
├── meta-yocto-bsp
├── oe-init-build-env
├── README.hardware -> meta-yocto-bsp/README.hardware
├── README.OE-Core
├── README.poky -> meta-poky/README.poky
├── README.qemu
└── scripts  // devtool늘 비롯하여 각종 oe-xxxxx tools 제공 

$ cd poky
$ ls
LICENSE     README.hardware  README.qemu  documentation  meta-poky      meta-skeleton   oe-init-build-env
README.LSB  README.poky      bitbake      meta           meta-selftest  meta-yocto-bsp  scripts

  http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/


  • poky 에 meta-raspberrypi (BSP Layer) 추가 

$ pwd
/home/jhlee/raspberrypi/poky

$ git clone -b master https://github.com/agherzan/meta-raspberrypi

$ tree -L 1 meta-raspberrypi
meta-raspberrypi
├── classes
├── conf
├── COPYING.MIT
├── docs
├── dynamic-layers
├── files
├── README.md
├── recipes-bsp
├── recipes-connectivity
├── recipes-core
├── recipes-devtools
├── recipes-graphics
├── recipes-kernel
├── recipes-multimedia
└── wic


$ ls
LICENSE     README.hardware  README.qemu  documentation  meta-openembedded  meta-raspberrypi  meta-skeleton   oe-init-build-env
README.LSB  README.poky      bitbake      meta           meta-poky          meta-selftest     meta-yocto-bsp  scripts

  https://layers.openembedded.org/layerindex/branch/master/layer/meta-raspberrypi/
  https://github.com/agherzan/meta-raspberrypi
  http://meta-raspberrypi.readthedocs.io/en/latest/readme.html
  http://git.yoctoproject.org/cgit.cgi/meta-raspberrypi/


  • poky 에 meta-oe (Base Layer) 추가 

$ pwd
/home/jhlee/raspberrypi/poky

$ git clone -b master git://git.openembedded.org/meta-openembedded 

$ tree -L 1 meta-openembedded/
meta-openembedded/
├── contrib
├── COPYING.MIT
├── meta-filesystems
├── meta-gnome
├── meta-initramfs
├── meta-multimedia  // 이 아래의 4개의 layer만  rpi-build/conf/bblayers.conf 에 추가 
├── meta-networking
├── meta-oe
├── meta-perl
├── meta-python
├── meta-webserver
├── meta-xfce
└── README

  https://layers.openembedded.org/layerindex/branch/master/layer/meta-oe/
  http://cgit.openembedded.org/meta-openembedded/tree/


  • Yocto poky 에서 구조확인가능 
  http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/


2.4 이외의 meta-layer 추가방법  

Cookbook을 보면 자세히 나오며 각각 Layer들을 추가하여 확장하기가 쉽다. 다만, Type은 반드시 확인을 해야한다.

  • OpenEmbeded Layer Index 의 meta-oe Layer 검색
  1. meta-oe (meta-openembedded)  Layer Type Base를 찾음 
  2. meta-raspberrypi  검색 과 Layer Type BSP 확인 



Reference Manual에는 Layer Type은 3가지밖에 없지만, 이곳에는 다음과 같이 더 분류를 하고 의미가 조금 다른 것 같다.


  • Layer Type 
  1. Base: Emdedded에서 기본 Layer로 개발 Tools 및 Kernel 관련부부구성 
  2. Machine (BSP) : 각 개별 Board에 맞게 BSP 가 구성되어있어 선택 
  3. Distribution : Poky를 기반으로 확장된 배포판으로 구성되어짐
  4. Miscellaneous :  개발환경 혹은 특정 ARCH에 의존적으로 구성이됨 
  5. Software : 쉽게 추가가능한 Opensource (이 Layer를 추가)

Base는 현재 meta-oeopenembedded-core 두 종류로 제공하고 있지만, meta-oe만 주로 사용한다

  1. meta-oe : Embedded에서 필요한 개발 Tool 및 Kernel
  2. openembedded-core:  많은 부분이 poky와 중복되는 것 같음 


OpenEmbedded Layer Index
  https://layers.openembedded.org/layerindex/branch/master/layers/

Yocto Site
  http://git.yoctoproject.org/cgit.cgi/

3. Yocto의 설정확인 및 변경 

bitbake를 사용하기 위해서 아래와 같이 기본빌드환경을 설정해줘야 한다

pocky 안에 oe-init-build-env를 실행하면, bitbake 사용 및 rpi-build directory가 생성이 된다.
물론 그냥 poky안에서 oe-init-build는 상관은 없지만, 모든 빌드내용이 rpi-build에 저장되기때문에 이를 외부를 분리하는 것이다.

$ source poky/oe-init-build-env rpi-build

build directory(rpi-build) 의 이름을 변경을 해도 상관없음

  • Raspberry PI  Yocto 전체구성
물론 rpi-build를 poky 안에도 생성이 가능하지만 이를 외부를 분리하여 Yocto와 Build 부분을 분리한다.

$ tree -d -L 2
├── poky
│   ├── bitbake
│   ├── documentation
│   ├── meta
│   ├── meta-openembedded  // 추가될 layers로 하위 디렉토리에 layer가 존재 
│   ├── meta-poky
│   ├── meta-raspberrypi  // 추가될 layer
│   ├── meta-selftest
│   ├── meta-skeleton
│   ├── meta-yocto-bsp
│   └── scripts
└── rpi-build   // 이곳에서 빌드를 진행하므로, 추후 제거 할때도 이부분만 제거 (2.1 이후 생성)
    ├── cache 
    ├── conf             // 빌드할 Layers 및 MACHINE  설정 
    ├── downloads        // GIT Download   
    ├── sstate-cache
    └── tmp              // tmp/deploy/image/machine/xxxxx  배포 

  • rpi-build 의 user configuration 설정 
  1. ./conf/bblayers.conf     // build할 Layer 추가 
  2. ./conf/local.conf         // build될 machine 설정 


3.1 rpi-build/conf/bblayers.conf  

본인이 bitbake를 이용하여 빌드하고자하는 각 Layer들을 적용을 하자

  • rpi-build/conf/bblayers.conf 에 Layer 추가  
meta-openembedded의 경우 다수의 meta-layer로 구성이 되어있으므로 아래와 같이 추가.

$ cd rpi-build 
$ vi ./conf/bblayers.conf
.......
BBLAYERS ?= " \
  /home/jhlee/raspberrypi/poky/meta \
  /home/jhlee/raspberrypi/poky/meta-poky \
  /home/jhlee/raspberrypi/poky/meta-yocto-bsp \
  /home/jhlee/raspberrypi/poky/meta-openembedded/meta-oe \
  /home/jhlee/raspberrypi/poky/meta-openembedded/meta-multimedia \
  /home/jhlee/raspberrypi/poky/meta-openembedded/meta-networking \
  /home/jhlee/raspberrypi/poky/meta-openembedded/meta-python \
  /home/jhlee/raspberrypi/poky/meta-raspberrypi \
  "


3.2  rpi-build/conf/local.conf 

MACHINE의 설정전체 변수관련부분 설정 MACHINE이 아니더라도 본인이 원하는 부분을 설정을 하면 전체 적용되므로 중요

  • rpi-build/conf/local.conf 에 Machine 설정
이제 본인의 board machine을 찾았으니, 이를 적용하자 (상위 conf 제외한 이름)

$ cd rpi-build 
$ vi ./conf/local.conf 
#
# Machine Selection
#
# You need to select a specific machine to target the build with. There are a selection
# of emulated machines available which can boot and run in the QEMU emulator:
#
#MACHINE ?= "qemuarm"
#MACHINE ?= "qemuarm64"
#MACHINE ?= "qemumips"
#MACHINE ?= "qemumips64"
#MACHINE ?= "qemuppc"
#MACHINE ?= "qemux86"
#MACHINE ?= "qemux86-64"
#
# There are also the following hardware board target machines included for 
# demonstration purposes:
#
#MACHINE ?= "beaglebone-yocto"
#MACHINE ?= "genericx86"
#MACHINE ?= "genericx86-64"
#MACHINE ?= "mpc8315e-rdb"
#MACHINE ?= "edgerouter"
#
MACHINE ?= "raspberrypi3-64"
# This sets the default machine to be qemux86 if no other machine is selected:
#MACHINE ??= "qemux86" 


3.3 MACHINE의 Config 확인 

conf/local.conf 에서 설정한 MACHINE 은 항상 동일한 이름으로 conf가 존재하며 이를 찾아 관련설정을  확실히 확인하자 

  • MACHINE raspberrypi3-64.conf  확인 
$ cd pocky 
$ find . -name machine | xargs ls        // MACHINE의 이름을 모를 경우 모든 BSP Layer 검색 
./meta/conf/machine:
include         qemuarm.conf    qemuarm64.conf   qemumips.conf     qemumips64.conf  
qemuppc.conf    qemux86-64.conf qemux86.conf

./meta-raspberrypi/conf/machine:
include/                raspberrypi-cm3.conf    raspberrypi0-wifi.conf  raspberrypi2.conf       raspberrypi3.conf       
raspberrypi-cm.conf     raspberrypi.conf        raspberrypi0.conf       raspberrypi3-64.conf  

./meta-selftest/conf/machine:
qemux86copy.conf

./meta-yocto-bsp/conf/machine:
beaglebone-yocto.conf  edgerouter.conf  genericx86-64.conf  genericx86.conf  include  mpc8315e-rdb.conf

or 
$ find . -name raspberrypi3-64.conf  // MACHINE 이름을 정확히 아는 경우 

주로 확인해야 할 것이 UBOOT 설정 과 KERNEL 및 Device Tree 가 될 것 같다

  • 지원 MACHINE 이름 
  https://layers.openembedded.org/layerindex/branch/master/machines/


4. Bitbake로 기본 빌드 

bitbake는 상위 pocky->bitbake안에 존재하므로 이것이 PATH에 적용이 되지 않을 경우는 아래와 같이 동작하지 않는다.
다시 설정하고 싶다면 2.를 다시 설정하면 되며, 상위 저장된 설정도 기억하고 있다.

  • Bitbake로 빌드진행  
$ bitbake core-image-base 

빌드를 할 경우, 상당한 시간과 용량을 필요로 하며, 용량은 VDI의 경우 최소 50G로 잡자.
처음 30G (Ubuntu까지 설치된 상태)로 빌드를 진행을  했는데, 용량부족으로 실패했다.


4.1 core-image-minimal 와 core-image-base 차이 

yocto에서 image를 생성하기 위해서 상위 target 설정이외 sato or x11 등 다양하게 확장제공하고 있지만, 일단 2개의 정확한 차이를 알아두고 어떻게 확장하는지 알아보자.

  • bitbake에서 image를 만들때 가장 많이 사용하는 Target or Recipe 
  1. core-image-minimal: 기본으로 boot하고 기본동작되는 확인
  2. core-image-base: core-image-minimal 에 MACHINE의 HW의 모든기능을 제공 및 테스트 가능 

  • core-image-base 와 core-image-minimal 각 위치확인 
$ pwd
/home/jhlee/raspberrypi/poky

$ find . -name core-image-minimal*
./meta/recipes-core/images/core-image-minimal-mtdutils.bb
./meta/recipes-core/images/core-image-minimal-initramfs.bb
./meta/recipes-core/images/core-image-minimal.bb
./meta/recipes-core/images/core-image-minimal-dev.bb

$ find . -name core-image-base*
./meta/recipes-core/images/core-image-base.bb

  • core-image-minimal 의 구성확인  
  1. IMAGE_INSTALL : packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL} 직접정의 
  2. inherit core-image : core-image*.bbclass를 사용 

$ cat ./meta/recipes-core/images/core-image-minimal.bb // 아래의 core-image.bbclass 부분과 비교 
SUMMARY = "A small image just capable of allowing a device to boot."

IMAGE_INSTALL = "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL}"

IMAGE_LINGUAS = " "

LICENSE = "MIT"

inherit core-image

IMAGE_ROOTFS_SIZE ?= "8192"
IMAGE_ROOTFS_EXTRA_SPACE_append = "${@bb.utils.contains("DISTRO_FEATURES", "systemd", " + 4096", "" ,d)}" 


  • core-image-base 의 구성  (core-image.bbclass의 IMAGE_INSTALL 사용)
  1. IMAGE_INSTALL:  설정정의가 없으므로, core-image*.bbclass에 정의된 것으로 동작 
  2. inherit core-image : core-image*.bbclass를 사용 

$ cat ./meta/recipes-core/images/core-image-base.bb
SUMMARY = "A console-only image that fully supports the target device \
hardware."

IMAGE_FEATURES += "splash"

LICENSE = "MIT"

inherit core-image 


  • core-image.bbclass  ( inherit core-image 검색)
core-image-minimal 과 core-image-base 의 차이는 IMAGE_INSTALL 차이 
core-image-base의 경우 packagegroup-base-extended 부분이 추가됨


$ find . -name core-image*bb* 
..
./meta/classes/core-image.bbclass
..
$ cat ./meta/classes/core-image.bbclass //  inherit core-image 관련부분 확인 

CORE_IMAGE_BASE_INSTALL = '\
    packagegroup-core-boot \
    packagegroup-base-extended \
    \
    ${CORE_IMAGE_EXTRA_INSTALL} \
    '

IMAGE_INSTALL ?= "${CORE_IMAGE_BASE_INSTALL}"  

inherit image 


  • image.bbclass (inherit image)
image를 만드는 시작점인 것 같으며, 소스를 보면 전체 동작방식을 대충 이해가 가며 python으로도 구성이되어 소스내용이 길다.

$ find . -name image*bb*  // inherit image 관련부분 검색  
..
./meta/classes/image.bbclass

$ cat ./meta/classes/image.bbclass  
IMAGE_CLASSES ??= ""

# rootfs bootstrap install
# warning -  image-container resets this
ROOTFS_BOOTSTRAP_INSTALL = "run-postinsts"

# Handle inherits of any of the image classes we need
IMGCLASSES = "rootfs_${IMAGE_PKGTYPE} image_types ${IMAGE_CLASSES}"
# Only Linux SDKs support populate_sdk_ext, fall back to populate_sdk_base
# in the non-Linux SDK_OS case, such as mingw32
IMGCLASSES += "${@['populate_sdk_base', 'populate_sdk_ext']['linux' in d.getVar("SDK_OS")]}"
IMGCLASSES += "${@bb.utils.contains_any('IMAGE_FSTYPES', 'live iso hddimg', 'image-live', '', d)}"
IMGCLASSES += "${@bb.utils.contains('IMAGE_FSTYPES', 'container', 'image-container', '', d)}"
IMGCLASSES += "image_types_wic"
IMGCLASSES += "rootfs-postcommands"
IMGCLASSES += "image-postinst-intercepts"
inherit ${IMGCLASSES}
..... 너무길어 중략 (do_rootfs 비롯하여 다른 중요부분도 한번봐야함)


공통적으로 inherit core-image로 공유해서 사용되어지고 있으며, 이 부분은 bbclass 로 되어있고, 이 공유하며,
중요한 부분은 IMAGE_INSTALL 의 정의차이를 보면 될 것 같다.

아래링크참조
  https://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#ref-classes-core-image
  https://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#ref-classes-image
  https://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html


4.2 core-image-xxx 확장 및 본인의 Image target 확장 

recipe 내에서 include recipe-core/images/core-image-base.bb 추가하여 확장하는 구조이다.

  • raspberry pi target recipe 확장분석  
core-image-minimal 기반으로 본인이 필요한 Package들을 IMAGE_INSTALL 추가하는 방식
rpi-basic-image는 앞으로 안 사용되어질 거라고 하는데, core-image-base 로 하면 될 것 같다.

$ vi meta-raspberrypi/recipes-core/images/rpi-basic-image.bb  
# Base this image on core-image-minimal
include recipes-core/images/core-image-minimal.bb

# Include modules in rootfs
IMAGE_INSTALL += " \
        kernel-modules \
        "

SPLASH = "psplash-raspberrypi"

IMAGE_FEATURES += "ssh-server-dropbear splash"

do_image_prepend() {
    bb.warn("The image 'rpi-basic-image' is deprecated, please use 'core-image-base' instead")
}


  • 나만의 target image recipe 로 확장 
IMAGE_INSTALL에 본인이 필요한 Package들을 정의하여 넣고, 새로운 Target Image recipe로 정의

$ vi meta-raspberrypi/recipes-core/images/core-image-jhlee.bb  
SUMMARY = "JHLee Sample Test Image"

# Base this image on core-image-minimal
include recipes-core/images/core-image-base.bb

# ssh server and systemd and tcpdump
IMAGE_INSTALL += "openssh systemd-analyze tcpdump"
        
export IMAGE_BASENAME = "core-image-jhlee"



recipe 검색
  https://layers.openembedded.org/layerindex/branch/master/recipes/


4.3 SD Image 확인 및 Writing Image

  • How to find SD image
bitbake로 core-image-base 빌드 한 후 deploy에서 확인 (SD Image)

$ cd rpi-build/tmp/deploy/images/raspberrypi3-64
$ ls *.rpi*
core-image-base-raspberrypi3-64-20180526144104.rootfs.rpi-sdimg  core-image-base-raspberrypi3-64.rpi-sdimg 


  • How To write SD Image 
Linux에서 SD Disk를 접근가능하다면 Image Writing을 할수 있다. ( Virtual Box도 연결해서 하면되지만 절차가 복잡)

$ sudo dd if=core-image-base-raspberrypi3-64.rpi-sdimg of=/dev/sde bs=1M   // 이부분 SD Disk와 연결되었을 경우

상위명령어 대신 이 Image 파일을 Window로 가져와서 Win32DiskImager를 이용하자

  • Win32DiskImager
  https://ahyuo.blogspot.com/2016/05/sd-card-writer-window.html


4.4 Bitbake Build 분석 및 에러사항

  • Bitbake 빌드 분석 
WARNING: Host distribution "ubuntu-14.04" has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.
Build Configuration:
BB_VERSION           = "1.37.0"
BUILD_SYS            = "x86_64-linux"        // HOST의 Build System 
NATIVELSBSTRING      = "universal-4.8"       // Ubuntu 일 경우 ubuntu로 표시  
TARGET_SYS           = "aarch64-poky-linux"  // Target system 이름 ARM을 사용할 경우 ARM이 표시됨 
MACHINE              = "raspberrypi3-64"     // Board의 Machine 이름   
DISTRO               = "poky"
DISTRO_VERSION       = "2.5"
TUNE_FEATURES        = "aarch64"              // Compiler 관련 설정  
TARGET_FPU           = ""                     // Hardware FPU 설정 
meta                 
meta-poky            
meta-yocto-bsp       = "master:13cc30cd7de4841990b600e83e1249c81a5171dd"
meta-oe              
meta-multimedia      
meta-networking      
meta-python          = "master:d59b9806f743cea0168cddf942a31dcf446839e6"
meta-raspberrypi     = "master:7f7bc9e778b6def018c451ecb23f5169cd18f5ed"


  • 문제사항 1
  https://github.com/WebPlatformForEmbedded/meta-wpe/issues/151

$ bitbake core-image-base 
ERROR: Unable to start bitbake server
ERROR: Last 10 lines of server log for this session (/home/jhlee/raspberrypi/rpi-build/bitbake-cookerdaemon.log):
    self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset)
  File "/home/jhlee/raspberrypi/poky/bitbake/lib/bb/cooker.py", line 197, in __init__
    self.initConfigurationData()
  File "/home/jhlee/raspberrypi/poky/bitbake/lib/bb/cooker.py", line 356, in initConfigurationData
    self.databuilder.parseBaseConfiguration()
  File "/home/jhlee/raspberrypi/poky/bitbake/lib/bb/cookerdata.py", line 317, in parseBaseConfiguration
    raise bb.BBHandledException
bb.BBHandledException
ERROR: The following required tools (as specified by HOSTTOOLS) appear to be unavailable in PATH, please install them in order to proceed:
  chrpath gawk makeinfo

아래 Package 설치 후 문제해결 (상위에 모두 표시)

$ sudo apt install gawk
$ sudo apt-get install chrpath
$ sudo apt-get install texinfo

  • 문제사항 2
WARNING: Host distribution "ubuntu-14.04" has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.
.......
ERROR: mpfr-native-3.1.5-r0 do_compile: oe_runmake failed
ERROR: mpfr-native-3.1.5-r0 do_compile: Function failed: do_compile (log file is located at /home/jhlee/raspberrypi/rpi-build/tmp/work/x86_64-linux/mpfr-native/3.1.5-r0/temp/log.do_compile.13203)
ERROR: Logfile of failure stored in: /home/jhlee/raspberrypi/rpi-build/tmp/work/x86_64-linux/mpfr-native/3.1.5-r0/temp/log.do_compile.13203
....
| x86_64-linux-libtool:   error: 'set_si_2exp.lo' is not a valid libtool object
| make[2]: *** [libmpfr.la] Error 1
| make[2]: Leaving directory `/home/jhlee/raspberrypi/rpi-build/tmp/work/x86_64-linux/mpfr-native/3.1.5-r0/build/src'
| make[1]: *** [all] Error 2
| make[1]: Leaving directory `/home/jhlee/raspberrypi/rpi-build/tmp/work/x86_64-linux/mpfr-native/3.1.5-r0/build/src'
| make: *** [all-recursive] Error 1
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.
| ERROR: Function failed: do_compile (log file is located at /home/jhlee/raspberrypi/rpi-build/tmp/work/x86_64-linux/mpfr-native/3.1.5-r0/temp/log.do_compile.13203)
ERROR: Task (virtual:native:/home/jhlee/raspberrypi/poky/meta/recipes-support/mpfr/mpfr_3.1.5.bb:do_compile) failed with exit code '1'


Ubuntu 16으로 변경 후 문제 해결 (처음 Ubuntu 14.04로 진행함)
  https://stackoverflow.com/questions/36226828/yocto-bitbake-script-not-displaying-echo-statement

2/20/2018

Ubuntu 설치된 중복 Package 관리방법

1. Ubuntu에서 Package 관리 방법 

Ubuntu의 기본 Package 관리방법
  https://ahyuo.blogspot.com/2015/07/ubuntu.html

APT가 기존의 것보다 상당히 많은 것 같아서 아래와 같이 나열해본다.

  • APT Command 관련 명령어 
  1. apt-get
  2. apt-cache
  3. apt (apt-get/apt-cache 혼합)
  4. apt-add-repository (add-apt-repository와 동일 )
  5. apt-key
  6. apt-ftparchive
  7. apt-extracttemplates
  8. apt-key
  9. apt-mark 
  10. apt-sortpkgs 

 상당히 많은 것 같은데, 현재 다 알필요가 없는 것 같아서 주요한 것만 다시 정리

  • update-alternative  명령 
  1. 내가 Download한 binary를 Package로 등록/삭제  
  2. 설치되었으며, 중복된 Package 중 내가 원하는 Version 선택가능  

  • 관련 Manual 
  https://linux.die.net/man/8/update-alternatives
  https://wiki.debian.org/HowToPackageForDebian

1.1 apt / update-alternatives 사용법 

apt를 보면 apt-get/apt-cache 기능을 간략하게 사용하는 것 같다.

$ apt
Usage: apt [options] command

CLI for apt.
Basic commands: 
 list - list packages based on package names
 search - search in package descriptions
 show - show package details

 update - update list of available packages

 install - install packages
 remove  - remove packages

 upgrade - upgrade the system by installing/upgrading packages
 full-upgrade - upgrade the system by removing/installing/upgrading packages

 edit-sources - edit the source information file


동일한 2개 Package를 설치했을 경우 선택가능 및 내가 원한것을 link로 연결하여 package에 연결한다.

$ sudo update-alternatives
update-alternatives: 아래의 옵션 중에 하나를 선택해서 사용한다. 
   --install link name path priority [--slave link name path]...
   --set name path
   --remove name path
   --remove-all name
   --all
   --auto name
   --display name
   --get-selections
   --set-selections
   --query name
   --list name
   --config name


  • 실행파일 link 존재 
/etc/alternatives/

  • 설정관리 File 존재 
/var/lib/dpkg/alternatives,


2. 중복된 Package Version 변경 ( update-alternatives)

일반적으로 package 가 설치가 되면, /usr/bin/실행파일 link 파일생성이 되고 관련 Package와 연결이 되어있다.
그래서 중복된 Package이지만 Version 이 다른 것을 여러개 설치가 가능하다.


  • OpenJDK 두 개의 Version 설치 

$ sudo apt-get install openjdk-7-jdk openjdk-6-jdk 


  • OpenJDK 중 java 의 version 변경 
$ ls /var/lib/dpkg/alternatives/ | grep java // 사용여부 확인 (등록된 Link 확인)
java
javac
javadoc
javah
javap
javaws

$ sudo update-alternatives --config java  // Version 설정변경 
대체 항목 java에 대해 (/usr/bin/java 제공) 2개 선택이 있습니다.

  선택       경로                                          우선순ꡬ태
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      자동 모드
* 1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      수동 모드
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      수동 모드


  • OpenJDK의 java 설치위치 확인 
$ sudo update-alternatives --list java
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java


  • OpenJDK의 java의 구조 파악 

$ sudo update-alternatives --query java
Name: java
Link: /usr/bin/java
Slaves:
 java.1.gz /usr/share/man/man1/java.1.gz
Status: manual    // Manual/Auto Mode   
Best: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java  // 추천해주는 Package (Auto mode)
Value: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java // 현재 사용중인 Package

Alternative: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java  // 실제 설치된 대체 Package 주소  
Priority: 1061  // 우선순위이며 Auto Mode일 경우 높은 것을 자동설정 
Slaves:
 java.1.gz /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz

Alternative: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java  // 실제 설치된 대체 Package 주소 
Priority: 1071
Slaves:
 java.1.gz /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz

설정된 모드를 더 쉽게 보여준다.

$ sudo update-alternatives --display java
java - 수동 모드
 링크가 현재 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 가리킴
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java - 우선순위 1061
  슬레이브 java.1.gz: /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - 우선순위 1071
  슬레이브 java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
현재 가장 '좋은' 버전은 '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'입니다.


  • java 실제 구조파악 
$ ll /usr/bin/java
lrwxrwxrwx 1 root root 22  2월 24  2017 /usr/bin/java -> /etc/alternatives/java*

$ ll /etc/alternatives/java // 실행파일 link 존재 
lrwxrwxrwx 1 root root 46 10월 16 12:49 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java*

$ vi /var/lib/dpkg/alternatives/java   // 관련 설정정보 (수동모드)  
manual
/usr/bin/java
java.1.gz
/usr/share/man/man1/java.1.gz

/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
1061
/usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
1071
/usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz


  • 로그를 통한 설정확인 
$ ls /var/lib/dpkg/alternatives/     // 현재 update-alternatives를 설정된 file 전체검색 
animate                       fonts-japanese-gothic.ttf     jconsole                      newt-palette                  tdbbackup
appletviewer                  from                          jdb                           orbd                          telnet
automake                      ftp                           jexec                         pack200                       text.plymouth
awk                           gconftool                     jhat                          pager                         tnameserv
builtins.7.gz                 gem                           jinfo                         php                           traceroute6
......

$ cat /var/log/alternatives.log | tail -n 50  // 본인이 최근에 update-alternatives 사용한 흔적 ,더이전 log는  *.log.1 기록 



3. Download 한 실행파일 연결/제거 (update-alternatives)

Open JDK Download
  https://jdk.java.net/
  https://jdk.java.net/archive/

OpenJDK를 Download 하여 Link를 설정해보고 Link를 제거해보자.

  • 기본사용법 
update-alternatives --install link name path priority [--slave link name path]...
slave는 master 설정에 따라 동작한다고 한다.

  • Link 생성 및 설정변경 (Link만 생성)

$ sudo update-alternatives --install /usr/bin/java java /home/jhlee/jdk-9/bin/java 1091

$ sudo update-alternatives --config java  // 설정을 변경
대체 항목 java에 대해 (/usr/bin/java 제공) 3개 선택이 있습니다.

  선택       경로                                          우선순ꡬ태
------------------------------------------------------------
  0            /home/jhlee/jdk-9/bin/java                       1091      자동 모드
  1            /home/jhlee/jdk-9/bin/java                       1091      수동 모드
* 2            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      수동 모드
  3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      수동 모드


  • Link 제거 (Link만 제거)

$ sudo update-alternatives --remove java /home/jhlee/jdk-9/bin/java 
update-alternatives: 수동으로 선택한 대체 항목을 지우는 중 - java을(를) 자동 모드로 변경합니다
update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in 자동 모드


  https://blog.thinkbee.kr/linux/linux-update-alternatives/
  https://askubuntu.com/questions/26498/how-to-choose-the-default-gcc-and-g-version
  https://blog.thinkbee.kr/linux/linux-update-alternatives/