Updated flasher script with some quality of life (#2141)

* Added automatic retries

* Generalized naming
This commit is contained in:
Karakurt
2025-07-17 03:10:50 +03:00
committed by GitHub
parent c00df49708
commit 580bc4f70d

View File

@@ -1,19 +1,21 @@
#!/bin/bash #!/bin/bash
# TS100 Flasher for Linux by Alex Wigen (https://github.com/awigen) # TS100 Flasher for Linux by Alex Wigen (https://github.com/awigen)
# Jan 2021 - Update by Ysard (https://github.com/ysard) # Jan 2021 - Update by Ysard (https://github.com/ysard)
# Jul 2025 - Update by Karakurt
DIR_TMP="/tmp/ts100" DIR_TMP="/tmp/ironos"
HEX_FIRMWARE="$DIR_TMP/ts100.hex" HEX_FIRMWARE="$DIR_TMP/ts100.hex"
MAX_TRIES=5
usage() { usage() {
echo echo
echo "#################" echo "#######################"
echo "# TS100 Flasher #" echo "# TS100/TS101 Flasher #"
echo "#################" echo "#######################"
echo echo
echo " Usage: $0 <HEXFILE>" echo " Usage: $0 <HEXFILE>"
echo echo
echo "This script has been tested to work on Fedora." echo "This script has been tested to work on Fedora and Arch Linux."
echo "If you experience any issues please open a ticket at:" echo "If you experience any issues please open a ticket at:"
echo "https://github.com/Ralim/IronOS/issues/new" echo "https://github.com/Ralim/IronOS/issues/new"
echo echo
@@ -44,12 +46,12 @@ is_attached() {
} }
instructions="not printed" instructions="not printed"
wait_for_ts100() { wait_for_iron() {
while ! is_attached; do while ! is_attached; do
if [ "$instructions" = "not printed" ]; then if [ "$instructions" = "not printed" ]; then
echo echo
echo "#####################################################" echo "#####################################################"
echo "# Waiting for TS100 config disk device to appear #" echo "# Waiting for config disk device to appear #"
echo "# #" echo "# #"
echo "# Connect the soldering iron with a USB cable while #" echo "# Connect the soldering iron with a USB cable while #"
echo "# holding the button closest to the tip pressed #" echo "# holding the button closest to the tip pressed #"
@@ -61,7 +63,7 @@ wait_for_ts100() {
done done
} }
mount_ts100() { mount_iron() {
mkdir -p "$DIR_TMP" mkdir -p "$DIR_TMP"
user="${UID:-$(id -u)}" user="${UID:-$(id -u)}"
if ! sudo mount -t msdos -o uid=$user "$DEVICE" "$DIR_TMP"; then if ! sudo mount -t msdos -o uid=$user "$DEVICE" "$DIR_TMP"; then
@@ -70,11 +72,12 @@ mount_ts100() {
fi fi
} }
umount_ts100() { umount_iron() {
if ! (mountpoint "$DIR_TMP" > /dev/null && sudo umount "$DIR_TMP"); then if ! (mountpoint "$DIR_TMP" > /dev/null && sudo umount "$DIR_TMP"); then
echo "Failed to unmount $DIR_TMP" echo "Failed to unmount $DIR_TMP"
exit 1 exit 1
fi fi
sleep 1
sudo rmdir "$DIR_TMP" sudo rmdir "$DIR_TMP"
} }
@@ -84,19 +87,22 @@ check_flash() {
if [ -f "$RDY_FIRMWARE" ]; then if [ -f "$RDY_FIRMWARE" ]; then
echo -e "\e[92mFlash is done\e[0m" echo -e "\e[92mFlash is done\e[0m"
echo "Disconnect the USB and power up the iron. You're good to go." echo "Disconnect the USB and power up the iron. You're good to go."
return 0
elif [ -f "$ERR_FIRMWARE" ]; then elif [ -f "$ERR_FIRMWARE" ]; then
echo -e "\e[91mFlash error; Please retry!\e[0m" echo -e "\e[91mFlash error; Please retry!\e[0m"
return 1
else else
echo -e "\e[91mUNKNOWN error\e[0m" echo -e "\e[91mUNKNOWN error\e[0m"
echo "Flash result: " echo "Flash result: "
ls "$DIR_TMP"/ts100* ls "$DIR_TMP"/ts100*
return 1
fi fi
} }
cleanup() { cleanup() {
enable_gautomount enable_gautomount
if [ -d "$DIR_TMP" ]; then if [ -d "$DIR_TMP" ]; then
umount_ts100 umount_iron
fi fi
} }
trap cleanup EXIT trap cleanup EXIT
@@ -121,19 +127,28 @@ fi
disable_gautomount disable_gautomount
wait_for_ts100 TRIES=0
echo "Found TS100 config disk device on $DEVICE" while [ $TRIES -lt $MAX_TRIES ]; do
wait_for_iron
NAME=$(sudo fatlabel "$DEVICE" 2>/dev/null)
echo "Found $NAME config disk device on $DEVICE"
mount_ts100 mount_iron
echo "Mounted config disk drive, flashing..." echo "Mounted config disk drive, flashing..."
dd if="$1" of="$HEX_FIRMWARE" oflag=direct dd if="$1" of="$HEX_FIRMWARE" oflag=direct
umount_ts100 umount_iron
echo "Waiting for TS100 to flash" echo "Waiting for $NAME to flash"
sleep 5 sleep 5
echo "Remounting config disk drive" echo "Remounting config disk drive"
wait_for_ts100 wait_for_iron
mount_ts100 mount_iron
check_flash check_flash && exit 0
echo "Retrying automatically..."
TRIES=$((TRIES + 1))
done
echo -e "\e[91mMax retries reached.\e[0m"
exit 1