code style

2017年7月17日 星期一

Device Tree(4)Device Node Requirements

一個device tree最少要由一個root node,cpus node, memory node組成。

Root Node
Root node表示符號為"/",下表是它的屬性

Aliases Node
這個屬性在root的位置,node name為aliases。必須要為小寫字元開頭,長度為1~31字元,主要是用來減少冗長的路徑名稱。
可用字元如下圖:






例:
aliases {
  serial0 = "/simple-bus@fe000000/serial@llc500";
  ethernet0 = "/simple-bus@fe000000/ethernet@31c000";
}

就可用serial0來代表/simple-bus@fe000000/serial@llc500

Memory Node
表示實際系統上的memory layout,屬性見下圖:














例:
一個 64-bit Power system 的 physical memory layout:
RAM: starting address 0x0, length 0x80000000 (2GB)
RAM: starting address 0x100000000, length 0x100000000 (4GB)

在root node定義address and size,這裡表示reg 屬性需要2個32-bit cells
#address-cells = <2>;
#size-cells = <2>;

可用下面兩種方式表示這兩段記憶體

(1)
memory@0 {
   device_type = "memory";
   reg = <0x000000000 0x00000000 0x00000000 0x80000000
              0x000000001 0x00000000  0x00000001 0x00000000>;
};

(2)
memory@0 {
device_type = "memory";
reg = <0x000000000 0x00000000 0x00000000 0x80000000>;
};

memory@100000000 {
device_type = "memory";
reg = <0x000000001 0x00000000 0x00000001 0x00000000>;
};

Chosen Node
用來描述由系統firmware指定的runtime parameter。會放在root node底下。原本通過tag list傳遞的一些 kernel的運行時參數可以通過Device Tree傳遞。例如command line可以通過bootargs這個property這個屬性傳遞,node屬性如下圖:















例:
chosen {
   bootargs = “root=/dev/nfs rw nfsroot=192.168.1.1 console=ttyS0,115200”;
};

CPUS Node
表示實際系統上的CPU,因為可能不只一個CPU又或是多核心,cpus node包含cpu node,等下會說到。cpus node屬性如下圖:



CPU Node
表示實際系統上的CPU,屬性如下圖:














































Device Tree(3)Interrupts and Interrupt Mapping

Properties for Interrupt Generating Devices
interrupt-parent 
在device tree中interrupt controller有一個interrupt-parent 屬性,這個用來表示interrupt之間的路由關係,它用一個phandle value表示其parent。各個interrupt controller的定義是不一樣的,有的用3個u32,有的用4個。

interrupt tree 有可能和device tree是不一樣的。
這個node本身如果沒有這interrupt-parent 的話,就是用parent node的interrupt-parent。

interrupts
一個能產生中斷的設備,必須要定義interrups這屬性。這裡指的就是設備產生的interrupt,描述interrupt source的又叫interrupt specifier。使用<u32>來表示。

例:
interrupts = <0xA 8>;
表示interrupt number:0xA, level/sense:8

Properties for Interrupt Controllers
interrupt-controller
Value type:<empty>
用來表示interrupt-controller

interrupt-cells
Value type:<u32>
用來表示interrupt-controller需要幾個單位做interrupt specifier

 Interrupt Nexus Properties
一個interrupt nexus node應該要有一個#interrupt-cells 屬性
interrupt nexus
用來轉譯的,nexus的意思就是"連結",連結上下兩個domains的那個node。
例:
PCI controller device node定義了一個nexus node,用來轉譯PCI interrupt namespace(INTA,INTB,etc.)到interrupt controller的IRQ。

interrupt關係圖示例


上圖中沒有interrupt-parent的open-pic為root,有3個doamin,2個nexus nodes。可轉換為下圖:


2017年7月14日 星期五

Device Tree(2)Properties

Property Names:
由1~31個字元組成,內容為下述:
Character Description 0-9
digit a-z lowercase letter
,(comma ). (period) _ (underscore) +( plus sign) - (dash) ? (question mark) #(hash)

需要一個唯一的prefix,來辨別property的名稱或組織,例如:
fsl,channel-fifo-len
ibm,ppc-interrupt-server#s
linux,network-index

Property Values:
有下面幾種類型,記憶體排方式應該是看CPU 架構為主,little-endian或big-endian:
empty => 如果是true-false的話,可以為空。
u32 => 32bit 整數
u64 => 64bit 整數
string=> 字串
prop-encoded-array=>描述property用
phandle => 一個u32 value,可以用來給別的node拿來參考用,類似指標,指向另一個node。
stringlist => 連續的字串

Standard Properties:
device tree是使用 Device Tree Source(DTS)格式來描述nodes和properties。下面列出一些標準的properties。


Property:compatible
Value type:<stringlist>
用來描述driver model,OS會照stringlist順序去找尋driver model,建議格式為 "manufacturer,model"。
例:
compatible = “fsl,mpc8641-uart”, “ns16550";

在這例子中有兩個string,OS會先去找“fsl,mpc8641-uart”, 如果找不到就會改去找 general ns16650 device type。

Property:model
Value type:<string>
driver名稱及model number。
例:
model = “fsl,MPC8349EMITX”;

Property:phandle
Value type:<u32>
一個在device tree中的唯一值,給其他的node參考用。
例:
pic@10000000 {
    phandle = <1>;
    interrupt-controller; 20
};
定義pandle=1,其他的node可用1這個值來使用pic@10000000。
例:
interrupt-parent = <1>;

Property:status
Value type:<string>
顯示driver的操作,有4種。
okay=>表示可操作
disabled=>表示目前為關閉,不可操作
fail=>表示目前為錯誤,需要修復,不可操作
fail-sss=>表示目前為錯誤,需要修復,不可操作。sss用來指示錯誤原因。

Property:#address-cells and #size-cells
Value type:<u32>
表示在child node's 的reg裡的address and size。如果沒有寫,default為2 and 1。
#size-cells是可以為0的,那reg裡面的size就會被省略。
例:
裡面表示soc的child serial node裡的reg有一個address (0x4600)和一個size(0x100)。

Property:reg
Value type:<prop-encoded-array>, 表示方式為(address, length)
register,主要是指memory-mapped IO register的offsets and lengths。
例:
#address-cells為1 and #size-cells為1
reg = <0x3000 0x20 0xFE00 0x100>;
代表在0x3000有一個32byte的block和0xFE00有一個256 byte block

Property:ranges
Value type:<empty> or <prop-encoded-array>, 表示方式為(child-bus-address, parent-bus-address, length)
表示 register定址的範圍
例:
定址範圍有0x00100000, 1024KB,child 定址在0x0, mapping 到parent 0xe0000000。
在此例中,serial的offset 為04600,而mapping後的位置為0xe0004600

Property:device_type
Value type:<string>
原本在IEEE1275中用來描述FCode,因為ePAPR沒有FCode,為了相容性,只用在cpu and memory上。
例:
 memory {
   device_type = "memory";
   reg = <0x00000000 0x100000000>; /* 4 GB */
 };








Device Tree(1)觀念和介紹

概念:
Linux  Kernel從3.x開始引入設備樹的概念。樹狀結構來描述硬體,每一個node有property/value來描述屬性,除了root node之外,都會有一個parent。原則上是非動態偵測的device,就要加入device tree,例如PCI。

下圖表示一個最簡單可以開機的OS的device tree,包含了平台、CPU、memory等資訊。 



Node Names:
名稱組成方式為 => node-name@unit-address

node-name為長度1~31的大小寫英文數字以及 ,(comma) .(period) _(underscore) +(plus sign) -(dash)組成。開頭必頭為英文字母。

unit-address要符合reg property。unit-address可以省略,只要名稱不要和其他兄弟節點一樣即可。

root node的名稱是slash(/)。

例如ethernet@fe001000和ethernet@fe002000這兩個node就是以unit-address來分別。

建議的node-name:
• atm
• cache-controller
• compact-flash 9
• can
• cpu
• crypto
• disk
• display
• dma-controller
• ethernet
• ethernet-phy
• fdc
• flash
• gpio
• i2c
• ide
• interrupt-controller
• isa
• keyboard
• mdio
• memory
• memory-controller
• mouse
• nvram
• parallel
• pc-card
• pci
• pcie
• rtc
• sata
• scsi
• serial
• sound
• spi
• timer
• usb
• vme
• watchdog



2017年7月6日 星期四

Buildroot (3)常用指令及基本觀念

make list-defconfigs:
列出所有的defconfig,如果這裡有廠商給的config,請放在configs資料夾下,Buildroot才會
偵測到

make help:
使用說明

make clean:
當toolchain變動時或任何大的變動,請下這指令,會刪除所有build產生的東西(including build directories, host, staging and target trees, the images and the toolchain)

make distclean:
刪除所有的檔案,除了source files。注意! 當ccache 開啟時,make clean or make distclean不會刪除cache。

何時要rebuild:
Buildroot不會偵測在make menuconfig, make xconfig後的變動,user要自已判斷需不需要rebuild。關於rebuild判斷的參考:

(1)target architecture configuration變動時,整個rebuild

(2)toolchain configuration變動時,整個rebuild

(3)新增package時,不需要整個rebuild。
a.如果Buildroot 偵測到package沒有built過,則會build it。
b.如果這package是其它package的可選library時,且它已build過,Buildroot不會自動重build這 package。
c.自已手動reubild package或整個Buildroot

Ex:例如我們原本built了一個ctorrent package,裡面不含openssl 。但後來想要支援openssl,我們就在設定裡新增openssl,此時Buildroot只會built新的openssl,不會rebuild
ctorrent! 這時需要我們手動rebuild ctorrent或者整個rebuild。

(4)移除一個package時,Buildroot並不會去刪時它,除非你整個rebuild

(5)package的設定變動時,Buildroot並不會去rebuild這個package

(6)當root filesystem的框架變動時,需要整個rebuild

如何rebuild一個package或移除一個package時不用整個rebuild?移除一個package時,並須要整個rebuild。而最簡單的rebuild一個package的方法是刪除output/build/<package>這個資料夾,可以下 make <package>dirclean來進行移除的動作。

make <package>-rebuild:
重新compilation and installation,這個指令會執行package裡面的makefile。

make <package>-reconfig:
重新configuration, compilation and installation,這個指令會執行package裡面的makefile。

Building out-of-tree:
預設輸出會在output資料夾下,如果想要更改輸出資料夾,請參考下述指令
make O=/tmp/build
or
cd /tmp/build
make O=$PWD -C path/to/buildroot
如果/tmp/build資料夾不存在的話,Buildroot會建立,最終結果會產生在這資料夾下。
這裡可以使用絕對位置和相對位置,相對位置是指相對於 Buildroot source directory。
這裡要注意的是,.config也會移到你改變輸出的位置。

Environment variables:
HOSTCXX =>host C++ Compiler
HOSTCC => host C Compiler
UBLIBC_CONFIG_FILE=<path/to/.config>=>uClibc configuration的位置
BUSYBOX_CONFIG_FILE=<path/to/.config>=>BusyBox configuration的位置
BR2_CCACHE_DIR=>ccache 的位置
BR2_DL_DIR=> 下載下來的檔案位置
BR2_GRAPH_XXX=>產生graph的相關設定

Buildroot 圖片分析指令:
要先確認有安裝graphviz工具,sudo apt-get install graphviz。
make graph-depends:
產生整個Buildroot的depends圖片,位置在output/graphs/graph-depends.pdf 

make <pkg>-graph-depends:
產生單一package的depends圖片,位置在output/graphs/<pkg>-graph-depends.pdf 

make graph-build:
產生整個Buildroot中要build每個package所花費的時間,位置在output/graphs/
  • build.hist-build.pdf, a histogram of the build time for each package, ordered in the build order.
  • build.hist-duration.pdf, a histogram of the build time for each package, ordered by duration (longest first)
  • build.hist-name.pdf, a histogram of the build time for each package, order by package name.
  • build.pie-packages.pdf, a pie chart of the build time per package
  • build.pie-steps.pdf, a pie chart of the global time spent in each step of the packages build process
make graph-size:
產生整個Buildroot中要build每個package所花費的時間,位置在output/graphs/




2017年7月5日 星期三

Buildroot (2)設定

Cross-compilation toolchain:
Buildroot 提供兩種toolchain設定:
1. internal toolchain backend
使用Buildroot自帶的toolchain,支援uClibc-ng, glibc and musl,需選擇Linux kernel headers、C Library、GCC compiler、binutils等工具和版本。

2.external toolchain backend
有三個方式可選:
(1)Use a predefined externel toolchain profile,讓Buildroot去下載安裝
(2)Use a predefined externel toolchain profile,告訴Buildroot這toolchain放在系統那邊,不要去下載安裝
(2)Use a completely externel toolchain,通常這是指晶片商提供的toolchain,我們需要指定Toolchain path,Toolchain prefix and External toolchain C library。一般而言會提供一個設定檔,執行這個檔案,例如 make XXXX_defconfig。再執行make menuconfig,會看到在menu中已經設好了,唯一要手動的是,path和prefix。如果build的時後顯示找不到toolchain,大多是這兩個參數設錯。

例如:
BR2_TOOLCHAIN_EXTERNAL_PATH="/home/<user>/<work directory>/armv7-marvell-linux-gnueabihf/"

BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-marvell-linux-gnueabihf"

BusyBox:
可用default的BusyBox設定或使用BR2_PACKAGE_BUSYBOX_CONFIG這個參數來讀取已定義好的設定。也可使用 make busybox-menuconfig 來編輯BusyBox。

uClibc:
和BusyBox類似,使用BR2_UCLIBC_CONFIG來讀取已定義好的設定。也可使用 make uclibc-menuconfig 來編輯BusyBox。

Linux kernel:
使用BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG來讀取已定義好的設定
使用BR2_LINUX_KERNEL_USE_DEFCONFIG來使用default值
使用 make linux-menuconfig 來編輯

Barebox:
U-Boot二代,使用上和Linux kernel類似
使用BR2_LINUX_TARGET_BAREBOX_USE_CUSTOM_CONFIG來讀取已定義好的設定
使用BR2_LINUX_TARGET_BAREBOX_USE_DEFCONFIG來使用default值
使用 make barebox-menuconfig 來編輯

U-Boot:
U-Boot板本要2015.04以上
使用BR2_LINUX_TARGET_UBOOT_USE_CUSTOM_CONFIG來讀取已定義好的設定
使用BR2_LINUX_TARGET_UBOOT_USE_DEFCONFIG來使用default值
使用 make uboot-menuconfig 來編輯

Buildroot (1)介紹

Buildroot是一簡化且自動化處理產生corss-compilation toolchain, root filesystem, Linux Kernel, bootloader的工具,便於開發embedded system。

Host: 主機、宿主,一般而言就是我們的PC、Notebook
Target: 目標設備

安裝Buildroot必須的packages:
  • Build tools:
    • which
    • sed
    • make (version 3.81 or any later)
    • binutils
    • build-essential (only for Debian based systems)
    • gcc (version 2.95 or any later)
    • g++ (version 2.95 or any later)
    • bash
    • patch
    • gzip
    • bzip2
    • perl (version 5.8.7 or any later)
    • tar
    • cpio
    • python (version 2.6 or any later)
    • unzip
    • rsync
    • file (must be in /usr/bin/file)
    • bc
  • Source fetching tools:
    • wget

可選是否要安裝的packages:

    • ncurses5 to use the menuconfig interface
    • qt4 to use the xconfig interface(sudo apt-get install qt4-qmake libqt4-dev)
    • glib2gtk2 and glade2 to use the gconfig interface
  • Source fetching tools:
    • bazaar
    • cvs
    • git
    • mercurial
    • rsync
    • scp
    • subversion
  • Java-related packages:
    • The javac compiler
    • The jar tool
  • Documentation generation tools:
    • asciidoc, version 8.6.3 or higher
    • w3m
    • python with the argparse module (automatically present in 2.7+ and 3.2+)
    • dblatex (required for the pdf manual only)
  • Graph generation tools:
    • graphviz to use graph-depends and <pkg>-graph-depends
    • python-matplotlib to use graph-build
空間夠的話,建議全部一起安裝,例如git或graphviz(make graph-depends時會用到)又或python都很常用。


Quick Start:
首先我們需要產生一個 .config檔,可使用下面四種指令,用圖形化的視窗來設定:
1. make menuconfig最基本也是最多人用的
2. make nconfig 新的圖形介面
3. make xconfig Qt-based的圖形介面
4. make gconfig GTK-based的圖形介面

只是畫面不同,重點在設定完,會在目前目錄下(也就是top-level的目錄)產生一個.config檔(隱藏檔),這裡面有你設定好的設定,之後也可直接更改此檔來做設定。設定完後下make,沒意外的話,一切就會自動完成。

要注意的是,這裡不能在top-level資料夾下 make -jN的指令,一般我們會在4核下的cpu 裡下make -j8來進行多工的處理,可是Buildroot不支援在top-level的並行處理。取而代之的是使用BR2_JLEVEL。這選項告訴Buildroot在每個獨立的package裡下make -jN,例如修改.config的BR2_JLEVEL=8。

make的流程:
  • download source files (as required);
  • configure, build and install the cross-compilation toolchain, or simply import an external toolchain;
  • configure, build and install selected target packages;
  • build a kernel image, if selected;
  • build a bootloader image, if selected;
  • create a root filesystem in selected formats.
最後結果輸出在output資料夾。

output資料夾內容:
images => kernel image,bootloader, root filesystem images等等
build => 所有下載或自定義build好的packages
staging => 這資料包含一些研發工具,用來compile libraries and applications給target使用
target => 目標設備的root filesystem範本,依照手冊說明,不包含dev,因為make的時後並     不是用root啟動,這裡比較奇怪,我沒有下sudo make,可是target底下也是有dev這資料夾?   也有可能是之前有下過sudo make,而資料夾未被移除?
host => 主機上bulidroot所需的工具
graphs=>如果下make graph-depends等輔助指令,可產生package的相依性、生成的size、      build的時間等等資訊,會放在這個資料夾裡

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.

2017年6月15日 星期四

BitBake (1)Overview

BitBake是OpenEmbedded的一個 task executor,使用Python撰寫,主要功用是分析recipes後建置輸出package,也被Yocto Project採用。觀念上,BitBake類似GNU Make。而makefile也就是recipe。它分析recipe後,可得知建置所需的dependencies, source file locations, checksums, description....等等資訊,再開始建置。下面是Bitbake的幾種data 類型:


Recipes:
描述source code 的位置、和如何configure and compile the source code等等資訊。副檔名為.bb。

Configuration Files:
定義machine configuration options, distribution configuration options, compiler tuning options,general common configuration options, and user configuration options。副檔名為.conf。


Classes:
抽象的基本build subroutines,使用inheritance mechanism(繼承機制)提供創出新的.bb檔,類似物件導象中的Class。副檔名為.bbclass。

Layers:
Metadata 是由許多的layers組成。這些layers允許你分離不同客制化的設定。

Append Files:
一般.bb和.bbappend會使用相同的檔名,用副檔名來區分。副檔名為.bbappend。