Yocto中的补丁是如何工作的

13

我正在使用BBB来理解yocto-project。我不确定补丁(patch)是如何工作的。这是我的项目目录。

├── meta-testlayer
├── poky
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-hello
    └── helloworld
        ├── helloworld-0.1
        │   ├── helloworld.c
        │   ├── helloworld.patch
        │   └── newhelloworld.c
        └── helloworld_0.1.bb

"

“helloworld.c”和“newhelloworld.c”仅在一个printf()语句上有所不同。以下是“helloworld.c”的内容:

"
#include <stdio.h>

int main(int argc, char **argv)
{

    printf("Hi, this is my first custom recipe. Have a good day\n");
    return 0;
}

"newhelloworld.c"的内容:

#include <stdio.h>

int main(int argc, char **argv)
{

    printf("Let see if patch works\n");
    printf("Hi, this patch is from the test-layer\n");
    return 0;
}

这是我使用 diff helloworld.c newhelloworld.c > helloworld.patch 命令创建的补丁文件。

6c6,7
<     printf("Hi, this is my first custom recipe. Have a good day\n");
---
>     printf("Let see if patch works\n");
>     printf("Hi, this patch is from the test-layer\n");

这是"helloworld_0.1.bb"文件的内容。

SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

#here we specify the source we want to build
SRC_URI = "file://helloworld.c"
SRC_URI += "file://helloworld.patch"

#here we specify the source directory, where we can do all the building and expect sources to be placed
S = "${WORKDIR}"

#bitbake task
do_compile() {
         ${CC} ${LDFLAGS} helloworld.c -o helloworld
}

#bitbake task
do_install() {
         install -d ${D}${bindir}
         install -m 0755 helloworld ${D}${bindir}
}

当我运行bitbake -c patch helloworld时,出现了以下错误信息:
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: helloworld-0.1-r0 do_patch: Command Error: 'quilt --quiltrc /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/helloworld/0.1-r0/recipe-sysroot-native/etc/quiltrc push' exited with 0  Output:
Applying patch helloworld.patch
patch: **** Only garbage was found in the patch input.
Patch helloworld.patch does not apply (enforce with -f)
ERROR: helloworld-0.1-r0 do_patch: Function failed: patch_do_patch
ERROR: Logfile of failure stored in: /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/helloworld/0.1-r0/temp/log.do_patch.22267
ERROR: Task (/home/guest/yocto_practice/meta-testlayer/recipes-hello/helloworld/helloworld_0.1.bb:do_patch) failed with exit code '1'
NOTE: Tasks Summary: Attempted 11 tasks of which 8 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  /home/guest/yocto_practice/meta-testlayer/recipes-hello/helloworld/helloworld_0.1.bb:do_patch
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.

这里提供的信息不足以说明为什么您无法应用该补丁——但也许它与 meta-test 中的其他补丁冲突了?如果您将自己的补丁放入 meta-test 层中,则根本不需要 bbappend:您只需修改 helloworld_0.1.bb 即可。 - Jussi Kukkonen
我应该在这里粘贴日志截图吗?同样,如何从同一层应用补丁? - user7345878
3个回答

24

首先,创建补丁:

diff -u helloworld.c newhelloworld.c > helloworld.patch

或者使用Git(将x替换为您想要提取补丁的提交次数):

git format-patch -x

应用补丁的两种方法:

  • 将其放入您的测试层中,在您的.bb文件中添加一行: SRC_URI += " file://example.patch "

  • 将其放入另一个层中,但仅在它不是您的层(例如meta-oe、meta-fsl、meta-qt等)时才需要。

对于此情况,请在您的.bbappend文件中使用:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://helloworld.patch "

你的补丁有问题,你是怎么做的? - PierreOlivier
我已经在问题中添加了我的example.patch文件内容。 如果我执行bitabke helloworldbitbake -c patch helloworld,我会收到错误提示。 还有一件事,我必须先应用补丁,然后再烘焙配方吗? 还是我可以直接烘焙helloworld配方? - user7345878
bitbake helloworld 运行默认的“构建”任务,该任务依赖于“补丁”任务:换句话说,在需要时会自动进行修补。 - Jussi Kukkonen
根据错误截图显示:您的补丁文件已经损坏(即使修复也无法正确地打补丁到您粘贴的源代码中,就我所知——它只是一个不正确的补丁)。也许您需要先了解一下补丁的工作原理? - Jussi Kukkonen
5
diff命令必须从其中一个父目录中调用,这次我使用了 diff -u。它起作用了。谢谢。 - user7345878
显示剩余4条评论

3
创建一个.bbappend文件用于该配方。
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://your.patch "

2
  • bitbake -c devshell recipe
  • git init
  • git add *
  • git commit (sourcetree recorded by git)
  • 使用您喜欢的任何编辑器编辑文件,然后保存它(例如:vi /path/to/file)
  • git status(显示文件已修改)
  • git add /path/to/file
  • git commit -m "根据所做的更改添加合适的注释"
  • git log(显示已进行更改和提交历史记录)
  • git format-patch HEAD~1(输出由最后一次提交创建的补丁文件)
  • ls(检查补丁文件是否存在)
  • 将补丁文件复制到recipe/files文件夹中
  • 执行exit退出devshell
  • 编辑recipe.bb或创建recipe.bbappend文件并在SRC_URI变量中添加补丁文件
  • 示例:
   FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
   SRC_URI += " file://patchfile.patch "
  • 使用 bitbake image_name 重新构建镜像

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接