原文 http://blog.csdn.net/xiaofeng_yan/article/details/6757725
1 當你已經編完一個系統比如sato映像,在編一個meta-toolchain的映像如何重用已經下載的源碼。
修改build/local.conf變量
DL_DIR=
2 如果你用ctl+c中斷了編譯過程,在重新編譯的時候poky可能出現了一些問題。你個以這樣做來避免出現問題。
PC$rm -rf tmp/cache/default-glibc
PC$rm -rf tmp/stamps/出現問題的包
3 增加編譯的速度
如果你是多核的計算機修改build/local.conf變量
BB_NUMBER_THREADS = "4" 或 “2”
PARALLEL_MAKE = "-j 4" 或 “-j 2”
4 TOPDIR=poky/build
5 git更新本地文件
git checkout -f
git clone git://git.pokylinux.org/poky.git
cd poky/
git remote add contrib git://git.pokylinux.org/poky-contrib.git
git remote update
git branch -r | grep 'xf/distro'
git push git@git.pokylinux.org:poky-contrib.git contrbute-xiaofeng.yan:xiaofeng/distro
git commit --amend --author='Xiaofeng Yan '
./create-pull-request -r origin/master -b xiaofeng/distro
send-pull-request -t poky@yoctoproject.org -a -p pull-29801
git checkout branch-->切換分支
git
6 -sh: source: poky-init-build-env: file not found
可能當前的用戶環境有問題。這是可以換一個用戶。但不是根用戶。應該不是bash環境,詳細請看/etc/passwd,看看是用那個shell
7 CLFLAGS_append = "-fPIC"
如果要給gcc添加參數,可以用這個變量追加。
8 為什么文件的后面要加入這個變量BBCLASSEXTEND = "native"
在解壓源碼包的時候出現了兩個文件。而程序會進入只有patchs的目錄下。
這個不知道是什么原因?有待調查。
這是因為在命名.bb文件的時候,一定按下列方式進行。例如:
man-1.5.bb(錯)
man_1.5.bb(對)
命名方式:名字_版本.bb
9 如果在編譯的過程中要使用root用戶怎么辦呢?
在方法的前面加fakeroot
例如:
fakeroot do_configure(){
}
10 fakeroot: FAKEROOTKEY set to 1844291688
fakeroot: nested operation not yet supported
上述的錯誤是因為如果在.bb 文件中使用了fakeroot的和環境,那么你就不能在單獨的命令用fakeroot
例如:
fakeroot do_configure(){
}
do_compile(){
fakeroot make -f Makefile //因為do_configure使用了fakeroot那么這里再用fakeroot就有問題了。正確的使用方法如下
}
fakeroot do_dompile(){
make -f Makefile
}
11 .bb文件的語法
do_configure (){
}//正確的使用方法
do_configure ()
{
}//錯誤的使用方法
12 如何在poky的環境下打補丁
file://XXX.patch;patch=1 這種方法好像對傳統的patch行不通。有待調查。
可以用這種方式用以前的方式打patch
do_configure_prepend() {
patch -p0 < ${WORKDIR}/man-1.5k-confpath.patch
patch -p1 < ${WORKDIR}/man-1.5h1-make.patch
}
13 do_configure 方法可能和bitbake默認的不一樣,具體差異有待調查。
14 如何打印環境變量
環境變量只有在compile和install階段在能夠通過echo命令在屏幕上輸出。
如果想在其他階段看環境變量的值可以用下面的方法:例如
do_configure (){
${S}/configure
echo ${S} > 1.log
echo ${D} >> 1.log
}
PC$bitbake PACKAGENAME -c devshell
devshell$vim 1.log
/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4
/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/image
15 如何開各個過程具體過程以及bb文件隱含的變量值和默認的 build過程。
看build/tmp/work/arch/package/temp/run.do_*的其中一個文件有詳細的說明。
16 貌似函數與函數之間要有一行空行。
17 通常修改的是packages/tasks里的一個描述任務的bb文件。
你可以通過
bitbake -g 映像名稱
生成映像的依賴關系。然后在生成的depends.dot中找到映像依賴packages/tasks目錄的哪些bb文件。然后在這些bb文件中找一個合適的位置加入your_bb。
假設映像依賴task-base.bb,你只要在task-base.bb中的
RDEPENDS_task-base = "\
下增加一行your_bb就可以了。
當然最好找一個與要增加的package比較相近的bb文件和任務。例如在poky中我在task-poky.bb
RDEPENDS_task-poky-apps-x11-core = "\
中增加我的package。
假設你修改了task-base.bb,只要重新bitbake 這個bb文件再bitbake 映像就可以了。
18 如何在bb文件中使用bash編程
例如:
pkg_postinst_dpkg () {
#!/bin/sh
if [ "x$D" != "x" ]; then
install -d $D/${sysconfdir}/rcS.d
# this happens at S98 where our good 'ole packages script used to run
echo -e "#!/bin/sh
dpkg --configure -a
rm -f /${sysconfdir}/rcS.d/S${DPKG_INIT_POSITION}configure
" > ${IMAGE_ROOTFS}/${sysconfdir}/rcS.d/S${DPKG_INIT_POSITION}configure
chmod 0755 $D/${sysconfdir}/rcS.d/S${DPKG_INIT_POSITION}configure
fi
}
19 變量賦值和引號:
所有的變量賦值時,內容要用雙引號括起來。(如果不用可能現在能工作,但后面就不一定能工作
了)
VAR1 = "${OTHERVAR}"
VAR2 = "The version is ${PV}"
20 變量值追加(有空格):+=
你可以給已經有值的變量使用符號“+=”追加一個值。注意這個操作會在原值和你追加的值中間添
上空格:
SRC_URI += "file://fix-makefile.patch;patch=1"
變量值前加:=+
你可以給已有值的變量內容前面加上一個值,使用符號"=+".注意這個操作會在原值和你追加的值中間添
上空格:
VAR =+ "Starts"
變量值追加:_append方式
你可以使用_append方式來給一個已經存在的變量追加值,跟+=不一樣的是這種方式不會在原值和
你要追加的值中間加上空格。下面的例子中自己添上了空格,這樣就不會跟原來的值直接合在一起。
SRC_URI_append = " file://fix-makefile.patch;patch=1"
_append方式也可以用來覆蓋某個值,但是僅僅是在指定目標機器和平台的時候有用:
SRC_URI_append_sh4 = " file://fix-makefile.patch;patch=1"
你可以把追加符理解為變量自己本身。所以+=和=+符號可以和_append一起來使用,比如:
SRC_URI_append = " file://fix-makefile.patch;patch=1"
SRC_URI_append += "file://fix-install.patch;patch=1"
變量值前加:_prepend 方式
使用_prepend在已有的變量前面加上一個值。和_apend一樣,這里_prepend和=+的區別就是沒有
空格。
例如:CFLAGS_prepend = "-I${S}/myincludes "
同樣在指定機器名的時候_prepend也是覆蓋的意思。如:
CFLAGS_prepend_sh4 = " file://fix-makefile.patch;patch=1"
同樣_prepend也可以和+=,=+一起來使用,例如:
CFLAGS_prepend = "-I${S}/myincludes "
CFLAGS_prepend += "-I${S}/myincludes2 "
空格和制表符
縮進應該使用空格,而不是制表符。所以說現在制表符也可以工作,但是OE只是承諾過支持空格。
代碼風格:oe-stylize.py
為了幫助你在“配方“中使用正確的(譯者注:標准的可能更合適些)格式,oe在contrib目錄里
提供了一個oe-stylize.py腳本,使用它你可以把你的“配方”格式化成標准的格式.運行腳本的
時候會輸出一些警告信息,你需要手動把這些刪除.
contrib/oe-stylize.py myrecipe.bb > fixed-recipe.bb
vi fixed-recipe.bb
mv fixed.recipe.bb myrecipe.bb
使用python的高級操作:${@...}
為了獲取更高級的功能,你可以使用python語句,比如變量替換和搜索。
Python語句在聲明變量之前要添加@符號。
CXXFLAGS := "${@'${CXXFLAGS}'.replace('-frename-registers', '')}"
21 sysroot目錄是存放中間過程的頭文件和庫等。用於其他包編譯所需的依賴。
22 The BBCLASSEXTEND = "native" says this package can be built both as a native host package, as well as a target package.
| rm: cannot remove `/usr/share/man/man1/ldd.1.gz': Permission denied | rm: cannot remove `/usr/share/man/man1/time.1.gz': Permission denied | rm: cannot remove `/usr/share/man/man2/_Exit.2.gz': Permission denied | rm: cannot remove `/usr/share/man/man2/__clone2.2.gz': Permission denied | rm: cannot remove `/usr/share/man/man2/_exit.2.gz': Permission denied ...... 解決辦法是增加了MANDIR do_compile() { oe_runmake -f Makefile DESTDIR=${D} MANDIR=${D}${mandir} } 24 有這樣的問題: do_configure (){ ${S}/configure } do_compile (){ oe_runmake -f Makefile mandir=${D}${mandir} } fakeroot do_install(){ mkdir -p ${D}/usr/local/man/man1 mkdir -p ${D}/usr/local/man/man5 mkdir -p ${D}/usr/local/man/man7 oe_runmake install DESTDIR=${D} } NOTE: make install DESTDIR=/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/image make[1]: Entering directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4' make[2]: Entering directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/include' test -d /usr/local/man || /home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/mkinstalldirs /usr/local/man test -d /usr/local/man/man1 || /home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/mkinstalldirs /usr/local/man/man1 mkdir /usr/local/man/man1 mkdir: cannot create directory `/usr/local/man/man1': Permission denied make[2]: [install_man] Error 1 (ignored) test -d /usr/local/man/man5 || /home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/mkinstalldirs /usr/local/man/man5 mkdir /usr/local/man/man5 mkdir: cannot create directory `/usr/local/man/man5': Permission denied make[2]: [install_man] Error 1 (ignored) test -d /usr/local/man/man7 || /home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/mkinstalldirs /usr/local/man/man7 mkdir /usr/local/man/man7 mkdir: cannot create directory `/usr/local/man/man7': Permission denied make[2]: [install_man] Error 1 (ignored) make[2]: Leaving directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/include' make[2]: Entering directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/libs/libgroff' make[2]: Leaving directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/libs/libgroff' make[2]: Entering directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/libs/libdriver' make[2]: Leaving directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/libs/libdriver' make[2]: Entering directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/libs/libbib' make[2]: Leaving directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/libs/libbib' make[2]: Entering directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/roff/groff' test -d /usr/local/bin || /home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/mkinstalldirs /usr/local/bin rm -f /usr/local/bin/groff /usr/bin/install -c groff /usr/local/bin/groff /usr/bin/install: cannot create regular file `/usr/local/bin/groff': Permission denied make[2]: *** [install_prog] Error 1 make[2]: Leaving directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4/src/roff/groff' make[1]: *** [src/roff/groff] Error 2 make[1]: Leaving directory `/home/yxfyanxiaofengyxf/mydata/poky/green-3.3/build/tmp/work/i586-poky-linux/groff-1.18.1.4-r0/groff-1.18.1.4' make: *** [install] Error 2 FATAL: oe_runmake failed ERROR: Function do_install failed 這個問題是這樣解決的 do_configure (){ mkdir -p ${D}/usr/local ${S}/configure --prefix=${D}/usr/local } do_compile (){ oe_runmake -f Makefile mandir=${D}${mandir} } fakeroot do_install(){ mkdir -p ${D}/usr/local/man/man1 mkdir -p ${D}/usr/local/man/man5 mkdir -p ${D}/usr/local/man/man7 oe_runmake install DESTDIR=${D} } 25 ipk的包的形成是怎么形成的,貌似自動install的好多文件沒有打進ipk包中。不知道這個問題怎么解決。 目前暫時解決的辦法,${PN}-locale的包默認貌似沒有打進image中。如果想要把想要的東西打進image中可以 這樣做: FILES_${PN} += "${datadir}/locale" 26 下列是一些重要變量的值。 ${datadir}=/usr/share ${sysconfdir}=/etc sharedstatedir = /com ${STAGING_DIR_HOST} = sysroot --host=${BUILD_SYS} TARGET_ARCH 27 如何定義自己的目錄變量 PC$vim conf/bitbake.conf 在合適的位置上添加自己的變量。 28 _prepend和_append注意家空格。 29 do_postinst_${PN}(){ 裝載后進行的動作,包的內容可用 } do_preinst_${PN}(){ 裝載前進行的動作,包的內容不可用。 } do_prerm_${PN}(){ 卸載前進行的動作,包的內容可用 } do_postrm_${PN}(){ 卸載后進行的動作,包的內容不可用。 } 30 對於patch問題,貌似只有在 PC$bitbake packagename -c devshell PC$quilt new xxx.patch PC$quilt add file PC$quilt refresh 這樣形成的patch,才能夠先這樣運用 file://xxx.patch;patch=1 其他只能用do_configure_prepend(){}中實現。 31 doc locale 形成的ipk包貌似不會默認打入image.這個開關在哪里還需調查。 32 如何用gcc的參數定義一個宏的字符串 gcc -DVAR='"hello"' 注意單雙引號的用法,先單好在雙號。 33 EXTRA_OEMAKE = "CC='${CC}'"有時候在編譯的過程中會出現錯誤。可以用這個選項。 34 a patch line would be changed from: file://some.patch;patch=1;pnum=2 to: file://some.patch;striplevel=2 and a patch line: file://another.diff;patch=1;pnum=1 could be changed to: file://another.diff 35 ${HOST_ARCH}表示當前的體系結構 ${BUILD_ARCH} 36 LIC_FILES_CHKSUM = "file://README;beginline=5;endline=29;md5=af80f631f3848bd0e9478df399015287" 如何得到校驗和。 將一個錯誤的校驗和放在md5=xxx 在運行bitbake man-pages 的時候回報錯,並返回一個正確的校驗值。 37 update-alternatives --install ${bindir}/last last last.${PN} 200 這句話的意思是:先install last,然后mv last last.${PN},然后ln -s last.${PN} last. 200是優先級貌似越大優先級越高。 38 PARALLEL_MAKE = "" 當你看到並行編譯的時候出現了問題,但是log里卻沒有錯誤,可是又編譯不過去,那么就用上面的變量加入PARALLEL_MAKE = "-j 1"不讓並行編譯。 39 如果在編譯的過程中,出現了這樣的提示; No rule to make target "aaa", needed by `bbb`. Stop 一般出的問題是由於你的bbb 需要用到你的aaa, 而makefile中你的aaa的路徑是錯誤的。 把aaa的路徑修改為正確的路徑就OK了。 還有一種可能就是在編譯bbb的時候需要 aaa,但是卻沒有aaa這個庫文件。解決的辦法就是,就是先編譯這個庫文件。 do_compile_prepend(){ if [ -d tools ];then make -C tools/gnulib/lib fi } 40 如果在鏈表中增加了包,比如在poky-iamge-lsb的情況下。 你需要增加這些步驟 PC#bitbake task-poky-lsb -c clean PC#bitbake poky-image-lsb -c clean PC#rm sstate-contorl/sstate-package-name PC#bitbake poky-image-lsb 41 放送patch 1. install the msmtp PC#sudo apt-get install msmtp 2. create the msmtp config file like PC#vim /home/yan/.msmtprc: tls on tls_certcheck off tls_starttls on port 25 host prod-webmail.windriver.com from xiaofeng.yan@windriver.com auth on user xyan password !yan1223 3. You can double check if /usr/sbin/sendmail links to msmtp, If not, just link it PC# sudo ln -sf `which msmtp` /usr/sbin/sendmail 42 bitbake eglibc -e 看打包時,eglibc里的變量的值,比如PACKAGE 43 bitbake -b qt-x11-free-native_3.3.5.bb -e | grep ^PROVIDES bitbake -b qt-x11-free-native_3.3.5.bb -e | grep ^PN 44 提供者的錯誤解決。 NOTE: Resolving any missing task queue dependencies ERROR: Nothing RPROVIDES 'gtk+-demo' (but /buildarea/yxf/poky.gtk_direectfb/meta/recipes-graphics/tasks/task-gtk-directfb.bb RDEPENDS on or otherwise requires it) NOTE: Runtime target 'gtk+-demo' is unbuildable, removing... Missing or unbuildable dependency chain was: ['gtk+-demo'] ERROR: Required build target 'core-image-gtk-directfb' has no buildable providers. 這個就是說,沒有找到gtk+-demo這個包的提供者。 $vi meta/recipes-gnome/gtk+/gtk+.inc 加入下面的語句 PACKAGES += "libgail gtk+-demo" FILES_gtk+-demo = " \ ${datadir}/gtk-2.0/demo/* \ ${bindir}/gtk-demo \ " 其實,bitbake提供者就是看PACKAGES里定義的包的名字。