在 Yocto 專案中,`bitbake` 是一個關鍵的構建工具,用於根據配置文件和配方(recipes)自動化地構建 Linux 系統映像和軟體包。透過執行 `bitbake` 命令,系統會自動處理下載、編譯和生成的過程。
以下是一些常見的 `bitbake` 命令及其功能:
1. **構建映像或軟體包**:
```bash
bitbake <recipe>
```
例如,構建預設的核心映像:
```bash
bitbake core-image-minimal
```
這將根據配方文件中的規範來構建最小的 Linux 系統映像。
2. **構建特定的軟體包**:
如果您只想構建單獨的軟體包,例如某個應用程式:
```bash
bitbake <package-name>
```
例如,構建 `bash`:
```bash
bitbake bash
```
3. **清除構建結果**:
如果需要清理先前構建的結果,可以使用以下命令:
```bash
bitbake -c clean <recipe>
```
這將清除構建過程中生成的中間文件和輸出。
4. **查看構建過程的詳細日誌**:
如果在構建過程中遇到錯誤,您可以查看詳細的日誌輸出:
```bash
bitbake <recipe> -v
```
5. **列出所有可用的配方**:
若想知道所有可構建的配方,可以使用:
```bash
bitbake-layers show-recipes
```
```
xauth:
meta 1:1.1.2
xbindkeys:
meta-oe 1.8.7
...
```
::: success
在上述輸出中,`xauth` 和 `xbindkeys` 是配方名稱,`meta` 和 `meta-oe` 是它們所屬的層,後面的數字如 `1:1.1.2` 和 `1.8.7` 則代表配方的版本資訊。
:::
6. **列出配方的所有執行的任務**:
要查看特定配方的所有可用任務,可以使用:
```bash
bitbake -c listtasks <recipe>
```
這將列出該配方中定義的所有任務,幫助您了解可執行的操作。
例如,構建 `openssh`:
```bash
bitbake -c listtasks openssh
```
結果:
```shell
NOTE: No setscene tasks
NOTE: Executing Tasks
do_build Default task for a recipe - depends on all other normal tasks required to 'build' a recipe
do_checkuri Validates the SRC_URI value
do_clean Removes all output files for a target
do_cleanall Removes all output files, shared state cache, and downloaded source files for a target
do_cleansstate Removes all output files and shared state cache for a target
do_collect_spdx_deps
do_compile Compiles the source in the compilation directory
do_compile_ptest_base Compiles the runtime test suite included in the software being built
do_configure Configures the source by enabling and disabling any build-time and configuration options for the software being built
do_configure_ptest_base Configures the runtime test suite included in the software being built
```
7. **查看環境變數**:
如果需要檢查特定配方、鏡像的環境變數,可以使用:
```bash
bitbake -e core-image-minimal | grep ^<variable_name>=
```
例如,查看 `PN` 變數:
```bash
bitbake -e core-image-minimal | grep ^IMAGE_INSTALL=
```
結果
```bash
IMAGE_INSTALL="packagegroup-core-boot openssh python3 python3-pip rpi-gpio raspi-gpio "
```
:::info
這個命令會解析整個配方、鏡像 可能會花很多時間才會有輸出,不是電腦當掉
:::
透過熟練運用這些 `bitbake` 命令,您可以更有效地管理和定制 Yocto 專案的構建過程。