## Buildroot patch structure

#### Keeping track of applied patches

Whenever a patch is applied to a source code directory in buildroot, a text file named .applied_patches_list is created inside that source directory. This file contains a list of all the patch filenames that were applied to that source code, just for reference.

#### Linux kernel patches

The Linux kernel has several patch levels available for it in the buildroot patch system. Buildroot first downloads the chosen kernel source from the mirror site, followed by any selected minor patch. Buildroot then extracts the kernel source from the compressed file and applies the minor patch, if one was chosen. After extracting the source and applying the official minor patch, buildroot looks for more patches in the following locations and in the order shown:

1. a custom, user downloaded kernel patch can be located in $(DL_DIR) and the filename is stored as $(LINUX26_BSP_PATCH)
2. Atmel keeps their official kernel patches in target/device/Atmel/Linux/kernel-patches with subdirectories for each kernel release. They also keep any board-specific patches in $(BR2_BOARD_PATH)
3. globally available patches are kept in toolchain/kernel-headers
4. IPMI (Intelligent Platform Management Interface) kernel patches are kept in toolchain/kernel-headers/ipmi
5. LZMA kernel compression support patches are kept in toolchain/kernel-headers/lzma
6. Real-time Linux kernel patches are kept in $(LINUX_RT_SOURCE)
7. Openswan kernel patches are kept in package/openswan

#### Package source patches

Any patches for the Linux programs supported by buildroot are kept in that program's corresponding package/ directory.

#### How the patching is done

Patches are applied in buildroot by running a shell script called toolchain/patch-kernel.sh with three arguments. The first argument is the target directory where the source code to be patched is saved. The second argument is the directory where the patch is saved. The third argument is the filename pattern to match when looking in the patch directory. The third argument can include wildcards to select multiple patch files.