Skip to content

Instantly share code, notes, and snippets.

@cactushydrocodone
Last active June 8, 2019 13:13
Show Gist options
  • Save cactushydrocodone/52215540fb2e4918506617ea8bfc62fa to your computer and use it in GitHub Desktop.
Save cactushydrocodone/52215540fb2e4918506617ea8bfc62fa to your computer and use it in GitHub Desktop.
[Motorola BECKHAM] Flash slot_a to slot_b
#!/bin/sh
# This script has one simple target: copy slot_a to slot_b.
# Or in other words: Copy the working slot (in my case slot_a) to the defunct slot (slot_b)
# Use this in TWRP
# I dont expect this to work on ANY other phone!
# dd is commented out down there, as i dont want people to accidentally flash their phones to bricks. Uncomment to flash.
# Go to the named partitions dir in /dev/
cd /dev/block/platform/c0c4000.sdhci/by-name
# Loop for every file in there.
for file_a in *_a; do
# Enter an empty line so you can look at it without getting autism
echo -e "\n "
# Strip the last character from $file_a
file_b=${file_a%?}
# Add "b" as the last character
file_b="${file_b}b"
# Calculate the checksums, this could take a while.
chksum_a=$(md5sum "$file_a" | cut -c -32)
chksum_b=$(md5sum "$file_b" | cut -c -32)
# Compare the checksums
if [ "$chksum_a" == "$chksum_b" ]; then
# If the checksum matches, dont do anything more.
echo "[[SUCCESS]] $file_b matches $file_a"
else
# If the checksums dont match, print an error
echo "[ERROR] $file_b ($chksum_b) doesnt match $file_a ($chksum_a)"
# dd $file_a to $file_b, COMMENTED!
## dd if="$file_a" of="$file_b"
# reset the checksum variables
chksum_a=""
chksum_b=""
# Calculate the checksums again after the flash
chksum_a=$(md5sum "$file_a" | cut -c -32)
chksum_b=$(md5sum "$file_b" | cut -c -32)
# Compare them _again_
if [ "$chksum_a" == "$chksum_b" ]; then
# Both slots match now, yippie
echo "[[AFTER FLASH ]][[SUCCESS]] $file_b matches NOW $file_a"
else
# Both slots stil dont match, very bad.
echo "[[AFTER FLASH ]][[ERROR]] $file_b STILL doesnt match $file_a :("
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment