Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions firmware-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#where the stuff is
script_url="https://raw.githubusercontent.com/MrChromebox/scripts/master/"
scriptdir="$(realpath "$(dirname "$0")")"

#ensure output of system tools in en-us for parsing
export LC_ALL=C
Expand All @@ -30,18 +31,43 @@ fi
printf "\ec"
echo -e "\nMrChromebox Firmware Utility Script starting up"

if [ "$1" = '-n' ]; then
# Emulate curl by copying files from the directory with the script, or log the URLs to download & fail.
# Intended for no-network (=> no-OOBE on ChromeOS) and reproduction scenarios.
# Logs the curl cmdlines to stdout (for script(1) use) and to ./curls;
# this means that you can use a reusable medium on the chromebook and do
# mount /dev/sda /media
# bash /media/firmware-utl.sh -n
# umount /media
# on the target machine, then `sh curls` on a trusted network-connected machine,
# and repeat this twice to get all the artifacts for your system.
curl() {
{ printf '%q ' curl "$@"; echo; } | tee -a "$scriptdir/curls"
OPTIND=1
curl_file=
while getopts sLOo: curl_flag; do
case "$curl_flag" in
[sLO]) ;;
o) curl_file="$OPTARG" ;;
*) echo "unknown curl flag -$curl_flag" >&2; return 1 ;;
esac
done
shift "$((OPTIND - 1))"
[ -n "$curl_file" ] || curl_file="${1##*/}"
[ -s "$scriptdir/$curl_file" ] && cp -v "$scriptdir/$curl_file" .
}
export CURL=curl

#check for cmd line param, expired CrOS certs
if ! curl -sLo /dev/null https://mrchromebox.tech/index.html || [[ "$1" = "-k" ]]; then
elif ! curl -sLo /dev/null https://mrchromebox.tech/index.html || [[ "$1" = "-k" ]]; then
export CURL="curl -k"
else
export CURL="curl"
fi

#get support scripts
echo -e "\nDownloading supporting files..."
rm -rf firmware.sh >/dev/null 2>&1
rm -rf functions.sh >/dev/null 2>&1
rm -rf sources.sh >/dev/null 2>&1
rm -rf firmware.sh functions.sh sources.sh >/dev/null 2>&1
$CURL -sLO ${script_url}firmware.sh
rc0=$?
$CURL -sLO ${script_url}functions.sh
Expand Down
37 changes: 6 additions & 31 deletions firmware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -593,22 +593,9 @@ function restore_fw_from_usb()
{
read -rep "
Connect the USB/SD device which contains the backed-up stock firmware and press [Enter] to continue. "

list_usb_devices || { exit_red "No USB devices available to read firmware backup."; return 1; }
usb_dev_index=""
while [[ "$usb_dev_index" = "" || ($usb_dev_index -le 0 && $usb_dev_index -gt $num_usb_devs) ]]; do
read -rep "Enter the number for the device which contains the stock firmware backup: " usb_dev_index
if [[ "$usb_dev_index" = "" || ($usb_dev_index -le 0 && $usb_dev_index -gt $num_usb_devs) ]]; then
echo -e "Error: Invalid option selected; enter a number from the list above."
fi
done
usb_device="${usb_devs[${usb_dev_index}-1]}"
mkdir /tmp/usb > /dev/null 2>&1
mount "${usb_device}" /tmp/usb > /dev/null 2>&1
if [ $? -ne 0 ]; then
mount "${usb_device}1" /tmp/usb
fi
if [ $? -ne 0 ]; then
if ! mount_usb_device; then
echo_red "USB device failed to mount; cannot proceed."
read -rep "Press [Enter] to return to the main menu."
umount /tmp/usb > /dev/null 2>&1
Expand Down Expand Up @@ -789,23 +776,11 @@ USB/SD devices are connected. "
backup_fail "No USB devices available to store firmware backup."
return 1
fi

usb_dev_index=""
while [[ "$usb_dev_index" = "" || ($usb_dev_index -le 0 && $usb_dev_index -gt $num_usb_devs) ]]; do
read -rep "Enter the number for the device to be used for firmware backup: " usb_dev_index
if [[ "$usb_dev_index" = "" || ($usb_dev_index -le 0 && $usb_dev_index -gt $num_usb_devs) ]]; then
echo -e "Error: Invalid option selected; enter a number from the list above."
fi
done

usb_device="${usb_devs[${usb_dev_index}-1]}"
mkdir /tmp/usb > /dev/null 2>&1
if ! mount "${usb_device}" /tmp/usb > /dev/null 2>&1; then
if ! mount "${usb_device}1" /tmp/usb > /dev/null 2>&1; then
backup_fail "USB backup device failed to mount; cannot proceed."
return 1
fi
if ! mount_usb_device; then
backup_fail "USB backup device failed to mount; cannot proceed."
return 1
fi

backupname="stock-firmware-${boardName}-$(date +%Y%m%d).rom"
echo_yellow "\nSaving firmware backup as ${backupname}"
if ! cp /tmp/bios.bin /tmp/usb/${backupname}; then
Expand Down
20 changes: 20 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ function list_usb_devices()
return 0
}

##########################################
# Mount the found USB device on /tmp/usb #
##########################################
function mount_usb_device()
{
usb_dev_index=""
while [[ "$usb_dev_index" = "" || ($usb_dev_index -le 0 && $usb_dev_index -gt $num_usb_devs) ]]; do
read -rep "Enter the number for the device to be used for firmware backup: " usb_dev_index
if [[ "$usb_dev_index" = "" || ($usb_dev_index -le 0 && $usb_dev_index -gt $num_usb_devs) ]]; then
echo -e "Error: Invalid option selected; enter a number from the list above."
fi
done

usb_device="${usb_devs[${usb_dev_index}-1]}"
mkdir /tmp/usb > /dev/null 2>&1
mount "${usb_device}" /tmp/usb > /dev/null 2>&1 ||
mount "${usb_device}1" /tmp/usb > /dev/null 2>&1 ||
{ mounted="$(df -x devtmpfs "${usb_device}" || df -x devtmpfs "${usb_device}1")" 2>/dev/null && mount --bind "${mounted}" /tmp/usb > /dev/null 2>&1; }
}


################
# Get cbfstool #
Expand Down