Yocto - bb脚本中使用的SRC_URI、SRCREV和S

我们遇到的各种自己不了解的技术或产品时,都需要阅读用户手册。用户手册里的内容很多时,除了由目录组织文档结构外,通常还有有一个词汇表,一般作为附录放在文档最后。

通过这个按照字母排序的词汇表,可以在对整个文档还不够了解的情况下,快速的定位到自己需要的内容。

比如,我们打开Yocto的manual:Welcome to the Yocto Project Documentation — The Yocto Project ® 4.3.999 documentation

在左侧列表中找到“Reference Manual”,点开,在展开的列表中,继续选择“12 Variables Glossary”,上方点击首字母S,在下方页面中搜索到SRI_URI。

然后就可以得到关于SRI_URI的有用介绍:

See the BitBake manual for the initial description for this variable: SRC_URI.

有关该变量的初始描述,请参阅 BitBake 手册: SRC_URI。

所以,这个变量是用于BitBake的,它会识别和使用这个变量。你在bb脚本中设置这个变量,bitbake在构建时使用。

Bitbake关于此变量的说明的链接:

5 Variables Glossary — Bitbake dev documentation

SRC_URI

源文件列表 - 本地或远程。这个变量告诉 BitBake 在编译时要提取哪些文件,以及如何提取。例如,如果配方或附加文件需要从互联网上获取一个 tar 包,配方或附加文件就会使用 SRC_URI 条目指定该 tar 包。另一方面,如果配方或附加文件需要获取一个压缩包、应用两个补丁并包含一个自定义文件,则配方或附加文件需要一个 SRC_URI 变量来指定所有这些来源。

The list of source files — local or remote. This variable tells BitBake which bits to pull for the build and how to pull them. For example, if the recipe or append file needs to fetch a single tarball from the Internet, the recipe or append file uses a SRC_URI entry that specifies that tarball. On the other hand, if the recipe or append file needs to fetch a tarball, apply two patches, and include a custom file, the recipe or append file needs an SRC_URI variable that specifies all those sources.

下面的列表解释了可用的 URI 协议。URI 协议高度依赖于特定的 BitBake Fetcher 子模块。根据 BitBake 使用的撷取器,会使用不同的 URL 参数。有关所支持的提取器的详细信息,请参阅提取器部分。

The following list explains the available URI protocols. URI protocols are highly dependent on particular BitBake Fetcher submodules. Depending on the fetcher BitBake uses, various URL parameters are employed. For specifics on the supported Fetchers, see the Fetchers section.

* az://: Fetches files from an Azure Storage account using HTTPS.

* bzr://: Fetches files from a Bazaar revision control repository.

* ccrc://: Fetches files from a ClearCase repository.

* cvs://: Fetches files from a CVS revision control repository.

* file://: Fetches files, which are usually files shipped with the Metadata, from the local machine. The path is relative to the FILESPATH variable. Thus, the build system searches, in order, from the following directories, which are assumed to be a subdirectories of the directory in which the recipe file (.bb) or append file (.bbappend) resides:

    * ${BPN}: the base recipe name without any special suffix or version numbers.

    * ${BP} - ${BPN}-${PV}: the base recipe name and version but without any special package name suffix.

    * files: files within a directory, which is named files and is also alongside the recipe or append file.

* ftp://: Fetches files from the Internet using FTP.

* git://: Fetches files from a Git revision control repository.

* gitsm://: Fetches submodules from a Git revision control repository.

* hg://: Fetches files from a Mercurial (hg) revision control repository.

* http://: Fetches files from the Internet using HTTP.

* https://: Fetches files from the Internet using HTTPS.

* npm://: Fetches JavaScript modules from a registry.

* osc://: Fetches files from an OSC (OpenSUSE Build service) revision control repository.

* p4://: Fetches files from a Perforce (p4) revision control repository.

* repo://: Fetches files from a repo (Git) repository.

* ssh://: Fetches files from a secure shell.

* svn://: Fetches files from a Subversion (svn) revision control repository.

这里还有一些值得一提的选项:

Here are some additional options worth mentioning:

  • downloadfilename:指定存储下载文件时使用的文件名。

  • name:在 SRC_URI 中指定多个文件或 git 仓库时,用于识别与 SRC_URI 校验和或 SRCREV 关联的名称。例如

SRC_URI = "git://example.com/foo.git;branch=main;name=first \

           git://example.com/bar.git;branch=main;name=second \

           http://example.com/file.tar.gz;name=third"

SRCREV_first = "f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"

SRCREV_second = "e242ed3bffccdf271b7fbaf34ed72d089537b42f"

SRC_URI[third.sha256sum] = "13550350a8681c84c861aac2e5b440161c2b33a3e4f302ac680ca5b686de48de"

  • subdir: 将文件(或提取其内容)放入指定的子目录。该选项对于不常见的 tar 包或其他存档文件很有用,因为这些存档中的文件可能没预先放在一个子目录中。

  • subpath: 在使用 Git fetcher 时,将checkout代码仓库的树状文件结构的一部分。如果不设置subpath,也可以在设置S变量时指定使用git代码仓库的某个子目录。

  • unpack: 如果文件是存档格式,控制是否解压缩。默认操作是解压文件。=1是解压,=0是不解压。

SRCREV

12 Variables Glossary — The Yocto Project ® 4.3.999 documentation

用于构建软件包的源代码的修订版本。此变量仅适用于 Subversion、Git、Mercurial 和 Bazaar。如果你想构建一个固定的修订版本,又想避免每次 BitBake 解析你的配方时都在远程版本库中执行查询,你应该指定一个完整修订版本标识符的 SRCREV,而不仅仅是一个标签。

The revision of the source code used to build the package. This variable applies only when using Subversion, Git, Mercurial and Bazaar. If you want to build a fixed revision and you want to avoid performing a query on the remote repository every time BitBake parses your recipe, you should specify a SRCREV that is a full revision identifier and not just a tag.

S

12 Variables Glossary — The Yocto Project ® 4.3.999 documentation

已解压缩的配方要用的源代码,其所在构建目录中的位置。默认情况下,该目录为 ${WORKDIR}/${BPN}-${PV},其中 ${BPN} 是基本配方名称,${PV} 是配方版本。如果源代码压缩包将代码提取到 ${BPN}-${PV} 以外的目录,或者源代码是从 Git 或 Subversion 等 SCM 获取的,则必须在配方中设置 S,以便 OpenEmbedded 构建系统知道在哪里可以找到已解压的源代码。

The location in the Build Directory where unpacked recipe source code resides. By default, this directory is ${WORKDIR}/${BPN}-${PV}, where ${BPN} is the base recipe name and ${PV} is the recipe version. If the source tarball extracts the code to a directory named anything other than ${BPN}-${PV}, or if the source code is fetched from an SCM such as Git or Subversion, then you must set S in the recipe so that the OpenEmbedded build system knows where to find the unpacked source.

举例来说,假设源代码目录的顶级文件夹名为 poky,默认的编译目录为 poky/build。在这种情况下,构建系统用来保存名为db的配方的解压文件的工作目录如下:

As an example, assume a Source Directory top-level folder named poky and a default Build Directory at poky/build. In this case, the work directory the build system uses to keep the unpacked recipe for db is the following:

poky/build/tmp/work/qemux86-poky-linux/db/5.1.19-r3/db-5.1.19

解压后的源代码位于 db-5.1.19 文件夹中。

下一个示例假设有一个 Git 仓库。默认情况下,Git 仓库会在 do_fetch 过程中克隆到 ${WORKDIR}/git。由于该路径与默认值 S 不同,因此必须特别设置,以便找到源代码:

The unpacked source code resides in the db-5.1.19 folder.

This next example assumes a Git repository. By default, Git repositories are cloned to ${WORKDIR}/git during do_fetch. Since this path is different from the default value of S, you must set it specifically so the source can be located:

SRC_URI = "git://path/to/repo.git;branch=main"

S = "${WORKDIR}/git"

FETCHERS

4 File Download Support — Bitbake dev documentation

4.3 Fetchers

如前所述,URL 前缀决定了 BitBake 使用哪个提取子模块。每个子模块可以支持不同的 URL 参数,下面将对此进行介绍。

As mentioned earlier, the URL prefix determines which fetcher submodule BitBake uses. Each submodule can support different URL parameters, which are described in the following sections.

4.3.1 Local file fetcher (file://)   #本地文件提取器

该子模块处理以 file:// 开头的 URL。在 URL 中指定的文件名可以是文件的绝对路径,也可以是相对路径。如果文件名是相对路径,则使用 FILESPATH 变量的内容,与 PATH 用于查找可执行文件的方式相同。如果找不到文件,则假定在调用download()方法时,文件在 DL_DIR 中可用。

This submodule handles URLs that begin with file://. The filename you specify within the URL can be either an absolute or relative path to a file. If the filename is relative, the contents of the FILESPATH variable is used in the same way PATH is used to find executables. If the file cannot be found, it is assumed that it is available in DL_DIR by the time the download() method is called.

如果指定一个目录,则整个目录都会被解压缩。

下面是几个 URL 示例,第一个是相对 URL,第二个是绝对 URL:

If you specify a directory, the entire directory is unpacked.

Here are a couple of example URLs, the first relative and the second absolute:

SRC_URI = "file://relativefile.patch"

SRC_URI = "file:///Users/ich/very_important_software"

4.3.5 Git Fetcher (git://)   #Git仓库提取器

这个提取子模块从 Git 源代码控制系统中取回代码。提取器的工作原理是在 GITDIR(通常是 DL_DIR/git2)中创建一个远程的裸克隆。然后从裸克隆中再clone到工作目录,也就是checkout一个特定的tree,解压到工作目录。这样做是为了尽量减少磁盘上的重复数据量,并使解包过程更快。使用的可执行文件可通过 FETCHCMD_git 设置。

This fetcher submodule fetches code from the Git source control system. The fetcher works by creating a bare clone of the remote into GITDIR, which is usually DL_DIR/git2. This bare clone is then cloned into the work directory during the unpack stage when a specific tree is checked out. This is done using alternates and by reference to minimize the amount of duplicate data on the disk and make the unpack process fast. The executable used can be set with FETCHCMD_git.

此提取器支持的参数如下:

  • “protocol”: The protocol used to fetch the files. The default is “git” when a hostname is set. If a hostname is not set, the Git protocol is “file”. You can also use “http”, “https”, “ssh” and “rsync”.

  • “nocheckout”: Tells the fetcher to not checkout source code when unpacking when set to “1”. Set this option for the URL where there is a custom routine to checkout code. The default is “0”.

  • “rebaseable”: Indicates that the upstream Git repository can be rebased. You should set this parameter to “1” if revisions can become detached from branches. In this case, the source mirror tarball is done per revision, which has a loss of efficiency. Rebasing the upstream Git repository could cause the current revision to disappear from the upstream repository. This option reminds the fetcher to preserve the local cache carefully for future use. The default value for this parameter is “0”.

  • “nobranch”: Tells the fetcher to not check the SHA validation for the branch when set to “1”. The default is “0”. Set this option for the recipe that refers to the commit that is valid for any namespace (branch, tag, …) instead of the branch.

  • “bareclone”: Tells the fetcher to clone a bare clone into the destination directory without checking out a working tree. Only the raw Git metadata is provided. This parameter implies the “nocheckout” parameter as well.

  • “branch”: The branch(es) of the Git tree to clone. Unless “nobranch” is set to “1”, this is a mandatory parameter. The number of branch parameters must match the number of name parameters.

  • “rev”: The revision to use for the checkout. The default is “master”.

  • “tag”: Specifies a tag to use for the checkout. To correctly resolve tags, BitBake must access the network. For that reason, tags are often not used. As far as Git is concerned, the “tag” parameter behaves effectively the same as the “rev” parameter.

  • “subpath”: Limits the checkout to a specific subpath of the tree. By default, the whole tree is checked out.

  • “destsuffix”: The name of the path in which to place the checkout. By default, the path is git/.

  • “usehead”: Enables local git:// URLs to use the current branch HEAD as the revision for use with AUTOREV. The “usehead” parameter implies no branch and only works when the transfer protocol is file://.

注意:

在使用protocol参数时,当协议为 "ssh "时,SRC_URI中的预期URL 与通常传递给 git clone 命令的不同,后者是由 Git 服务器提供的URL来提取内容的。例如,通过 SSH 克隆时,GitLab 服务器返回的 mesa 的 URL 是 git@gitlab.freedesktop.org:mesa/mesa.git,但 SRC_URI 中的预期 URL 却如下:

SRC_URI = "git://git@gitlab.freedesktop.org/mesa/mesa.git;branch=main;protocol=ssh;..."

注意项目路径前的:字符改为/。

一些URL的例子如下:

SRC_URI = "git://github.com/fronteed/icheck.git;protocol=https;branch=${PV};tag=${PV}"

SRC_URI = "git://github.com/asciidoc/asciidoc-py;protocol=https;branch=main"

SRC_URI = "git://git@gitlab.freedesktop.org/mesa/mesa.git;branch=main;protocol=ssh;..."

当使用 git 作为软件主源代码的获取器时,应相应地设置 S:

S = "${WORKDIR}/git"

注意:

不支持在 git:// urls 中直接指定密码。原因有几个: SRC_URI 通常会被写入日志或其他地方,这很容易泄露密码;而且不删除密码的话,会导致元数据共享太容易。可以使用 SSH 密钥、~/.netrc 和 ~/.ssh/config 文件作为替代。

在 git fetcher 中使用标签可能会导致令人惊讶的行为。Bitbake 需要将标签解析到特定版本,为此必须连接并使用上游版本库(upstream repository)。这是因为标签(tag)指向的版本(revision)可能会发生变化,我们曾在著名的公共软件源中看到过这种情况。这可能意味着网络连接比预期的要多得多,而且每次构建时都要重新解析配方。源镜像(Source mirrors)也会被绕过,因为上游版本库是准确解析版本的唯一真实来源。出于这些原因,虽然提取器可以支持标签,但我们还是建议在配方中具体指定修订版本。

联合起来使用

通过上面的介绍,在bb文件中通过这些变量来获取需要构建的目标文件的源代码。

比如,项目里通常会使用git协议来获取源代码。而在本地调试时,可以修改称本地路径。

第一种:

SRC_URI = "git://git@github.com:7999/platform/projectname.git;protocol=ssh;nobranch=1"

SRCREV = "c3f56703e58af33dbf808f903de694bcde3269cd"

S = "${WORKDIR}/git"

第二种:

SRC_URI = "file://${TOPDIR}/../../projectname"

S = "${WORKDIR}/${TOPDIR}/../../projectname"

这里用到了${TOPDIR}。

(结束)

<think>好的,我需要回答用户关于高通平台使用Yocto项目的教程构建系统的询问。首先,我得回顾用户提供的引用内容,特别是引用1、2、3中的相关信息。 引用1提到高通Yocto项目通过BSP支持嵌入式开发,适合不同层次的开发者。引用2详细说明了Yocto项目的作用,以及高通等厂商如何利用它来扩展生态。引用3则涉及Yocto构建系统的配方文件管理网络更新方法。这些引用为我提供了基础信息,比如BSP支持、BitBake工具的使用以及配方文件的管理。 接下来,我需要整理一个结构清晰的教程步骤。用户需要的是具体的构建流程,所以应该分步骤说明环境配置、获取BSP层、配置构建目录、定制镜像、构建系统、部署镜像等环节。同时,根据引用3的内容,要包括如何管理配方更新内核的方法。 需要确保每个步骤中的命令操作正确无误,并且符合Yocto的标准流程。例如,初始化构建环境时,通常使用`source`命令导入环境脚本。获取高通BSP层可能需要通过Git仓库,如引用3中提到的配方文件管理,可能需要使用`git clone`命令。 另外,用户可能需要了解如何定制镜像,比如修改本地配置文件`local.conf`,添加所需的软件包。构建过程中的`bitbake`命令是关键,需要正确指定目标镜像,比如`core-image-minimal`。 部署部分,可能需要将生成的镜像烧录到设备,这涉及到具体的硬件操作,但用户可能只需要生成镜像文件的路径,如`tmp/deploy/images/`目录下的内容。 在常见问题部分,应该涵盖构建失败的可能原因、如何加快构建速度、更新BSP层的方法,以及如何添加自定义软件包,这些内容能帮助用户解决实际遇到的问题。 最后,根据引用2提到的分层管理策略,需要解释层(Layer)的概念,说明如何通过`bitbake-layers`命令管理层的结构,确保用户理解如何组织自己的配方配置。 需要确保所有技术术语步骤描述准确,避免错误。同时,使用中文回答,保持语言自然流畅,结构清晰,分步骤说明,并在适当的地方添加引用标记,如引用1、2、3中的相关内容。 可能还需要验证一些命令的正确性,比如`bitbake-layers show-recipes`是否正确,以及高通BSP层的具体名称仓库地址是否正确。由于用户提供的信息中没有具体的仓库URL,可能需要假设常用的高通开源资源位置,或建议用户参考高通官方文档。 总结下来,回答的结构应该是教程步骤分点展开,每个步骤包含必要的命令说明,然后列出常见问题及解决方法,最后相关问题部分引导用户深入了解更多细节。确保所有LaTeX格式正确,如独立公式使用`$$...$$`,行内公式用`$...$`,但在这个问题中可能涉及较少数学公式,更多是代码块命令行的展示。</think>### 高通平台使用Yocto项目的构建系统教程 #### 1. 环境配置 首先需要搭建Yocto项目的基础环境,包括安装依赖包配置工作目录: ```bash sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev mkdir ~/yocto-qualcomm && cd ~/yocto-qualcomm git clone git://git.yoctoproject.org/poky -b kirkstone # 以Yocto 4.0版本为例 ``` #### 2. 获取高通BSP层 高通的Yocto支持通过BSP(Board Support Package)层实现,通常以`meta-qcom`命名: ```bash git clone https://git.code.sf.net/p/yocto/meta-qcom # 示例仓库地址 ``` 注:具体仓库需参考高通官方文档,部分平台(如Snapdragon)可能提供专有层[^1][^2]。 #### 3. 初始化构建环境 ```bash cd poky source oe-init-build-env ../build # 创建构建目录 ``` 此时会生成`conf/local.conf``conf/bblayers.conf`配置文件。 #### 4. 配置层依赖 修改`conf/bblayers.conf`,添加高通BSP层路径: ```python BBLAYERS += " ${TOPDIR}/../meta-qcom " ``` 通过命令验证层结构: ```bash bitbake-layers show-layers # 显示已加载层[^3] ``` #### 5. 选择目标设备 在`conf/local.conf`中指定目标机器型号,例如: ```makefile MACHINE = "qcom-apq8016" # 以骁龙410处理器为例 ``` #### 6. 构建基础镜像 执行核心构建命令: ```bash bitbake core-image-minimal # 构建最小化系统镜像 ``` 完整桌面系统可替换为`core-image-sato`。 #### 7. 部署输出文件 生成的镜像位于: ``` tmp/deploy/images/qcom-apq8016/core-image-minimal-qcom-apq8016.wic ``` 可通过`dd`命令或高通专用工具烧录到设备。 --- ### 关键组件解析 | 组件 | 功能说明 | 高通平台扩展 | |---------------|----------------------------------|---------------------------| | BitBake | 任务执行引擎,解析配方文件 | 添加`qcom-*.bb`专用配方 | | OpenEmbedded | 提供基础元数据 | 通过BSP层覆盖硬件配置 | | 设备树编译器 | 生成硬件描述文件 | 包含骁龙系列DTS文件 | --- ### 常见问题解决 1. **构建失败提示依赖缺失** 检查`meta-qcom`层是否完整克隆,并验证`BBLAYERS`路径配置。 2. **加速构建过程** 在`local.conf`中启用并行编译下载缓存: ```makefile BB_NUMBER_THREADS = "8" PARALLEL_MAKE = "-j 8" SSTATE_DIR ?= "/home/share/sstate-cache" ``` 3. **更新内核版本** 修改内核配方文件: ```bash vi ../meta-qcom/recipes-kernel/linux/linux-yocto_%.bbappend ``` 修改`SRCREV`字段为新的提交哈希。 4. **添加自定义软件包** 创建新的配方文件: ```bash vi ../meta-custom/recipes-core/package/hello-world_1.0.bb ``` 内容示例: ```python DESCRIPTION = "Custom application" LICENSE = "MIT" SRC_URI = "file://hello.c" do_compile() { ${CC} ${CFLAGS} ${LDFLAGS} hello.c -o hello } do_install() { install -d ${D}${bindir} install -m 0755 hello ${D}${bindir} } ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值