[FL-3174] Dolphin builder in ufbt; minor ufbt/fbt improvements (#2601)

* ufbt: added "dolphin_ext" target (expects "external" subfolder in cwd with dolphin assets); cleaned up unused code
* ufbt: codestyle fixes
* scripts: fixed style according to ruff linter
* scripts: additional cleanup & codestyle fixes
* github: pass target hw code when installing local SDK with ufbt
* ufbt: added error message for missing folder in dolphin builder
* scripts: more linter fixes
* sdk: added flipper_format_stream; ufbt: support for --extra-define
* fbt: reduced amount of global defines
* scripts, fbt: rearranged imports

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
hedger
2023-05-03 08:48:49 +03:00
committed by GitHub
parent 015ab4a024
commit c3ececcf96
73 changed files with 311 additions and 382 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ class App:
if isinstance(return_code, int):
return self._exit(return_code)
else:
self.logger.error(f"Missing return code")
self.logger.error("Missing return code")
return self._exit(255)
def _exit(self, code):
+4 -4
View File
@@ -6,7 +6,7 @@ import xml.etree.ElementTree as ET
import posixpath
import os
from flipper.utils import *
from flipper.utils import file_sha256, timestamp
from flipper.assets.coprobin import CoproBinary, get_stack_type
@@ -45,13 +45,13 @@ class Copro:
cube_manifest = ET.parse(cube_manifest_file)
cube_package = cube_manifest.find("PackDescription")
if not cube_package:
raise Exception(f"Unknown Cube manifest format")
raise Exception("Unknown Cube manifest format")
cube_version = cube_package.get("Patch") or cube_package.get("Release")
if not cube_version or not cube_version.startswith("FW.WB"):
raise Exception(f"Incorrect Cube package or version info")
raise Exception("Incorrect Cube package or version info")
cube_version = cube_version.replace("FW.WB.", "", 1)
if cube_version != reference_cube_version:
raise Exception(f"Unsupported cube version")
raise Exception("Unsupported cube version")
self.version = cube_version
def _getFileName(self, name):
+2 -1
View File
@@ -1,6 +1,7 @@
import struct
import math
import os, os.path
import os
import os.path
import sys
+5 -7
View File
@@ -1,13 +1,11 @@
import multiprocessing
import logging
import os
import sys
import shutil
from collections import Counter
from flipper.utils.fff import *
from flipper.utils.templite import *
from .icon import *
from flipper.utils.fff import FlipperFormatFile
from flipper.utils.templite import Templite
from .icon import ImageTools, file2image
def _convert_image_to_bm(pair: set):
@@ -121,7 +119,7 @@ class DolphinBubbleAnimation:
self.meta["Passive frames"] + self.meta["Active frames"]
== ordered_frames_count
)
except EOFError as e:
except EOFError:
raise Exception("Invalid meta file: too short")
except AssertionError as e:
self.logger.exception(e)
@@ -158,7 +156,7 @@ class DolphinBubbleAnimation:
except AssertionError as e:
self.logger.exception(e)
self.logger.error(
f"Animation {self.name} bubble slot {bubble_slot} got incorrect data: {bubble}"
f"Animation {self.name} bubble slot {bubble['Slot']} got incorrect data: {bubble}"
)
raise Exception("Meta file is invalid: incorrect bubble data")
except EOFError:
+3 -9
View File
@@ -1,9 +1,6 @@
import logging
import argparse
import subprocess
import io
import os
import sys
ICONS_SUPPORTED_FORMATS = ["png"]
@@ -36,11 +33,8 @@ class ImageTools:
@staticmethod
def is_processing_slow():
try:
from PIL import Image, ImageOps
import heatshrink2
return False
except ImportError as e:
except ImportError:
return True
def __init__(self):
@@ -52,7 +46,7 @@ class ImageTools:
try:
from PIL import Image, ImageOps
except ImportError as e:
except ImportError:
self.__pil_unavailable = True
self.logger.info("pillow module is missing, using convert cli util")
return self.png2xbm(file)
@@ -72,7 +66,7 @@ class ImageTools:
try:
import heatshrink2
except ImportError as e:
except ImportError:
self.__hs2_unavailable = True
self.logger.info("heatshrink2 module is missing, using heatshrink cli util")
return self.xbm2hs(data)
+2 -3
View File
@@ -1,11 +1,10 @@
import datetime
import logging
import os
import posixpath
from pathlib import Path
from flipper.utils import *
from flipper.utils.fstree import *
from flipper.utils import timestamp, file_md5
from flipper.utils.fstree import FsNode, compare_fs_trees
MANIFEST_VERSION = 0
+1 -3
View File
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
import logging
import struct
from enum import Enum
from dataclasses import dataclass
@@ -181,7 +179,7 @@ class OptionBytesData:
def gen_values(self):
obref = ObReferenceValuesGenerator()
converted_refs = list(obref.apply(ob) for ob in self.obs)
list(obref.apply(ob) for ob in self.obs)
return obref
+4 -4
View File
@@ -14,7 +14,7 @@ class CubeProgrammer:
if "port" in config and config["port"]:
connect.append(f"port={config['port']}")
else:
connect.append(f"port=swd")
connect.append("port=swd")
if "serial" in config and config["serial"]:
connect.append(f"sn={config['serial']}")
self.params.append("-c " + " ".join(connect))
@@ -43,20 +43,20 @@ class CubeProgrammer:
return output.decode()
def getVersion(self):
output = self._execute(["--version"])
self._execute(["--version"])
def checkOptionBytes(self, option_bytes):
output = self._execute(["-ob displ"])
ob_correct = True
for line in output.split("\n"):
line = line.strip()
if not ":" in line:
if ":" not in line:
self.logger.debug(f"Skipping line: {line}")
continue
key, data = line.split(":", 1)
key = key.strip()
data = data.strip()
if not key in option_bytes.keys():
if key not in option_bytes.keys():
self.logger.debug(f"Skipping key: {key}")
continue
self.logger.debug(f"Processing key: {key} {data}")
+2 -2
View File
@@ -151,7 +151,7 @@ class FlipperStorage:
try:
# TODO: better decoding, considering non-ascii characters
line = line.decode("ascii")
except:
except Exception:
continue
line = line.strip()
@@ -194,7 +194,7 @@ class FlipperStorage:
try:
# TODO: better decoding, considering non-ascii characters
line = line.decode("ascii")
except:
except Exception:
continue
line = line.strip()
-1
View File
@@ -1,6 +1,5 @@
import datetime
import hashlib
import os
def timestamp():
+5 -5
View File
@@ -31,13 +31,13 @@ class OpenOCDProgrammer(Programmer):
config["interface"] = interface
config["target"] = "target/stm32wbx.cfg"
if not serial is None:
if serial is not None:
if interface == "interface/cmsis-dap.cfg":
config["serial"] = f"cmsis_dap_serial {serial}"
elif "stlink" in interface:
config["serial"] = f"stlink_serial {serial}"
if not port_base is None:
if port_base is not None:
config["port_base"] = port_base
self.openocd = OpenOCD(config)
@@ -59,7 +59,7 @@ class OpenOCDProgrammer(Programmer):
raise Exception(f"File {file_path} not found")
self.openocd.start()
self.openocd.send_tcl(f"init")
self.openocd.send_tcl("init")
self.openocd.send_tcl(
f"program {file_path} 0x{address:08x}{' verify' if verify else ''} reset exit"
)
@@ -196,7 +196,7 @@ class OpenOCDProgrammer(Programmer):
if ob_need_to_apply:
stm32.option_bytes_apply(self.openocd)
else:
self.logger.info(f"Option Bytes are already correct")
self.logger.info("Option Bytes are already correct")
# Load Option Bytes
# That will reset and also lock the Option Bytes and the Flash
@@ -256,7 +256,7 @@ class OpenOCDProgrammer(Programmer):
already_written = False
if already_written:
self.logger.info(f"OTP memory is already written with the given data")
self.logger.info("OTP memory is already written with the given data")
return OpenOCDProgrammerResult.Success
self.reset(self.RunMode.Stop)
+3 -3
View File
@@ -123,7 +123,7 @@ class STM32WB55:
def clear_flash_errors(self, oocd: OpenOCD):
# Errata 2.2.9: Flash OPTVERR flag is always set after system reset
# And also clear all other flash error flags
self.logger.debug(f"Resetting flash errors")
self.logger.debug("Resetting flash errors")
self.FLASH_SR.load(oocd)
self.FLASH_SR.OP_ERR = 1
self.FLASH_SR.PROG_ERR = 1
@@ -218,7 +218,7 @@ class STM32WB55:
raise Exception("Flash lock failed")
def option_bytes_apply(self, oocd: OpenOCD):
self.logger.debug(f"Applying Option Bytes")
self.logger.debug("Applying Option Bytes")
self.FLASH_CR.load(oocd)
self.FLASH_CR.OPT_STRT = 1
@@ -228,7 +228,7 @@ class STM32WB55:
self.flash_wait_for_operation(oocd)
def option_bytes_load(self, oocd: OpenOCD):
self.logger.debug(f"Loading Option Bytes")
self.logger.debug("Loading Option Bytes")
self.FLASH_CR.load(oocd)
self.FLASH_CR.OBL_LAUNCH = 1
self.FLASH_CR.store(oocd)
+2 -2
View File
@@ -77,8 +77,8 @@ class TempliteCompiler:
return
lines = self.block.splitlines()
margin = min(len(l) - len(l.lstrip()) for l in lines if l.strip())
self.block = "\n".join("\t" * self.offset + l[margin:] for l in lines)
margin = min(len(line) - len(line.lstrip()) for line in lines if line.strip())
self.block = "\n".join("\t" * self.offset + line[margin:] for line in lines)
self.blocks.append(self.block)
if self.block.endswith(":"):
self.offset += 1