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.
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"
)