~hacktivista/hackware-boot

ref: 3372c1b0c5bcdc910dbb8290f24e05333dd7bb62 hackware-boot/x230t-flash_ec_firmware.sh -rwxr-xr-x 3.7 KiB
3372c1b0Felix Freeman Disable authentic battery validation on X230t EC Firmware 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
#
# This file is part of "Hackware boot" and licensed under the terms of the
# Hacktivista General Public License version 0.1 or (at your option) any later
# version. You should have received a copy of this license along with the
# software. If not, see <https://hacktivista.org/licenses/>.

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 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.

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. Select option 2 "Update system program".
5. Read instructions carefully and proceed with the EC firmware update.

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