diff --git a/dcc_parser/dcc_parser.py b/dcc_parser/dcc_parser.py index ba0433538a892edb30a62c1792df5fdb021a5e74..4792e1959f9c3ec6ec6035ae3c79752503ff742c 100644 --- a/dcc_parser/dcc_parser.py +++ b/dcc_parser/dcc_parser.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015, 2017, The Linux Foundation. All rights reserved. +# Copyright (c) 2015, 2017, 2019 The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -22,6 +22,14 @@ count = 0 address = [] data = [] +def bm(msb, lsb): + 'Creates a bitmask from msb to lsb' + return int(('1' * (msb - lsb + 1)) + ('0' * lsb), 2) + + +def bvalsel(msb, lsb, val): + 'Masks and returns the bits from msb to lsb in val' + return ((val & bm(msb, lsb)) >> lsb) def log_init(name, path, filename): # Set up logger @@ -95,6 +103,11 @@ def read_config(config_pt): if options.config_offset is not None: config_pt.seek(int(options.config_offset, 16), 1) + if options.config_loopoffset is not None: + config_loopoffset = int(options.config_loopoffset) + else: + config_loopoffset = 13 + while True: word = config_pt.read(4) if len(word) != 4: @@ -131,8 +144,8 @@ def read_config(config_pt): else: offset = 0 elif descriptor == loop_descriptor: - loop_offset = val & 0x1FFF - loop_count = (val & 0xFFFE000) >> 13 + loop_offset = val & bm(config_loopoffset, 0) + loop_count = bvalsel(27, config_loopoffset, val) if loop_offset == 0: continue @@ -228,6 +241,8 @@ if __name__ == '__main__': help='DCC driver version 2') parser.add_option('--config-offset', dest='config_offset', help='Start offset for DCC configuration') + parser.add_option('--config-loopoffset', dest='config_loopoffset', + help='Offset of loop value') (options, args) = parser.parse_args()