Patching OpenWRT

1. Locate the hostapd Package Source

  1. Navigate to the OpenWRT source directory:
    cd /path/to/openwrt/
  2. Locate the hostapd package files:
    cd package/network/services/hostapd

2. Extract the Source Code

  1. Ensure you have the original source tarball downloaded:b
    make package/network/services/hostapd/download
  2. Extract the source files for modification:
    make package/network/services/hostapd/prepare V=s This will extract the source files into the build_dir/ directory.

3. Make Changes to the Source Code

  1. Navigate to the extracted source directory:
    cd build_dir/target-*/hostapd-*/
  2. Modify the source files as needed. For example:
    nano src/ap/your_file.c

4. Generate the Patch File

  1. After making your changes, navigate back to the OpenWRT source directory:
    cd /path/to/openwrt/
  2. Use diff to create a patch file:
    diff -uNr package/network/services/hostapd/hostapd-*/src/ap/your_file.c \ build_dir/target-*/hostapd-*/src/ap/your_file.c > my_changes.patch Replace your_file.c with the actual filename you modified.
  3. To generate a patch file from two git branches:
    git diff <source-branch> <target-branch> my-patch-file.patch

5. Add the Patch to OpenWRT

  1. Move your patch file to the patches directory for hostapd:
    mv my_changes.patch package/network/services/hostapd/patches/
  2. Ensure the patch is in the correct format:
    • Patch files in OpenWRT use the naming convention ###-description.patch, where ### is a three-digit number (e.g., 001-my-fix.patch).

6. Rebuild and Test

  1. Clean and rebuild the package:
    make package/network/services/hostapd/{clean,compile} V=s
  2. If the build succeeds, the patch has been applied correctly, and you can test the resulting firmware.

7. Troubleshooting

  • If the patch fails during application, verify that the paths in the patch file match the source tree structure.
  • Use patch to manually test the patch:
    patch -p1 < package/network/services/hostapd/patches/001-my-fix.patch

By following these steps, you can create, apply, and test a custom patch for the hostapd package in OpenWRT.

Scroll to Top