How to apply patches to a package in Buildroot?
Asked Answered
A

4

11

I am working on an embedded system that uses buildroot as a tool for building the kernel and the root filesystem. I want to apply some patches to this kernel source tree, Can somebody tell me how buildroot apply patches?

Aymer answered 17/6, 2011 at 8:3 Comment(0)
A
3

After studying the buildroot architecture, I came to know that buildroot uses quilt tool for applying the patches. quilt keeps track of all the patches in the a file named "series" which is present in the "patches" directory. You have to keep your patches in this directory. And add your entry of patches in the series file in the order in which you want the patches to be applied keeping the patch to be applied first at the top.

This way when you will run the buildroot makefile, it will automatically apply the patches listed in the series file.

Aymer answered 27/6, 2011 at 14:13 Comment(3)
Buildroot does not use quilt (at least, it did not use it these last years).Slavocracy
The buildroot docs mention "series" files as used by quilt.Hardbitten
Currently buildroot.org/downloads/manual/manual.html#_providing_patches states: "Previously, a series file, as used by quilt, could also be added in the package directory. In that case, the series file defines the patch application order. This is deprecated, and will be removed in the future. Do not use a series file." So this answer will soon be deprecated.Workable
I
10

To expand on @pradeepchhentri's answer. Quilt will look for a file located in the same folder as the *.mk file. To construct the appropriate file:

  1. diff your source package from the original into a file called

    packagename-number-description.patch

    where

    packagename - has to be identical to the package name

    number - is the order in which the patches should be applied if you have more than one patch to apply (otherwise it will be applied alphabetically)

    description - can be any free text

  2. Place this file into the package at the same level as the [packagename].mk file and the package/Config.in file.

Don't forget to blow away your build files or do a [package]-rebuild if you do this. You should see a "Patching..." message if this is done correctly.

Ingesta answered 17/6, 2011 at 8:4 Comment(1)
Small additional tip that helped me, so I put it here: Download commit as patch from github.Andalusite
D
6

some details about patch files in the buildroot project:

  1. you have to

    diff -u "old_file" "new_file" > file.patch
    

while standing exactly above extracted location of your package tar.gz defined in

PACKAGE_NAME_SOURCE

it means, your path to the file must include extracted package folder name.

  1. in case you wonder if the "old_file" path would be different from the original one - don't worry, the important one is the "new_file" path and name - it should match your package extracted one.

  2. naming convention for the patches already used/defined in buildroot (all parts are separated with '-' sign):

    • 4 digits patch priority (starting from 0001)
    • target filename
    • reason for patching
    • .patch extention

example:

0001-configure.ac-convert-AC_TRY_COMPILE-AC_COMPILE_IFELS.patch
  1. deposit patch file inside buildroot/package/"your package name"/ folder.

there is no need for configuration files to modify, all patches will be tried for application automatically.

  1. in case of the failure, the reject-patch file (named similar to the file you are trying to patch but with .rej extention) will be deposited inside package extracted folder.
Dmso answered 16/5, 2017 at 18:33 Comment(0)
R
4

Use *_OVERRIDE_SRCDIR and track everything in submodules

Instead of using patches, I highly recommend that you to this instead:

myproject/
  .git/
  submodules/buildroot/
  submodules/source_of_my_package/

and just track the source of your in a submodule that points to your fork of the project with your patches on top.

This will make everything much saner and easy to keep track of.

More info at: How to modify the source of Buildroot packages for package development?

BR2_GLOBAL_PATCH_DIR out-of-tree patches

Directory structure:

Add to config:

BR2_GLOBAL_PATCH_DIR=../global_patch_dir

Then build with:

cd buildroot
make

The patch should be applied to output/build/packagename-1.0.0/ before build.

Resonant answered 3/6, 2017 at 5:23 Comment(0)
A
3

After studying the buildroot architecture, I came to know that buildroot uses quilt tool for applying the patches. quilt keeps track of all the patches in the a file named "series" which is present in the "patches" directory. You have to keep your patches in this directory. And add your entry of patches in the series file in the order in which you want the patches to be applied keeping the patch to be applied first at the top.

This way when you will run the buildroot makefile, it will automatically apply the patches listed in the series file.

Aymer answered 27/6, 2011 at 14:13 Comment(3)
Buildroot does not use quilt (at least, it did not use it these last years).Slavocracy
The buildroot docs mention "series" files as used by quilt.Hardbitten
Currently buildroot.org/downloads/manual/manual.html#_providing_patches states: "Previously, a series file, as used by quilt, could also be added in the package directory. In that case, the series file defines the patch application order. This is deprecated, and will be removed in the future. Do not use a series file." So this answer will soon be deprecated.Workable

© 2022 - 2024 — McMap. All rights reserved.