2017-10-06 22:11:50 +00:00
|
|
|
#!/usr/bin/python2
|
|
|
|
|
|
|
|
## Quick little pyelftools script to test the size of a CC430F6137
|
|
|
|
## firmware image, warning the user if it looks too big.
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
from elftools.elf.elffile import ELFFile
|
|
|
|
from elftools.elf.sections import SymbolTableSection
|
|
|
|
|
|
|
|
|
|
|
|
def process_file(filename):
|
2018-05-24 18:56:02 +00:00
|
|
|
print("%s:" % filename);
|
2017-10-06 22:11:50 +00:00
|
|
|
with open(filename, 'rb') as f:
|
|
|
|
printsizes(f)
|
|
|
|
|
|
|
|
|
|
|
|
def printsizes(stream):
|
|
|
|
elffile = ELFFile(stream);
|
|
|
|
|
2018-05-24 18:56:02 +00:00
|
|
|
|
2017-10-06 22:11:50 +00:00
|
|
|
text=elffile.get_section_by_name('.text');
|
|
|
|
textlen=len(text.data());
|
2019-05-17 15:21:29 +00:00
|
|
|
rodata=elffile.get_section_by_name('.rodata');
|
|
|
|
rodatalen=len(rodata.data());
|
|
|
|
codeperc=(textlen+rodatalen)*100.0/32768;
|
|
|
|
print("\t%d bytes of .text, %d bytes of .rodata (%d%% Flash)" % (textlen,rodatalen,codeperc));
|
|
|
|
if codeperc>90:
|
|
|
|
print("WARNING: %d percent of Flash is used!"%codeperc);
|
2017-10-06 22:11:50 +00:00
|
|
|
|
2018-05-24 18:56:02 +00:00
|
|
|
datalen=0;
|
|
|
|
bsslen=0;
|
|
|
|
noinitlen=0;
|
|
|
|
|
2017-10-06 22:11:50 +00:00
|
|
|
data=elffile.get_section_by_name('.data');
|
|
|
|
datalen=len(data.data());
|
|
|
|
bss=elffile.get_section_by_name('.bss');
|
|
|
|
bsslen=len(bss.data());
|
2017-11-18 18:04:02 +00:00
|
|
|
noinit=elffile.get_section_by_name('.noinit');
|
2018-05-24 18:56:02 +00:00
|
|
|
if noinit!=None:
|
|
|
|
noinitlen=len(noinit.data());
|
2017-11-18 18:04:02 +00:00
|
|
|
dataperc=(datalen+bsslen+noinitlen)*100.0/4096;
|
2018-05-24 18:56:02 +00:00
|
|
|
|
|
|
|
if datalen+bsslen+noinitlen>0:
|
2019-05-17 15:21:29 +00:00
|
|
|
print("\t%d bytes of .data, %d bytes of .bss, %d bytes of .noinit (%d%% RAM)"
|
2018-05-24 18:56:02 +00:00
|
|
|
%(datalen,bsslen,noinitlen,dataperc));
|
2017-10-06 22:11:50 +00:00
|
|
|
if dataperc>80:
|
2018-01-28 21:47:05 +00:00
|
|
|
print("WARNING: %d percent of data is used!"%dataperc);
|
2017-10-06 22:11:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
for filename in sys.argv[1:]:
|
|
|
|
process_file(filename)
|