summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-09-07 10:42:43 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-09-07 10:42:43 +0200
commit315f0744b249cf483b9ce9a318066d2a54e21c25 (patch)
treeaf4efd2ca27e9545de4678f9abf021c0a6bfbdc9
parentdd4cb31da6c7768dea7a62057057d5cd0f2bf8e2 (diff)
add machine-readable binary size output ("make attributes")
-rwxr-xr-xscript/size.py40
-rw-r--r--src/arch/arduino-nano/Makefile.inc5
-rw-r--r--src/arch/blinkenrocket/Makefile.inc5
-rw-r--r--src/arch/esp8266/Makefile.inc6
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc5
-rw-r--r--src/arch/msp430fr5994lp/Makefile.inc5
-rw-r--r--src/arch/posix/Makefile.inc5
-rw-r--r--src/arch/stm32f446re-nucleo/Makefile.inc6
8 files changed, 70 insertions, 7 deletions
diff --git a/script/size.py b/script/size.py
new file mode 100755
index 0000000..e553314
--- /dev/null
+++ b/script/size.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+import json
+import re
+import subprocess
+import sys
+
+
+def main(size_executable, rom_sections, ram_sections):
+ rom_sections = rom_sections.split(",")
+ ram_sections = ram_sections.split(",")
+
+ status = subprocess.run(
+ [size_executable, "-A", "build/system.elf"],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True,
+ )
+
+ section_size = dict()
+
+ for line in status.stdout.split("\n"):
+ match = re.match("[.](\S+)\s+(\d+)", line)
+ if match:
+ section = match.group(1)
+ size = int(match.group(2))
+ section_size[section] = size
+
+ total = {
+ "ROM": sum(map(lambda section: section_size[section], rom_sections)),
+ "RAM": sum(map(lambda section: section_size[section], ram_sections)),
+ }
+
+ output = {"section": section_size, "total": total}
+
+ print(json.dumps(output))
+
+
+if __name__ == "__main__":
+ main(*sys.argv[1:])
diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc
index 6768c35..ea8c89b 100644
--- a/src/arch/arduino-nano/Makefile.inc
+++ b/src/arch/arduino-nano/Makefile.inc
@@ -173,4 +173,7 @@ arch_info:
@echo "Counter Overflow: 65536/255"
@echo "Monitor: ${SERIAL_PORT} ${uart_baud}"
-.PHONY: arch_clean arch_help arch_info monitor program size
+attributes: build/system.elf
+ ${QUIET}script/size.py avr-size text,data data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program size
diff --git a/src/arch/blinkenrocket/Makefile.inc b/src/arch/blinkenrocket/Makefile.inc
index ba66152..50b464a 100644
--- a/src/arch/blinkenrocket/Makefile.inc
+++ b/src/arch/blinkenrocket/Makefile.inc
@@ -84,4 +84,7 @@ arch_info:
@echo "Counter Overflow: ?/?"
@echo "Monitor: ${SERIAL_PORT} 115200"
-.PHONY: arch_clean arch_help arch_info monitor program
+attributes: build/system.elf
+ ${QUIET}script/size.py avr-size text,data data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc
index ecb5a7d..89c244a 100644
--- a/src/arch/esp8266/Makefile.inc
+++ b/src/arch/esp8266/Makefile.inc
@@ -11,6 +11,7 @@ AR = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-ar
LD = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc
OBJCOPY = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-objcopy
OBJDUMP = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-objdump
+SIZE = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-size
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 --c_compiler ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++ -p . --Xcompiler
@@ -110,4 +111,7 @@ arch_info:
@echo "Counter Overflow: 4294967296/0"
@echo "Monitor: ${SERIAL_PORT} 115200"
-.PHONY: arch_clean arch_help arch_info monitor program
+attributes: build/system.elf
+ ${QUIET}script/size.py ${SIZE} text,irom0.text data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index af285ac..99b5de2 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -156,4 +156,7 @@ arch_info:
@echo "sleep_ms Overflow: 250 500"
@echo "Monitor: /dev/${SERIAL_PORT} 115200"
-.PHONY: arch_clean arch_help arch_info monitor program
+attributes: build/system.elf
+ ${QUIET}script/size.py ${SIZE} text,data data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program
diff --git a/src/arch/msp430fr5994lp/Makefile.inc b/src/arch/msp430fr5994lp/Makefile.inc
index 68d3894..1bce0b5 100644
--- a/src/arch/msp430fr5994lp/Makefile.inc
+++ b/src/arch/msp430fr5994lp/Makefile.inc
@@ -179,4 +179,7 @@ arch_info:
@echo "sleep_ms Overflow: 250 500"
@echo "Monitor: /dev/${SERIAL_PORT} 115200"
-.PHONY: arch_clean arch_help arch_info monitor program
+attributes: build/system.elf
+ ${QUIET}script/size.py ${SIZE} text,data data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program
diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc
index adbea7a..158d879 100644
--- a/src/arch/posix/Makefile.inc
+++ b/src/arch/posix/Makefile.inc
@@ -70,4 +70,7 @@ arch_info:
@echo "Counter Overflow: 18446744073709551616/1"
@echo "Monitor: run build/system.elf"
-.PHONY: arch_clean arch_help arch_info monitor program run
+attributes: build/system.elf
+ ${QUIET}script/size.py size text data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program run
diff --git a/src/arch/stm32f446re-nucleo/Makefile.inc b/src/arch/stm32f446re-nucleo/Makefile.inc
index e5f4641..70384b5 100644
--- a/src/arch/stm32f446re-nucleo/Makefile.inc
+++ b/src/arch/stm32f446re-nucleo/Makefile.inc
@@ -14,6 +14,7 @@ CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
OBJCOPY = arm-none-eabi-objcopy
OBJDUMP = arm-none-eabi-objdump
+SIZE = arm-none-eabi-size
CXX_TARGETS += src/arch/stm32f446re-nucleo/arch.cc
@@ -125,4 +126,7 @@ arch_info:
@echo "Counter Overflow: 65536/255"
@echo "Monitor: /dev/${SERIAL_PORT} 115200"
-.PHONY: arch_clean arch_help arch_info monitor program
+attributes: build/system.elf
+ ${QUIET}script/size.py ${SIZE} text,data data,bss
+
+.PHONY: arch_clean arch_help arch_info attributes monitor program