2

I want to apply a patch to buildroot package. I'm using br2-external tree to keep my customizations out of buildroot tree. Buildroot can find my patch, but fails when trying to apply it.

I have set BR2_GLOBAL_PATCH_DIR="${BR2_EXTERNAL_PATH}/board/myboard/patches" and put the patch in ${BR2_EXTERNAL_PATH}/board/myboard/patches/packagename/0001-name-of-patch.patch. I generated the patch by going to buildroot repo, applying the changes to package, committing them with git and creating a patch from the last commit: git format-patch HEAD~1 So the patch looks like this:

diff --git a/package/rpi-firmware/cmdline.txt b/package/rpi-firmware/cmdline.txt
index 155a54693b..630cfa9e00 100644
--- a/package/rpi-firmware/cmdline.txt
+++ b/package/rpi-firmware/cmdline.txt
@@ -1 +1 @@
-old code line
+new code line

However, when I run make, during patching the file to patch cannot be found (wrong path)

Applying 0001-name-of-patch.patch using patch:
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/package/rpi-firmware/cmdline.txt b/package/rpi-firmware/cmdline.txt
|index 155a54693b..630cfa9e00 100644
|--- a/package/rpi-firmware/cmdline.txt
|+++ b/package/rpi-firmware/cmdline.txt
--------------------------
No file to patch.  Skipping patch.

I also tried rpi-firmware/cmdline.txt and cmdline.txt paths.

What path should I use in the patch file? Should it be relative to package, relative to buildroot repository root, or pointing to package relative to the global patch directory? I followed https://buildroot.org/downloads/manual/manual.html#customize-patches but couldn't find the answer to this question.

Filip Kubicz
  • 459
  • 1
  • 5
  • 17
  • 1
    AFAIK you cannot patch the files in the **package/** directory using **make**. There is no special **.stamp_patched** file written to each **package//** subdirectory to ensure that patches are applied only once and should not be applied again. Patches are typically applied to the files in **output/build//**. – sawdust Oct 06 '20 at 23:11
  • Thanks for comment ;) I'm fine with patching it in output/build/. All I want is to make the patched package land in my image. The problem here I think is that the source is in buildroot/package/, while the patch is in ${BR2_GLOBAL_PATCH_DIR}. – Filip Kubicz Oct 07 '20 at 05:34
  • 1
    *"The problem here I think is that the source is in buildroot/package/..."* -- Yes, and there is no copy of it in **output/build//**. Perhaps you can patch the *installed* version of the file, **$(BINARIES_DIR)/rpi-firmware/cmdline.txt**, using a post-build script? – sawdust Oct 07 '20 at 09:18
  • Thanks, that's the alternative I was thinking about, and I went with this solution. – Filip Kubicz Oct 07 '20 at 14:50

1 Answers1

3

As mentioned by @sawdust its not possible to patch a file in buildroot package directory buildroot/package/<package_name>. You can only patch the source of the package, i.e. the source files downloaded to output/build/<package_name>/.

I ended up with using a post-build script to modify the file after it has been copied, as described in https://buildroot.org/downloads/manual/manual.html#rootfs-custom (option BR2_ROOTFS_POST_BUILD_SCRIPT="${BR2_EXTERNAL_PATH}/board/myboard/scripts/post-build.sh")

Filip Kubicz
  • 459
  • 1
  • 5
  • 17
  • 1
    You may always fork entire BR repository and apply whatever patches you want. For example, I'm doing like this in https://github.com/andy-shev/buildroot. – 0andriy Oct 09 '20 at 19:21