顯示具有 OpenEmbedded - Yocto Project Reference Manual 標籤的文章。 顯示所有文章
顯示具有 OpenEmbedded - Yocto Project Reference Manual 標籤的文章。 顯示所有文章

2020年6月27日 星期六

Note for Yocto Project Development Tasks Manual v3.1 - CH3.2. Customizing Images


Yocto 可以讓User自訂image以滿足特定需求, 這個章節就是在介紹如何自訂image.
最簡單的image.bb就是全部空白
images/machine-image-brook.bb
inherit image
IMAGE_FEATURES = ""
LICENSE = "MIT"
IMAGE_LINGUAS = ""
build結果
brook@vista:~/apps_proc/poky/build/tmp-glibc/work/oe-linux-gnueabi/machine-image-brook$ find 1.0-r0/rootfs/
1.0-r0/rootfs/
1.0-r0/rootfs/var
1.0-r0/rootfs/var/cache
1.0-r0/rootfs/var/cache/opkg
1.0-r0/rootfs/var/lib
1.0-r0/rootfs/var/lib/opkg
1.0-r0/rootfs/lib
1.0-r0/rootfs/lib/systemd
1.0-r0/rootfs/lib/systemd/system
1.0-r0/rootfs/lib/systemd/system/run-postinsts.service
1.0-r0/rootfs/etc
1.0-r0/rootfs/etc/timestamp
1.0-r0/rootfs/etc/version
1.0-r0/rootfs/etc/systemd
1.0-r0/rootfs/etc/systemd/system
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants/run-postinsts.service
1.0-r0/rootfs/run
1.0-r0/rootfs/usr
1.0-r0/rootfs/usr/sbin
1.0-r0/rootfs/usr/sbin/run-postinsts


3.2.1. Customizing Images Using local.conf

最簡單的客製化image就是在local.conf中加入一個package, 雖然彈性有限, 但相對簡單. 比如在local.conf加入一行
     IMAGE_INSTALL_append = " strace"
記住, strace前面有一個空白, 爾且是必須的. 此外, 善用+=運算符號可以增加可讀性.

images/machine-image-brook.bb
inherit image
IMAGE_FEATURES = ""
LICENSE = "MIT"
IMAGE_LINGUAS = ""

build結果
brook@vista:~/apps_proc/poky/build/tmp-glibc/work/oe-linux-gnueabi/machine-image-brook$ find 1.0-r0/rootfs/
1.0-r0/rootfs/
1.0-r0/rootfs/var
1.0-r0/rootfs/var/cache
1.0-r0/rootfs/var/cache/opkg
1.0-r0/rootfs/var/lib
1.0-r0/rootfs/var/lib/opkg
1.0-r0/rootfs/lib
1.0-r0/rootfs/lib/libnss_compat.so.2
1.0-r0/rootfs/lib/libresolv.so.2
1.0-r0/rootfs/lib/libresolv-2.28.so
1.0-r0/rootfs/lib/libnss_files.so.2
1.0-r0/rootfs/lib/libm.so.6
1.0-r0/rootfs/lib/libBrokenLocale-2.28.so
1.0-r0/rootfs/lib/libc-2.28.so
1.0-r0/rootfs/lib/libanl.so.1
1.0-r0/rootfs/lib/libutil.so.1
1.0-r0/rootfs/lib/libc.so.6
1.0-r0/rootfs/lib/libutil-2.28.so
1.0-r0/rootfs/lib/libnss_dns-2.28.so
1.0-r0/rootfs/lib/libnsl.so.1
1.0-r0/rootfs/lib/libdl-2.28.so
1.0-r0/rootfs/lib/libnss_compat-2.28.so
1.0-r0/rootfs/lib/ld-linux-armhf.so.3
1.0-r0/rootfs/lib/libnsl-2.28.so
1.0-r0/rootfs/lib/libpthread-2.28.so
1.0-r0/rootfs/lib/libnss_files-2.28.so
1.0-r0/rootfs/lib/libm-2.28.so
1.0-r0/rootfs/lib/libnss_dns.so.2
1.0-r0/rootfs/lib/librt-2.28.so
1.0-r0/rootfs/lib/libpthread.so.0
1.0-r0/rootfs/lib/libBrokenLocale.so.1
1.0-r0/rootfs/lib/libdl.so.2
1.0-r0/rootfs/lib/systemd
1.0-r0/rootfs/lib/systemd/system
1.0-r0/rootfs/lib/systemd/system/run-postinsts.service
1.0-r0/rootfs/lib/libanl-2.28.so
1.0-r0/rootfs/lib/ld-2.28.so
1.0-r0/rootfs/lib/librt.so.1
1.0-r0/rootfs/sbin
1.0-r0/rootfs/sbin/ldconfig
1.0-r0/rootfs/etc
1.0-r0/rootfs/etc/timestamp
1.0-r0/rootfs/etc/version
1.0-r0/rootfs/etc/ld.so.conf
1.0-r0/rootfs/etc/systemd
1.0-r0/rootfs/etc/systemd/system
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants
1.0-r0/rootfs/etc/systemd/system/sysinit.target.wants/run-postinsts.service
1.0-r0/rootfs/run
1.0-r0/rootfs/usr
1.0-r0/rootfs/usr/sbin
1.0-r0/rootfs/usr/sbin/run-postinsts
1.0-r0/rootfs/usr/bin
1.0-r0/rootfs/usr/bin/strace
1.0-r0/rootfs/usr/bin/strace-log-merge


3.2.2. Customizing Images Using Custom IMAGE_FEATURES and EXTRA_IMAGE_FEATURES

另一個方式是設定IMAGE_FEATURES與EXTRA_IMAGE_FEATURES, 這兩個功能相似, IMAGE_FEATURES是在recipe使用, 而EXTRA_IMAGE_FEATURES是在local.conf 使用. 可以參考meta/classes/core-image.bbclass了解更多細節
簡單來說, IMAGE_FEATURES 會被轉成是當的packages或configurations後加入IMAGE_INSTALL變數中. 而EXTRA_IMAGE_FEATURES變數會在bitbake.conf中, 將其加入IMAGE_FEATURES內.
EXTRA_IMAGE_FEATURES ??= ""
IMAGE_FEATURES += "${EXTRA_IMAGE_FEATURES}"


3.2.3. Customizing Images Using Custom .bb Files

你也可以透過recipe (.bb)自訂image內容, images/machine-image-brook.bb
inherit image
IMAGE_INSTALL = "strace"
IMAGE_FEATURES = ""
LICENSE = "MIT"
IMAGE_LINGUAS = ""
build結果與3.2.1.結果相同

3.2.4. Customizing Images Using Custom Package Groups

複雜一點的image,可以透過創建package group recipe來客製化image, 比如在meta/recipes-core/packagegroups/創建packagegroup-image-brook.bb, 內容如下
SUMMARY = "Brook's sckagegroup"
PR = "r0"

inherit packagegroup

PACKAGES = "\
    ${PN}-apps \
    ${PN}-tools \
    "

RDEPENDS_${PN}-apps = "\
    strace \
    "

RDEPENDS_${PN}-tools = "\
    busybox \
    "

RRECOMMENDS_${PN}-tools = "\
    openssl \
    "

加完之後, 可以使用bitbake確認是否可用
jenkins@vista:~/apps_proc/poky/build$ bitbake -s|grep brook
packagegroup-image-brook                              :1.0-r0

接著就可以在images/machine-image-brook.bb中使用這packagegroup
inherit image

IMAGE_INSTALL = "packagegroup-image-brook-tools"

IMAGE_FEATURES = ""

LICENSE = "MIT"

IMAGE_LINGUAS = ""
結果就是會安裝busybox, 當然你也可以安裝"packagegroup-image-brook-apps".

    參考資料:
  • https://www.yoctoproject.org/docs/3.1/dev-manual/dev-manual.html, The Yocto Project Development Tasks Manual



2020年5月3日 星期日

Yocto Project Reference Manual - extrausers.bbclass


extrausers.bbclass這個class允許我們在image中加入新的userand group,透過EXTRA_USERS_PARAMS 來設定,如:
新增兩個user,"tester-jim"與"tester-sue" ,其密碼都是tester01
     inherit extrausers
     EXTRA_USERS_PARAMS = "\
         useradd -P tester01 tester-jim; \
         useradd -P tester01 tester-sue; \
         "

也可以用於變更(設定)密碼
     inherit extrausers
     EXTRA_USERS_PARAMS = "\
         usermod -P 1876*18 root; \
         "

更複雜的例子如下
     inherit extrausers
     EXTRA_USERS_PARAMS = "\
         useradd -p '' tester; \
         groupadd developers; \
         userdel nobody; \
         groupdel -g video; \
         groupmod -g 1020 developers; \
         usermod -s /bin/sh tester; \
         "


    參考資料:
  • https://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#ref-classes-extrausers, extrausers.bbclass




2017年12月9日 星期六

Note for Yocto Project Reference Manual v2.4 - ch8.141 update-alternatives.bbclass


當有多個recipes提供相同的命令時, update-alternatives.bbclass可以幫你做替代("alternative"), 例如,可以從busybox,binutils和elfutils中使用ar命令。 update-alternatives.bbclass會幫你重新命名,以便安裝多個package而不會發生衝突。無論安裝或隨後刪除哪些package,ar命令仍然有效。
要使用update-alternatives.bbclass,你需要為這個package定義一些變量:
ALTERNATIVE_ = "name1 name2 name3 ..."
列出所有這個package的alternatives指令

設定name這個命令的link的路徑
ALTERNATIVE_LINK_NAME[name] = "target"

設定該package的預設priority,數值越大,priority越高
ALTERNATIVE_PRIORITY

針對特定命令另外設定priority,數值越大,priority越高
ALTERNATIVE_PRIORITY[name] = "20"


範例

brook這個package的檔案結構
brook@vista:~/oe-core/meta/recipes-devtools/brook$ tree
.
|-- brook-1.0.0
|   |-- brookbox
|   |-- copyright
|   `-- insmod
`-- brook_1.0.0.bb

1 directory, 4 files
brookbox類似busybox,後面會有多個檔案link到該檔案,而insmod是一個獨立檔案

brook_1.0.0.bb
SUMMARY = "Brook demo update-alternatives"
DESCRIPTION = "This package is used for Brook to demo update-alternatives"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://${WORKDIR}/copyright;md5=afcc69d729fbf1d0a2af28ce44a23991 \
"
SRC_URI = "file://insmod \
        file://copyright \
        file://brookbox \
"
inherit update-alternatives

ALTERNATIVE_${PN} = "insmod route reboot shutdown poweroff"
ALTERNATIVE_PRIORITY = "100"

ALTERNATIVE_LINK_NAME[insmod] = "${base_sbindir}/insmod"
ALTERNATIVE_PRIORITY[insmod] = "50"

ALTERNATIVE_LINK_NAME[route] = "${base_sbindir}/route"
ALTERNATIVE_PRIORITY[route] = "50"

ALTERNATIVE_LINK_NAME[reboot] = "${base_sbindir}/reboot"

ALTERNATIVE_LINK_NAME[shutdown] = "${base_sbindir}/shutdown"
ALTERNATIVE_PRIORITY[shutdown] = "10"

ALTERNATIVE_LINK_NAME[poweroff] = "${base_sbindir}/poweroff"
ALTERNATIVE_PRIORITY[poweroff] = "500"

do_install () {
        install -d                              ${D}${base_sbindir}
        install -m 0755    ${WORKDIR}/insmod    ${D}${base_sbindir}/insmod
        install -m 0755    ${WORKDIR}/brookbox  ${D}${base_sbindir}/brook
        ln -s ${base_sbindir}/brook ${D}${base_sbindir}/route
        ln -s ${base_sbindir}/brook ${D}${base_sbindir}/reboot
        ln -s ${base_sbindir}/brook ${D}${base_sbindir}/shutdown
        ln -s ${base_sbindir}/brook ${D}${base_sbindir}/poweroff
}
sysvinit也同時註冊了reboot,shutdown與poweroff,其priority都是200,而這裡的priority分別為100,10,500,所以最後結果如下

brook@vista:~/oe-core/build/tmp-glibc/work/oe-linux-gnueabi/image/1.0-r0/rootfs$ ls -al sbin/|grep brook
-rwxr-xr-x  1 jenkins jenkins      6 Dec  9 22:17 brook
lrwxrwxrwx  1 jenkins jenkins     18 Dec  9 22:17 insmod -> /sbin/insmod.brook
-rwxr-xr-x  1 jenkins jenkins      6 Dec  9 22:17 insmod.brook
lrwxrwxrwx  1 jenkins jenkins     20 Dec  9 22:17 poweroff -> /sbin/poweroff.brook
lrwxrwxrwx  1 jenkins jenkins     11 Dec  9 22:17 poweroff.brook -> /sbin/brook
lrwxrwxrwx  1 jenkins jenkins     11 Dec  9 22:17 reboot.brook -> /sbin/brook
lrwxrwxrwx  1 jenkins jenkins     17 Dec  9 22:17 route -> /sbin/route.brook
lrwxrwxrwx  1 jenkins jenkins     11 Dec  9 22:17 route.brook -> /sbin/brook
lrwxrwxrwx  1 jenkins jenkins     11 Dec  9 22:17 shutdown.brook -> /sbin/brook

reboot與shutdown都小於sysvinit,所以不適用brook,poweroff高於sysvinit,所以使用brook這個package提供的命令





熱門文章