forked from tiancj/hid_download_py
-
Notifications
You must be signed in to change notification settings - Fork 2
/
uartprogram
executable file
·59 lines (54 loc) · 2.15 KB
/
uartprogram
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
#!/usr/bin/env python3
# encoding: utf8
#
# HID Download Tool
#
# Copyright (c) BekenCorp. (chunjian.tian@bekencorp.com). All rights reserved.
#
# This software may be distributed under the terms of the BSD license.
# See README for more details.
import sys
import os
import argparse
from bkutils import UartDownloader
from bkutils import Unpackager
# import hid
import threading
# parse commandline arguments
def parse_args():
description = '''Beken Uart Downloader.'''
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-d', '--device',
default='/dev/ttyUSB0',
help="Uart device, default /dev/ttyUSB0")
parser.add_argument('-s', '--startaddr', type=lambda x: int(x, 16),
default=0x11000,
help="burn flash address, defaults to 0x11000")
parser.add_argument('-l', '--length', type=lambda x: int(x, 16),
default=0x119000,
help="length to read, defaults to 0x119000")
parser.add_argument('-b', '--baudrate', type=int,
default=921600,
help="burn uart baudrate, defaults to 921600")
parser.add_argument('-u', '--unprotect', action="store_true",
help="unprotect flash first, used by BK7231N")
parser.add_argument('-r', '--read', action="store_true",
help="read flash")
parser.add_argument('-w', '--write', action="store_true",
help="write flash")
parser.add_argument('-p', '--unpackage', action="store_true",
help="unPackage firmware")
parser.add_argument('filename',
help='specify file_crc.bin')
args = parser.parse_args()
return args
args = parse_args()
if args.unpackage:
Unpackager(args.filename, args.filename + '.unpackage.bin')
else:
downloader = UartDownloader(args.device, args.baudrate, args.unprotect)
if args.read:
downloader.read(args.filename, args.startaddr, args.length)
else:
if args.write:
downloader.programm(args.filename, args.startaddr)