Skip to content

Instantly share code, notes, and snippets.

@bkanuka
Last active February 1, 2020 12:57
Show Gist options
  • Save bkanuka/a6e0b75a356e1aa451de971317962441 to your computer and use it in GitHub Desktop.
Save bkanuka/a6e0b75a356e1aa451de971317962441 to your computer and use it in GitHub Desktop.
Upgrades ath10k QC6174 from upstream. Would probably work with other wifi drivers with minor changes
#!/usr/bin/bash
# gist id: a6e0b75a356e1aa451de971317962441
# Exit on any error
set -e
BACKED_UP=false
backup_firmware () {
if [[ $BACKED_UP != true ]]; then
BACKUP_FILENAME="$(date '+%s')-QCA6174.tar.gz"
echo Backing up current firmware to $BACKUP_FILENAME
tar -zcf $BACKUP_FILENAME -C /lib/firmware/ath10k QCA6174
BACKED_UP=true
fi
}
GIT_DIR="ath10k-firmware"
echo Pulling new firmware
# Pull new firmware, Clone if that fails
git -C $GIT_DIR pull || git clone https://github.com/kvalo/ath10k-firmware.git $GIT_DIR
# Updating firmware
CURRENT_SHA=$(sha1sum /lib/firmware/ath10k/QCA6174/hw3.0/firmware-6.bin | awk '{print $1}')
echo Current firmware SHA: $CURRENT_SHA
CURRENT_FILENAME=$(find $GIT_DIR -name 'firmware-6.bin*' -type f -exec sha1sum {} + |
grep $CURRENT_SHA |
awk '{print $2}')
#echo Current firmware matches upstream file: $CURRENT_FILENAME
cd $GIT_DIR
NEWEST_FILENAME=$(find . -name 'firmware-6.bin*' -type f `# Find firmware files` \
-printf '%p ' `# print filenames without newline` \
-exec git log -1 --format="%ad" --date=raw -- {} \; | # get git modified time
awk -v GIT_DIR="$GIT_DIR" '{print $2 " " GIT_DIR substr($1,2)}' | # put time first
sort -r | head -n1 | awk '{print $2}') # sort and take newest
cd ..
echo Newest firmware: $NEWEST_FILENAME
NEWEST_SHA=$(sha1sum $NEWEST_FILENAME | awk '{print $1}')
echo Newest firmware SHA: $NEWEST_SHA
if [[ $NEWEST_SHA != $CURRENT_SHA ]]; then
backup_firmware
echo Copying new firmware
sudo cp $NEWEST_FILENAME /lib/firmware/ath10k/QCA6174/hw3.0/firmware-6.bin
else
echo No need to update firmware
fi
echo Checking if board.bin is updated
CURRENT_SHA=$(sha1sum /lib/firmware/ath10k/QCA6174/hw3.0/board.bin | awk '{print $1}')
NEWEST_SHA=$(sha1sum $GIT_DIR/QCA6174/hw3.0/board.bin | awk '{print $1}')
echo Current firmware SHA: $CURRENT_SHA
echo Newest firmware SHA: $NEWEST_SHA
if [[ $NEWEST_SHA != $CURRENT_SHA ]]; then
backup_firmware
echo Copying new board.bin
sudo cp $GIT_DIR/QCA6174/hw3.0/board.bin /lib/firmware/ath10k/QCA6174/hw3.0/board.bin
else
echo No need to update board.bin
fi
echo Checking if board-2.bin is updated
CURRENT_SHA=$(sha1sum /lib/firmware/ath10k/QCA6174/hw3.0/board-2.bin | awk '{print $1}')
NEWEST_SHA=$(sha1sum $GIT_DIR/QCA6174/hw3.0/board-2.bin | awk '{print $1}')
echo Current firmware SHA: $CURRENT_SHA
echo Newest firmware SHA: $NEWEST_SHA
if [[ $NEWEST_SHA != $CURRENT_SHA ]]; then
backup_firmware
echo Copying new board-2.bin
sudo cp $GIT_DIR/QCA6174/hw3.0/board-2.bin /lib/firmware/ath10k/QCA6174/hw3.0/board-2.bin
else
echo No need to update board-2.bin
fi
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment