forked from flipperdevices/flipperzero-firmware
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathob.py
executable file
·80 lines (63 loc) · 2.07 KB
/
ob.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/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()()