1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

Merge branch 'fz-dev' into dev

This commit is contained in:
MX
2022-12-28 21:01:36 +03:00
21 changed files with 276 additions and 139 deletions

View File

@@ -27,14 +27,14 @@ Also display type, region and etc...
## Core1 and Core2 firmware flashing
Core2 goes first, then Core1.
Never flash FUS or you will loose your job, girlfriend and keys in secure enclave.
Never flash FUS or you will lose your job, girlfriend and keys in secure enclave.
## Option Bytes
!!! Setting incorrect Option Bytes may brick your MCU !!!
Defaults are mostly OK, but there are couple things that we'd like to tune.
Also OB may be damaged, so we've made couple scripts to check and set option bytes.
Also, OB may be damaged, so we've made couple scripts to check and set option bytes.
!!! Setting incorrect Option Bytes may brick your MCU !!!
@@ -69,4 +69,4 @@ Then run
python scripts/slideshow.py -i assets/slideshow/my_show/ -o assets/slideshow/my_show/.slideshow
```
Upload generated .slideshow file to Flipper's internal storage and restart it.
Upload generated .slideshow file to Flipper's internal storage and restart it.

68
scripts/power.py Executable file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python3
from flipper.app import App
from flipper.storage import FlipperStorage
from flipper.utils.cdc import resolve_port
class Main(App):
# this is basic use without sub-commands, simply to reboot flipper / power it off, not meant as a full CLI wrapper
def init(self):
self.parser.add_argument("-p", "--port", help="CDC Port", default="auto")
self.subparsers = self.parser.add_subparsers(help="sub-command help")
self.parser_power_off = self.subparsers.add_parser(
"power_off", help="Power off command, won't return to CLI"
)
self.parser_power_off.set_defaults(func=self.power_off)
self.parser_reboot = self.subparsers.add_parser(
"reboot", help="Reboot command help"
)
self.parser_reboot.set_defaults(func=self.reboot)
self.parser_reboot2dfu = self.subparsers.add_parser(
"reboot2dfu", help="Reboot to DFU, won't return to CLI"
)
self.parser_reboot2dfu.set_defaults(func=self.reboot2dfu)
def _get_flipper(self):
if not (port := resolve_port(self.logger, self.args.port)):
return None
flipper = FlipperStorage(port)
flipper.start()
return flipper
def power_off(self):
if not (flipper := self._get_flipper()):
return 1
self.logger.debug("Powering off")
flipper.send("power off" + "\r")
flipper.stop()
return 0
def reboot(self):
if not (flipper := self._get_flipper()):
return 1
self.logger.debug("Rebooting")
flipper.send("power reboot" + "\r")
flipper.stop()
return 0
def reboot2dfu(self):
if not (flipper := self._get_flipper()):
return 1
self.logger.debug("Rebooting to DFU")
flipper.send("power reboot2dfu" + "\r")
flipper.stop()
return 0
if __name__ == "__main__":
Main()()

View File

@@ -1,6 +1,8 @@
#!/usr/bin/env python3
import sys, os, time
import logging
import os
import sys
import time
def flp_serial_by_name(flp_name):
@@ -31,6 +33,12 @@ def main():
flipper_name = sys.argv[1]
elapsed = 0
flipper = flp_serial_by_name(flipper_name)
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s",
level=logging.INFO,
datefmt="%Y-%m-%d %H:%M:%S",
)
logging.info("Waiting for Flipper to be ready...")
while flipper == "" and elapsed < UPDATE_TIMEOUT:
elapsed += 1
@@ -38,9 +46,11 @@ def main():
flipper = flp_serial_by_name(flipper_name)
if flipper == "":
print(f"Cannot find {flipper_name} flipper. Guess your flipper swam away")
logging.error("Flipper not found!")
sys.exit(1)
logging.info(f"Found Flipper at {flipper}")
sys.exit(0)

View File

@@ -1,28 +1,32 @@
#!/usr/bin/env python3
import sys, os
import serial
import logging
import re
import sys
import serial
from await_flipper import flp_serial_by_name
LEAK_THRESHOLD = 3000 # added until units are fixed
def main():
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s",
level=logging.INFO,
datefmt="%Y-%m-%d %H:%M:%S",
)
logging.info("Trying to run units on flipper")
flp_serial = flp_serial_by_name(sys.argv[1])
if flp_serial == "":
print("Name or serial port is invalid")
logging.error("Flipper not found!")
sys.exit(1)
with serial.Serial(flp_serial, timeout=1) as flipper:
logging.info(f"Found Flipper at {flp_serial}")
flipper.baudrate = 230400
flipper.flushOutput()
flipper.flushInput()
flipper.timeout = 300
flipper.timeout = 180
flipper.read_until(b">: ").decode("utf-8")
flipper.write(b"unit_tests\r")
@@ -41,9 +45,13 @@ def main():
status_pattern = re.compile(status_re)
tests, time, leak, status = None, None, None, None
total = 0
for line in lines:
print(line)
logging.info(line)
if "()" in line:
total += 1
if not tests:
tests = re.match(tests_pattern, line)
if not time:
@@ -53,8 +61,8 @@ def main():
if not status:
status = re.match(status_pattern, line)
if leak is None or time is None or leak is None or status is None:
print("Failed to get data. Or output is corrupt")
if None in (tests, time, leak, status):
logging.error(f"Failed to parse output: {leak} {time} {leak} {status}")
sys.exit(1)
leak = int(re.findall(r"[- ]\d+", leak.group(0))[0])
@@ -62,16 +70,18 @@ def main():
tests = int(re.findall(r"\d+", tests.group(0))[0])
time = int(re.findall(r"\d+", time.group(0))[0])
if tests > 0 or leak > LEAK_THRESHOLD or status != "PASSED":
print(f"Got {tests} failed tests.")
print(f"Leaked {leak} bytes.")
print(f"Status by flipper: {status}")
print(f"Time elapsed {time/1000} seconds.")
if tests > 0 or status != "PASSED":
logging.error(f"Got {tests} failed tests.")
logging.error(f"Leaked (not failing on this stat): {leak}")
logging.error(f"Status: {status}")
logging.error(f"Time: {time/1000} seconds")
sys.exit(1)
print(
f"Tests ran successfully! Time elapsed {time/1000} seconds. Passed {tests} tests."
logging.info(f"Leaked (not failing on this stat): {leak}")
logging.info(
f"Tests ran successfully! Time elapsed {time/1000} seconds. Passed {total} tests."
)
sys.exit(0)