code style

2017年6月22日 星期四

U-Boot make error=>dirname: missing operand

在compile Marvell的U-Boot時,出現dirname: missing operand。
一開始以為是makefile傳入的參數錯誤,但不是。
後來上網查,說是有兩個原因。

1:
在64bit OS下運行32 bit的compile,建議裝"ia32-libs",又有人說"ia32-libs"太舊,
要改裝"libc6:i386"。我確實是在64bit 的Ubuntu 16下運行,但都裝了也是不行。

2:
toolchain的位置錯誤。這個讓我try了好久,一般之前我都是設定toolchain位置的bin資料夾即可,但是U-Boot上要加上compiler的prefix才行。

原本
export CROSS_COMPILE=/<your toolchain path>/armv7-marvell-linux-gnueabi/bin
改成
export CROSS_COMPILE=/<your toolchain path>/armv7-marvell-linux-gnueabi/bin/arm-marvell-linux-gnueabi-

這樣make時會合併prefix字串變成arm-marvell-linux-gnueabi-gcc、arm-marvell-linux-gnueabi-ld等等。實際上的prefix要看你的bin底下的compile tool name為準。

Bitbake(2)Hello World Example

從Hello World來理解bitbake的處理過程:


1.安裝Bitbake並設定PATH
使用git下載 bitbake並安裝
$git clone git://git.openembedded.org/bitbake
設定PATH
$export PATH=/home/<your directory>/bitbake/bin:$PATH

2. 新建一個工作目錄,並試著run bitbake
$mkdir ~/hello
$cd hello
$bitbake
會出現下面的錯誤訊息
The BBPATH variable is not set and bitbake did not
     find a conf/bblayers.conf file in the expected location.
     Maybe you accidentally invoked bitbake from the wrong directory?
     DEBUG: Removed the following variables from the environment:
     GNOME_DESKTOP_SESSION_ID, XDG_CURRENT_DESKTOP,
     GNOME_KEYRING_CONTROL, DISPLAY, SSH_AGENT_PID, LANG, no_proxy,
     XDG_SESSION_PATH, XAUTHORITY, SESSION_MANAGER, SHLVL,
     MANDATORY_PATH, COMPIZ_CONFIG_PROFILE, WINDOWID, EDITOR,
     GPG_AGENT_INFO, SSH_AUTH_SOCK, GDMSESSION, GNOME_KEYRING_PID,
     XDG_SEAT_PATH, XDG_CONFIG_DIRS, LESSOPEN, DBUS_SESSION_BUS_ADDRESS,
     _, XDG_SESSION_COOKIE, DESKTOP_SESSION, LESSCLOSE, DEFAULTS_PATH,
     UBUNTU_MENUPROXY, OLDPWD, XDG_DATA_DIRS, COLORTERM, LS_COLORS


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

2.設定BBPATH,run bitbake

$BBPATH="/home/<your directory>/hello"
$export BBPATH
$bitbake

ERROR: Traceback (most recent call last):
       File "/home/scott-lenovo/bitbake/lib/bb/cookerdata.py", line 163, in wrapped
         return func(fn, *args)
       File "/home/scott-lenovo/bitbake/lib/bb/cookerdata.py", line 173, in parse_config_file
         return bb.parse.handle(fn, data, include)
       File "/home/scott-lenovo/bitbake/lib/bb/parse/__init__.py", line 99, in handle
         return h['handle'](fn, data, include)
       File "/home/scott-lenovo/bitbake/lib/bb/parse/parse_py/ConfHandler.py", line 120, in handle
         abs_fn = resolve_file(fn, data)
       File "/home/scott-lenovo/bitbake/lib/bb/parse/__init__.py", line 117, in resolve_file
         raise IOError("file %s not found in %s" % (fn, bbpath))
     IOError: file conf/bitbake.conf not found in /home/scott-lenovo/hello

     ERROR: Unable to parse conf/bitbake.conf: file conf/bitbake.conf not found in /home/scott-lenovo/hello


找不到conf/bitbake.conf,而這個檔案應該建在hello底下。

3.建立conf/bitbake.conf,run bitbake

先在hello底下建立conf資料夾
$ mkdir conf
再在conf下建立bitbake.conf,並輸入底下內容

TMPDIR  = "${TOPDIR}/tmp"
CACHE   = "${TMPDIR}/cache"
STAMP   = "${TMPDIR}/stamps"
T       = "${TMPDIR}/work"
B       = "${TMPDIR}"

TOPDIR => build directory,也就是hello資料夾
TMPDIR => 建立在build資料夾下
CACHE => 建立在TMPDIR(tmp)資料夾下,儲存Meatadata的cache,讓Bitbake不用每次重新parse
STAMP => 用來建立recipe stamp files
T => 用來放暫存檔的地方,大多是task logs and scriptsS。
B => Bitbake建置recipes時,執行functions的地方

執行Bitbake
$bitbake

ERROR: Traceback (most recent call last):
  File "/home/scott-lenovo/bitbake/lib/bb/cookerdata.py", line 163, in wrapped
    return func(fn, *args)
  File "/home/scott-lenovo/bitbake/lib/bb/cookerdata.py", line 177, in _inherit
    bb.parse.BBHandler.inherit(bbclass, "configuration INHERITs", 0, data)
  File "/home/scott-lenovo/bitbake/lib/bb/parse/parse_py/BBHandler.py", line 92, in inherit
    include(fn, file, lineno, d, "inherit")
  File "/home/scott-lenovo/bitbake/lib/bb/parse/parse_py/ConfHandler.py", line 100, in include
    raise ParseError("Could not %(error_out)s file %(fn)s" % vars(), oldfn, lineno)
ParseError: ParseError in configuration INHERITs: Could not inherit file classes/base.bbclass

ERROR: Unable to parse base: ParseError in configuration INHERITs: Could not inherit file classes/base.bbclass

這次是找不到classes/base.bbclass。classes是用來放基本的classes,它類似物件導向語言裡的classes。
base.bbclass是用來給每個recipe繼承的。

4.建立classes/base.bbclass,run bitbake

建立classes資料夾
$ cd $HOME/hello
$ mkdir classes

在base.bbclass輸入

addtask build

執行bitbake
 $ bitbake
     Nothing to do.  Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.

5. 新建一個mylayer和printhello.bb,run bitbake printhello.bb
 $ cd $HOME
 $ mkdir mylayer
 $ cd mylayer
 $ mkdir conf

在conf資料夾下新增一個layer.conf並輸入下面內容:
 BBPATH .= ":${LAYERDIR}"
 BBFILES += "${LAYERDIR}/*.bb"
 BBFILE_COLLECTIONS += "mylayer"
 BBFILE_PATTERN_mylayer := "^${LAYERDIR}/"

在mylayer資料夾下新增一個printhello.bb並輸入下面內容:
DESCRIPTION = "Prints Hello World"
     PN = 'printhello'
     PV = '1'

     python do_build() {
        bb.plain("********************");
        bb.plain("*                  *");
        bb.plain("*  Hello, World!   *");
        bb.plain("*                  *");
        bb.plain("********************");
     }

執行 bitbake printhello
$ cd $HOME/hello
$ bitbake printhello
ERROR: no recipe files to build, check your BBPATH and BBFILES?

Summary: There was 1 ERROR message shown, returning a non-zero exit code.
因為bitbake不知printhello.bb在那裡。

6.新增bblayers.conf,執行bitbake printhello
在hello/conf底下,新增bblayers.conf告訴bitbake printhello.bb的位置
BBLAYERS ?= " \
       /home/<you>/mylayer \

執行 bitbake printhello
 $ bitbake printhello
     Parsing recipes: 100% |##################################################################################|
     Time: 00:00:00
     Parsing of 1 .bb files complete (0 cached, 1 parsed). 1 targets, 0 skipped, 0 masked, 0 errors.
     NOTE: Resolving any missing task queue dependencies
     NOTE: Preparing runqueue
     NOTE: Executing RunQueue Tasks
     ********************
     *                  *
     *  Hello, World!   *
     *                  *
     ********************
     NOTE: Tasks Summary: Attempted 1 tasks of which 0 didn't need to be rerun and all succeeded.