3333 args .iface , args .iface , bootloader .CAN_BITRATE , ignore_failure = True )
3434
3535
36+ def load_and_start_firmware (bootloader_interface , firmware_image ):
37+ while True :
38+ try :
39+ info ('Flashing the firmware [%d bytes]...' , len (firmware_image ))
40+ bootloader_interface .unlock ()
41+ bootloader_interface .load_firmware (firmware_image )
42+ except Exception as ex :
43+ error ('Flashing failed: %r' , ex )
44+ if not input ('Try harder?' , yes_no = True ):
45+ abort ('Flashing failed' )
46+ else :
47+ input ('Set PIO0_1 high (J4 open), then press ENTER' )
48+ info ('Starting the firmware...' )
49+ bootloader_interface .reset ()
50+ break
51+
52+
3653def process_one_device ():
3754 execute_shell_command ('ifconfig %s down && ifconfig %s up' , args .iface , args .iface )
3855
56+ # Flashing firmware without signature
57+ with closing (bootloader .BootloaderInterface (args .iface )) as bli :
58+ input ('\n ' .join (['1. Set PIO0_3 low, PIO0_1 low (J4 closed, J3 open)' ,
59+ '2. Power on the device and connect it to CAN bus' ,
60+ '3. Press ENTER' ]))
61+
62+ with CLIWaitCursor ():
63+ load_and_start_firmware (bli , firmware_base )
64+
65+ # Testing the device
66+ input ('\n ' .join (['1. Make sure that LED indicators are blinking' ,
67+ '2. Test button operation' ,
68+ '3. Press ENTER' ]))
69+
70+ # Installing signature
3971 with closing (bootloader .BootloaderInterface (args .iface )) as bli :
72+ info ("Now we're going to sign the device" )
4073 input ('\n ' .join (['1. Set PIO0_3 low, PIO0_1 low (J4 closed, J3 open)' ,
41- '2. Connect the device to CAN bus ' ,
74+ '2. Reset the device (e.g. cycle power) ' ,
4275 '3. Press ENTER' ]))
4376
4477 with CLIWaitCursor ():
@@ -52,26 +85,7 @@ def process_one_device():
5285 ['existing' , 'NEW' ][gensign_response .new ])
5386 firmware_with_signature = firmware_base .ljust (SIGNATURE_OFFSET , b'\xFF ' ) + gensign_response .signature
5487
55- while True :
56- try :
57- info ('Flashing the firmware [%d bytes]...' , len (firmware_with_signature ))
58- bli .unlock ()
59- bli .load_firmware (firmware_with_signature )
60- except Exception as ex :
61- error ('Flashing failed: %r' , ex )
62- if not input ('Try harder?' , yes_no = True ):
63- abort ('Flashing failed' )
64- else :
65- break
66-
67- input ('Set PIO0_1 high (J4 open), then press ENTER' )
68-
69- info ('Starting the firmware...' )
70- bli .reset ()
71-
72- input ('\n ' .join (['1. Make sure that LED indicators are blinking' ,
73- '2. Test button operation' ,
74- '3. Press ENTER' ]))
88+ load_and_start_firmware (bli , firmware_with_signature )
7589
7690
7791run (process_one_device )
0 commit comments