Skip to content

Instantly share code, notes, and snippets.

@LorenzoAncora
Last active September 20, 2018 19:05
Show Gist options
  • Save LorenzoAncora/07e15fd189f355b1434f40163c05f94c to your computer and use it in GitHub Desktop.
Save LorenzoAncora/07e15fd189f355b1434f40163c05f94c to your computer and use it in GitHub Desktop.
#!/bin/bash
# DTB UPDATER 0.2 for Raspberry Pi 3 (aarch64)
# Copyright (C) 2018 Lorenzo Ancora
# DTB UPDATER is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# DTB UPDATER is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# EXAMPLE: update_DT_RPi3.sh "https://gist.github.com/chschlue/e0e02ecb1c455a7c8db3a53f9b408d6b/raw/16ec1953f34534a941bb90b2f6f42f30888157fc/bcm2710-rpi-3-b.dtb" "bcm2710-rpi-3-b.dtb"
# RETURN CODES: 0 (SUCCESS), 1 (FAILURE), 2 (FAILURE)
#
DTBURL=$1 # Full URL of the DTB file.
DTBDST="/boot/firmware/" # Firmware directory of the Raspberry Pi 3.
DTBFIL=$2 # Destination filename under DTBDST.
CKNAME="sha256.txt" # File which contains the OUTPUT of "sha256sum --tag <DTBFILE>", placed in the execution directory of this script.
function exitFailure () {
echo "FAILURE: $1."
if [ $2 -eq 1 ]; then
echo "WARNING: your Wi-Fi interfaces may not be recognized."
echo "WARNING: make sure that the latest" $DTBFIL "is in" $DTBDST "before rebooting."
fi
exit $2
}
if [ ! -f $DTBDST$DTBFIL ]; then
echo "Installing DTB file for Raspberry Pi 3 from" $DTBURL "..."
wget --quiet --timeout=7 --random-wait --tries=3 --retry-connrefused $DTBURL --output-document=$DTBDST$DTBFIL
if [ -f $DTBDST$DTBFIL ]; then
echo "DTB STATUS: UPDATED."
else exitFailure "DOWNLOAD FAILED" 1
fi
cp $CKNAME $DTBDST$CKNAME
pushd "$DTBDST" > /dev/null
sha256sum --status --strict --check $CKNAME
ckRes=$?
popd > /dev/null
if [ $ckRes -eq 0 ]; then
echo "DTB INTEGRITY: CONFIRMED."
rm -f $DTBDST$CKNAME
else exitFailure "NEW DTB FILE IS CORRUPTED" 1
fi
exit 0 # SUCCESS
else exitFailure "DTB ALREADY INSTALLED (PLEASE BACKUP AND DELETE $DTBFIL FROM $DTBDST)" 2
fi
### EXAMPLE OUTPUT: ###
# Installing DTB file for Raspberry Pi 3 from https://gist.github.com/chschlue/e0e02ecb1c455a7c8db3a53f9b408d6b/raw/16ec1953f34534a941bb90b2f6f42f30888157fc/bcm2710-rpi-3-b.dtb ...
# DTB STATUS: UPDATED.
# DTB INTEGRITY: CONFIRMED.
### EOF ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment