Buildroot 2024.02中BR2_GLOBAL_PATCH_DIR引发非补丁包hash文件缺失错误的修复咨询
Short Answer: You don't need to modify package/pkg-generic.mk—there are cleaner workarounds available.
What's Causing This?
The issue stems from how Buildroot's pkg-generic.mk constructs the $(2)_HASH_FILES variable: it unconditionally checks both the package's native directory and the global patch directory (from BR2_GLOBAL_PATCH_DIR) for hash files. Even if you don't have patches for a package (like aria2), it still tries to look for [global-patch-dir]/[package-name]/[package-name].hash—and throws an error when that file doesn't exist.
Solutions
Option 1: Create Empty Hash Files for Unpatched Packages (Quick Fix)
For packages where you don't need patches (like aria2), just create an empty hash file in the corresponding patch directory. Buildroot will recognize it as a valid (but empty) hash source, and fall back to the package's native hash file:
# Create the directory for aria2 in your patch tree mkdir -p /home/admin/buildroot-external-my/patches/aria2 # Touch an empty hash file touch /home/admin/buildroot-external-my/patches/aria2/aria2.hash
This works because Buildroot prioritizes the package's native hash file first—this empty file just satisfies the lookup check without affecting the actual download validation.
Option 2: Avoid Global Patch Directory for Unpatched Packages (Cleaner Long-Term Fix)
Instead of using BR2_GLOBAL_PATCH_DIR for all packages, specify patch directories only for packages that actually need patches:
- Remove the global
BR2_GLOBAL_PATCH_DIRsetting from your configuration - For packages that do need patches (like dhcpcd), explicitly set their patch directory in your external package's makefile or config:
DHCPCD_PATCH_DIRS = $(BR2_EXTERNAL_MY_PATH)/patches/dhcpcd
This way, Buildroot won't scan the patch directory for hash files for every package—only the ones you've explicitly configured to use patches.
Why Modifying pkg-generic.mk Is Not Recommended
Tinkering with Buildroot's core makefiles has downsides:
- Your changes will be overwritten when you upgrade Buildroot to a newer version, forcing you to re-apply the patch every time
- It breaks the intended design of Buildroot's hash lookup logic, which could lead to unexpected behavior elsewhere
- The solutions above are non-intrusive and maintainable without modifying core code
内容的提问来源于stack exchange,提问作者Papillon

