-
Notifications
You must be signed in to change notification settings - Fork 6
/
provision_xous.sh
executable file
·84 lines (76 loc) · 1.83 KB
/
provision_xous.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
echo "WARNING: this script is for un-bricking devices, and will overwrite any secret keys stored in the gateware"
UPDATE_FPGA=1
UPDATE_KERNEL=1
UPDATE_LOADER=1
SKIP_PROMPT=0
for arg in "$@"
do
case $arg in
-k|--kernel-skip)
UPDATE_KERNEL=0
shift
;;
-l|--loader-skip)
UPDATE_LOADER=0
shift
;;
-f|--fpga-skip)
UPDATE_FPGA=0
shift
;;
-y|--yes)
SKIP_PROMPT=1
shift
;;
--key)
shift
KEY="--key $1"
shift
;;
-h|--help)
echo "$0 provisions betrusted. --kernel-skip skips the kernel, --fpga-skip skips the FPGA. This script will overwrite any secret keys stored in the gateware."
exit 0
;;
*)
OTHER_ARGUMENTS+=("$1")
shift
;;
esac
done
md5sum ../precursors/soc_csr.bin
md5sum ../precursors/loader.bin
md5sum ../precursors/xous.img
if [ $SKIP_PROMPT -eq 0 ]
then
read -p "This script does a factory reset. You will lose your root keys if you update the FPGA. Proceed? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
fi
sudo ./reset_soc.sh
if [ $UPDATE_FPGA -eq 1 ]
then
if [ -z "$KEY" ]
then
cd jtag-tools && ./jtag_gpio.py -f ../../precursors/soc_csr.bin --raw-binary --spi-mode -r $KEY
cd ..
else
./jtag-tools/encrypt-bitstream.py -i 0 -f ../precursors/soc_csr.bin -o soc_csr_enc.bin $KEY -d
cd jtag-tools && ./jtag_gpio.py -f ../soc_csr_enc.bin --raw-binary --spi-mode -r $KEY
cd ..
fi
fi
if [ $UPDATE_LOADER -eq 1 ]
then
cd jtag-tools && ./jtag_gpio.py -f ../../precursors/loader.bin --raw-binary -a 0x500000 -s -r $KEY
cd ..
fi
if [ $UPDATE_KERNEL -eq 1 ]
then
cd jtag-tools && ./jtag_gpio.py -f ../../precursors/xous.img --raw-binary -a 0x980000 -s -r -n $KEY
cd ..
fi
sudo ./reset_soc.sh