User avatar
algorithm
Posts: 329
Joined: Mon Nov 25, 2013 9:09 pm
Location: Flatland

Check for new firmware

Sat May 10, 2014 7:55 am

Bash script. I ripped off a part of rpi-update and added a little sugar around it. Save as fwupd (or any other name), make executable: "chmod 755 fwupd", move to somewhere in the path: "sudo mv fwupd /usr/local/bin/". Two mutually exclusive arguments: -q for quiet operation (eg.: "if fwupd -q; then echo yes; else echo no; fi") and -v to print the firmware IDs.

Exits 0 ("success") if firmware update available, non-zero ("fail") if not or no connection. This is why I made it; rpi-update itself returns success on firmware update AND if you are already up to date, so no way to tell if a reboot is needed in my wrapper script (another script, which also does apt-get upgrade).

Code: Select all

#!/bin/bash

URI="https://api.github.com/repos/Hexxeh/rpi-firmware/git/refs/heads/master"

[ "$1" = "-q" ] && QUIET=1
[ "$1" = "-v" ] && VERBOSE=1

OLD=$(cat "/boot/.firmware_revision")
NEW=$(curl -s "$URI" | awk '{ if ($1 == "\"sha\":") { print substr($2, 2, 40) } }')

if [ -z "$NEW" ]; then
	[ $QUIET ] || echo "Can't download firmware update." 1>&2
	exit 1
elif [ "$NEW" = "$OLD" ]; then
	[ $QUIET ] || echo "Firmware is up to date." 1>&2
	[ $VERBOSE ] && echo "Version: ${OLD}" 1>&2
	exit 2
elif [ -z "$OLD" ]; then
	[ $QUIET ] || echo "Firmware never updated. Update available."
else
	[ $QUIET ] || echo "Firmware update available."
	[ $VERBOSE ] && echo "Current: ${OLD}"
fi
[ $VERBOSE ] && echo "Update : ${NEW}"
exit 0
Edit: one old version typo in the script, and the awk line was wrapped so I parameterised the uri.

User avatar
algorithm
Posts: 329
Joined: Mon Nov 25, 2013 9:09 pm
Location: Flatland

Re: Check for new firmware

Sat May 10, 2014 10:12 am

By the way, when updating to yesterday's 3f722be8d8de6740b32d76ef938a05744bf0d34f firmware, one model B I have became unresponsive on the (ethernet) network after soft reboot. Not sure if related to firmware revision. All fine again after power off/on. Not tried other Pis, yet.

Return to “Raspberry Pi OS”