code style

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的時間等等資訊,會放在這個資料夾裡