-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoflash.py
84 lines (75 loc) · 2.03 KB
/
autoflash.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
81
82
83
84
import logging
import argparse
import ipaddress
from autoflash import OPENWRT_DEFAULT_LAN_IP
from autoflash import run_autoflash
def parse_args():
parser = argparse.ArgumentParser(
prog="autoflash", description="Huawei APXXXXDN Autoflasher"
)
parser.add_argument(
"ramboot_file_name",
type=str,
help="Ramboot filename (only!), eg. openwrt-ath79-generic-huawei_apXXXXdn-initramfs-kernel.bin",
)
parser.add_argument(
"--sysupgrade-path",
type=str,
help="Sysupgrade file path, eg. openwrt-ath79-generic-huawei_apXXXXdn-squashfs-sysupgrade.bin. "
"If not provided, the script will only ramboot the AP.",
)
parser.add_argument(
"--port",
type=str,
default="/dev/ttyUSB0",
help="Serial port, default is /dev/ttyUSB0",
)
parser.add_argument(
"--speed", type=int, default=9600, help="Baudrate, default is 9600"
)
parser.add_argument(
"-p",
"--password",
type=str,
default="[email protected]",
help="Bootloader Password",
)
parser.add_argument(
"--ap-ip",
type=ipaddress.IPv4Address,
default=OPENWRT_DEFAULT_LAN_IP,
help="IP address for the AP",
)
parser.add_argument(
"-d",
"--debug",
help="Enable debug logging, ie. show serial output",
action="store_const",
dest="loglevel",
const=logging.DEBUG,
default=logging.WARNING,
)
parser.add_argument(
"-v",
"--verbose",
help="Enable verbose logging",
action="store_const",
dest="loglevel",
const=logging.INFO,
)
return parser.parse_args()
def main():
args = parse_args()
logging.basicConfig(level=args.loglevel)
run_autoflash(
args.ramboot_file_name,
args.sysupgrade_path,
args.port,
args.speed,
args.password,
args.ap_ip,
)
if args.loglevel == logging.DEBUG:
print()
if __name__ == "__main__":
main()