歡迎
版權所有©2010-2019 Linux基金會
歡迎!這個簡短的文檔通過Yocto Project幫助您一步步構建一個典型鏡像文件,該文件還介紹瞭如何配置特定的硬件構建環境。您將使用Yocto Project構建一個名為Poky的嵌入式OS。
Linux開發環境
確保您的主機滿足以下要求:
- 可用磁盤空間50個GB
- 運行受Yocto Project支持的Linux發行版(即Fedora、openSUSE、CentOS、Debian、Ubuntu的發行版)
- Git 1.8.3.1或更高
- tar 1.27或更高版本
- Python 3.4.0或更高版本
安裝必要的環境
您必須在主機上安裝必要的安裝包。下面的命令基於Ubuntu環境:
$ sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib \
build-essential chrpath socat cpio python python3 python3-pip python3-pexpect \
xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \
xterm
使用Git克隆Poky
完成上述安裝後,您需要從Poky的倉庫中克隆到本地,執行下面的命令:
$ git clone git://git.yoctoproject.org/poky
Cloning into 'poky'...
remote: Counting objects: 432160, done.
remote: Compressing objects: 100% (102056/102056), done.
remote: Total 432160 (delta 323116), reused 432037 (delta 323000)
Receiving objects: 100% (432160/432160), 153.81 MiB | 8.54 MiB/s, done.
Resolving deltas: 100% (323116/323116), done.
Checking connectivity... done.
移動到poky目錄,並看看標籤:
$ cd poky
$ git fetch --tags
$ git tag
1.1_M1.final
1.1_M1.rc1
1.1_M1.rc2
1.1_M2.final
1.1_M2.rc1
.
.
.
yocto-2.5
yocto-2.5.1
yocto-2.5.2
yocto-2.6
yocto-2.6.1
yocto-2.6.2
yocto-2.7
yocto_1.5_M5.rc8
在這個例子中,檢查出的分支是基於yocto-2.7版本:
$ git checkout tags/yocto-2.7 -b my-yocto-2.7
Switched to a new branch 'my-yocto-2.7'
以前的Git的checkout命令創建一個本地分支名為my-yocto-2.7。在該分支提供給您的文件正是在Yocto計劃yocto-2.7版本發佈時的資料庫中的文件相匹配的“warrior”的開發分支。
構建軟件包
使用下面的步驟來建立軟件包。構建過程創建整個Linux發行版,其中包括工具鏈、源文件。
初始化構建環境:
從poky目錄中,運行 oe-init-build-env
$ cd ~/poky
$ source oe-init-build-env
You had no conf/local.conf file. This configuration file has therefore been
created for you with some default values. You may wish to edit it to, for
example, select a different MACHINE (target hardware). See conf/local.conf
for more information as common configuration options are commented.
You had no conf/bblayers.conf file. This configuration file has therefore been
created for you with some default values. To add additional metadata layers
into your configuration please add entries to conf/bblayers.conf.
The Yocto Project has extensive documentation about OE including a reference
manual which can be found at:
http://yoctoproject.org/documentation
For more information about OpenEmbedded see their website:
http://www.openembedded.org/
### Shell environment set up for builds. ###
You can now run 'bitbake <target>'/<target>
Common targets are:
core-image-minimal
core-image-sato
meta-toolchain
meta-ide-support
You can also run generated qemu images with a command like 'runqemu qemux86'
除此之外,該腳本將創建build目錄,腳本運行後,您的當前工作目錄設置為bulid目錄。之後初始化完成後,build目錄包含初始化過程中創建的所有文件。
檢查您的本地配置文件
當你建立構建環境,build下的子目錄conf裡一個名為local.conf的配置文件變為可用。對於這個例子,默認被設置為建立一個qemux86目標,這是適合於仿真。
開始構建
使用下面命令構建軟件包
$ bitbake core-image-sato
使用QEMU模擬您的軟件包
構建這個軟件包需要很長的時間,取決於計算機運行速度。一旦這個特定的軟件包構建,您就可以開始使用QEMU:
$ runqemu qemux86
退出QEMU
通過在關機圖標單擊或通過Ctrl-C退出QEMU。
自定義生成支持特定硬件的軟件包
到目前為止,所有你做的是迅速建立僅適用於模擬的軟件包。本節將展示如何通過添加硬件層到Yocto Project開發環境來定製你的構建來支持特定的硬件。
Notes
按照慣例,層名稱開頭的字符串“meta-”。
請按照以下步驟添加硬件層:
查找層
已經存在的硬件層有很多。Yocto Project源倉庫有許多硬件層。本示例添加 meta-altera層。
克隆層
使用git複製硬件層到本地,您可以把副本創建再Poky文件夾下:
$ cd ~/poky
$ git clone https://github.com/kraj/meta-altera.git
Cloning into 'meta-altera'...
remote: Counting objects: 25170, done.
remote: Compressing objects: 100% (350/350), done.
remote: Total 25170 (delta 645), reused 719 (delta 538), pack-reused 24219
Receiving objects: 100% (25170/25170), 41.02 MiB | 1.64 MiB/s, done.
Resolving deltas: 100% (13385/13385), done.
Checking connectivity... done.
更改配置以建立一個特定的機器
該機在local.conf檔案變量指定用於構建的計算機。對於此示例,將設備設定為變量“cyclone5”。這些配置用於:https://github.com/kraj/meta-altera/blob/master/conf/machine/cyclone5.conf。
添加圖層的圖層配置文件
在構建過程中使用層之前,您必須將它添加到您的bblayers.conf文件,該文件是在發現 build目錄下
$ cd ~/poky/build
$ bitbake-layers add-layer ../meta-altera
NOTE: Starting bitbake server... Parsingrecipes:100%|######################################| Time: 0:00:32
Parsing of 918 .bb files complete (0 cached, 918 parsed). 1401 targets, 123 skipped, 0 masked, 0 errors.
完成這些步驟後已經添加了 meta-altera 層到您的Yocto Project開發環境,配置並構建"cyclone5"。
構建屬於自己的通用層
也許您需要一個應用程序或一組特定的行為來隔離現有開發環境。您可以通過 bitbake-layers create-layer 命令創建一個通用層. 該工具通過設置帶有layer.conf配置文件的子目錄,包含example.bb菜譜,許可文件和自述文件的recipes-example子目錄,自動創建圖層。
$ cd ~/poky
$ bitbake-layers create-layer meta-mylayer
NOTE: Starting bitbake server...
Add your new layer with 'bitbake-layers add-layer meta-mylayer'layer”
構建時間真的是特別特別特別特別長
閱讀更多 物聯網小生 的文章