improve flash and recover scripts (#1349)

* improve flash and recover scripts

* update references

* cleanup

* less spaces

---------

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh 2023-04-16 15:08:46 -07:00 committed by GitHub
parent 9cd01ac263
commit 2f79621893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 20 deletions

View File

@ -4,18 +4,15 @@ Programming
**Panda**
```
./recover.sh # flash bootstub
```
```
./flash.sh # flash application
./recover.py # flash bootstub
./flash.py # flash application
```
Troubleshooting
----
If your panda will not flash and green LED is on, use `recover.sh`.
If panda is blinking fast with green LED, use `flash.sh`.
If your panda will not flash and green LED is on, use `recover.py`.
If panda is blinking fast with green LED, use `flash.py`.
Otherwise if LED is off and panda can't be seen with `lsusb` command, use [panda paw](https://comma.ai/shop/products/panda-paw) to go into DFU mode.

17
board/flash.py Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env python3
import os
import subprocess
from panda import Panda
board_path = os.path.dirname(os.path.realpath(__file__))
if __name__ == "__main__":
subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) {board_path}", shell=True)
serials = Panda.list()
print(f"found {len(serials)} panda(s) - {serials}")
for s in serials:
print("flashing", s)
with Panda(serial=s) as p:
p.flash()

View File

@ -1,5 +0,0 @@
#!/usr/bin/env sh
set -e
scons -u -j$(nproc)
printf %b 'from python import Panda\nfor serial in Panda.list(): Panda(serial).flash()' | PYTHONPATH=.. python3

26
board/recover.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import os
import time
import subprocess
from panda import Panda, PandaDFU
board_path = os.path.dirname(os.path.realpath(__file__))
if __name__ == "__main__":
subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) {board_path}", shell=True)
for s in Panda.list():
print("putting", s, "in DFU mode")
with Panda(serial=s) as p:
p.reset(enter_bootstub=True)
p.reset(enter_bootloader=True)
# wait for reset pandas to come back up
time.sleep(1)
dfu_serials = PandaDFU.list()
print(f"found {len(dfu_serials)} panda(s) in DFU - {dfu_serials}")
for s in dfu_serials:
print("flashing", s)
PandaDFU(s).recover()

View File

@ -1,8 +0,0 @@
#!/usr/bin/env sh
set -e
scons -u -j$(nproc)
# Recovers panda from DFU mode only, use flash.sh after power cycling panda
printf %b 'from python import Panda\nfor serial in Panda.list(): Panda(serial).reset(enter_bootstub=True); Panda(serial).reset(enter_bootloader=True)' | PYTHONPATH=.. python3
sleep 1
printf %b 'from python import PandaDFU\nfor serial in PandaDFU.list(): PandaDFU(serial).recover()' | PYTHONPATH=.. python3