hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
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
#!/bin/bash
PROGRAM=${0##*/}
 
#reset npu
/usr/bin/npu_powerctrl -i
/usr/bin/npu_powerctrl -o
sleep 1
 
if [ $# -ne 4 ]; then
   echo 'Usage: '$PROGRAM' loader uboot trust boot'
   exit
fi
DIR="/usr/share/npu_fw"
UPGRADE_TOOL=/usr/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...' >>  /tmp/npu.log
   $UPGRADE_TOOL db $LOADER > /dev/null
   if [ $? -ne 0 ]; then
       echo 'failed to download loader!' >>  /tmp/npu.log
       return $RET1;
   fi
   echo 'download loader ok' >>  /tmp/npu.log
 
   sleep 1
   echo 'start to wait loader...' >>  /tmp/npu.log
   $UPGRADE_TOOL td > /dev/null
   if [ $? -ne 0 ]; then
       echo 'failed to wait loader!' >>  /tmp/npu.log
       return $RET1
   fi
   echo 'loader is ready'  >>  /tmp/npu.log
 
   echo 'start to write uboot...' >>  /tmp/npu.log
   $UPGRADE_TOOL wl $UBOOT_ADDR $UBOOT > /dev/null
   if [ $? -ne 0 ]; then
       echo 'failed to write uboot!' >>  /tmp/npu.log
       return $RET1
   fi
   echo 'write uboot ok' >>  /tmp/npu.log
 
   echo 'start to write trust...'
   $UPGRADE_TOOL wl $TRUST_ADDR $TRUST > /dev/null
   if [ $? -ne 0 ]; then
       echo 'failed to write trust!' >>  /tmp/npu.log
       return $RET1
   fi
   echo 'write trust ok' >>  /tmp/npu.log
 
   echo 'start to write boot...' >>  /tmp/npu.log
   $UPGRADE_TOOL wl $BOOT_ADDR $BOOT > /dev/null
   if [ $? -ne 0 ]; then
       echo 'failed to write boot!' >>  /tmp/npu.log
       return $RET1
   fi
   echo 'write boot ok' >>  /tmp/npu.log
   RET1=0
   return $RET1
}
 
function check_device_ready_func()
{
   echo 'start to wait device...' >  /tmp/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
           /usr/bin/npu_powerctrl -o
           sleep 3
           echo 'reset npu to retry!!!' >> /tmp/npu.log
       fi
   done
   if [ $i -ge 10 ]; then
       echo 'failed to wait device!'  >>  /tmp/npu.log
       return $RET
   fi
   echo 'device is ready' >>  /tmp/npu.log
   RET=0
   return $RET
}
 
function poweron_Npu_func()
{
   /usr/bin/npu_powerctrl -i
   sleep 0.1
   /usr/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!!!" >> /tmp/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...' >>  /tmp/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!' >>  /tmp/npu.log
   exit
fi
echo 'run system ok' >>  /tmp/npu.log