-
Notifications
You must be signed in to change notification settings - Fork 33
/
ubt.py
executable file
·73 lines (59 loc) · 2.11 KB
/
ubt.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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0 OR MIT
# -*- coding: utf-8 -*-
__license__ = "GPL-2.0"
__copyright__ = "Copyright (c) 2024, SaluteDevices"
__version__ = '0.0.1'
import argparse
import logging
import sys
from enum import Enum
from adnl import do_adnl_burn
from pyamlboot.amlimage import AmlImagePack
from pyamlboot.optimus import do_optimus_burn
class WipeFormat(Enum):
no = 0
normal = 1
all = 3
def __str__(self):
return self.name
def main():
logging.basicConfig(level=logging.DEBUG,
format='[%(asctime)s] [%(levelname)-8s]: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
parser = argparse.ArgumentParser()
parser.add_argument('--img',
required=True,
type=argparse.FileType('rb'),
help='Specify location path to aml_upgrade_package.img')
parser.add_argument('--reset',
action='store_true',
default=False,
help='Reset after success')
parser.add_argument('--no-erase-bootloader',
action='store_true',
default=False,
help='Erase bootloader')
parser.add_argument('--wipe',
type=lambda x: WipeFormat[x],
choices=list(WipeFormat),
default='normal',
help='Destroy all partitions')
parser.add_argument('--password',
type=argparse.FileType('rb'),
help='Unlock usb mode using password file provided')
parser.add_argument('--version', action='version', version=__version__)
args = parser.parse_args()
aml_img = AmlImagePack(args.img)
adnl = True
# If image contains 'usb_flow', it is ADNL
try:
aml_img.item_get('aml', 'usb_flow')
except ValueError:
adnl = False
if adnl:
do_adnl_burn(args.reset, args.wipe.value, aml_img)
else:
do_optimus_burn(args, aml_img)
if __name__ == '__main__':
sys.exit(main())