From 01e6db5c2e05f4dfde50c5b8823f2b5fa8d447e1 Mon Sep 17 00:00:00 2001 From: slurdge Date: Thu, 18 Jul 2019 22:26:01 +0200 Subject: [PATCH] Add a simple tool to analyze elf files --- CHANGELOG.md | 1 + tools/analyzesize.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 tools/analyzesize.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 89a4d7ec8..bedc1dc04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Add a simple python tool to check the elf sizes (@slurdge) - Change: new keys for Vigik badges in default_keys.dict (@luminouw) - Add 'hw standalone' to jump to standalone mode from command line or script (@doegox) - Add to 'hf 14a apdu' print apdu and compose apdu (@merlokk) diff --git a/tools/analyzesize.py b/tools/analyzesize.py new file mode 100755 index 000000000..ef14e2879 --- /dev/null +++ b/tools/analyzesize.py @@ -0,0 +1,31 @@ +#! /usr/bin/python3 + +import json +import subprocess +import sys + +def print_increase(x, y, name): + if x > y: + print("{} increase by: {} (0x{:08X}) bytes ({}%)".format(name, x-y, x-y, (x-y)*100/y)) + else: + print("{} decrease by: {} (0x{:08X}) bytes ({}%)".format(name, y-x, y-x, (y-x)*100/x)) +dbname = "tools/data.json" +db = json.load(open(dbname,"r")) + +if len(sys.argv) < 3: + print("Usage: analazysize.py ") + exit(-1) +action, name = sys.argv[1:3] +currentdata = subprocess.run(["arm-none-eabi-size","armsrc/obj/fullimage.stage1.elf"], stdout=subprocess.PIPE).stdout +currentdata = currentdata.split(b"\n")[1].strip() +text,data,bss = [int(x) for x in currentdata.split(b"\t")[:3]] +if action.lower() == "add": + db[name] = [text, data, bss] + json.dump(db, open(dbname, "w")) +elif action.lower() == "diff": + text_ref, data_ref, bss_ref = db[name] + flash_ref = text_ref+data_ref + flash = text+data + print_increase(flash, flash_ref, "Flash") + print_increase(bss, bss_ref, "RAM") + \ No newline at end of file