flipperzero-firmware/scripts/flipper/assets/copro.py

111 lines
4.0 KiB
Python
Raw Normal View History

import logging
import datetime
import shutil
import json
from os.path import basename
import xml.etree.ElementTree as ET
[FL-2150] Dolphin animation refactoring (#938) * Dolphin Animation Refactoring, part 1 * Remove animations from desktop * Remove excess, first start * Split animation_manager with callbacks * allocate view inside animation_view * Work on ViewComposed * Draw white rectangles under bubble corners * Fix bubbles sequence * RPC: remove obsolete include "status.pb.h" * Add animations manifest decoding * Flipper file: add strict mode * FFF: Animation structures parsing * Assembling structure of animation * Lot of view fixes: Add multi-line bubbles Add support for passive bubbles (frame_order values starts from passive now) Add hard-coded delay (active_shift) for active state enabling Fix active state handling Fix leaks Fix parsing uncorrect bubble_animation meta file Fix bubble rules of showing * Animation load/unload & view freeze/unfreeze * Blocking & system animations, fixes: View correct activation Refactoring + blocking animation Freeze first passive/active frames Many insert/eject SD tests fixes Add system animations Add Loader events app started/finished Add system no_sd animation * Assets: dolphin packer. Scripts: minor refactoring. * Desktop: update logging tags. Scripts: add metadata to dolphin bundling process, extra sorting for fs traversing. Make: phony assets rules. * Github: rebuild assets on build * Docker: add missing dependencies for assets compilation * Docker: fix run command syntax * ReadMe: update naming rules with link to source * Assets: recompile icons * Loader: add loader event * Desktop, Gui, Furi Core: const shenanigans macros Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-01-02 21:39:56 +00:00
from flipper.utils import *
from flipper.assets.coprobin import CoproBinary, get_stack_type
CUBE_COPRO_PATH = "Projects/STM32WB_Copro_Wireless_Binaries"
MANIFEST_TEMPLATE = {
"manifest": {"version": 0, "timestamp": 0},
"copro": {
"fus": {"version": {"major": 1, "minor": 2, "sub": 0}, "files": []},
"radio": {
"version": {},
"files": [],
},
},
}
class Copro:
def __init__(self, mcu):
self.mcu = mcu
self.version = None
self.cube_dir = None
self.mcu_copro = None
self.logger = logging.getLogger(self.__class__.__name__)
def loadCubeInfo(self, cube_dir, cube_version):
if not os.path.isdir(cube_dir):
raise Exception(f'"{cube_dir}" doesn\'t exists')
self.cube_dir = cube_dir
self.mcu_copro = os.path.join(self.cube_dir, CUBE_COPRO_PATH, self.mcu)
if not os.path.isdir(self.mcu_copro):
raise Exception(f'"{self.mcu_copro}" doesn\'t exists')
cube_manifest_file = os.path.join(self.cube_dir, "package.xml")
cube_manifest = ET.parse(cube_manifest_file)
cube_package = cube_manifest.find("PackDescription")
if not cube_package:
raise Exception(f"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")
cube_version = cube_version.replace("FW.WB.", "", 1)
if cube_version != cube_version:
raise Exception(f"Unsupported cube version")
self.version = cube_version
def addFile(self, array, filename, **kwargs):
source_file = os.path.join(self.mcu_copro, filename)
destination_file = os.path.join(self.output_dir, filename)
shutil.copyfile(source_file, destination_file)
array.append(
{"name": filename, "sha256": file_sha256(destination_file), **kwargs}
)
def bundle(self, output_dir, stack_file_name, stack_type, stack_addr=None):
if not os.path.isdir(output_dir):
raise Exception(f'"{output_dir}" doesn\'t exists')
self.output_dir = output_dir
stack_file = os.path.join(self.mcu_copro, stack_file_name)
manifest_file = os.path.join(self.output_dir, "Manifest.json")
# Form Manifest
manifest = dict(MANIFEST_TEMPLATE)
manifest["manifest"]["timestamp"] = timestamp()
copro_bin = CoproBinary(stack_file)
self.logger.info(f"Bundling {copro_bin.img_sig.get_version()}")
stack_type_code = get_stack_type(stack_type)
manifest["copro"]["radio"]["version"].update(
{
"type": stack_type_code,
"major": copro_bin.img_sig.version_major,
"minor": copro_bin.img_sig.version_minor,
"sub": copro_bin.img_sig.version_sub,
"branch": copro_bin.img_sig.version_branch,
"release": copro_bin.img_sig.version_build,
}
)
if not stack_addr:
stack_addr = copro_bin.get_flash_load_addr()
self.logger.info(f"Using guessed flash address 0x{stack_addr:x}")
# Old FUS Update
self.addFile(
manifest["copro"]["fus"]["files"],
"stm32wb5x_FUS_fw_for_fus_0_5_3.bin",
condition="==0.5.3",
address="0x080EC000",
)
# New FUS Update
self.addFile(
manifest["copro"]["fus"]["files"],
"stm32wb5x_FUS_fw.bin",
condition=">0.5.3",
address="0x080EC000",
)
# BLE Full Stack
self.addFile(
manifest["copro"]["radio"]["files"],
stack_file_name,
address=f"0x{stack_addr:X}",
)
# Save manifest to
with open(manifest_file, "w", newline="\n") as file:
json.dump(manifest, file)