mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00:00
727f043747
* Scripts: option bytes check * Scripts: option bytes set * Scripts: openocd config * Scripts: increased readability, process IPCCBR option byte * Scripts: split dap_ob.py * Updater: process IPCCBR option byte * Scripts: move chip-related functions to chip definition * Scripts: freeze CPU registers * Scripts: flash programming routine * ob.py * otp.py * otp: handle errors correctly * downgrade to python 3.9 * correct type hinting * Scripts: fix path to ob.data Co-authored-by: あく <alleteam@gmail.com>
80 lines
2.1 KiB
Python
Executable file
80 lines
2.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
from os import path
|
|
|
|
from flipper.app import App
|
|
from flipper.utils.programmer_openocd import OpenOCDProgrammer
|
|
|
|
|
|
class Main(App):
|
|
def init(self):
|
|
# Subparsers
|
|
self.subparsers = self.parser.add_subparsers(help="sub-command help")
|
|
|
|
# Check command
|
|
self.parser_check = self.subparsers.add_parser(
|
|
"check", help="Check Option Bytes"
|
|
)
|
|
self._add_args(self.parser_check)
|
|
self.parser_check.set_defaults(func=self.check)
|
|
|
|
# Set command
|
|
self.parser_set = self.subparsers.add_parser("set", help="Set Option Bytes")
|
|
self._add_args(self.parser_set)
|
|
self.parser_set.set_defaults(func=self.set)
|
|
|
|
def _add_args(self, parser):
|
|
parser.add_argument(
|
|
"--port-base", type=int, help="OpenOCD port base", default=3333
|
|
)
|
|
parser.add_argument(
|
|
"--interface",
|
|
type=str,
|
|
help="OpenOCD interface",
|
|
default="interface/cmsis-dap.cfg",
|
|
)
|
|
parser.add_argument(
|
|
"--serial", type=str, help="OpenOCD interface serial number"
|
|
)
|
|
parser.add_argument(
|
|
"--ob-path",
|
|
type=str,
|
|
help="Option bytes file",
|
|
default=path.join(path.dirname(__file__), "ob.data"),
|
|
)
|
|
|
|
def check(self):
|
|
self.logger.info(f"Checking Option Bytes")
|
|
|
|
# OpenOCD
|
|
openocd = OpenOCDProgrammer(
|
|
self.args.interface,
|
|
self.args.port_base,
|
|
self.args.serial,
|
|
)
|
|
|
|
return_code = 1
|
|
if openocd.option_bytes_validate(self.args.ob_path):
|
|
return_code = 0
|
|
|
|
return return_code
|
|
|
|
def set(self):
|
|
self.logger.info(f"Setting Option Bytes")
|
|
|
|
# OpenOCD
|
|
openocd = OpenOCDProgrammer(
|
|
self.args.interface,
|
|
self.args.port_base,
|
|
self.args.serial,
|
|
)
|
|
|
|
return_code = 1
|
|
if openocd.option_bytes_set(self.args.ob_path):
|
|
return_code = 0
|
|
|
|
return return_code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
Main()()
|