game-and-watch-backup/5_restore.sh

56 lines
2.0 KiB
Bash
Raw Normal View History

2020-11-29 10:58:55 +00:00
#!/bin/bash
2021-11-14 14:06:48 +00:00
source config.sh $@
if [[ $TARGET == "mario" ]] && \
test -f backups/flash_backup.bin && test -f backups/internal_flash_backup.bin && \
! test -f backups/flash_backup_$TARGET.bin && ! test -f backups/internal_flash_backup_$TARGET.bin \
; then
echo "Discovered mario backups with old names. Renaming files to the new format."
mv backups/flash_backup.bin backups/flash_backup_$TARGET.bin
mv backups/internal_flash_backup.bin backups/internal_flash_backup_$TARGET.bin
fi
2020-11-29 10:58:55 +00:00
2021-11-14 14:06:48 +00:00
if ! test -f backups/internal_flash_backup_$TARGET.bin; then
echo "No backup of internal flash found in backups/internal_flash_backup_$TARGET.bin"
2020-11-29 10:58:55 +00:00
exit 1
fi
2021-11-14 14:06:48 +00:00
if ! test -f backups/flash_backup_$TARGET.bin; then
echo "No backup of SPI flash found in backups/flash_backup_$TARGET.bin"
2020-11-29 10:58:55 +00:00
exit 1
fi
echo "Ok, restoring original firmware! (We will not lock the device, so you won't have to repeat this procedure!)"
2020-11-29 10:58:55 +00:00
if [[ $LARGE_FLASH == "1" ]]; then
echo "Restoring large SPI flash (no verify)..."
# verify is broken on large flashes
VERIFY_CMD=""
else
echo "Restoring SPI flash..."
VERIFY_CMD="verify"
fi
2021-11-14 14:06:48 +00:00
if ! ${OPENOCD} -f "openocd/target_${TARGET}.cfg" -f "openocd/interface_${ADAPTER}.cfg" \
2020-11-29 10:58:55 +00:00
-c "init;" \
-c "halt;" \
-c "program backups/flash_backup_${TARGET}.bin 0x90000000 ${VERIFY_CMD};" \
2020-11-29 11:31:12 +00:00
-c "exit;" >>logs/5_openocd.log 2>&1; then
2021-11-14 14:06:48 +00:00
echo "Restoring SPI flash failed. Check debug connection and try again."
2020-11-29 10:58:55 +00:00
exit 1
fi
2021-11-14 14:06:48 +00:00
echo "Restoring internal flash..."
if ! ${OPENOCD} -f "openocd/target_${TARGET}.cfg" -f "openocd/interface_${ADAPTER}.cfg" \
-c "init;" \
-c "halt;" \
-c "program backups/internal_flash_backup_${TARGET}.bin 0x08000000 verify;" \
-c "reset;" \
2021-11-14 14:06:48 +00:00
-c "exit;" >>logs/5_openocd.log 2>&1; then
echo "Restoring internal flash failed. Check debug connection and try again."
exit 1
fi
2020-11-29 11:31:12 +00:00
echo "Success, your device should be running the original firmware again!"
2020-12-02 04:14:00 +00:00
echo "(You should power-cycle the device now)"