From ed170784c5159a164bbaef93cd87fbf16b90aab0 Mon Sep 17 00:00:00 2001 From: Maciej Pijanowski Date: Mon, 31 Oct 2022 12:30:11 +0100 Subject: [PATCH] clevo/ec-flash.sh: add Signed-off-by: Maciej Pijanowski --- clevo/clevo-ec-flash | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 clevo/clevo-ec-flash diff --git a/clevo/clevo-ec-flash b/clevo/clevo-ec-flash new file mode 100755 index 0000000..85710d9 --- /dev/null +++ b/clevo/clevo-ec-flash @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +error_exit() { + _error_msg="$1" + echo "$_error_msg" + exit 1 +} + +error_check() { + _error_code=$? + _error_msg="$1" + [ "$_error_code" -ne 0 ] && error_exit "$_error_msg : ($_error_code)" +} + +# Method to access IT5570 IO Depth 2 registers +it5570_i2ec() { + # TODO: Use /dev/port instead of iotools + + # Address high byte + iotools io_write8 0x2e 0x2e + iotools io_write8 0x2f 0x11 + iotools io_write8 0x2e 0x2f + iotools io_write8 0x2f $(($2>>8 & 0xff)) + + # Address low byte + iotools io_write8 0x2e 0x2e + iotools io_write8 0x2f 0x10 + iotools io_write8 0x2e 0x2f + iotools io_write8 0x2f $(($2 & 0xff)) + + # Data + iotools io_write8 0x2e 0x2e + iotools io_write8 0x2f 0x12 + iotools io_write8 0x2e 0x2f + + case $1 in + "r") + iotools io_read8 0x2f + ;; + "w") + iotools io_write8 0x2f $3 + ;; + esac +} + +it5570_shutdown() { + echo -n "Syncing disks... " + sync + echo "Done." + echo "The computer will shut down automatically in 5 seconds" + sleep 5 + # shut down using EC external watchdog reset + it5570_i2ec w 0x1f01 0x20 + it5570_i2ec w 0x1f07 0x01 +} + +update_ec() { + echo "Getting EC firmware update..." + cp $EC_UPDATE_PATH /tmp/ecupdate.rom + error_check "Failed to get EC firmware update file. Please check if path \ + $EC_UPDATE_PATH is correct." + + echo "Updating EC..." + flashrom -p ite_ec -w /tmp/ecupdate.rom + error_check "Failed to update EC firmware" + + echo "Successfully updated EC firmware" +} + +usage() { + echo "Usage:" + echo " $0 EC_UPDATE_FILE" + echo " EC_UPDATE_FILE - This argument takes path to EC update file" + exit 1 +} + +if [ $# -ne 1 ]; then + usage +fi + +EC_UPDATE_PATH=$1 + +update_ec + +it5570_shutdown