-
Notifications
You must be signed in to change notification settings - Fork 0
/
npu_upgrade_pcie
executable file
·156 lines (138 loc) · 3.23 KB
/
npu_upgrade_pcie
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/vendor/bin/sh
PROGRAM=${0##*/}
#reset npu
/vendor/bin/npu_powerctrl -i
/vendor/bin/npu_powerctrl -o
sleep 1
if [ $# -ne 4 ]; then
echo 'Usage: '$PROGRAM' loader uboot trust boot'
exit
fi
DIR="/vendor/etc/npu_fw"
UPGRADE_TOOL=/vendor/bin/upgrade_tool
LOADER=$DIR/$1
UBOOT=$DIR/$2
TRUST=$DIR/$3
BOOT=$DIR/$4
UBOOT_ADDR=0x20000
TRUST_ADDR=0x20800
BOOT_ADDR=0x21000
function download_func()
{
local RET1=1
echo 'start to download loader...' >> /data/vendor/npu.log
$UPGRADE_TOOL db $LOADER > /dev/null
if [ $? -ne 0 ]; then
echo 'failed to download loader!' >> /data/vendor/npu.log
return $RET1;
fi
echo 'download loader ok' >> /data/vendor/npu.log
sleep 1
echo 'start to wait loader...' >> /data/vendor/npu.log
$UPGRADE_TOOL td > /dev/null
if [ $? -ne 0 ]; then
echo 'failed to wait loader!' >> /data/vendor/npu.log
return $RET1
fi
echo 'loader is ready' >> /data/vendor/npu.log
echo 'start to write uboot...' >> /data/vendor/npu.log
$UPGRADE_TOOL wl $UBOOT_ADDR $UBOOT > /dev/null
if [ $? -ne 0 ]; then
echo 'failed to write uboot!' >> /data/vendor/npu.log
return $RET1
fi
echo 'write uboot ok' >> /data/vendor/npu.log
echo 'start to write trust...'
$UPGRADE_TOOL wl $TRUST_ADDR $TRUST > /dev/null
if [ $? -ne 0 ]; then
echo 'failed to write trust!' >> /data/vendor/npu.log
return $RET1
fi
echo 'write trust ok' >> /data/vendor/npu.log
echo 'start to write boot...' >> /data/vendor/npu.log
$UPGRADE_TOOL wl $BOOT_ADDR $BOOT > /dev/null
if [ $? -ne 0 ]; then
echo 'failed to write boot!' >> /data/vendor/npu.log
return $RET1
fi
echo 'write boot ok' >> /data/vendor/npu.log
RET1=0
return $RET1
}
function check_device_ready_func()
{
echo 'start to wait device...' > /data/vendor/npu.log
local i=0
local RET=1
while [ $i -lt 10 ]; do
$UPGRADE_TOOL ld > /dev/null
if [ $? -ne 0 ]; then
i=$((i+1))
echo $i
sleep 0.1
else
sleep 0.1
break
fi
if [ $i -eq 5 ]; then
/vendor/bin/npu_powerctrl -o
sleep 3
echo 'reset npu to retry!!!' >> /data/vendor/npu.log
fi
done
if [ $i -ge 10 ]; then
echo 'failed to wait device!' >> /data/vendor/npu.log
return $RET
fi
echo 'device is ready' >> /data/vendor/npu.log
RET=0
return $RET
}
function poweron_Npu_func()
{
/vendor/bin/npu_powerctrl -i
sleep 0.1
/vendor/bin/npu_powerctrl -o
sleep 1
}
if [ ! -f $UPGRADE_TOOL ]; then
echo $UPGRADE_TOOL 'is not existed!'
exit
fi
if [ ! -f $LOADER ]; then
echo $LOADER 'is not existed!'
exit
fi
if [ ! -f $UBOOT ]; then
echo $UBOOT 'is not existed!'
exit
fi
if [ ! -f $TRUST ]; then
echo $TRUST 'is not existed!'
exit
fi
if [ ! -f $BOOT ]; then
echo $BOOT 'is not existed!'
exit
fi
check_device_ready_func
if [ $? = 1 ];then
echo "check_device_ready error!!!" >> /data/vendor/npu.log
poweron_Npu_func
check_device_ready_func
fi
download_func
if [ $? = 1 ];then
echo "reset download_func"
poweron_Npu_func
check_device_ready_func
download_func
fi
echo 'start to run system...' >> /data/vendor/npu.log
$UPGRADE_TOOL rs $UBOOT_ADDR $TRUST_ADDR $BOOT_ADDR $UBOOT $TRUST $BOOT > /dev/null
if [ $? -ne 0 ]; then
echo 'failed to run system!' >> /data/vendor/npu.log
exit
fi
echo 'run system ok' >> /data/vendor/npu.log
echo 1 > /sys/devices/platform/f8000000.pcie/pcie_deferred