buildroot使用介紹

buildroot使用介紹

buildroot是Linux平臺上一個(gè)構(gòu)建嵌入式Linux系統(tǒng)的框架。整個(gè)Buildroot是由Makefile腳本和Kconfig配置文件構(gòu)成的。你可以和編譯Linux內(nèi)核一樣,通過buildroot配置,menuconfig修改,編譯出一個(gè)完整的可以直接燒寫到機(jī)器上運(yùn)行的Linux系統(tǒng)軟件(包含boot、kernel、rootfs以及rootfs中的各種庫和應(yīng)用程序)。

使用buildroot搭建基于qemu的虛擬開發(fā)平臺,參考《通過buildroot+qemu搭建ARM-Linux虛擬開發(fā)環(huán)境》。

1. buildroot入門

首先如何使用buildroot,1.選擇一個(gè)defconfig;2.根據(jù)需要配置buildroot;3.編譯buildroot;4.在qemu或者目標(biāo)板上運(yùn)行buildroot構(gòu)建的系統(tǒng)。

1.1 buildroot目錄介紹

進(jìn)入buildroot首先映入眼簾的是一系列目錄,簡要介紹如下:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">.
├── arch: 存放CPU架構(gòu)相關(guān)的配置腳本,如arm/mips/x86,這些CPU相關(guān)的配置,在制作工具鏈時(shí),編譯uboot和kernel時(shí)很關(guān)鍵.
├── board
├── boot
├── CHANGES
├── Config.in ├── Config.in.legacy
├── configs: 放置開發(fā)板的一些配置參數(shù).
├── COPYING
├── DEVELOPERS
├── dl: 存放下載的源代碼及應(yīng)用軟件的壓縮包.
├── docs: 存放相關(guān)的參考文檔.
├── fs: 放各種文件系統(tǒng)的源代碼.
├── linux: 存放著Linux kernel的自動構(gòu)建腳本.
├── Makefile
├── Makefile.legacy
├── output: 是編譯出來的輸出文件夾.
│ ├── build: 存放解壓后的各種軟件包編譯完成后的現(xiàn)場.
│ ├── host: 存放著制作好的編譯工具鏈,如gcc、arm-linux-gcc等工具.
│ ├── images: 存放著編譯好的uboot.bin, zImage, rootfs等鏡像文件,可燒寫到板子里, 讓linux系統(tǒng)跑起來.
│ ├── staging │ └── target: 用來制作rootfs文件系統(tǒng),里面放著Linux系統(tǒng)基本的目錄結(jié)構(gòu),以及編譯好的應(yīng)用庫和bin可執(zhí)行文件. (buildroot根據(jù)用戶配置把.ko .so .bin文件安裝到對應(yīng)的目錄下去,根據(jù)用戶的配置安裝指定位置)
├── package:下面放著應(yīng)用軟件的配置文件,每個(gè)應(yīng)用軟件的配置文件有Config.in和soft_name.mk。
├── README
├── support
├── system
└── toolchain</pre>

復(fù)制代碼

1.2 buildroot配置

通過make xxx_defconfig來選擇一個(gè)defconfig,這個(gè)文件在config目錄下。

然后通過make menuconfig進(jìn)行配置。

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">Target options --->選擇目標(biāo)板架構(gòu)特性。 Build options --->配置編譯選項(xiàng)。 Toolchain ---> 配置交叉工具鏈,使用buildroot工具鏈還是外部提供。
System configuration ---> Kernel ---> Target packages ---> Filesystem images ---> Bootloaders ---> Host utilities ---> Legacy config options ---></pre>

復(fù)制代碼

1.3 make命令使用

通過make help可以看到buildroot下make的使用細(xì)節(jié),包括對package、uclibc、busybox、linux以及文檔生成等配置。

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">Cleaning:
clean - delete all files created by build
distclean - delete all non-source files (including .config)

Build:
all - make world
toolchain - build toolchain

Configuration:
menuconfig - interactive curses-based configurator--------------------------------對整個(gè)buildroot進(jìn)行配置 savedefconfig - Save current config to BR2_DEFCONFIG (minimal config)----------------保存menuconfig的配置 Package-specific:-------------------------------------------------------------------------------對package配置 <pkg> - Build and install <pkg> and all its dependencies---------------------單獨(dú)編譯對應(yīng)APP <pkg>-source - Only download the source files for <pkg>
<pkg>-extract - Extract <pkg> sources <pkg>-patch - Apply patches to <pkg>
<pkg>-depends - Build <pkg>'s dependencies
<pkg>-configure - Build <pkg> up to the configure step <pkg>-build - Build <pkg> up to the build step <pkg>-show-depends - List packages on which <pkg> depends <pkg>-show-rdepends - List packages which have <pkg> as a dependency <pkg>-graph-depends - Generate a graph of <pkg>'s dependencies
<pkg>-graph-rdepends - Generate a graph of <pkg>'s reverse dependencies
<pkg>-dirclean - Remove <pkg> build directory-----------------------------------------清除對應(yīng)APP的編譯目錄 <pkg>-reconfigure - Restart the build from the configure step <pkg>-rebuild - Restart the build from the build step--------------------------------單獨(dú)重新編譯對應(yīng)APP

busybox:
busybox-menuconfig - Run BusyBox menuconfig

uclibc:
uclibc-menuconfig - Run uClibc menuconfig

linux:
linux-menuconfig - Run Linux kernel menuconfig-----------------------------------------配置Linux并保存設(shè)置
linux-savedefconfig - Run Linux kernel savedefconfig
linux-update-defconfig - Save the Linux configuration to the path specified
by BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE

Documentation:
manual - build manual in all formats manual-pdf - build manual in PDF graph-build - generate graphs of the build times----------------------------------對編譯時(shí)間、編譯依賴、文件系統(tǒng)大小生成圖標(biāo)
graph-depends - generate graph of the dependency tree
graph-size - generate stats of the filesystem size</pre>

復(fù)制代碼

2. buildroot框架

Buildroot提供了函數(shù)框架和變量命令框架(下一篇文章將介紹細(xì)節(jié)),采用它的框架編寫的app_pkg.mk這種Makefile格式的自動構(gòu)建腳本,將被package/pkg-generic.mk 這個(gè)核心腳本展開填充到buildroot主目錄下的Makefile中去。

最后make all執(zhí)行Buildroot主目錄下的Makefile,生成你想要的image。 package/pkg-generic.mk中通過調(diào)用同目錄下的pkg-download.mk、pkg-utils.mk文件,已經(jīng)幫你自動實(shí)現(xiàn)了下載、解壓、依賴包下載編譯等一系列機(jī)械化的流程。

你只要需要按照格式寫Makefile腳app_pkg.mk,填充下載地址,鏈接依賴庫的名字等一些特有的構(gòu)建細(xì)節(jié)即可。 總而言之,Buildroot本身提供構(gòu)建流程的框架,開發(fā)者按照格式寫腳本,提供必要的構(gòu)建細(xì)節(jié),配置整個(gè)系統(tǒng),最后自動構(gòu)建出你的系統(tǒng)。

image

對buildroot的配置通過Config.in串聯(lián)起來,起點(diǎn)在根目錄Config.in中。

| 配置選項(xiàng) | Config.in位置 | |
| Target options | arch/Config.in | |
| Build options | Config.in | |
| Toolchain | toolchain/Config.in | |
| System configuration | system/Config.in | |
| Kernel | linux/Config.in | |
| Target packages | package/Config.in | |
| Target packages->Busybox | | |
| Filesystem images | fs/Config.in | |
| Bootloaders | boot/Config.in | |
| Host utilities | package/Config.in.host | |
| Legacy config options | Config.in.legacy | |
| | | |

3. 配置Linux Kernel

對Linux內(nèi)核的配置包括兩部分:通過make menuconfig進(jìn)入Kernel對內(nèi)核進(jìn)行選擇,通過make linux-menuconfig對內(nèi)核內(nèi)部進(jìn)行配置。

3.1 選擇Linux內(nèi)核版本

如下“Kernel version”選擇內(nèi)核的版本、“Defconfig name”選擇內(nèi)核config文件、“Kernel binary formant”選擇內(nèi)核格式、“Device tree source file names”選擇DT文件,

在“Linux Kernel Tools”中選擇內(nèi)核自帶的工具,比如perf。

image

可以選擇“Custom Git repository”來指定自己的Git庫,在“Custom repository version”中指定branch名稱。

選擇“Using an in-tree defconfig file”,在“Defconfig name”中輸入defconfig名稱,注意不需要末尾_defconfig。

選擇“Use a device tree present in the kernel”,在“Device Tree Source file names”中輸入dts名稱,不需要.dts擴(kuò)展名。

3.1.1 Kernel binary format

可以選擇vmlinux或者uImage。

uImage是uboot專用的映像文件,它是在zImage之前加上一個(gè)長度為64字節(jié)的“頭”,說明這個(gè)內(nèi)核的版本、加載位置、生成時(shí)間、大小等信息;其0x40之后與zImage沒區(qū)別。

zImage是ARM Linux常用的一種壓縮映像文件,uImage是U-boot專用的映像文件,它是在zImage之前加上一個(gè)長度為0x40的“頭”,說明這個(gè)映像文件的類型、加載位置、生成時(shí)間、大小等信息。

vmlinux編譯出來的最原始的內(nèi)核elf文件,未壓縮。

zImage是vmlinux經(jīng)過objcopy gzip壓縮后的文件, objcopy實(shí)現(xiàn)由vmlinux的elf文件拷貝成純二進(jìn)制數(shù)據(jù)文件。

uImage是U-boot專用的映像文件,它是在zImage之前加上一個(gè)長度為0x40的tag。

選擇vmlinux和uImage的區(qū)別在于:

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">PATH="/bin..." BR_BINARIES_DIR=/home/.../output/images /usr/bin/make -j9 HOSTCC="/usr/bin/gcc" HOSTCFLAGS="" ARCH=csky INSTALL_MOD_PATH=/home/.../output/target CROSS_COMPILE="/home/.../output/host/bin/csky-abiv2-linux-" DEPMOD=/home/.../output/host/sbin/depmod INSTALL_MOD_STRIP=1 -C /home/.../linux uImage</pre>

如果是vmlinux,在結(jié)尾就是vmlinux。

3.2 對Kernel進(jìn)行配置

通過make linux-menuconfig可以對內(nèi)核內(nèi)部細(xì)節(jié)進(jìn)行配置。

讓Linux內(nèi)核帶符號表:

CONFIG_COMPILE_TEST is not set

CONFIG_DEBUG_INFO=y

4. 配置文件系統(tǒng)APP

對目標(biāo)板文件系統(tǒng)內(nèi)容進(jìn)行配置主要通過make menuconfig進(jìn)入Target packages進(jìn)行。

image

在Filesystem images中配置文件系統(tǒng)采用的格式,以及是否使用RAM fs。

image

4.1 ramfs

如果選中“initial RAM filesystem linked into linux kernel”,那么文件系統(tǒng)會集成到vmlinux中。

如不選中,則vmlinux中只包括內(nèi)核,文件系統(tǒng)會以其他形似提供,比如rootfs.cpio。

如果定義了BR2_TARGET_ROOTFS_INITRAMFS,那么在編譯的末期需要重新編譯內(nèi)核,將rootfs.cpio加入到vmlinux中。

fs/initramfs/initramfs.mk中:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">rootfs-initramfs: linux-rebuild-with-initramfs

rootfs-initramfs-show-depends:
@echo rootfs-cpio

.PHONY: rootfs-initramfs rootfs-initramfs-show-depends

ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS),y)
TARGETS_ROOTFS += rootfs-initramfs
endif</pre>

復(fù)制代碼

在linux/linux.mk中:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">.PHONY: linux-rebuild-with-initramfs
linux-rebuild-with-initramfs: (LINUX_DIR)/.stamp_target_installed linux-rebuild-with-initramfs:(LINUX_DIR)/.stamp_images_installed
linux-rebuild-with-initramfs: rootfs-cpio
linux-rebuild-with-initramfs:
@(call MESSAGE,"Rebuilding kernel with initramfs") # Build the kernel.(LINUX_MAKE_ENV) (MAKE)(LINUX_MAKE_FLAGS) -C (LINUX_DIR)(LINUX_TARGET_NAME)
(LINUX_APPEND_DTB) # Copy the kernel image(s) to its(their) final destination(call LINUX_INSTALL_IMAGE,(BINARIES_DIR)) # If there is a .ub file copy it to the final destination test ! -f(LINUX_IMAGE_PATH).ub || cp (LINUX_IMAGE_PATH).ub(BINARIES_DIR)</pre>

復(fù)制代碼

在打開initramfs的情況下,重新將rootfs.cpio編譯進(jìn)內(nèi)核vmlinxu中。

然后將uImage之類的文件拷貝到BINARIES_DIR中。

5. 添加自己的APP

要添加自己的本地APP, 首先在package/Config.in中添加指向新增APP目錄的Config.in;

然后在package中新增目錄helloworld,并在里面添加Config.in和helloworld.mk;

最后添加對應(yīng)的helloworld目錄。

5.1 添加package/Config.in入口

系統(tǒng)在make menuconfig的時(shí)候就可以找到對應(yīng)的APP的Config.in。

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">diff --git a/package/Config.in b/package/Config.in index 43d75a9..6ef9fad 100644
--- a/package/Config.in
+++ b/package/Config.in @@ -1868,5 +1868,8 @@ menu "Text editors and viewers" source "package/uemacs/Config.in" source "package/vim/Config.in" endmenu +menu "Private package"

  •   source "package/helloworld/Config.in"
    

+endmenu</pre>

復(fù)制代碼

如果在make menuconfig的時(shí)候選中helloworld,在make savedefconfig的時(shí)候就會打開BR2_PACKAGE_HELLOWORLD=y。

5.2 配置APP對應(yīng)的Config.in和mk文件

helloworld/Config.in文件,通過make menuconfig可以對helloworld進(jìn)行選擇。

只有在BR2_PACKAGE_HELLOWORLD=y條件下,才會調(diào)用helloworld.mk進(jìn)行編譯。

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">config BR2_PACKAGE_HELLOWORLD bool "helloworld" help
This is a demo to add local app.</pre>

buildroot編譯helloworld所需要的設(shè)置helloworld.mk,包括源碼位置、安裝目錄、權(quán)限設(shè)置等。

下面的HELLOWORLD的開頭也是必須的。

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">################################################################################

helloworld

################################################################################

HELLOWORLD_VERSION:= 1.0.0 HELLOWORLD_SITE:= $(CURDIR)/work/helloworld
HELLOWORLD_SITE_METHOD:=local
HELLOWORLD_INSTALL_TARGET:=YES

define HELLOWORLD_BUILD_CMDS
(MAKE) CC="(TARGET_CC)" LD="(TARGET_LD)" -C(@D) all
endef

define HELLOWORLD_INSTALL_TARGET_CMDS
(INSTALL) -D -m 0755(@D)/helloworld $(TARGET_DIR)/bin
endef

define HELLOWORLD_PERMISSIONS /bin/helloworld f 4755 0 0 - - - - - endef

(eval(generic-package))</pre>

復(fù)制代碼

如果源碼在git上,需要如下設(shè)置:

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;"> DMA_TEST_VERSION:=master--------------------------------------倉庫分支名稱
DMA_TEST_SITE:=http://.../dma.git-----------------------------倉庫git地址
DMA_TEST_SITE_METHOD:=git-------------------------------------獲取源碼的方式</pre>

_VERSION結(jié)尾的變量是源碼的版本號;_SITE_METHOD結(jié)尾的變量是源碼下載方法;_SITE結(jié)尾變量是源碼下載地址。

_BUILD_CMDS結(jié)尾的變量會在buildroot框架編譯的時(shí)候執(zhí)行,用于給源碼的Makefile傳遞編譯選項(xiàng)和鏈接選項(xiàng),調(diào)用源碼的Makefile。

_INSTALL_TARGET_CMDS結(jié)尾的變量是在編譯完之后,自動安裝執(zhí)行,一般是讓buildroot把編譯出來的的bin或lib拷貝到指定目錄。

(eval(generic-package)) 最核心的就是這個(gè)東西了,一定不能夠漏了,不然源碼不會被編譯,這個(gè)函數(shù)就是把整個(gè).mk構(gòu)建腳本,通過Buildroot框架的方式,展開到Buildroot/目錄下的Makfile中,生成的構(gòu)建目標(biāo)(構(gòu)建目標(biāo)是什么,還記得Makefile中的定義嗎?)。

5.3 編寫APP源碼

簡單的編寫一個(gè)helloworld.c文件:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">#include <stdio.h>

void main(void)
{
printf("Hello world.\n");
}</pre>

復(fù)制代碼

然后編寫Makefile文件:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">CPPFLAGS += LDLIBS += all: helloworld

analyzestack: helloworld.o
(CC)(CFLAGS) (LDFLAGS) -o@ ^(LDLIBS)

clean:
rm -f *.o helloworld

.PHONY: all clean</pre>

復(fù)制代碼

5.4 通過make menuconfig選中APP

通過Target packages -> Private package進(jìn)入,選中helloworld。

image

然后make savedefconfig,對helloworld的配置就會保存到qemu_arm_vexpress_defconfig中。

image

5.5 編譯APP

可以和整個(gè)平臺一起編譯APP;或者make helloworld單獨(dú)編譯。

這兩個(gè)文件在選中此APP之后,都會被拷貝到output/build/helloworld-1.0.0文件夾中。

然后生成的bin文件拷貝到output/target/bin/helloworld,這個(gè)文件會打包到文件系統(tǒng)中。

如果需要清空相應(yīng)的源文件,通過make helloworld-dirclean。

5.6 運(yùn)行APP

在shell中輸入helloworld,可以得到如下結(jié)果。

image

添加APP工作完成。

6. uboot配置

使用uboot作為bootloader,需要進(jìn)行一些配置。

在選中U-boot作為bootloader之后,會彈出一系列相關(guān)配置。

“U-Boot board name”配置configs的defconfig名稱。

“U-Boot Version”選擇Custom Git repository,然后在“URL of custom repository”中選擇自己的git地址,并在“Custom repository version”中選擇git的分支。

在“U-Boot binary format”中選擇想要輸出的image格式,比如u-boot.img或者u-image.bin。

還可以選擇“Intall U-Boot SPL binary image”,選擇合適的SPL。

image

7. Finalizing target

在buildroot編譯的末期,需要對編譯結(jié)果進(jìn)行一些檢查或者其他操作。

buildroot預(yù)留了兩個(gè)接口:

BR2_ROOTFS_OVERLAY - 指向一個(gè)目錄,此目錄下的所有文件將會覆蓋到output/target下。比如一些配置文件,或者預(yù)編譯的庫等可以在此階段處理。

BR2_ROOTFS_POST_BUILD_SCRIPT - 一個(gè)腳本,更加復(fù)雜的對文件進(jìn)行刪除、重命名、strip等等功能。

BR2_ROOTFS_POST_IMAGE_SCRIPT - 對最終生成的images進(jìn)行打包處理等。

7.1 FS Overlay

有些應(yīng)用或者配置不通過編譯,直接采取拷貝的方式集成到rootfs中,可以設(shè)置“System configuration”->“Root filesystem overlay directories”。

設(shè)置的目錄中的內(nèi)容,會對output/target進(jìn)行覆蓋。

相關(guān)處理在Makefile中如下:

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;"> @(foreach d,(call qstrip,(BR2_ROOTFS_OVERLAY)), \(call MESSAGE,"Copying overlay (d)"); \ rsync -a --ignore-times --keep-dirlinks(RSYNC_VCS_EXCLUSIONS) \ --chmod=u=rwX,go=rX --exclude .empty --exclude '*~'
(d)/(TARGET_DIR)$(sep))</pre>

7.2 post build

除了fs overlay這種方式,buildroot還提供了一個(gè)腳本進(jìn)行更加復(fù)雜的處理。

可以進(jìn)行文件刪除、重命名,甚至對帶調(diào)試信息的文件進(jìn)行strip等。

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;"> @(foreach s,(call qstrip,(BR2_ROOTFS_POST_BUILD_SCRIPT)), \(call MESSAGE,"Executing post-build script (s)"); \(EXTRA_ENV) (s)(TARGET_DIR) (call qstrip,(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))</pre>

一個(gè)post_build.sh范例,對一系列文件進(jìn)行刪除和strip操作:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">#!/bin/sh

set -x set +o errexit

cp -a {BINARIES_DIR}/deepeye1000e_hk.dtb{BINARIES_DIR}/deepeye1000.dtb

Strip files in tbc_lists.txt. tbc means 'to be stripped'.

STRIP={HOST_DIR}/bin/csky-abiv2-linux-strip for file in `cat{BR2_EXTERNAL_INTELLIF_PATH}/board/deepeye1000e_hk/tbs_lists.txt` do
if [ -e {TARGET_DIR}{file} ]; then
echo Strip {file}.{STRIP} {TARGET_DIR}{file} else echo Not found ${file}.
fi
done

Delete files in tbd_lists.txt. tbd means 'to be deleted'

for file in cat ${BR2_EXTERNAL_INTELLIF_PATH}/board/deepeye1000e_hk/tbd_lists.txt do
if [ -e {TARGET_DIR}{file} ]; then
echo Delete {file}. rm{TARGET_DIR}{file} else echo Not found{file}.
fi
done

${BR2_EXTERNAL_INTELLIF_PATH}/board/common/post_build.sh</pre>

復(fù)制代碼

7.2 post image

post image在post build之后,更傾向于生成完整的release文件。包括進(jìn)行一些images打包、debug文件打包等等。

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">.PHONY: target-post-image
target-post-image: (TARGETS_ROOTFS) target-finalize @(foreach s, (call qstrip,(BR2_ROOTFS_POST_IMAGE_SCRIPT)),
(call MESSAGE,"Executing post-image script(s)");
(EXTRA_ENV)(s) (BINARIES_DIR)(call qstrip,(BR2_ROOTFS_POST_SCRIPT_ARGS))(sep))</pre>

一個(gè)范例如下,對images文件進(jìn)行打包操作。

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">#!/bin/sh set -x -e

IMG_DIR=output/images
DEBUG_DIR=${IMG_DIR}/debug
KERNEL_DIR=output/build/linux-master

ROOTFS_CPIO={IMG_DIR}/rootfs.cpio KERNEL_IMAGE={IMG_DIR}/uImage SPL_IMAGE={IMG_DIR}/u-boot-spl-bh.bin UBOOT_IMAGE={IMG_DIR}/u-boot.bin

IMG_TAR=images.tar.gz
DEBUG_TAR=debug.tar.gz
IMG_MD5=images.md5

rm -f {IMG_TAR}{DEBUG_TAR} ${IMG_MD5}

mkdir -p {DEBUG_DIR} cp -a{KERNEL_DIR}/vmlinux {KERNEL_DIR}/System.map{ROOTFS_CPIO} {DEBUG_DIR}/ tar -czf{IMG_TAR} {KERNEL_IMAGE}{SPL_IMAGE} {UBOOT_IMAGE} tar -czf{DEBUG_TAR} -C {IMG_DIR} debug/ md5sum{IMG_TAR} > ${IMG_MD5}</pre>

復(fù)制代碼

8. buildroot編譯性能

buildroot還提供了一些命令,用于分析buildroot編譯過程中耗時(shí)、依賴關(guān)系、文件系統(tǒng)尺寸等等。

通過make help發(fā)現(xiàn)相關(guān)命令:

復(fù)制代碼

<pre style="margin: 0px 0px 0px 22px; white-space: pre-wrap; word-wrap: break-word; font-size: 12px !important; font-family: "Courier New" !important;">Documentation:
manual - build manual in all formats
manual-html - build manual in HTML
manual-split-html - build manual in split HTML
manual-pdf - build manual in PDF
manual-text - build manual in text
manual-epub - build manual in ePub
graph-build - generate graphs of the build times
graph-depends - generate graph of the dependency tree
graph-size - generate stats of the filesystem size
list-defconfigs - list all defconfigs (pre-configured minimal systems)</pre>

復(fù)制代碼

8.1 編譯耗時(shí)

執(zhí)行make graph-build會生成如下文件:

image

其中比較有參考意義的文件是build.hist-duration.pdf文件,按照耗時(shí)從大到小排列。

通過此圖可以明白整個(gè)編譯流程時(shí)間都耗在哪里,針對性進(jìn)行分析優(yōu)化,有利于提高編譯效率。

image

8.2 編譯依賴關(guān)系

生成graph-depends.pdf,可以看出各個(gè)編譯模塊之間的依賴關(guān)系。

buildroot的庫會根據(jù)依賴關(guān)系被自動下載,通過此圖也可以了解某些某塊被誰依賴。

image

8.3 編譯結(jié)果尺寸分析

通過graph-size.pdf文件可以對整個(gè)編譯結(jié)果組成有個(gè)大概理解。

image

另外更有參考意義的是file-size-stats.csv和package-size-stats.csv文件。

通過file和package兩個(gè)視角,更加詳細(xì)的了解整個(gè)rootfs空間都被那些文件占用。

image
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容