Skip to content

Instantly share code, notes, and snippets.

@Strykar
Created June 22, 2025 19:05
Show Gist options
  • Save Strykar/5e82b0f180e76fa49399e2ba1f5c9b9c to your computer and use it in GitHub Desktop.
Save Strykar/5e82b0f180e76fa49399e2ba1f5c9b9c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
declare -A seen=()
declare -A unowned=()
check_dyndbg_enabled() {
if grep -qw 'dyndbg="func fw_log_firmware_info +p"' /proc/cmdline && [[ -r /proc/dynamic_debug/control ]]; then
echo "✔ dyndbg is set and control file is readable"
else
echo "⚠ dyndbg is not properly set or control file is missing" >&2
exit 1
fi
}
extract_firmware_paths() {
# Extract firmware file names from journalctl logs of current boot
journalctl -b --no-pager \
| grep -oiE '((firmware file|loaded FW|found device firmware|DMC firmware)[^:]*:?\s*)?[a-zA-Z0-9._/-]+\.(bin|ri|ucode|tplg|sfi|ddc)' \
| grep -oE '[a-zA-Z0-9._/-]+\.(bin|ri|ucode|tplg|sfi|ddc)' \
| grep -vE '^usr\.bin($|/)' \
| sort -u
}
find_firmware_path() {
local firmware_dir="/usr/lib/firmware"
local fw_file="$1"
local path
# Try exact matches including compressed variants
for ext in "" ".zst" ".xz" ".gz"; do
for candidate in "${firmware_dir}/${fw_file}${ext}" "${firmware_dir}"/*/"${fw_file}${ext}"; do
[[ -e $candidate ]] && { echo "$candidate"; return 0; }
done
done
# If not found, try prefix/suffix wildcard match in firmware_dir recursively (first match)
path=$(find "${firmware_dir}" -type f -name "*${fw_file}*" 2>/dev/null | head -n 1 || true)
if [[ -n $path ]]; then
echo "$path"
return 0
fi
# Not found at all
return 1
}
list_firmware_owners() {
local fw_file pkg normalized found_owner
while read -r fw_file; do
[[ -z "$fw_file" ]] && continue
normalized=$(find_firmware_path "$fw_file" || true)
if [[ -z "$normalized" ]]; then
unowned["$fw_file"]=1
continue
fi
if [[ -n "${seen[$normalized]+_}" ]]; then
continue
fi
seen["$normalized"]=1
found_owner=0
if pkg=$(pacman --color=never -Qo "$normalized" 2>/dev/null | awk '{print $(NF-1)}'); then
if [[ -n "$pkg" ]]; then
printf '→ %-65s owned by %s\n' "$normalized" "$pkg"
found_owner=1
fi
fi
[[ $found_owner -eq 0 ]] && unowned["$normalized"]=1
done < <(extract_firmware_paths)
}
report_unowned_firmware() {
if (( ${#unowned[@]} )); then
echo
echo "⚠ Unowned firmware files found:"
for fw in "${!unowned[@]}"; do
echo " $fw"
done
else
echo
echo "✔ All loaded firmware files are known to pacman."
fi
}
main() {
check_dyndbg_enabled
list_firmware_owners
report_unowned_firmware
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment