Skip to content

Instantly share code, notes, and snippets.

@Fail-Safe
Last active April 16, 2025 11:18
Show Gist options
  • Save Fail-Safe/2b33040fcf56e148744cfb43e82ce589 to your computer and use it in GitHub Desktop.
Save Fail-Safe/2b33040fcf56e148744cfb43e82ce589 to your computer and use it in GitHub Desktop.
Downloads the mt7986 firmware files from a given mtk-openwrt-feeds commit hash
#!/bin/sh
if [ $# -eq 0 ]; then
printf "No arguments supplied. Please provide the commit hash for the firmware release you wish to download.\n"
exit 1
fi
# $1 will be the incoming commit hash
fw_url="https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+archive/${1}/autobuild_mac80211_release/package/kernel/mt76/src/firmware.tar.gz"
orig_pwd="$(pwd)"
os_release_name=$(grep -e '^NAME=' /etc/os-release | cut -d= -f2 | tr -d '"')
if [ "$os_release_name" == "OpenWrt" ]; then
orig_pwd="/tmp"
fi
fw_path="$orig_pwd/mt7986-firmware"
fw_tmp_path="$fw_path/tmp"
fw_src_file="$fw_tmp_path/fw.tar.gz"
dl_bin="curl"
os_name="$(uname)"
cleanup() {
printf " > Cleaning up...\n\n"
rm -r "$fw_tmp_path"
}
which "$dl_bin" > /dev/null 2>&1
if [ $? -eq 1 ]; then
dl_bin="wget"
which "$dl_bin" > /dev/null 2>&1
if [ $? -eq 1 ]; then
printf "Could not locate 'curl' or 'wget' on this host. Please install one of these tools and try again.\n"
exit 1
fi
fi
printf "> This is a $os_name system\n\n"
printf "> Will use '$dl_bin' as the download tool\n\n"
printf " > Creating firmware temporary directory: %s\n\n" "$fw_tmp_path"
mkdir -p "$fw_tmp_path"
printf " > Pulling requested firmware source at commit: %s...\n\n" "$1"
if [ "$dl_bin" == "curl" ]; then
eval "$dl_bin" -o "$fw_src_file" "$fw_url"
else
eval "$dl_bin" -O "$fw_src_file" "$fw_url"
fi
printf "\n"
printf " > Expanding firmware source...\n\n"
tar -C "$fw_tmp_path" -xzvf "$fw_src_file"
printf "\n"
printf " > Moving mt7986 firmware binaries to: %s\n\n" "$fw_path"
if [ "$os_name" = "Darwin" ]; then
find -E "$fw_tmp_path/" -type f -regex ".*mt7986_(r|w).*\.bin" -exec mv {} "$fw_path/" \;
elif [ "$os_name" = "Linux" ]; then
find "$fw_tmp_path/" -type f -regex ".*mt7986_\(r\|w\).*\.bin" -exec mv {} "$fw_path/" \;
else
printf "Unsupported OS. This can be fixed, but I need more details from you.\n\n"
cleanup
exit 1
fi
cleanup
printf " > The calculated md5 for the firmware files are:\n"
eval $(which md5sum) "$fw_path/*"
printf "\n"
cd "$orig_pwd" || exit 1
printf "> Done!\n\n"
@MasterKeyxda
Copy link

How do you find the md5sum for ${1} argument? I am running 23.05 but would like a newer FW (if it has any improvements)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment