~hacktivista/hackware-boot

3372c1b0c5bcdc910dbb8290f24e05333dd7bb62 — Felix Freeman 20 days ago 8082083 main
Disable authentic battery validation on X230t EC Firmware
1 files changed, 82 insertions(+), 43 deletions(-)

M x230t-flash_ec_firmware.sh
M x230t-flash_ec_firmware.sh => x230t-flash_ec_firmware.sh +82 -43
@@ 6,53 6,67 @@
# version. You should have received a copy of this license along with the
# software. If not, see <https://hacktivista.org/licenses/>.

echo '> Upgrade EC firmware'

echo 'Installing dependencies: curl and El-Torito'
sudo apt-get install -qy curl genisoimage perl

echo 'Downloading ISO'
curl -#LO https://download.lenovo.com/pccbbs/mobiles/gcuj32us.iso --output-dir /tmp/

echo 'Making ISO bootable'
geteltorito -o /tmp/gcuj32us.bootable.iso /tmp/gcuj32us.iso

# scan removable storages and request if not inserted
while
	STORAGE_DEVICES=$(lsblk -dno PATH,VENDOR,MODEL,SIZE,RM | sed -nEe '/.*1$/{ s/[[:space:]]+/ /g; s/(.*)1/\1/p }' | nl -s ') ' -w 1)
	[ -z "$STORAGE_DEVICES" ]
do
	echo 'Please insert a removable storage device. Then press <Enter> to continue.'
	read -r _CHOICE
done

# select a storage media
STORAGE_DEVICES_COUNT=$(echo "$STORAGE_DEVICES" | wc -l)
while
	cat <<- EOF

	Select a removable storage device:
	$STORAGE_DEVICES

	Type a device number from 1 to $STORAGE_DEVICES_COUNT and press <Enter>.
	If the device is mounted please unmount it before proceeding.
	WARNING: ALL ITS PARTITIONS AND CONTENTS WILL BE WIPED!
	EOF
	read -r CHOICE
	! expr "$CHOICE" : "[1-$STORAGE_DEVICES_COUNT]" 1> /dev/null
do true; done

STORAGE_PATH=$(echo "$STORAGE_DEVICES" | sed -nEe "/$CHOICE/ { s/$CHOICE\) ([^ ]+).*/\1/p }")

# write EC firmware into it
sudo dd if=/tmp/gcuj32us.bootable.iso of="$STORAGE_PATH" bs=1M status=progress
echo '> Upgrade and patch EC firmware'

echo 'Installing dependencies'
sudo apt-get install -qy git wget build-essential mtools libssl-dev

echo 'Cloning thinkpad-ec patcher repo'
git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/hamishcoleman/thinkpad-ec.git

cd thinkpad-ec

echo 'Patching EC firmware ISO'
make really_clean
make patch_disable_keyboard clean
make patch_enable_battery clean
make patched.x230t.img

echo 'Making original ISO bootable'
./scripts/geteltorito -o gcuj32us.bootable.img gcuj32us.iso.orig

select_storage_path () {

	# scan removable storages and request if not inserted
	while
		STORAGE_DEVICES=$(lsblk -dno PATH,VENDOR,MODEL,SIZE,RM | sed -nEe '/.*1$/{ s/[[:space:]]+/ /g; s/(.*)1/\1/p }' | nl -s ') ' -w 1)
		[ -z "$STORAGE_DEVICES" ]
	do
		echo 'Please insert a removable storage device. Then press <Enter> to continue.'
		read -r _CHOICE
	done

	# select a storage media
	STORAGE_DEVICES_COUNT=$(echo "$STORAGE_DEVICES" | wc -l)
	while
		cat <<- EOF

		Select a removable storage device:
		$STORAGE_DEVICES

		Type a device number from 1 to $STORAGE_DEVICES_COUNT and press <Enter>.
		If the device is mounted please unmount it before proceeding.
		WARNING: ALL ITS PARTITIONS AND CONTENTS WILL BE WIPED!
		EOF
		read -r CHOICE
		! expr "$CHOICE" : "[1-$STORAGE_DEVICES_COUNT]" 1> /dev/null
	do true; done

	STORAGE_PATH=$(echo "$STORAGE_DEVICES" | sed -nEe "/$CHOICE/ { s/$CHOICE\) ([^ ]+).*/\1/p }")

}

# select removable storage
select_storage_path
# write original EC firmware update into it
sudo dd if=gcuj32us.bootable.img of="$STORAGE_PATH" bs=4M status=progress conv=fsync
echo 'Done! Please remove the storage device and press <Enter>.'
read -r _CHOICE

cat << EOF
=================================================
NOW WE WILL FLASH THE EC FIRMWARE INTO THE LAPTOP
=================================================
==================================================================
NOW WE WILL UPDATE THE ORIGINAL BIOS AND EC FIRMWARE IN THE LAPTOP
==================================================================

Previous to flashing the firmware please verify the battery is propertly charged and both the battery and the AC power are connected to the laptop.



@@ 65,3 79,28 @@ Previous to flashing the firmware please verify the battery is propertly charged
When you are done with that press <Enter> here to continue.
EOF
read -r _CHOICE

# select removable storage
select_storage_path
# write patched EC firmware update into it
sudo dd if=patched.x230t.img of="$STORAGE_PATH" bs=4M status=progress conv=fsync
echo 'Done! Please remove the storage device and press <Enter>.'
read -r _CHOICE

cd - 1>/dev/null

cat << EOF
=========================================================
NOW WE WILL FLASH THE PATCHED EC FIRMWARE INTO THE LAPTOP
=========================================================

Previous to flashing the firmware please verify the battery is propertly charged and both the battery and the AC power are connected to the laptop.

1. Connect the storage device with the EC Firmware update.
2. Turn it on and press F12 repeatedly to show the boot menu.
3. Select the removable storage. The firmware update software will boot.
4. Proceed with the EC firmware update.

When you are done with that press <Enter> here to continue.
EOF
read -r _CHOICE