diff --git a/hex_free_size.py b/hex_free_size.py new file mode 100644 index 0000000..cde49c9 --- /dev/null +++ b/hex_free_size.py @@ -0,0 +1,39 @@ +#------------------------------------------------------------------------------- +# hex_free_space +# 02/05/2022 +# tool script used to estimate the free space left in a µP based on the number +# of 0xFF bytes in the hex file. This methode only works for filled hex files. +# +# usage ex: python hex_free_size somehexfile.hex somemorehexfile.hex +#------------------------------------------------------------------------------- + +import fileinput +import re + +free_space = 0 +free_threshold = 16 + +p = re.compile(r':[0-9A-F]{8,8}([0-9A-F]{32,32})') +for line in fileinput.input(): + val = re.search(p, line) + if val: + data = val.group(0) + count = 0 + for char in data: + if char == 'F': + count += 1 + if count <= free_threshold: + continue + + for char in data: + if char == 'F': + if first: + first = False + else: + first = True + free_space += 1 + else: + first = True + +print("estimated free space: " + str(free_space)) + diff --git a/lst_diff.py b/lst_diff.py new file mode 100644 index 0000000..2b8420b --- /dev/null +++ b/lst_diff.py @@ -0,0 +1,49 @@ +#------------------------------------------------------------------------------- +# lst_diff +# 22/03/2022 +# tool script used to summarize the code size of a list of .lst, which display +# the size of segment CODE in their last lines +# +# usage ex: find lst_folder -name *.lst | python lst_diff.py > output.txt +# the output can then be compared using diff +#------------------------------------------------------------------------------- + +import fileinput +import re + +code_size = 0 + +p_code = re.compile("CODE") +# list of input lst files +for lst_file in fileinput.input(): + + lst = lst_file.rstrip('\n') + i = 0 + buff = [] + + # get 3 lines containing code size infos + for line in reversed(list(open(lst, encoding="latin-1"))): + i += 1 + if i > 3 and i < 7: + buff.append(line) + elif i >= 7: + break + + #parse lines + for line in buff: + if re.search(p_code, line): + toks = line.split() + size = 0 + try: + size += int(toks[1]) + except: + pass + if size != 0: + size += 1000 * int(toks[0]) + else: + size += int(toks[0]) + code_size += size + print(lst.split('/').pop() + ": " + str(size)) + +print("total: " + str(code_size)) + diff --git a/map_diff.py b/map_diff.py new file mode 100644 index 0000000..8ea5707 --- /dev/null +++ b/map_diff.py @@ -0,0 +1,32 @@ +#------------------------------------------------------------------------------- +# map_diff +# 22/03/2022 +# tool script used to easily compare diffs of (IAR) .map files +# +# usage ex: diff -hu file1.map file2.map | python map_diff.py +#------------------------------------------------------------------------------- + +import fileinput +import re + +old_size = 0x0 +new_size = 0x0 +prev_line = "" +total_diff = 0 + +p = re.compile('0x\w+ ') +for line in fileinput.input(): + val = re.search(p, line) + if val: + if line[0] == '-': + old_size = int(val.group(0), base=16) + prev_line = line + else: + new_size = int(val.group(0), base=16) + if new_size != old_size: + diff = new_size-old_size + total_diff += diff + print(prev_line + line + "diff: " + str(diff)) + +print("total diff: " + str(total_diff)) + diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..ec51774 --- /dev/null +++ b/utils.py @@ -0,0 +1,6 @@ +def twos_complement(hexstr,bits): + value = int(hexstr,16) + if value & (1 << (bits-1)): + value -= 1 << bits + return value +