-
Notifications
You must be signed in to change notification settings - Fork 58
/
5_restore.sh
executable file
·55 lines (47 loc) · 1.96 KB
/
5_restore.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
48
49
50
51
52
53
54
55
#!/bin/bash
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
if ! test -f backups/internal_flash_backup_$TARGET.bin; then
echo "No backup of internal flash found in backups/internal_flash_backup_$TARGET.bin"
exit 1
fi
if ! test -f backups/flash_backup_$TARGET.bin; then
echo "No backup of SPI flash found in backups/flash_backup_$TARGET.bin"
exit 1
fi
echo "Ok, restoring original firmware! (We will not lock the device, so you won't have to repeat this procedure!)"
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
if ! ${OPENOCD} -f "openocd/target_${TARGET}.cfg" -f "openocd/interface_${ADAPTER}.cfg" \
-c "init;" \
-c "halt;" \
-c "program backups/flash_backup_${TARGET}.bin 0x90000000 ${VERIFY_CMD};" \
-c "exit;" >>logs/5_openocd.log 2>&1; then
echo "Restoring SPI flash failed. Check debug connection and try again."
exit 1
fi
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;" \
-c "exit;" >>logs/5_openocd.log 2>&1; then
echo "Restoring internal flash failed. Check debug connection and try again."
exit 1
fi
echo "Success, your device should be running the original firmware again!"
echo "(You should power-cycle the device now)"