Yocto - 如何给配方文件添加源码patch

Yocto - How to patch in a recipe with devtool
Yocto: Modifying, building, deploying and patching a recipe with Yocto devtool
[ Yocto: 使用 Yocto devtool 修改、构建、部署和修补配方  ]
OpenEmbedded 从源代码构建所有内容的一个好处是,对构建的任何内容进行修改都相当容易,但第一次这样做可能有点令人生畏。
作为构建配方的一部分,OE 会创建一个 <output_dir>/tmp/work/<architecture>/<recipe>/<version> 目录,称为 "工作目录"。构建配方的所有工作都在此完成。在这个目录中,你可以找到源代码,通常位于名为 <recipe_name>-<version> 或 "git"(取决于获取源代码的方式)的子目录下。在这里做一些简单的修改,然后重新编译,这是很诱人的做法(过去人们也经常这么做),但有几个原因说明这不是个好主意:
One of the useful things about OpenEmbedded building everything from source is that it's fairly easy to make changes to anything that gets built, but doing so for the first time can be a bit daunting.
As part of building a recipe, OE creates a <output_dir>/tmp/work/<architecture>/<recipe>/<version> directory, known as the "work directory". This is where all of the work done to build a recipe takes place. One of the things you'll find in this directory is the source, usually under a subdirectory named <recipe_name>-<version> or "git" (depending on how the fetched source is provided). The temptation (and what people used to do in the past) is to simply make changes here and then recompile, but there are several reasons why that's not a good idea:
  • 它很笨拙--你必须使用 bitbake -c compile -f 或 bitbake -C compile 来强制重新编译,因为编译系统不知道你做了任何改动
  • 稍有不慎,就很容易丢失修改内容,例如,运行 bitbake -c clean 会抹掉目录
  • It's awkward - you have to use bitbake -c compile -f or bitbake -C compile to force recompilation, since the build system doesn't know that you've made any changes
  • You can easily lose your changes if you're not careful e.g. running bitbake -c clean will wipe the directory out
另外,除了work目录,还有work-shared目录可以存放一些源文件。比如Kernel source就在这个目录里。
幸运的是,如果你使用的是 Fido (1.8) 或更高版本,有一个更好的方法,那就是使用 devtool 命令:
devtool 允许你将一个 Yocto 配方解压缩到本地文件夹中,这样你就可以在其中工作了。
devtool 会创建一个临时层,级别设置为 99,这样它就会覆盖所有其他层。它会检查你的代码,并创建一个 "devtool "分支。
在源文件中添加配方补丁的步骤如下:
Luckily if you're using the Fido (1.8) or later release, there's a much better method using the devtool command:
devtool allows you to extract a Yocto recipe into a local folder so that you can work on it.
devtool creates a temporary layer with level set to 99, so that it overrides all other layers. It checks out your code and creates a ‘devtool’ branch.
Adding a recipe patch to source files can be done using the following steps:
1.  运行 devtool modify <recipe_name>。这将获取配方源代码并解压到工作区目录 (<output_dir>/workspace/sources/<recipe_name>)。如果源代码还不是一个 Git 仓库,它会初始化一个。
在 bitbake 终端运行以下命令,开始基于此配方工作。
From your bitbake terminal, run the following command to start work on a recipe.
Run devtool modify <recipe_name >. This fetches the recipe sources and unpacks them to a workspace directory (<output_dir>/workspace/sources/<recipe_name>). If the source isn’t already a Git repository, it initializes one.
e.g. 
$ devtool modify libusbgx
使用这个命令,会将bb文件中的源码展开,包括SRC_URI中已经添加的Patch文件,也会应用到源码上。
2. 现在检查一下要修改的软件包名称 (PN)。
Now discover the package-name (PN) to be modified.
$ devtool status
NOTE: Starting bitbake server...
libusbgx: /home/workspace/yocto-bsp/build/workspace/sources/libusbgx
3. 对源代码进行所需的修改。您可以编辑代码并提交更改。
Make the desired changes to the source code. You can edit the code and commit changes.
$ cd build/workspace/sources/libusbgx
$ git add .
$ git commit -m "my linux modifications"
4.  运行 devtool build <recipe_name> 或构建包含修改后软件包的整个映像,以测试您所做的更改。
然后运行下面命令构建此配方:
Test your changes by running devtool build <recipe_name> or even building an entire image that incorporates the modified package.
You can then build the recipe by running:
$ devtool build libusbgx
5. 可选择性的使用 devtool deploy-target 在目标机上测试更改。这将把 do_install 安装的文件复制到目标机器上,前提是目标机器有网络访问权限(ssh),而且映像中已经存在所需的依赖项。
你可以使用以下方法部署二进制文件:
Optionally, test the changes on the target using devtool deploy-targe t. This will copy the files installed at do_install over to the target machine assuming it has network access(ssh), and any dependencies are already present in the image.
You can deploy the binaries with:
devtool deploy-target recipe_name root@192.168.1.1
部署使用 SSH,因此需要指定用户名。
The deployment uses SSH, so you need to specify the user name.
6. 你可能需重复修改代码,编译,并测试。直到达到想要的结果。  
Repeat steps 3 / 4 / 5 until you’re satisfied with the results. 
7. 将修改提交到本地 git 仓库后,您可能想将修改作为补丁发布。在使用 git commit 提交改动后,有两个选项可以将改动作为补丁应用。
  • devtool update-recipe <recipe_name> 用于更新原始配方,通常适用于自己的配方或向上游层提交修改的情况。
  • devtool update-recipe -a <layerpath> <recipe_name>以 bbappend 的形式将更改提交给不同层应用。如果您的更改是自定义而非错误修正,这通常是您所需要的方法。
Once you have committed your changes to the local git repository, you may want to publish your changes as a patch. There are two options  to apply your changes as a patch after  commit your changes using git commit.
  • devtool update-recipe <recipe_name> to update the original recipe, usually appropriate if it’s your own recipe or if you’re submitting changes back to the upstream layer.
  • devtool update-recipe -a <layerpath> <recipe_name> to put your changes in the form of a bbappend to be applied by a different layer. This is usually the desired method if your changes are customisations rather than bugfixes.
使用第一种方法,会自动将当前本地git的第一个commit生成patch文件,拷贝到配方的内容目录中,并将文件路径加入到配方文件的SRC_URI中。
但我试验了下,如果配方文件原本还加了其他patch的话,使用这种方法会将其他patch文件都删除,配方文件中的patch条目也删除。然后替换成新生成的这个。
第二种方法的举例:
devtool update-recipe -a /home/nxp/meta-harrier-bsp u-boot-imx
Where,
/home/nxp/meta-harrier-bsp
is the root directory of the layer and
u-boot-imx
is the recipe name.
You’ll then end-up with a .bbappend file created in
home/nxp/meta-harrier-bsp/recipes-bsp/u-boot/u-boot-imx_2018.03.bbappend
8. 还可以手动执行来完成打Patch操作。
代码修改提交完成后,运行以下命令生成patch文件:
$ git format-patch -1
这里的数字 1 表示取最近的一个commit作为patch。可以取多个commit,把1 改为相应的数字即可。
生成patch文件后,将文件拷贝到recipe的内容文件夹。然后将patch文件名加到SRC_URI中,比如:
SRCBRANCH="master"
SRC_URI = "git://github.com/libusbgx/libusbgx.git;branch=${SRCBRANCH};protocol=https \
           file://Update.patch \           
           "
可以调整patch文件的名字,使其易于理解。
在bitbake使用的源码临时构建目录中修改代码并提交代码后,也可以使用上面的方法来创建patch。
9. 如果你已完成配方相关工作,则运行 devtool reset <recipe_name>。
这样会清除workspace中此recipe的相关内容,此时使用bitbake构建此recipe则不再使用workspace中的内容,而是使用临时构建目录中的源码来构建。
If you're finished working on the recipe, run devtool reset <recipe_name>.
devtool reset recipe_name
通过以上操作,就完成了给recipe中的源码加入patch的任务。
这只是 devtool 的功能之一,它还提供了一些强大的工具来帮助你维护配方和修改源代码。有机会可以多研究。
This is just one of the things that devtool can do - it provides some powerful tools to help you maintain recipes and make changes to source code.
参考:
1,Yocto
2,Koan software
​3, Others
  • 21
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

夜流冰

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

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

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

打赏作者

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

抵扣说明:

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

余额充值