Generating a Patch Using diff

1. Extract the Original Source

Ensure you have a pristine copy of the original source for comparison. You can extract it from the tarball in the dl directory:

tar -xf dl/<package>-<version>.tar.gz -C /tmp/

This will create a directory like /tmp/<package>-<version>/.

Using buildroot’s mechanism

Clean the build directory and apply current patches of buildroot

make <pkg>-dirclean   # Remove <pkg> build directory
make <pkg>-extract    # Extract <pkg> sources
make <pkg>-patch      # Apply patches to <pkg> (Optional)

cp -r output/build/<package> /tmp/ 

2. Generate the Patch

Use the diff command to create a unified diff between the original and modified sources:

diff -Naur /tmp/<package>/ output/build/<package>/ > 0001-custom-changes.patch

# OR

git diff --no-index /tmp/<package> output/build/<package > 0001-custom-changes.patch
  • -N: Treat absent files as empty.
  • -a: Treat all files as text.
  • -u: Output in unified format.
  • -r: Recursively compare directories.

3. Place the Patch in Buildroot’s Package Directory

Move the generated patch to the appropriate location within Buildroot:

mv 0001-custom-changes.patch package/<package>/

Buildroot automatically applies patches in this directory during the build process.

4. Rebuild the Package

To apply the patch and rebuild the package:

make <package>-rebuild

Considerations

  • Patch Naming: Prefix your patch files with numbers (e.g., 0001-, 0002-) to ensure they are applied in the correct order.
  • Patch Description: It’s good practice to include a header in your patch file describing the changes and their purpose.

References

Quilt