forked from ghidraninja/game-and-watch-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_backup_flash.sh
executable file
·47 lines (36 loc) · 1.47 KB
/
2_backup_flash.sh
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
#!/bin/bash
source config.sh $1
if [[ $# -ne 1 ]]; then
echo "Usage: backup_flash.sh <Adapter: jlink or stlink>"
exit 1
fi
if test -f backups/flash_backup.bin; then
echo "Already have a backup in backups/flash_backup.bin, refusing to overwrite."
exit 1
fi
echo "Make sure your Game & Watch is turned on and in the time screen. Press return when ready!"
read -n 1
echo "Attempting to dump flash using adapter ${ADAPTER}."
echo "Running OpenOCD... (This will take roughly 30 seconds, your Game and Watch screen will blink in between.)"
if ! ${OPENOCD} -f openocd/flash_"${ADAPTER}".cfg >>logs/2_openocd.log 2>&1; then
echo "Failed to dump SPI flash from device. Verify debug connection and try again."
exit 1
fi
echo "Validating ITCM dump..."
if ! shasum --check shasums/itcm_backup.bin.sha1 >/dev/null 2>&1; then
echo "Failed to correctly dump ITCM. Restart Game & Watch and try again."
exit 1
fi
echo "Extracting checksummed part..."
if ! dd if=backups/flash_backup.bin of=backups/flash_backup_checksummed.bin count=1040384 bs=1 >/dev/null 2>&1; then
echo "Failed to access flash_backup.bin"
echo "Verify openocd works correctly"
exit 1
fi
echo "Validating checksum..."
if ! shasum --check shasums/flash_backup_checksummed.bin.sha1 >/dev/null 2>&1; then
echo "Failed to verify checksum. Try again."
exit 1
fi
rm backups/flash_backup_checksummed.bin
echo "Looks good! Successfully backed up the (encrypted) SPI flash to flash_backup.bin!"