BitBake 是一種類似 make 的程式編譯工具,主要用於 OpenEmbedded 和 Yocto 專案建構 Linux 發行版本。


BitBake

基本上,BitBake 是一個 Python 程序,由使用者建立的配置設定啟動,可以為使用者指定的目標專案執行建構的任務,即所謂的配方(recipes)。

Config、tasks 與 recipes

通過 BitBake 執行特定目的的設定檔 Config、tasks 與 recipes,這些設定檔包含變量與可執行的 shell、python 代碼。

所以理論上,BitBake 可以執行代碼,你也可以使用 BitBake 執行建構專案程式之外的事情,但是並不推薦這麼做。

BitBake 是一種建構專案程式的工具,因此有一些特殊的功能,比如可以定義依賴關係。

BitBake 可以解決依賴關係,並將其任務以正確順序運行。

此外,建構專案程式包通常包含相同或相似的任務。

比如常見的任務:
下載原始代碼,解壓原始代碼,執行 configure,執行 make,或簡單的輸出 log。

Bitbake 提供一種機制,可通過一種可配置的方式,抽象、封裝和重用這個功能。

下載
$git clone git://git.openembedded.org/bitbake

安裝
$export PATH=/home/<your directory>/bitbake/bin:$PATH
$export PYTHONPATH=/home/<your directory>/bitbake/lib:$PYTHONPATH

當我們啟動 bitbake 時,它會試著去找 medtata files。
而 BBPATH 就是指示那些檔案放那的變數。
如果沒有設定它,bitbake 會不知道去那找 .conf 和 .bb。


build/
     ├── mytarget
     │   ├── bitbake.lock
     │   └── conf
     │       └── bblayers.conf
     └── mylayer
         ├── classes
         │   └── base.bbclass
         └── conf
             ├── bitbake.conf
             └── layer.conf


(=> bblayer path)
(=> mylayer 的檔名不限定為 mylayer)
build/mylayer/conf/layer.conf
build/mylayer/conf/bitbake.conf
(=> bbclass)
build/mylayer/class/base.bbclass

layer.conf
--------------------
BBPATH .= ":${LAYERDIR}"                      (=> BBPATH  是用來搜尋 conf 和 class 的設定文件)
BBFILES += "${LAYERDIR}/*.bb"                 (=> BBFILES 是用來搜尋 bb 和 bbappend 設定文件)
--------------------

base.bbclass 和 bitbake.conf 可以從 bitbake 安裝目錄中取得或是參考改寫。

bitbake.conf
--------------------
TMPDIR  = "${TOPDIR}/tmp"                     (=> 在 build 資料夾下)(TOPDIR => build directory)
CACHE   = "${TMPDIR}/cache"                   (=> 在 TMPDIR 下,儲存 Meatadata 的 cache,讓 Bitbake 不用每次重新 parse)
STAMP   = "${TMPDIR}/stamps"                  (=> 用來建立 recipe stamp files)
T       = "${TMPDIR}/work"                    (=> 用來放暫存檔的地方,大多是 task logs and scripts。)
B       = "${TMPDIR}"                         (=> 建置 recipes 時,執行 functions 的地方)
--------------------


(=> target path)
(=> local.conf 的檔名不限定為 local)
build/mytarget/conf/bblayers.conf

bblayers.conf
--------------------
(=> BBPATH  是用來搜尋 conf 和 class 的設定文件)
BBPATH := "${TOPDIR}"

(=> BBFILES 是用來搜尋 bb 和 bbappend 設定文件)
BBFILES ?= ""

(=> BBLAYERS 是一個layer目錄的list,會引用list指向的layer層的conf設定)
(list 裡面的每個變量值指向一個layer目錄。這個目錄下面又有conf/layer.conf。layer.conf裡面又有BBPATH以及當前層的一些配置。)
BBLAYERS ?= "/home/<your directory>/mylayer"

(=> 程式編譯的目標,目標可以多個)
BBFILE_COLLECTIONS += "mytarget mytarget1 mytarget2"
(=> 程式編譯的目錄位置)
BBFILE_PATTERN_mytarget := "^${LAYERDIR}/"

MACHINE = " "
DISTRO  = " "
--------------------

顯示 bitbake 輔助文件。
bitbake --help

顯示 recipes 和 tasks 列表。
$bitbake -s

運行所有 recipes 的所有 tasks。
bitbake world

編譯目標映像。(-k 盡可能往前編譯,即使遇到錯誤)
bitbade -k <image-name>
(e.g.)
bitbake som6x80-image-qt5

列出跟目標映像有相依性的 package。
bitbake <image-name> -g -u depexp
(e.g.)
$bitbake fsl-image-gui -g -u depexp

取得目標映像的原始碼。
bitbake <image-name> -c fetchall

執行編譯目標 package 中的某個 task 任務。
bitbake <package> -c <task>
(e.g.)
$bitbake linux-imx
$bitbake linux-imx -f -c compile

構建一個 recipe,執行該 recipe 的所有 tasks。
bitbade <package>

顯示特定 package 提供的 task。
bitbake <package> -c listtasks

開啟包含編譯目標 package 所需系統環境的新 shell。
bitbake <package> -c devshell

列出所有 layer
bitbake-layers show-layers

列出所有 recipes
bitbake-layers show-recipes

列出跟 image 有關的所有 recipes
bitbake-layers show-recipes "*-image-*"

開啟編譯核心的設定
bitbake virtual/kernel -c menuconfig
 

arrow
arrow
    全站熱搜

    BB 發表在 痞客邦 留言(0) 人氣()