1#!/bin/bash 2PROGRAM=${0##*/} 3 4#reset npu 5/usr/bin/npu_powerctrl -i 6/usr/bin/npu_powerctrl -o 7sleep 1 8 9if [ $# -ne 4 ]; then 10 echo 'Usage: '$PROGRAM' loader uboot trust boot' 11 exit 12fi 13DIR="/usr/share/npu_fw" 14UPGRADE_TOOL=/usr/bin/upgrade_tool 15 16LOADER=$DIR/$1 17UBOOT=$DIR/$2 18TRUST=$DIR/$3 19BOOT=$DIR/$4 20UBOOT_ADDR=0x20000 21TRUST_ADDR=0x20800 22BOOT_ADDR=0x21000 23 24function download_func() 25{ 26 local RET1=1 27 echo 'start to download loader...' >> /tmp/npu.log 28 $UPGRADE_TOOL db $LOADER > /dev/null 29 if [ $? -ne 0 ]; then 30 echo 'failed to download loader!' >> /tmp/npu.log 31 return $RET1; 32 fi 33 echo 'download loader ok' >> /tmp/npu.log 34 35 sleep 1 36 echo 'start to wait loader...' >> /tmp/npu.log 37 $UPGRADE_TOOL td > /dev/null 38 if [ $? -ne 0 ]; then 39 echo 'failed to wait loader!' >> /tmp/npu.log 40 return $RET1 41 fi 42 echo 'loader is ready' >> /tmp/npu.log 43 44 echo 'start to write uboot...' >> /tmp/npu.log 45 $UPGRADE_TOOL wl $UBOOT_ADDR $UBOOT > /dev/null 46 if [ $? -ne 0 ]; then 47 echo 'failed to write uboot!' >> /tmp/npu.log 48 return $RET1 49 fi 50 echo 'write uboot ok' >> /tmp/npu.log 51 52 echo 'start to write trust...' 53 $UPGRADE_TOOL wl $TRUST_ADDR $TRUST > /dev/null 54 if [ $? -ne 0 ]; then 55 echo 'failed to write trust!' >> /tmp/npu.log 56 return $RET1 57 fi 58 echo 'write trust ok' >> /tmp/npu.log 59 60 echo 'start to write boot...' >> /tmp/npu.log 61 $UPGRADE_TOOL wl $BOOT_ADDR $BOOT > /dev/null 62 if [ $? -ne 0 ]; then 63 echo 'failed to write boot!' >> /tmp/npu.log 64 return $RET1 65 fi 66 echo 'write boot ok' >> /tmp/npu.log 67 RET1=0 68 return $RET1 69} 70 71function check_device_ready_func() 72{ 73 echo 'start to wait device...' > /tmp/npu.log 74 local i=0 75 local RET=1 76 while [ $i -lt 10 ]; do 77 $UPGRADE_TOOL ld > /dev/null 78 if [ $? -ne 0 ]; then 79 i=$((i+1)) 80 echo $i 81 sleep 0.1 82 else 83 sleep 0.1 84 break 85 fi 86 if [ $i -eq 5 ]; then 87 /usr/bin/npu_powerctrl -o 88 sleep 3 89 echo 'reset npu to retry!!!' >> /tmp/npu.log 90 fi 91 done 92 if [ $i -ge 10 ]; then 93 echo 'failed to wait device!' >> /tmp/npu.log 94 return $RET 95 fi 96 echo 'device is ready' >> /tmp/npu.log 97 RET=0 98 return $RET 99} 100 101function poweron_Npu_func() 102{ 103 /usr/bin/npu_powerctrl -i 104 sleep 0.1 105 /usr/bin/npu_powerctrl -o 106 sleep 1 107} 108 109if [ ! -f $UPGRADE_TOOL ]; then 110 echo $UPGRADE_TOOL 'is not existed!' 111 exit 112fi 113 114if [ ! -f $LOADER ]; then 115 echo $LOADER 'is not existed!' 116 exit 117fi 118 119if [ ! -f $UBOOT ]; then 120 echo $UBOOT 'is not existed!' 121 exit 122fi 123 124if [ ! -f $TRUST ]; then 125 echo $TRUST 'is not existed!' 126 exit 127fi 128 129if [ ! -f $BOOT ]; then 130 echo $BOOT 'is not existed!' 131 exit 132fi 133 134check_device_ready_func 135if [ $? = 1 ];then 136 echo "check_device_ready error!!!" >> /tmp/npu.log 137 poweron_Npu_func 138 check_device_ready_func 139fi 140 141download_func 142if [ $? = 1 ];then 143 echo "reset download_func" 144 poweron_Npu_func 145 check_device_ready_func 146 download_func 147fi 148 149echo 'start to run system...' >> /tmp/npu.log 150$UPGRADE_TOOL rs $UBOOT_ADDR $TRUST_ADDR $BOOT_ADDR $UBOOT $TRUST $BOOT > /dev/null 151if [ $? -ne 0 ]; then 152 echo 'failed to run system!' >> /tmp/npu.log 153 exit 154fi 155echo 'run system ok' >> /tmp/npu.log 156