yocto添加層簡介


yocto系統為我們提供了很好的制作嵌入式linux基礎鏡像的途徑,yocto默認采用分層結構來組織所有的軟件包。下面介紹一下如何在yocto上創建一個層以及如何使用該層。我們的目標是向linux內核源代碼打patch,我們不希望去修改yocto目前已有的層,我們自己創建一個層來實現對linux內核打patch的工作,這樣即使yocto的linux內核層在以后的版本中出現變更也不會影響到我們自己創建的層。

1、生成linux patch文件。作為例子我們向linux內核的init/calibrate.c文件中添加開機啟動打印信息,具體patch文件如下:

diff --git a/init/calibrate.c b/init/calibrate.c
index fda0a7b..01e3a5f 100644
--- a/init/calibrate.c
+++ b/init/calibrate.c
@@ -265,6 +265,12 @@ void __cpuinit calibrate_delay(void)
        static bool printed;
        int this_cpu = smp_processor_id();
 
+       printk("*************************************\n");
+       printk("*                                   *\n");
+       printk("*        HELLO YOCTO KERNEL         *\n");
+       printk("*                                   *\n");
+       printk("*************************************\n");
+
        if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
                lpj = per_cpu(cpu_loops_per_jiffy, this_cpu);
                if (!printed)
該patch名稱為0001-calibrate-Add-printk-example.patch。

2、在poky同級目錄下創建一個新目錄meta-mylayer,並且在該目錄下生成conf, recipes-kernel/linux/linux-yocto目錄結構;

3、在meta-mylayer/conf目錄下創建新層的配置文件layer.conf,layer.conf的具體內容如下:

# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
            ${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "mylayer"
BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
BBFILE_PRIORITY_mylayer = "5"

4、在meta-mylayer/recipes-kernel/linux/目錄下生成linux-yocto_3.10.bbappend文件,該文件用於通知bitbake有新的內容要加載到linux-yocto編譯過程中,具體linux-yocto_3.10.bbappend文件內容如下:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://0001-calibrate-Add-printk-example.patch"

5、將生成的.patch文件放在meta-mylayer/recipes-kernel/linux/linux-yocto/目錄下;

到此,新建的層已經完畢。該層的具體目錄結構如下:

meta-mylayer/
├── conf
│   └── layer.conf
└── recipes-kernel
    └── linux
        ├── linux-yocto
        │   └── 0001-calibrate-Add-printk-example.patch
        └── linux-yocto_3.10.bbappend
6、使能新加入的層。修改build/conf/bblayer.conf文件,將新加入的層添加到bblayer.conf文件中,即:

BBLAYERS += " ${BSPDIR}/sources/meta-mylayer"

7、重新編譯打patch的源代碼包。

    # bitbake -c cleansstate linux-yocto

    # bitbake -k linux-yocto

8、驗證打patch后的內核。

    # runqemu qemux86

    # dmesg | less

到此,在yocto上如何添加一層介紹完畢。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM