@ -3,13 +3,16 @@
import os
import os
import time
import time
from panda import BASEDIR as PANDA_BASEDIR , Panda , PandaDFU , build_st
from panda import BASEDIR as PANDA_BASEDIR , Panda , PandaDFU
from common . basedir import BASEDIR
from common . basedir import BASEDIR
from common . gpio import gpio_init , gpio_set
from common . gpio import gpio_init , gpio_set
from selfdrive . hardware import TICI
from selfdrive . hardware import TICI
from selfdrive . hardware . tici . pins import GPIO_HUB_RST_N , GPIO_STM_BOOT0 , GPIO_STM_RST_N
from selfdrive . hardware . tici . pins import GPIO_HUB_RST_N , GPIO_STM_BOOT0 , GPIO_STM_RST_N
from selfdrive . swaglog import cloudlog
from selfdrive . swaglog import cloudlog
PANDA_FW_FN = os . path . join ( PANDA_BASEDIR , " board " , " obj " , " panda.bin.signed " )
def set_panda_power ( power = True ) :
def set_panda_power ( power = True ) :
if not TICI :
if not TICI :
return
return
@ -25,24 +28,9 @@ def set_panda_power(power=True):
gpio_set ( GPIO_STM_RST_N , not power )
gpio_set ( GPIO_STM_RST_N , not power )
def get_firmware_fn ( ) :
def get_expected_signature ( ) :
signed_fn = os . path . join ( PANDA_BASEDIR , " board " , " obj " , " panda.bin.signed " )
if os . path . exists ( signed_fn ) :
cloudlog . info ( " Using prebuilt signed firmware " )
return signed_fn
else :
cloudlog . info ( " Building panda firmware " )
fn = " obj/panda.bin "
build_st ( fn , clean = False )
return os . path . join ( PANDA_BASEDIR , " board " , fn )
def get_expected_signature ( fw_fn = None ) :
if fw_fn is None :
fw_fn = get_firmware_fn ( )
try :
try :
return Panda . get_signature_from_firmware ( fw_fn )
return Panda . get_signature_from_firmware ( PANDA_FW_FN )
except Exception :
except Exception :
cloudlog . exception ( " Error computing expected signature " )
cloudlog . exception ( " Error computing expected signature " )
return b " "
return b " "
@ -71,8 +59,7 @@ def update_panda():
time . sleep ( 1 )
time . sleep ( 1 )
fw_fn = get_firmware_fn ( )
fw_signature = get_expected_signature ( )
fw_signature = get_expected_signature ( fw_fn )
try :
try :
serial = panda . get_serial ( ) [ 0 ] . decode ( " utf-8 " )
serial = panda . get_serial ( ) [ 0 ] . decode ( " utf-8 " )
@ -90,7 +77,7 @@ def update_panda():
if panda . bootstub or panda_signature != fw_signature :
if panda . bootstub or panda_signature != fw_signature :
cloudlog . info ( " Panda firmware out of date, update required " )
cloudlog . info ( " Panda firmware out of date, update required " )
panda . flash ( fw_fn )
panda . flash ( )
cloudlog . info ( " Done flashing " )
cloudlog . info ( " Done flashing " )
if panda . bootstub :
if panda . bootstub :
@ -111,6 +98,7 @@ def update_panda():
cloudlog . info ( " Resetting panda " )
cloudlog . info ( " Resetting panda " )
panda . reset ( )
panda . reset ( )
def main ( ) :
def main ( ) :
set_panda_power ( )
set_panda_power ( )
update_panda ( )
update_panda ( )