summaryrefslogtreecommitdiff
path: root/debian/ath10k_helpers/ath10k-bdencoder
diff options
context:
space:
mode:
Diffstat (limited to 'debian/ath10k_helpers/ath10k-bdencoder')
-rwxr-xr-xdebian/ath10k_helpers/ath10k-bdencoder173
1 files changed, 147 insertions, 26 deletions
diff --git a/debian/ath10k_helpers/ath10k-bdencoder b/debian/ath10k_helpers/ath10k-bdencoder
index fe32eda..d613f63 100755
--- a/debian/ath10k_helpers/ath10k-bdencoder
+++ b/debian/ath10k_helpers/ath10k-bdencoder
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
#
# Copyright (c) 2015 Qualcomm Atheros, Inc.
# Copyright (c) 2018, The Linux Foundation. All rights reserved.
@@ -28,11 +28,14 @@ import subprocess
import logging
import sys
import shutil
+import mailbox
MAX_BUF_LEN = 2000000
# the signature length also includes null byte and padding
-ATH10K_BOARD_SIGNATURE = "QCA-ATH10K-BOARD"
+ATH10K_BOARD_SIGNATURE = b"QCA-ATH10K-BOARD"
+ATH11K_BOARD_SIGNATURE = b"QCA-ATH11K-BOARD"
+BOARD_SIGNATURE = b''
ATH10K_BOARD_SIGNATURE_LEN = 20
PADDING_MAGIC = 0x6d
@@ -40,6 +43,10 @@ DEFAULT_BD_API = 2
DEFAULT_BOARD_FILE = 'board-%d.bin' % DEFAULT_BD_API
DEFAULT_JSON_FILE = 'board-%d.json' % DEFAULT_BD_API
TYPE_LENGTH_SIZE = 8
+BIN_SUFFIX = '.bin'
+
+ATH10K_FIRMWARE_URL = 'https://github.com/kvalo/ath10k-firmware/commit'
+ATH11K_FIRMWARE_URL = 'https://github.com/kvalo/ath11k-firmware/commit'
ATH10K_BD_IE_BOARD = 0
ATH10K_BD_IE_BOARD_EXT = 1
@@ -68,12 +75,20 @@ def add_ie(buf, offset, id, value):
struct.pack_into('<B', padding, i, PADDING_MAGIC)
fmt = '<2i%ds%ds' % (len(value), padding_len)
+ if not isinstance(value, bytes):
+ value = value.encode()
struct.pack_into(fmt, buf, offset, id, len(value), value, padding.raw)
offset = offset + TYPE_LENGTH_SIZE + len(value) + padding_len
return offset
+def xclip(msg):
+ p = subprocess.Popen(['xclip', '-selection', 'clipboard'],
+ stdin=subprocess.PIPE)
+ p.communicate(msg.encode())
+
+
# to workaround annoying python feature of returning negative hex values
def hex32(val):
return val & 0xffffffff
@@ -93,7 +108,8 @@ class BoardName():
def parse_ie(buf, offset, length):
self = BoardName()
fmt = '<%ds' % length
- (self.name, ) = struct.unpack_from(fmt, buf, offset)
+ (name, ) = struct.unpack_from(fmt, buf, offset)
+ self.name = name.decode()
logging.debug('BoardName.parse_ie(): offset %d length %d self %s' %
(offset, length, self))
@@ -235,10 +251,21 @@ class Board():
class BoardContainer:
+ def find_board(self, name):
+ for board in self.boards:
+ for boardname in board.names:
+ if name == boardname.name:
+ return board
+
def add_board(self, data, names):
boardnames = []
ebdf = False
+
for name in names:
+ b = self.find_board(name)
+ if b:
+ self.boards.remove(b)
+
if "bmi-eboard-id" in name:
ebdf = True
boardnames.append(BoardName(name))
@@ -255,7 +282,7 @@ class BoardContainer:
self = BoardContainer()
if not os.path.exists(filename):
- print 'mapping file %s not found' % (filename)
+ print('mapping file %s not found' % (filename))
return
f = open(filename, 'r')
@@ -281,13 +308,13 @@ class BoardContainer:
# TODO: Find a better way to report problems,
# maybe return a list of strings? Or use an
# exception?
- print 'Warning: duplicate board name: %s' % (name.name)
+ print('Warning: duplicate board name: %s' % (name.name))
return
allnames.append(name)
def _add_signature(self, buf, offset):
- signature = ATH10K_BOARD_SIGNATURE + '\0'
+ signature = BOARD_SIGNATURE + b'\0'
length = len(signature)
pad_len = padding_needed(length)
length = length + pad_len
@@ -319,11 +346,11 @@ class BoardContainer:
offset = 0
- fmt = '<%dsb' % (len(ATH10K_BOARD_SIGNATURE))
+ fmt = '<%dsb' % (len(BOARD_SIGNATURE))
(signature, null) = struct.unpack_from(fmt, buf, offset)
- if signature != ATH10K_BOARD_SIGNATURE or null != 0:
- print "invalid signature found in %s" % name
+ if signature != BOARD_SIGNATURE or null != 0:
+ print("invalid signature found in %s" % name)
return 1
offset += ATH10K_BOARD_SIGNATURE_LEN
@@ -337,9 +364,9 @@ class BoardContainer:
offset += TYPE_LENGTH_SIZE
if offset + ie_len > buf_len:
- print 'Error: Buffer too short (%d + %d > %d)' % (offset,
+ print('Error: Buffer too short (%d + %d > %d)' % (offset,
ie_len,
- buf_len)
+ buf_len))
return 1
# FIXME: create separate ExtenderBoard() class and
@@ -362,7 +389,7 @@ class BoardContainer:
self.validate()
- print "board binary file '%s' is created" % name
+ print("board binary file '%s' is created" % name)
def get_bin(self):
buf = ctypes.create_string_buffer(MAX_BUF_LEN)
@@ -422,18 +449,18 @@ def cmd_extract(args):
b['data'] = filename
mapping.append(b)
- f = open(filename, 'w')
+ f = open(filename, 'wb')
f.write(board.data.data)
f.close()
- print "%s created size: %d" % (filename, len(board.data.data))
+ print("%s created size: %d" % (filename, len(board.data.data)))
filename = DEFAULT_JSON_FILE
f = open(filename, 'w')
f.write(json.dumps(mapping, indent=4))
f.close()
- print "%s created" % (filename)
+ print("%s created" % (filename))
def cmd_info(args):
@@ -441,7 +468,7 @@ def cmd_info(args):
cont = BoardContainer().open(filename)
- print cont.get_summary()
+ print(cont.get_summary())
def cmd_diff(args):
@@ -452,7 +479,7 @@ def cmd_diff(args):
filename1 = args.diffstat[0]
filename2 = args.diffstat[1]
- print diff_boardfiles(filename1, filename2, args.diff)
+ print(diff_boardfiles(filename1, filename2, args.diff))
def diff_boardfiles(filename1, filename2, diff):
@@ -460,11 +487,11 @@ def diff_boardfiles(filename1, filename2, diff):
container1 = BoardContainer().open(filename1)
(temp1_fd, temp1_pathname) = tempfile.mkstemp()
- os.write(temp1_fd, container1.get_summary(sort=True))
+ os.write(temp1_fd, container1.get_summary(sort=True).encode())
container2 = BoardContainer().open(filename2)
(temp2_fd, temp2_pathname) = tempfile.mkstemp()
- os.write(temp2_fd, container2.get_summary(sort=True))
+ os.write(temp2_fd, container2.get_summary(sort=True).encode())
# this function is used both with --diff and --diffstat
if diff:
@@ -480,13 +507,13 @@ def diff_boardfiles(filename1, filename2, diff):
if e.returncode == 1:
output = e.output
else:
- print 'Failed to run wdiff: %d\n%s' % (e.returncode, e.output)
+ print('Failed to run wdiff: %d\n%s' % (e.returncode, e.output))
return 1
except OSError as e:
- print 'Failed to run wdiff: %s' % (e)
+ print('Failed to run wdiff: %s' % (e))
return 1
- result += '%s\n' % (output)
+ result += '%s\n' % (output.decode())
# create simple statistics about changes in board images
@@ -547,14 +574,14 @@ def cmd_create(args):
def cmd_add_board(args):
if len(args.add_board) < 3:
- print 'error: --add-board requires 3 or more arguments, only %d given' % (len(args.add_board))
+ print('error: --add-board requires 3 or more arguments, only %d given' % (len(args.add_board)))
sys.exit(1)
board_filename = args.add_board[0]
new_filename = args.add_board[1]
new_names = args.add_board[2:]
- f = open(new_filename, 'r')
+ f = open(new_filename, 'rb')
new_data = f.read()
f.close()
@@ -566,13 +593,92 @@ def cmd_add_board(args):
container.add_board(new_data, new_names)
container.write(board_filename)
- print diff_boardfiles(temp_pathname, board_filename, False)
+ print(diff_boardfiles(temp_pathname, board_filename, False))
os.remove(temp_pathname)
+def git_get_head_id():
+ return subprocess.check_output(['git', 'log', '--format=format:%H', '-1'])
+
+
+def cmd_add_mbox(args):
+ if args.mode == 10:
+ firmware_url = ATH10K_FIRMWARE_URL
+ elif args.mode == 11:
+ firmware_url = ATH11K_FIRMWARE_URL
+
+ board_filename = args.add_mbox[0]
+ mbox_filename = args.add_mbox[1]
+
+ mbox = mailbox.mbox(mbox_filename)
+
+ for msg in mbox:
+ board_files = {}
+
+ for part in msg.walk():
+ filename = part.get_filename()
+
+ if not filename:
+ # not an attachment
+ continue
+
+ if not filename.endswith(BIN_SUFFIX):
+ continue
+
+ name = filename.rstrip(BIN_SUFFIX)
+ board_files[name] = part.get_payload(decode=True)
+
+ print('Found mail "%s" with %d board files' % (msg['Subject'],
+ len(board_files)))
+
+ # copy the original file for diff
+ (temp_fd, temp_pathname) = tempfile.mkstemp()
+ shutil.copyfile(board_filename, temp_pathname)
+
+ container = BoardContainer.open(board_filename)
+ for name, data in board_files.items():
+ names = [name]
+ container.add_board(data, names)
+
+ container.write(board_filename)
+
+ applied_msg = ''
+
+ if args.commit:
+ cmd = ['git', 'commit', '--quiet', '-m', msg['Subject'], board_filename]
+ subprocess.check_call(cmd)
+
+ applied_msg += 'Thanks, added to %s:\n\n' % (board_filename)
+
+ applied_msg += diff_boardfiles(temp_pathname, board_filename, False)
+ applied_msg += '\n\n'
+
+ if args.commit:
+ applied_msg += '%s/%s\n\n' % (ATH10K_FIRMWARE_URL, git_get_head_id())
+
+ os.remove(temp_pathname)
+
+ print('----------------------------------------------')
+ print(applied_msg)
+ print('----------------------------------------------')
+
+ xclip(applied_msg)
+
+
+def mode_parse(v):
+ if v == 'ath10k':
+ return 10
+ elif v == 'ath11k':
+ return 11
+ else:
+ raise argparse.ArgumentTypeError('ath10k or ath11k expected.')
+
+
def main():
- description = '''ath10k board-N.bin files manegement tool
+ global BOARD_SIGNATURE
+
+ description = '''ath10k/ath11k board-N.bin files management tool
ath10k-bdencoder is for creating (--create), listing (--info) and
comparing (--diff, --diffstat) ath10k board-N.bin files. The
@@ -612,17 +718,30 @@ can use --extract switch to see examples from real board-N.bin files.
cmd_group.add_argument('-a', '--add-board', metavar='NAME', nargs='+',
help='add a board file to an existing board-N.bin, first argument is the filename of board-N.bin to add to, second is the filename board file (board.bin) to add and then followed by one or more arguments are names used in board-N.bin')
+ cmd_group.add_argument('-A', '--add-mbox', metavar='FILENAME', nargs=2,
+ help='FIXME')
+
+ parser.add_argument('-C', '--commit', action='store_true',
+ help='commit changes to a git repository')
parser.add_argument('-v', '--verbose', action='store_true',
help='enable verbose (debug) messages')
parser.add_argument("-o", "--output", metavar="BOARD_FILE",
help='name of the output file, otherwise the default is: %s' %
(DEFAULT_BOARD_FILE))
+ parser.add_argument("-m", "--mode", metavar='MODE',
+ help='select between ath10k and ath11k mode (default: ath10k)',
+ default=10, type=mode_parse)
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
+ if args.mode == 10:
+ BOARD_SIGNATURE = ATH10K_BOARD_SIGNATURE
+ elif args.mode == 11:
+ BOARD_SIGNATURE = ATH11K_BOARD_SIGNATURE
+
if args.create:
return cmd_create(args)
elif args.extract:
@@ -635,6 +754,8 @@ can use --extract switch to see examples from real board-N.bin files.
return cmd_diff(args)
elif args.add_board:
return cmd_add_board(args)
+ elif args.add_mbox:
+ return cmd_add_mbox(args)
if __name__ == "__main__":
main()