Makefile: display firmware size
[RRG-proxmark3.git] / tools / analyzesize.py
blob4d02f86ef117fdf19c17e9f0661af385d940fd4a
1 #! /usr/bin/env python3
3 import json
4 import subprocess
5 import sys
7 def print_increase(x, y, name):
8 if x > y:
9 print("{} increase by: {} (0x{:08X}) bytes ({}%)".format(name, x-y, x-y, (x-y)*100/y))
10 else:
11 print("{} decrease by: {} (0x{:08X}) bytes ({}%)".format(name, y-x, y-x, (y-x)*100/x))
12 dbname = "tools/data.json"
13 try:
14 db = json.load(open(dbname,"r"))
15 except FileNotFoundError:
16 db = dict()
18 if len(sys.argv) < 3:
19 print("Usage: analyzesize.py <info|add|diff> <datasetname>")
20 exit(2)
21 action, name = sys.argv[1:3]
22 currentdata = subprocess.run(["arm-none-eabi-size","armsrc/obj/fullimage.stage1.elf"], stdout=subprocess.PIPE).stdout
23 currentdata = currentdata.split(b"\n")[1].strip()
24 text,data,bss = [int(x) for x in currentdata.split(b"\t")[:3]]
25 if action.lower() == "add":
26 db[name] = [text, data, bss]
27 json.dump(db, open(dbname, "w"))
28 elif action.lower() == "diff":
29 text_ref, data_ref, bss_ref = db[name]
30 flash_ref = text_ref+data_ref
31 flash = text+data
32 print_increase(flash, flash_ref, "Flash")
33 print_increase(bss, bss_ref, "RAM")