flipperzero-firmware/scripts/bin2dfu.py
hedger eb31fed0e2
[FL-2556] Update complete screen (#1332)
* Desktop: slideshow implementation
* Updater: handling splashscreen installation; added format version field to slideshow binary
* Desktop: added bidirectional slideshow navigation + instant cancel by "back" button; Updater: rebalanced update stages weights
* Updater: fixed missing field init; fixed potential loop when baking slideshows
* Assets: fixed "update complete" image to match original
* Desktop: added check for slideshow file version
* Scripts: slideshow.py cleanup
* Desktop: removed first start intro sequence
* Desktop: removed first start remnants
2022-06-21 23:11:34 +09:00

71 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import struct
from zlib import crc32
from flipper.app import App
class Main(App):
def init(self):
self.parser.add_argument("-i", "--input", help=".bin input path", required=True)
self.parser.add_argument(
"-o", "--output", help=".dfu output path", required=True
)
self.parser.add_argument(
"-a",
"--address",
help="Flash address",
type=lambda x: int(x, 0),
required=True,
)
self.parser.add_argument(
"-l", "--label", help="DFU Target label", required=True
)
self.parser.add_argument(
"--vid", help="USB Vendor ID", default=0x0483, type=lambda x: int(x, 0)
)
self.parser.add_argument(
"--pid", help="USB Product ID", default=0xDF11, type=lambda x: int(x, 0)
)
self.parser.set_defaults(func=self.convert)
def convert(self):
if not os.path.exists(self.args.input):
self.logger.error(f'"{self.args.input}" does not exist')
return 1
with open(self.args.input, mode="rb") as file:
bindata = file.read()
data = struct.pack("<II", self.args.address, len(bindata)) + bindata
# Target prefix
szTargetName = self.args.label.encode("ascii")
data = (
struct.pack("<6sBI255sII", b"Target", 0, 1, szTargetName, len(data), 1)
+ data
)
# Prefix
data = struct.pack("<5sBIB", b"DfuSe", 0x01, len(data) + 11, 1) + data
# Suffix
data += struct.pack(
"<HHHH3sB", 0xFFFF, self.args.pid, self.args.vid, 0x011A, b"UFD", 16
)
dwCRC = ~crc32(data) & 0xFFFFFFFF
data += struct.pack("<I", dwCRC)
open(self.args.output, "wb").write(data)
return 0
if __name__ == "__main__":
Main()()