Skip to content

Commit f2de9e1

Browse files
Add segment size printout to standard build process (#6525)
Since IRAM is such a precious resource on the ESP8266, dump out its size (and all other segments) at the end of the build process. Ex: Executable segment sizes: IROM : 338932 IRAM : 27263 DATA : 1476 RODATA : 2896 BSS : 30304 Sketch uses 370567 bytes (35%) of program storage space. Maximum is 1044464 bytes. Global variables use 34676 bytes (42%) of dynamic memory, leaving 47244 bytes for local variables. Maximum is 81920 bytes.
1 parent f5a7318 commit f2de9e1

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

platform.txt

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ runtime.tools.python3.path={runtime.platform.path}/tools/python3
1515
runtime.tools.esptool.path={runtime.platform.path}/tools/esptool
1616
runtime.tools.signing={runtime.platform.path}/tools/signing.py
1717
runtime.tools.elf2bin={runtime.platform.path}/tools/elf2bin.py
18+
runtime.tools.sizes={runtime.platform.path}/tools/sizes.py
1819
runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py
1920
runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
2021

@@ -112,6 +113,7 @@ recipe.objcopy.eep.pattern=
112113
## Create hex
113114
recipe.objcopy.hex.1.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.elf2bin}" --eboot "{runtime.tools.eboot}" --app "{build.path}/{build.project_name}.elf" --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --out "{build.path}/{build.project_name}.bin"
114115
recipe.objcopy.hex.2.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed" --legacy "{build.path}/{build.project_name}.bin.legacy_sig"
116+
recipe.objcopy.hex.3.pattern="{runtime.tools.python3.path}/python3" "{runtime.tools.sizes}" --elf "{build.path}/{build.project_name}.elf" --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin"
115117

116118
## Save hex
117119
recipe.output.tmp_file={build.project_name}.bin

tools/sizes.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
3+
# Display the segment sizes used by an ELF
4+
#
5+
# Copyright (C) 2019 - Earle F. Philhower, III
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
from __future__ import print_function
21+
import argparse
22+
import os
23+
import subprocess
24+
import sys
25+
26+
def get_segment_sizes(elf, path):
27+
sizes = {}
28+
sizes['IROM'] = 0
29+
sizes['IRAM'] = 0
30+
sizes['DATA'] = 0
31+
sizes['RODATA'] = 0
32+
sizes['BSS'] = 0
33+
p = subprocess.Popen([path + "/xtensa-lx106-elf-size", '-A', elf], stdout=subprocess.PIPE, universal_newlines=True )
34+
lines = p.stdout.readlines()
35+
for line in lines:
36+
words = line.split()
37+
if line.startswith('.irom0.text'):
38+
sizes['IROM'] = sizes['IROM'] + int(words[1])
39+
elif line.startswith('.text'): # Gets .text and .text1
40+
sizes['IRAM'] = sizes['IRAM'] + int(words[1])
41+
elif line.startswith('.data'): # Gets .text and .text1
42+
sizes['DATA'] = sizes['DATA'] + int(words[1])
43+
elif line.startswith('.rodata'): # Gets .text and .text1
44+
sizes['RODATA'] = sizes['RODATA'] + int(words[1])
45+
elif line.startswith('.bss'): # Gets .text and .text1
46+
sizes['BSS'] = sizes['BSS'] + int(words[1])
47+
return sizes
48+
49+
def main():
50+
parser = argparse.ArgumentParser(description='Report the different segment sizes of a compiled ELF file')
51+
parser.add_argument('-e', '--elf', action='store', required=True, help='Path to the Arduino sketch ELF')
52+
parser.add_argument('-p', '--path', action='store', required=True, help='Path to Xtensa toolchain binaries')
53+
54+
args = parser.parse_args()
55+
sizes = get_segment_sizes(args.elf, args.path)
56+
57+
sys.stderr.write("Executable segment sizes:" + os.linesep)
58+
for k in sizes.keys():
59+
sys.stderr.write("%-7s: %d%s" % (k, sizes[k], os.linesep))
60+
61+
return 0
62+
63+
if __name__ == '__main__':
64+
sys.exit(main())

0 commit comments

Comments
 (0)