-
Notifications
You must be signed in to change notification settings - Fork 1
/
burn_id.sh
executable file
·42 lines (32 loc) · 1.22 KB
/
burn_id.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
#!/bin/bash
# Always fail hard
set -e
i=1
if [ -f "id.bck" ]; then
i=`python -c 'import struct; f=open("id.bck", "rb"); print(struct.unpack(">H", f.read(2))[0]); f.close()'`
read -p "Restored last written id $i. Press any key to continue..."
((i=i+1))
fi
while :; do
read -p "Ready to burn $i. Press any key to continue..."
verify=`espefuse.py dump | grep BLOCK2 | cut -c 56-60 | python -c 'import sys,struct; print(struct.unpack("<H", bytes.fromhex(sys.stdin.read()))[0])'`
if [ "$verify" != "0" ]; then
read -p "Badge already contains an ID: $verify"
continue
fi
# Write binary
python -c 'import sys, struct; f=open("id.bin", "wb+"); f.write(struct.pack(">H", int(sys.argv[1])) + bytes([0]*30)); f.close()' $i
# Burn fuses
espefuse.py burn_block_data BLOCK2 id.bin --do-not-confirm > /dev/null
# Verify fuses
verify=`espefuse.py dump | grep BLOCK2 | cut -c 56-60 | python -c 'import sys,struct; print(struct.unpack("<H", bytes.fromhex(sys.stdin.read()))[0])'`
if [ "$i" != $verify ]; then
echo "Wrote $i, read $verify"
exit
fi
# Move the current id to the last one
rm -f id.bck
mv id.bin id.bck
# Increment i
((i=i+1))
done